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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
0fd0b64b
Commit
0fd0b64b
authored
May 01, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use stages position column to track stage index
parent
b337a086
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
27 additions
and
27 deletions
+27
-27
app/models/ci/stage.rb
app/models/ci/stage.rb
+3
-3
app/services/ci/ensure_stage_service.rb
app/services/ci/ensure_stage_service.rb
+1
-1
db/migrate/20180417101040_add_tmp_stage_priority_index_to_ci_builds.rb
...180417101040_add_tmp_stage_priority_index_to_ci_builds.rb
+2
-2
db/migrate/20180417101940_add_index_to_ci_stage.rb
db/migrate/20180417101940_add_index_to_ci_stage.rb
+1
-1
db/schema.rb
db/schema.rb
+2
-2
lib/gitlab/background_migration/migrate_stage_index.rb
lib/gitlab/background_migration/migrate_stage_index.rb
+4
-4
lib/gitlab/ci/pipeline/seed/stage.rb
lib/gitlab/ci/pipeline/seed/stage.rb
+1
-1
spec/factories/ci/stages.rb
spec/factories/ci/stages.rb
+1
-1
spec/lib/gitlab/background_migration/migrate_stage_index_spec.rb
...b/gitlab/background_migration/migrate_stage_index_spec.rb
+2
-2
spec/lib/gitlab/ci/pipeline/chain/create_spec.rb
spec/lib/gitlab/ci/pipeline/chain/create_spec.rb
+1
-1
spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb
spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb
+1
-1
spec/lib/gitlab/import_export/safe_model_attributes.yml
spec/lib/gitlab/import_export/safe_model_attributes.yml
+1
-1
spec/migrations/schedule_stages_index_migration_spec.rb
spec/migrations/schedule_stages_index_migration_spec.rb
+1
-1
spec/models/ci/stage_spec.rb
spec/models/ci/stage_spec.rb
+6
-6
No files found.
app/models/ci/stage.rb
View file @
0fd0b64b
...
@@ -17,7 +17,7 @@ module Ci
...
@@ -17,7 +17,7 @@ module Ci
validates
:project
,
presence:
true
validates
:project
,
presence:
true
validates
:pipeline
,
presence:
true
validates
:pipeline
,
presence:
true
validates
:name
,
presence:
true
validates
:name
,
presence:
true
validates
:p
riority
,
presence:
true
validates
:p
osition
,
presence:
true
end
end
after_initialize
do
after_initialize
do
...
@@ -25,9 +25,9 @@ module Ci
...
@@ -25,9 +25,9 @@ module Ci
end
end
before_validation
unless: :importing?
do
before_validation
unless: :importing?
do
next
if
p
riority
.
present?
next
if
p
osition
.
present?
self
.
p
riority
=
statuses
.
select
(
:stage_idx
)
self
.
p
osition
=
statuses
.
select
(
:stage_idx
)
.
where
(
'stage_idx IS NOT NULL'
)
.
where
(
'stage_idx IS NOT NULL'
)
.
group
(
:stage_idx
)
.
group
(
:stage_idx
)
.
order
(
'COUNT(*) DESC'
)
.
order
(
'COUNT(*) DESC'
)
...
...
app/services/ci/ensure_stage_service.rb
View file @
0fd0b64b
...
@@ -42,7 +42,7 @@ module Ci
...
@@ -42,7 +42,7 @@ module Ci
def
create_stage
def
create_stage
Ci
::
Stage
.
create!
(
name:
@build
.
stage
,
Ci
::
Stage
.
create!
(
name:
@build
.
stage
,
p
riority
:
@build
.
stage_idx
,
p
osition
:
@build
.
stage_idx
,
pipeline:
@build
.
pipeline
,
pipeline:
@build
.
pipeline
,
project:
@build
.
project
)
project:
@build
.
project
)
end
end
...
...
db/migrate/20180417101040_add_tmp_stage_priority_index_to_ci_builds.rb
View file @
0fd0b64b
...
@@ -7,10 +7,10 @@ class AddTmpStagePriorityIndexToCiBuilds < ActiveRecord::Migration
...
@@ -7,10 +7,10 @@ class AddTmpStagePriorityIndexToCiBuilds < ActiveRecord::Migration
def
up
def
up
add_concurrent_index
(
:ci_builds
,
[
:stage_id
,
:stage_idx
],
add_concurrent_index
(
:ci_builds
,
[
:stage_id
,
:stage_idx
],
where:
'stage_idx IS NOT NULL'
,
name:
'tmp_build_stage_p
riority
_index'
)
where:
'stage_idx IS NOT NULL'
,
name:
'tmp_build_stage_p
osition
_index'
)
end
end
def
down
def
down
remove_concurrent_index_by_name
(
:ci_builds
,
'tmp_build_stage_p
riority
_index'
)
remove_concurrent_index_by_name
(
:ci_builds
,
'tmp_build_stage_p
osition
_index'
)
end
end
end
end
db/migrate/20180417101940_add_index_to_ci_stage.rb
View file @
0fd0b64b
...
@@ -4,6 +4,6 @@ class AddIndexToCiStage < ActiveRecord::Migration
...
@@ -4,6 +4,6 @@ class AddIndexToCiStage < ActiveRecord::Migration
DOWNTIME
=
false
DOWNTIME
=
false
def
change
def
change
add_column
:ci_stages
,
:p
riority
,
:integer
add_column
:ci_stages
,
:p
osition
,
:integer
end
end
end
end
db/schema.rb
View file @
0fd0b64b
...
@@ -322,7 +322,7 @@ ActiveRecord::Schema.define(version: 20180425131009) do
...
@@ -322,7 +322,7 @@ ActiveRecord::Schema.define(version: 20180425131009) do
add_index
"ci_builds"
,
[
"project_id"
,
"id"
],
name:
"index_ci_builds_on_project_id_and_id"
,
using: :btree
add_index
"ci_builds"
,
[
"project_id"
,
"id"
],
name:
"index_ci_builds_on_project_id_and_id"
,
using: :btree
add_index
"ci_builds"
,
[
"protected"
],
name:
"index_ci_builds_on_protected"
,
using: :btree
add_index
"ci_builds"
,
[
"protected"
],
name:
"index_ci_builds_on_protected"
,
using: :btree
add_index
"ci_builds"
,
[
"runner_id"
],
name:
"index_ci_builds_on_runner_id"
,
using: :btree
add_index
"ci_builds"
,
[
"runner_id"
],
name:
"index_ci_builds_on_runner_id"
,
using: :btree
add_index
"ci_builds"
,
[
"stage_id"
,
"stage_idx"
],
name:
"tmp_build_stage_p
riority
_index"
,
where:
"(stage_idx IS NOT NULL)"
,
using: :btree
add_index
"ci_builds"
,
[
"stage_id"
,
"stage_idx"
],
name:
"tmp_build_stage_p
osition
_index"
,
where:
"(stage_idx IS NOT NULL)"
,
using: :btree
add_index
"ci_builds"
,
[
"stage_id"
],
name:
"index_ci_builds_on_stage_id"
,
using: :btree
add_index
"ci_builds"
,
[
"stage_id"
],
name:
"index_ci_builds_on_stage_id"
,
using: :btree
add_index
"ci_builds"
,
[
"status"
,
"type"
,
"runner_id"
],
name:
"index_ci_builds_on_status_and_type_and_runner_id"
,
using: :btree
add_index
"ci_builds"
,
[
"status"
,
"type"
,
"runner_id"
],
name:
"index_ci_builds_on_status_and_type_and_runner_id"
,
using: :btree
add_index
"ci_builds"
,
[
"status"
],
name:
"index_ci_builds_on_status"
,
using: :btree
add_index
"ci_builds"
,
[
"status"
],
name:
"index_ci_builds_on_status"
,
using: :btree
...
@@ -487,7 +487,7 @@ ActiveRecord::Schema.define(version: 20180425131009) do
...
@@ -487,7 +487,7 @@ ActiveRecord::Schema.define(version: 20180425131009) do
t
.
string
"name"
t
.
string
"name"
t
.
integer
"status"
t
.
integer
"status"
t
.
integer
"lock_version"
t
.
integer
"lock_version"
t
.
integer
"p
riority
"
t
.
integer
"p
osition
"
end
end
add_index
"ci_stages"
,
[
"pipeline_id"
,
"name"
],
name:
"index_ci_stages_on_pipeline_id_and_name"
,
unique:
true
,
using: :btree
add_index
"ci_stages"
,
[
"pipeline_id"
,
"name"
],
name:
"index_ci_stages_on_pipeline_id_and_name"
,
unique:
true
,
using: :btree
...
...
lib/gitlab/background_migration/migrate_stage_index.rb
View file @
0fd0b64b
...
@@ -26,19 +26,19 @@ module Gitlab
...
@@ -26,19 +26,19 @@ module Gitlab
FROM freqs
FROM freqs
)
)
UPDATE ci_stages SET p
riority
= indexes.index
UPDATE ci_stages SET p
osition
= indexes.index
FROM indexes WHERE indexes.stage_id = ci_stages.id
FROM indexes WHERE indexes.stage_id = ci_stages.id
AND ci_stages.p
riority
IS NULL;
AND ci_stages.p
osition
IS NULL;
SQL
SQL
else
else
<<~
SQL
<<~
SQL
UPDATE ci_stages
UPDATE ci_stages
SET p
riority
=
SET p
osition
=
(SELECT stage_idx FROM ci_builds
(SELECT stage_idx FROM ci_builds
WHERE ci_builds.stage_id = ci_stages.id
WHERE ci_builds.stage_id = ci_stages.id
GROUP BY ci_builds.stage_idx ORDER BY COUNT(*) DESC LIMIT 1)
GROUP BY ci_builds.stage_idx ORDER BY COUNT(*) DESC LIMIT 1)
WHERE ci_stages.id BETWEEN
#{
start_id
}
AND
#{
stop_id
}
WHERE ci_stages.id BETWEEN
#{
start_id
}
AND
#{
stop_id
}
AND ci_stages.p
riority
IS NULL
AND ci_stages.p
osition
IS NULL
SQL
SQL
end
end
end
end
...
...
lib/gitlab/ci/pipeline/seed/stage.rb
View file @
0fd0b64b
...
@@ -19,7 +19,7 @@ module Gitlab
...
@@ -19,7 +19,7 @@ module Gitlab
def
attributes
def
attributes
{
name:
@attributes
.
fetch
(
:name
),
{
name:
@attributes
.
fetch
(
:name
),
p
riority
:
@attributes
.
fetch
(
:index
),
p
osition
:
@attributes
.
fetch
(
:index
),
pipeline:
@pipeline
,
pipeline:
@pipeline
,
project:
@pipeline
.
project
}
project:
@pipeline
.
project
}
end
end
...
...
spec/factories/ci/stages.rb
View file @
0fd0b64b
...
@@ -21,7 +21,7 @@ FactoryBot.define do
...
@@ -21,7 +21,7 @@ FactoryBot.define do
pipeline
factory: :ci_empty_pipeline
pipeline
factory: :ci_empty_pipeline
name
'test'
name
'test'
p
riority
1
p
osition
1
status
'pending'
status
'pending'
end
end
end
end
spec/lib/gitlab/background_migration/migrate_stage_index_spec.rb
View file @
0fd0b64b
...
@@ -26,10 +26,10 @@ describe Gitlab::BackgroundMigration::MigrateStageIndex, :migration, schema: 201
...
@@ -26,10 +26,10 @@ describe Gitlab::BackgroundMigration::MigrateStageIndex, :migration, schema: 201
end
end
it
'correctly migrates stages indices'
do
it
'correctly migrates stages indices'
do
expect
(
stages
.
all
.
pluck
(
:p
riority
)).
to
all
(
be_nil
)
expect
(
stages
.
all
.
pluck
(
:p
osition
)).
to
all
(
be_nil
)
described_class
.
new
.
perform
(
100
,
101
)
described_class
.
new
.
perform
(
100
,
101
)
expect
(
stages
.
all
.
pluck
(
:p
riority
)).
to
eq
[
2
,
3
]
expect
(
stages
.
all
.
pluck
(
:p
osition
)).
to
eq
[
2
,
3
]
end
end
end
end
spec/lib/gitlab/ci/pipeline/chain/create_spec.rb
View file @
0fd0b64b
...
@@ -17,7 +17,7 @@ describe Gitlab::Ci::Pipeline::Chain::Create do
...
@@ -17,7 +17,7 @@ describe Gitlab::Ci::Pipeline::Chain::Create do
context
'when pipeline is ready to be saved'
do
context
'when pipeline is ready to be saved'
do
before
do
before
do
pipeline
.
stages
.
build
(
name:
'test'
,
p
riority
:
0
,
project:
project
)
pipeline
.
stages
.
build
(
name:
'test'
,
p
osition
:
0
,
project:
project
)
step
.
perform!
step
.
perform!
end
end
...
...
spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb
View file @
0fd0b64b
...
@@ -25,7 +25,7 @@ describe Gitlab::Ci::Pipeline::Seed::Stage do
...
@@ -25,7 +25,7 @@ describe Gitlab::Ci::Pipeline::Seed::Stage do
it
'returns hash attributes of a stage'
do
it
'returns hash attributes of a stage'
do
expect
(
subject
.
attributes
).
to
be_a
Hash
expect
(
subject
.
attributes
).
to
be_a
Hash
expect
(
subject
.
attributes
)
expect
(
subject
.
attributes
)
.
to
include
(
:name
,
:p
riority
,
:pipeline
,
:project
)
.
to
include
(
:name
,
:p
osition
,
:pipeline
,
:project
)
end
end
end
end
...
...
spec/lib/gitlab/import_export/safe_model_attributes.yml
View file @
0fd0b64b
...
@@ -232,7 +232,7 @@ Ci::Stage:
...
@@ -232,7 +232,7 @@ Ci::Stage:
-
id
-
id
-
name
-
name
-
status
-
status
-
p
riority
-
p
osition
-
lock_version
-
lock_version
-
project_id
-
project_id
-
pipeline_id
-
pipeline_id
...
...
spec/migrations/schedule_stages_index_migration_spec.rb
View file @
0fd0b64b
...
@@ -21,7 +21,7 @@ describe ScheduleStagesIndexMigration, :sidekiq, :migration do
...
@@ -21,7 +21,7 @@ describe ScheduleStagesIndexMigration, :sidekiq, :migration do
it
'schedules delayed background migrations in batches'
do
it
'schedules delayed background migrations in batches'
do
Sidekiq
::
Testing
.
fake!
do
Sidekiq
::
Testing
.
fake!
do
Timecop
.
freeze
do
Timecop
.
freeze
do
expect
(
stages
.
all
).
to
all
(
have_attributes
(
p
riority
:
be_nil
))
expect
(
stages
.
all
).
to
all
(
have_attributes
(
p
osition
:
be_nil
))
migrate!
migrate!
...
...
spec/models/ci/stage_spec.rb
View file @
0fd0b64b
...
@@ -89,9 +89,9 @@ describe Ci::Stage, :models do
...
@@ -89,9 +89,9 @@ describe Ci::Stage, :models do
end
end
describe
'#index'
do
describe
'#index'
do
context
'when stage has been imported and does not have p
riority
index set'
do
context
'when stage has been imported and does not have p
osition
index set'
do
before
do
before
do
stage
.
update_column
(
:p
riority
,
nil
)
stage
.
update_column
(
:p
osition
,
nil
)
end
end
context
'when stage has statuses'
do
context
'when stage has statuses'
do
...
@@ -100,21 +100,21 @@ describe Ci::Stage, :models do
...
@@ -100,21 +100,21 @@ describe Ci::Stage, :models do
end
end
it
'recalculates index before updating status'
do
it
'recalculates index before updating status'
do
expect
(
stage
.
reload
.
p
riority
).
to
be_nil
expect
(
stage
.
reload
.
p
osition
).
to
be_nil
stage
.
update_status
stage
.
update_status
expect
(
stage
.
reload
.
p
riority
).
to
eq
10
expect
(
stage
.
reload
.
p
osition
).
to
eq
10
end
end
end
end
context
'when stage does not have statuses'
do
context
'when stage does not have statuses'
do
it
'fallbacks to zero'
do
it
'fallbacks to zero'
do
expect
(
stage
.
reload
.
p
riority
).
to
be_nil
expect
(
stage
.
reload
.
p
osition
).
to
be_nil
stage
.
update_status
stage
.
update_status
expect
(
stage
.
reload
.
p
riority
).
to
eq
0
expect
(
stage
.
reload
.
p
osition
).
to
eq
0
end
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