Add Geo::ResetChecksumEvent model

These changes introduce a new Geo event that can be triggered to
reset the repositories checksums for a project on secondary nodes.

This event is necessary when you want to recalculate the checksum
on the primary node and make sure that the secondary node will redo
the calculation to avoid stale checksum in the database.
parent 3c77a0b5
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180907015926) do
ActiveRecord::Schema.define(version: 20180917214204) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -1085,6 +1085,7 @@ ActiveRecord::Schema.define(version: 20180907015926) do
t.integer "hashed_storage_attachments_event_id", limit: 8
t.integer "job_artifact_deleted_event_id", limit: 8
t.integer "upload_deleted_event_id", limit: 8
t.integer "reset_checksum_event_id", limit: 8
end
add_index "geo_event_log", ["repositories_changed_event_id"], name: "index_geo_event_log_on_repositories_changed_event_id", using: :btree
......@@ -1092,6 +1093,7 @@ ActiveRecord::Schema.define(version: 20180907015926) do
add_index "geo_event_log", ["repository_deleted_event_id"], name: "index_geo_event_log_on_repository_deleted_event_id", using: :btree
add_index "geo_event_log", ["repository_renamed_event_id"], name: "index_geo_event_log_on_repository_renamed_event_id", using: :btree
add_index "geo_event_log", ["repository_updated_event_id"], name: "index_geo_event_log_on_repository_updated_event_id", using: :btree
add_index "geo_event_log", ["reset_checksum_event_id"], name: "index_geo_event_log_on_reset_checksum_event_id", using: :btree
create_table "geo_hashed_storage_attachments_events", id: :bigserial, force: :cascade do |t|
t.integer "project_id", null: false
......@@ -1263,6 +1265,12 @@ ActiveRecord::Schema.define(version: 20180907015926) do
add_index "geo_repository_updated_events", ["project_id"], name: "index_geo_repository_updated_events_on_project_id", using: :btree
add_index "geo_repository_updated_events", ["source"], name: "index_geo_repository_updated_events_on_source", using: :btree
create_table "geo_reset_checksum_events", id: :bigserial, force: :cascade do |t|
t.integer "project_id", null: false
end
add_index "geo_reset_checksum_events", ["project_id"], name: "index_geo_reset_checksum_events_on_project_id", using: :btree
create_table "geo_upload_deleted_events", id: :bigserial, force: :cascade do |t|
t.integer "upload_id", null: false
t.string "file_path", null: false
......@@ -3079,6 +3087,7 @@ ActiveRecord::Schema.define(version: 20180907015926) do
add_foreign_key "geo_event_log", "geo_repository_deleted_events", column: "repository_deleted_event_id", name: "fk_c4b1c1f66e", on_delete: :cascade
add_foreign_key "geo_event_log", "geo_repository_renamed_events", column: "repository_renamed_event_id", name: "fk_86c84214ec", on_delete: :cascade
add_foreign_key "geo_event_log", "geo_repository_updated_events", column: "repository_updated_event_id", on_delete: :cascade
add_foreign_key "geo_event_log", "geo_reset_checksum_events", column: "reset_checksum_event_id", name: "fk_cff7185ad2", on_delete: :cascade
add_foreign_key "geo_event_log", "geo_upload_deleted_events", column: "upload_deleted_event_id", name: "fk_c1f241c70d", on_delete: :cascade
add_foreign_key "geo_hashed_storage_attachments_events", "projects", on_delete: :cascade
add_foreign_key "geo_hashed_storage_migrated_events", "projects", on_delete: :cascade
......@@ -3089,6 +3098,7 @@ ActiveRecord::Schema.define(version: 20180907015926) do
add_foreign_key "geo_repository_created_events", "projects", on_delete: :cascade
add_foreign_key "geo_repository_renamed_events", "projects", on_delete: :cascade
add_foreign_key "geo_repository_updated_events", "projects", on_delete: :cascade
add_foreign_key "geo_reset_checksum_events", "projects", on_delete: :cascade
add_foreign_key "gpg_key_subkeys", "gpg_keys", on_delete: :cascade
add_foreign_key "gpg_keys", "users", on_delete: :cascade
add_foreign_key "gpg_signatures", "gpg_key_subkeys", on_delete: :nullify
......
......@@ -8,6 +8,7 @@ module Geo
Geo::RepositoryDeletedEvent
Geo::RepositoryRenamedEvent
Geo::RepositoriesChangedEvent
Geo::ResetChecksumEvent
Geo::HashedStorageMigratedEvent
Geo::HashedStorageAttachmentsEvent
Geo::LfsObjectDeletedEvent
......@@ -54,6 +55,10 @@ module Geo
class_name: 'Geo::UploadDeletedEvent',
foreign_key: :upload_deleted_event_id
belongs_to :reset_checksum_event,
class_name: 'Geo::ResetChecksumEvent',
foreign_key: :reset_checksum_event_id
def self.latest_event
order(id: :desc).first
end
......@@ -76,7 +81,8 @@ module Geo
hashed_storage_attachments_event ||
lfs_object_deleted_event ||
job_artifact_deleted_event ||
upload_deleted_event
upload_deleted_event ||
reset_checksum_event
end
def project_id
......
# frozen_string_literal: true
module Geo
class ResetChecksumEvent < ActiveRecord::Base
include Geo::Model
include Geo::Eventable
belongs_to :project
validates :project, presence: true
end
end
# frozen_string_literal: true
class CreateGeoResetChecksumEvents < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def change
create_table :geo_reset_checksum_events, id: :bigserial do |t|
t.references :project, index: true, foreign_key: { on_delete: :cascade }, null: false
end
add_column :geo_event_log, :reset_checksum_event_id, :integer, limit: 8
end
end
# frozen_string_literal: true
class AddGeoResetChecksumEventsForeignKey < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_concurrent_foreign_key :geo_event_log, :geo_reset_checksum_events,
column: :reset_checksum_event_id, on_delete: :cascade
add_concurrent_index :geo_event_log, :reset_checksum_event_id
end
def down
remove_foreign_key :geo_event_log, column: :reset_checksum_event_id
remove_concurrent_index :geo_event_log, :reset_checksum_event_id
end
end
......@@ -35,6 +35,10 @@ FactoryBot.define do
trait :upload_deleted_event do
upload_deleted_event factory: :geo_upload_deleted_event
end
trait :reset_checksum_event do
reset_checksum_event factory: :geo_reset_checksum_event
end
end
factory :geo_repository_created_event, class: Geo::RepositoryCreatedEvent do
......@@ -138,4 +142,8 @@ FactoryBot.define do
upload { create(:upload, :namespace_upload) }
end
end
factory :geo_reset_checksum_event, class: Geo::ResetChecksumEvent do
project
end
end
......@@ -7,6 +7,7 @@ RSpec.describe Geo::EventLog, type: :model do
it { is_expected.to belong_to(:repository_deleted_event).class_name('Geo::RepositoryDeletedEvent').with_foreign_key('repository_deleted_event_id') }
it { is_expected.to belong_to(:repository_renamed_event).class_name('Geo::RepositoryRenamedEvent').with_foreign_key('repository_renamed_event_id') }
it { is_expected.to belong_to(:repository_updated_event).class_name('Geo::RepositoryUpdatedEvent').with_foreign_key('repository_updated_event_id') }
it { is_expected.to belong_to(:reset_checksum_event).class_name('Geo::ResetChecksumEvent').with_foreign_key('reset_checksum_event_id') }
it { is_expected.to belong_to(:hashed_storage_migrated_event).class_name('Geo::HashedStorageMigratedEvent').with_foreign_key('hashed_storage_migrated_event_id') }
it { is_expected.to belong_to(:hashed_storage_attachments_event).class_name('Geo::HashedStorageAttachmentsEvent').with_foreign_key('hashed_storage_attachments_event_id') }
it { is_expected.to belong_to(:lfs_object_deleted_event).class_name('Geo::LfsObjectDeletedEvent').with_foreign_key('lfs_object_deleted_event_id') }
......@@ -95,6 +96,13 @@ RSpec.describe Geo::EventLog, type: :model do
expect(subject.event).to eq upload_deleted_event
end
it 'returns reset_checksum_event when set' do
reset_checksum_event = build(:geo_reset_checksum_event)
subject.reset_checksum_event = reset_checksum_event
expect(subject.event).to eq reset_checksum_event
end
end
describe '#project_id' do
......
require 'spec_helper'
describe 'Every Geo event' do
subject { events }
it 'includes Geo::Eventable' do
is_expected.to all( satisfy { |klass| klass.ancestors.include?(Geo::Eventable) })
end
it 'has its class in Geo::EventLog::EVENT_CLASSES' do
expect(subject.map(&:name)).to match_array(Geo::EventLog::EVENT_CLASSES)
end
def events
root = Rails.root.join('ee', 'app', 'models')
geo = root.join('geo')
events = Dir[geo.join('**', '*.rb')]
.select { |path| path.end_with?('_event.rb') }
events.map! do |path|
ns = Pathname.new(path).relative_path_from(root).to_s.gsub('.rb', '')
ns.camelize.constantize
end
# Skip things that aren't models
events.select { |event| event < ActiveRecord::Base }
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Geo::ResetChecksumEvent, type: :model do
describe 'relationships' do
it { is_expected.to belong_to(:project) }
end
describe 'validations' do
it { is_expected.to validate_presence_of(:project) }
end
end
......@@ -31,16 +31,9 @@ describe Geo::PruneEventLogService do
end
it 'prunes all event tables' do
expect(service).to receive(:prune!).with(Geo::RepositoryCreatedEvent, anything)
expect(service).to receive(:prune!).with(Geo::RepositoryUpdatedEvent, anything)
expect(service).to receive(:prune!).with(Geo::RepositoryDeletedEvent, anything)
expect(service).to receive(:prune!).with(Geo::RepositoryRenamedEvent, anything)
expect(service).to receive(:prune!).with(Geo::RepositoriesChangedEvent, anything)
expect(service).to receive(:prune!).with(Geo::HashedStorageMigratedEvent, anything)
expect(service).to receive(:prune!).with(Geo::HashedStorageAttachmentsEvent, anything)
expect(service).to receive(:prune!).with(Geo::LfsObjectDeletedEvent, anything)
expect(service).to receive(:prune!).with(Geo::JobArtifactDeletedEvent, anything)
expect(service).to receive(:prune!).with(Geo::UploadDeletedEvent, anything)
Geo::EventLog::EVENT_CLASSES.each do |event_class|
expect(service).to receive(:prune!).with(event_class.constantize, anything)
end
service.execute
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment