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
44915d43
Commit
44915d43
authored
Aug 23, 2021
by
Heinrich Lee Yu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move code behind feature flag
Puts the changes under the use_insert_all_in_internal_id feature flag
parent
564b5ea7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
25 deletions
+86
-25
app/models/internal_id.rb
app/models/internal_id.rb
+46
-21
config/feature_flags/development/use_insert_all_in_internal_id.yml
...ature_flags/development/use_insert_all_in_internal_id.yml
+8
-0
spec/models/internal_id_spec.rb
spec/models/internal_id_spec.rb
+32
-4
No files found.
app/models/internal_id.rb
View file @
44915d43
...
@@ -223,19 +223,33 @@ class InternalId < ApplicationRecord
...
@@ -223,19 +223,33 @@ class InternalId < ApplicationRecord
# If another process was faster in doing this, we'll end up with that record
# If another process was faster in doing this, we'll end up with that record
# when we do the lookup after the insert.
# when we do the lookup after the insert.
def
create_record
def
create_record
scope
[
:project
].
save!
if
scope
[
:project
]
&&
!
scope
[
:project
].
persisted?
if
Feature
.
enabled?
(
:use_insert_all_in_internal_id
,
default_enabled: :yaml
)
scope
[
:namespace
].
save!
if
scope
[
:namespace
]
&&
!
scope
[
:namespace
].
persisted?
scope
[
:project
].
save!
if
scope
[
:project
]
&&
!
scope
[
:project
].
persisted?
scope
[
:namespace
].
save!
if
scope
[
:namespace
]
&&
!
scope
[
:namespace
].
persisted?
attributes
=
{
attributes
=
{
project_id:
scope
[
:project
]
&
.
id
||
scope
[
:project_id
],
project_id:
scope
[
:project
]
&
.
id
||
scope
[
:project_id
],
namespace_id:
scope
[
:namespace
]
&
.
id
||
scope
[
:namespace_id
],
namespace_id:
scope
[
:namespace
]
&
.
id
||
scope
[
:namespace_id
],
usage:
usage_value
,
usage:
usage_value
,
last_value:
initial_value
(
subject
,
scope
)
last_value:
initial_value
(
subject
,
scope
)
}
}
InternalId
.
insert_all
([
attributes
])
InternalId
.
insert_all
([
attributes
])
lookup
lookup
else
begin
subject
.
transaction
(
requires_new:
true
)
do
InternalId
.
create!
(
**
scope
,
usage:
usage_value
,
last_value:
initial_value
(
subject
,
scope
)
)
end
rescue
ActiveRecord
::
RecordNotUnique
lookup
end
end
end
end
end
end
...
@@ -330,21 +344,32 @@ class InternalId < ApplicationRecord
...
@@ -330,21 +344,32 @@ class InternalId < ApplicationRecord
end
end
def
create_record!
(
subject
,
scope
,
usage
,
value
)
def
create_record!
(
subject
,
scope
,
usage
,
value
)
scope
[
:project
].
save!
if
scope
[
:project
]
&&
!
scope
[
:project
].
persisted?
if
Feature
.
enabled?
(
:use_insert_all_in_internal_id
,
default_enabled: :yaml
)
scope
[
:namespace
].
save!
if
scope
[
:namespace
]
&&
!
scope
[
:namespace
].
persisted?
scope
[
:project
].
save!
if
scope
[
:project
]
&&
!
scope
[
:project
].
persisted?
scope
[
:namespace
].
save!
if
scope
[
:namespace
]
&&
!
scope
[
:namespace
].
persisted?
attributes
=
{
attributes
=
{
project_id:
scope
[
:project
]
&
.
id
||
scope
[
:project_id
],
project_id:
scope
[
:project
]
&
.
id
||
scope
[
:project_id
],
namespace_id:
scope
[
:namespace
]
&
.
id
||
scope
[
:namespace_id
],
namespace_id:
scope
[
:namespace
]
&
.
id
||
scope
[
:namespace_id
],
usage:
usage_value
,
usage:
usage_value
,
last_value:
value
last_value:
value
}
}
result
=
InternalId
.
insert_all
([
attributes
])
result
=
InternalId
.
insert_all
([
attributes
])
raise
RecordAlreadyExists
if
result
.
empty?
raise
RecordAlreadyExists
if
result
.
empty?
value
value
else
begin
subject
.
transaction
(
requires_new:
true
)
do
internal_id
=
InternalId
.
create!
(
**
scope
,
usage:
usage
,
last_value:
value
)
internal_id
.
last_value
end
rescue
ActiveRecord
::
RecordNotUnique
raise
RecordAlreadyExists
end
end
end
end
def
arel_table
def
arel_table
...
...
config/feature_flags/development/use_insert_all_in_internal_id.yml
0 → 100644
View file @
44915d43
---
name
:
use_insert_all_in_internal_id
introduced_by_url
:
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/68617
rollout_issue_url
:
milestone
:
'
14.3'
type
:
development
group
:
group::project management
default_enabled
:
false
spec/models/internal_id_spec.rb
View file @
44915d43
...
@@ -238,20 +238,48 @@ RSpec.describe InternalId do
...
@@ -238,20 +238,48 @@ RSpec.describe InternalId do
end
end
end
end
context
'when the feature flag is disabled'
do
context
'when the
explicit locking
feature flag is disabled'
do
before
do
before
do
stub_feature_flags
(
generate_iids_without_explicit_locking:
false
)
stub_feature_flags
(
generate_iids_without_explicit_locking:
false
)
end
end
it_behaves_like
'a monotonically increasing id generator'
context
'when the insert all feature flag is enabled'
do
before
do
stub_feature_flags
(
use_insert_all_in_internal_id:
true
)
end
it_behaves_like
'a monotonically increasing id generator'
end
context
'when the insert all feature flag is disabled'
do
before
do
stub_feature_flags
(
use_insert_all_in_internal_id:
false
)
end
it_behaves_like
'a monotonically increasing id generator'
end
end
end
context
'when the feature flag is enabled'
do
context
'when the
explicit locking
feature flag is enabled'
do
before
do
before
do
stub_feature_flags
(
generate_iids_without_explicit_locking:
true
)
stub_feature_flags
(
generate_iids_without_explicit_locking:
true
)
end
end
it_behaves_like
'a monotonically increasing id generator'
context
'when the insert all feature flag is enabled'
do
before
do
stub_feature_flags
(
use_insert_all_in_internal_id:
true
)
end
it_behaves_like
'a monotonically increasing id generator'
end
context
'when the insert all feature flag is disabled'
do
before
do
stub_feature_flags
(
use_insert_all_in_internal_id:
false
)
end
it_behaves_like
'a monotonically increasing id generator'
end
end
end
describe
'#increment_and_save!'
do
describe
'#increment_and_save!'
do
...
...
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