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
030d0b8e
Commit
030d0b8e
authored
Nov 05, 2019
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix: not found PruneOrphanedGeoEvents
parent
a654e92b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
0 deletions
+98
-0
changelogs/unreleased/30229-gitlab-backgroundmigration-pruneorphanedgeoevents-did-you-mean-prun.yml
...undmigration-pruneorphanedgeoevents-did-you-mean-prun.yml
+5
-0
ee/lib/gitlab/background_migration/prune_orphaned_geo_events.rb
.../gitlab/background_migration/prune_orphaned_geo_events.rb
+93
-0
No files found.
changelogs/unreleased/30229-gitlab-backgroundmigration-pruneorphanedgeoevents-did-you-mean-prun.yml
0 → 100644
View file @
030d0b8e
---
title
:
"
[Geo]
Fix:
undefined
Gitlab::BackgroundMigration::PruneOrphanedGeoEvents"
merge_request
:
19638
author
:
type
:
fixed
ee/lib/gitlab/background_migration/prune_orphaned_geo_events.rb
0 → 100644
View file @
030d0b8e
# frozen_string_literal: true
# This job is added to fix https://gitlab.com/gitlab-org/gitlab/issues/30229
# It's not used anywhere else.
# Can be removed in GitLab 13.*
module
Gitlab
module
BackgroundMigration
class
PruneOrphanedGeoEvents
BATCH_SIZE
=
50_000
RESCHEDULE_DELAY
=
5
.
minutes
EVENT_TABLES
=
%w[geo_repository_created_events
geo_repository_updated_events
geo_repository_deleted_events
geo_repository_renamed_events
geo_repositories_changed_events
geo_hashed_storage_migrated_events
geo_hashed_storage_attachments_events
geo_lfs_object_deleted_events
geo_job_artifact_deleted_events
geo_upload_deleted_events]
.
freeze
module
PrunableEvent
extend
ActiveSupport
::
Concern
include
EachBatch
included
do
scope
:orphans
,
->
do
where
(
<<-
SQL
.
squish
)
NOT EXISTS (
SELECT 1
FROM geo_event_log
WHERE geo_event_log.
#{
geo_event_foreign_key
}
=
#{
table_name
}
.id
)
SQL
end
end
class_methods
do
def
geo_event_foreign_key
table_name
.
singularize
.
sub
(
/^geo_/
,
''
)
+
'_id'
end
def
delete_batch_of_orphans!
deleted
=
where
(
id:
orphans
.
limit
(
BATCH_SIZE
)).
delete_all
vacuum!
if
deleted
.
positive?
deleted
end
def
vacuum!
connection
.
execute
(
"VACUUM
#{
table_name
}
"
)
rescue
ActiveRecord
::
StatementInvalid
=>
e
# ignore timeout, auto-vacuum will take care of it
raise
unless
e
.
message
=~
/statement timeout/i
end
end
end
def
perform
(
table_name
=
EVENT_TABLES
.
first
)
return
if
Gitlab
::
Database
.
read_only?
deleted_rows
=
prune_orphaned_rows
(
table_name
)
table_name
=
next_table
(
table_name
)
if
deleted_rows
.
zero?
BackgroundMigrationWorker
.
perform_in
(
RESCHEDULE_DELAY
,
self
.
class
.
name
,
table_name
)
if
table_name
end
def
prune_orphaned_rows
(
table
)
event_model
(
table
).
delete_batch_of_orphans!
end
def
event_model
(
table
)
Class
.
new
(
ActiveRecord
::
Base
)
do
include
PrunableEvent
self
.
table_name
=
table
end
end
def
next_table
(
table_name
)
return
if
EVENT_TABLES
.
last
==
table_name
index
=
EVENT_TABLES
.
index
(
table_name
)
return
unless
index
EVENT_TABLES
[
index
+
1
]
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