Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
b010130b
Commit
b010130b
authored
Dec 17, 2020
by
Adrien Kohlbecker
Committed by
Shinya Maeda
Dec 17, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix project transfer corrupting shared runners state
Fix project transfer corrupting shared runners state
parent
d7ed14ee
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
133 additions
and
0 deletions
+133
-0
changelogs/unreleased/ak-fix-project-transfer-2.yml
changelogs/unreleased/ak-fix-project-transfer-2.yml
+5
-0
db/post_migrate/20201110161542_cleanup_transfered_projects_shared_runners.rb
...01110161542_cleanup_transfered_projects_shared_runners.rb
+30
-0
db/schema_migrations/20201110161542
db/schema_migrations/20201110161542
+1
-0
lib/gitlab/background_migration/reset_shared_runners_for_transferred_projects.rb
...igration/reset_shared_runners_for_transferred_projects.rb
+30
-0
spec/lib/gitlab/background_migration/reset_shared_runners_for_transferred_projects_spec.rb
...ion/reset_shared_runners_for_transferred_projects_spec.rb
+35
-0
spec/migrations/20201110161542_cleanup_transfered_projects_shared_runners_spec.rb
...161542_cleanup_transfered_projects_shared_runners_spec.rb
+32
-0
No files found.
changelogs/unreleased/ak-fix-project-transfer-2.yml
0 → 100644
View file @
b010130b
---
title
:
Fix project transfer corrupting shared runners state
merge_request
:
47316
author
:
type
:
fixed
db/post_migrate/20201110161542_cleanup_transfered_projects_shared_runners.rb
0 → 100644
View file @
b010130b
# frozen_string_literal: true
class
CleanupTransferedProjectsSharedRunners
<
ActiveRecord
::
Migration
[
6.0
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
BATCH_SIZE
=
25_000
INTERVAL
=
3
.
minutes
MIGRATION
=
'ResetSharedRunnersForTransferredProjects'
disable_ddl_transaction!
class
Namespace
<
ActiveRecord
::
Base
include
EachBatch
self
.
table_name
=
'namespaces'
end
def
up
queue_background_migration_jobs_by_range_at_intervals
(
Namespace
,
MIGRATION
,
INTERVAL
,
batch_size:
BATCH_SIZE
)
end
def
down
# This migration fixes an inconsistent database state resulting from https://gitlab.com/gitlab-org/gitlab/-/issues/271728
# and as such does not require a down migration
end
end
db/schema_migrations/20201110161542
0 → 100644
View file @
b010130b
ebc304867bab499da3f9fa69b32373a328948b5068b226df5166042d1c1c7604
\ No newline at end of file
lib/gitlab/background_migration/reset_shared_runners_for_transferred_projects.rb
0 → 100644
View file @
b010130b
# frozen_string_literal: true
module
Gitlab
module
BackgroundMigration
# Resets inconsistent state of shared_runners_enabled for projects that have been transferred
class
ResetSharedRunnersForTransferredProjects
# Model specifically used for migration.
class
Namespace
<
ActiveRecord
::
Base
include
EachBatch
self
.
table_name
=
'namespaces'
end
# Model specifically used for migration.
class
Project
<
ActiveRecord
::
Base
self
.
table_name
=
'projects'
end
def
perform
(
start_id
,
stop_id
)
Project
.
reset_column_information
Namespace
.
where
(
id:
start_id
..
stop_id
).
each_batch
(
of:
1_000
)
do
|
relation
|
ids
=
relation
.
where
(
shared_runners_enabled:
false
,
allow_descendants_override_disabled_shared_runners:
false
).
select
(
:id
)
Project
.
where
(
namespace_id:
ids
).
update_all
(
shared_runners_enabled:
false
)
end
end
end
end
end
spec/lib/gitlab/background_migration/reset_shared_runners_for_transferred_projects_spec.rb
0 → 100644
View file @
b010130b
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Gitlab
::
BackgroundMigration
::
ResetSharedRunnersForTransferredProjects
,
schema:
20201110161542
do
let
(
:namespaces
)
{
table
(
:namespaces
)
}
let
(
:projects
)
{
table
(
:projects
)
}
let
(
:namespace_1
)
{
namespaces
.
create!
(
name:
'foo'
,
path:
'foo'
,
shared_runners_enabled:
true
,
allow_descendants_override_disabled_shared_runners:
false
)
}
let
(
:namespace_2
)
{
namespaces
.
create!
(
name:
'foo'
,
path:
'foo'
,
shared_runners_enabled:
false
,
allow_descendants_override_disabled_shared_runners:
false
)
}
let
(
:namespace_3
)
{
namespaces
.
create!
(
name:
'bar'
,
path:
'bar'
,
shared_runners_enabled:
false
,
allow_descendants_override_disabled_shared_runners:
true
)
}
let
(
:project_1_1
)
{
projects
.
create!
(
namespace_id:
namespace_1
.
id
,
shared_runners_enabled:
true
)
}
let
(
:project_1_2
)
{
projects
.
create!
(
namespace_id:
namespace_1
.
id
,
shared_runners_enabled:
false
)
}
let
(
:project_2_1
)
{
projects
.
create!
(
namespace_id:
namespace_2
.
id
,
shared_runners_enabled:
true
)
}
let
(
:project_2_2
)
{
projects
.
create!
(
namespace_id:
namespace_2
.
id
,
shared_runners_enabled:
false
)
}
let
(
:project_3_1
)
{
projects
.
create!
(
namespace_id:
namespace_3
.
id
,
shared_runners_enabled:
true
)
}
let
(
:project_3_2
)
{
projects
.
create!
(
namespace_id:
namespace_3
.
id
,
shared_runners_enabled:
false
)
}
it
'corrects each project shared_runners_enabled column'
do
expect
do
described_class
.
new
.
perform
(
namespace_1
.
id
,
namespace_3
.
id
)
project_1_1
.
reload
project_1_2
.
reload
project_2_1
.
reload
project_2_2
.
reload
project_3_1
.
reload
project_3_2
.
reload
end
.
to
not_change
(
project_1_1
,
:shared_runners_enabled
).
from
(
true
)
.
and
not_change
(
project_1_2
,
:shared_runners_enabled
).
from
(
false
)
.
and
change
(
project_2_1
,
:shared_runners_enabled
).
from
(
true
).
to
(
false
)
.
and
not_change
(
project_2_2
,
:shared_runners_enabled
).
from
(
false
)
.
and
not_change
(
project_3_1
,
:shared_runners_enabled
).
from
(
true
)
.
and
not_change
(
project_3_2
,
:shared_runners_enabled
).
from
(
false
)
end
end
spec/migrations/20201110161542_cleanup_transfered_projects_shared_runners_spec.rb
0 → 100644
View file @
b010130b
# frozen_string_literal: true
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20201110161542_cleanup_transfered_projects_shared_runners.rb'
)
RSpec
.
describe
CleanupTransferedProjectsSharedRunners
,
:sidekiq
,
schema:
20201110161542
do
let
(
:namespaces
)
{
table
(
:namespaces
)
}
let
(
:migration
)
{
described_class
.
new
}
let
(
:batch_interval
)
{
described_class
::
INTERVAL
}
let!
(
:namespace_1
)
{
namespaces
.
create!
(
name:
'foo'
,
path:
'foo'
)
}
let!
(
:namespace_2
)
{
namespaces
.
create!
(
name:
'bar'
,
path:
'bar'
)
}
let!
(
:namespace_3
)
{
namespaces
.
create!
(
name:
'baz'
,
path:
'baz'
)
}
describe
'#up'
do
before
do
stub_const
(
"
#{
described_class
}
::BATCH_SIZE"
,
2
)
end
it
'schedules ResetSharedRunnersForTransferredProjects background jobs'
do
Sidekiq
::
Testing
.
fake!
do
freeze_time
do
migration
.
up
expect
(
BackgroundMigrationWorker
.
jobs
.
size
).
to
eq
(
2
)
expect
(
described_class
::
MIGRATION
).
to
be_scheduled_delayed_migration
(
batch_interval
,
namespace_1
.
id
,
namespace_2
.
id
)
expect
(
described_class
::
MIGRATION
).
to
be_scheduled_delayed_migration
(
batch_interval
*
2
,
namespace_3
.
id
,
namespace_3
.
id
)
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment