Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-03-26 21:09:16 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-03-26 21:09:16 +0300
commit006a4f3c1c288c1ea59c3423225527897fa60d6e (patch)
treee4e0d2bb7de0b1ad82bd366088d007b9055d447a /app/models
parent2446c39adaea91d1120c9eb0936e93e9314171c1 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models')
-rw-r--r--app/models/clusters/agent_token.rb2
-rw-r--r--app/models/internal_id.rb35
2 files changed, 28 insertions, 9 deletions
diff --git a/app/models/clusters/agent_token.rb b/app/models/clusters/agent_token.rb
index b53bd30272a..d42279502c5 100644
--- a/app/models/clusters/agent_token.rb
+++ b/app/models/clusters/agent_token.rb
@@ -19,7 +19,7 @@ module Clusters
before_save :ensure_token
validates :description, length: { maximum: 1024 }
- validates :name, presence: true, length: { maximum: 255 }, on: :create
+ validates :name, presence: true, length: { maximum: 255 }
def track_usage
track_values = { last_used_at: Time.current.utc }
diff --git a/app/models/internal_id.rb b/app/models/internal_id.rb
index c735e593da7..b56bac58705 100644
--- a/app/models/internal_id.rb
+++ b/app/models/internal_id.rb
@@ -47,18 +47,10 @@ class InternalId < ApplicationRecord
def update_and_save(&block)
lock!
yield
- update_and_save_counter.increment(usage: usage, changed: last_value_changed?)
save!
last_value
end
- # Instrumentation to track for-update locks
- def update_and_save_counter
- strong_memoize(:update_and_save_counter) do
- Gitlab::Metrics.counter(:gitlab_internal_id_for_update_lock, 'Number of ROW SHARE (FOR UPDATE) locks on individual records from internal_ids')
- end
- end
-
class << self
def track_greatest(subject, scope, usage, new_value, init)
InternalIdGenerator.new(subject, scope, usage, init)
@@ -88,6 +80,8 @@ class InternalId < ApplicationRecord
end
class InternalIdGenerator
+ extend Gitlab::Utils::StrongMemoize
+
# Generate next internal id for a given scope and usage.
#
# For currently supported usages, see #usage enum.
@@ -123,6 +117,8 @@ class InternalId < ApplicationRecord
# init: Block that gets called to initialize InternalId record if not present
# Make sure to not throw exceptions in the absence of records (if this is expected).
def generate
+ self.class.internal_id_transactions_increment(operation: :generate, usage: usage)
+
subject.transaction do
# Create a record in internal_ids if one does not yet exist
# and increment its last value
@@ -138,6 +134,8 @@ class InternalId < ApplicationRecord
def reset(value)
return false unless value
+ self.class.internal_id_transactions_increment(operation: :reset, usage: usage)
+
updated =
InternalId
.where(**scope, usage: usage_value)
@@ -152,6 +150,8 @@ class InternalId < ApplicationRecord
#
# Note this will acquire a ROW SHARE lock on the InternalId record
def track_greatest(new_value)
+ self.class.internal_id_transactions_increment(operation: :track_greatest, usage: usage)
+
subject.transaction do
record.track_greatest_and_save!(new_value)
end
@@ -162,6 +162,8 @@ class InternalId < ApplicationRecord
end
def with_lock(&block)
+ self.class.internal_id_transactions_increment(operation: :with_lock, usage: usage)
+
record.with_lock(&block)
end
@@ -197,5 +199,22 @@ class InternalId < ApplicationRecord
rescue ActiveRecord::RecordNotUnique
lookup
end
+
+ def self.internal_id_transactions_increment(operation:, usage:)
+ self.internal_id_transactions_total.increment(
+ operation: operation,
+ usage: usage.to_s,
+ in_transaction: ActiveRecord::Base.connection.transaction_open?.to_s
+ )
+ end
+
+ def self.internal_id_transactions_total
+ strong_memoize(:internal_id_transactions_total) do
+ name = :gitlab_internal_id_transactions_total
+ comment = 'Counts all the internal ids happening within transaction'
+
+ Gitlab::Metrics.counter(name, comment)
+ end
+ end
end
end