Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reindex to job scheduler #16929

Merged
merged 1 commit into from
Feb 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/models/metric.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ class Metric < ApplicationRecord
BASE_COLS = ["id", "timestamp", "capture_interval_name", "resource_type", "resource_id", "resource_name", "tag_names", "parent_host_id", "parent_ems_cluster_id", "parent_ems_id", "parent_storage_id"]

include Metric::Common

def self.reindex_table_name
"metrics_#{Time.now.utc.hour + 1}"
end
end
6 changes: 6 additions & 0 deletions app/models/miq_schedule_worker/jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ def metric_purge_all_timer
end
end

def database_maintenance_reindex_timer
::Settings.database.maintenance.reindex_tables.each do |class_name|
queue_work(:class_name => class_name, :method_name => "reindex", :role => "database_operations", :zone => nil)
end
end

def check_for_stuck_dispatch(threshold_seconds)
class_n = "JobProxyDispatcher"
method_n = "dispatch"
Expand Down
7 changes: 7 additions & 0 deletions app/models/miq_schedule_worker/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,13 @@ def schedules_for_database_operations_role
:tags => [:database_operations, :database_metrics_purge_schedule],
) { enqueue(:metric_purge_all_timer) }

sched = ::Settings.database.maintenance.reindex_schedule
_log.info("database_maintenance_reindex_schedule: #{sched}")
scheduler.schedule_cron(
sched,
:tags => %i(database_operations database_maintenance_reindex_schedule),
) { enqueue(:database_maintenance_reindex_timer) }

@schedules[:database_operations]
end

Expand Down
6 changes: 6 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@
:scanning_job_timeout: 20.minutes
:concurrent_per_ems: 3
:database:
:maintenance:
:reindex_schedule: "1 * * * *"
:reindex_tables:
- Metric
- MiqQueue
- MiqWorker
:metrics_collection:
:collection_schedule: "1 * * * *"
:daily_rollup_schedule: "23 0 * * *"
Expand Down
10 changes: 10 additions & 0 deletions lib/extensions/ar_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,15 @@ class Base
def self.truncate
connection.truncate(table_name, "#{name} Truncate")
end

def self.reindex
_log.info("Reindexing table #{reindex_table_name}")
connection.reindex_table(reindex_table_name)
_log.info("Reindexing table #{reindex_table_name}")
end

def self.reindex_table_name
table_name
end
end
end
19 changes: 17 additions & 2 deletions spec/models/miq_schedule_worker/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@

@metrics_collection = {:collection_schedule => "1 * * * *", :daily_rollup_schedule => "23 0 * * *"}
@metrics_history = {:purge_schedule => "50 * * * *"}
@database_maintenance = {:reindex_schedule => "1 * * * *", :reindex_tables => %w(Metric MiqQueue MiqWorker)}
database_config = {:metrics_collection => @metrics_collection, :metrics_history => @metrics_history}
stub_server_configuration(:database => database_config)
end
Expand All @@ -287,7 +288,7 @@

it "queues the right items" do
scheduled_jobs = @schedule_worker.schedules_for_database_operations_role
expect(scheduled_jobs.size).to be(3)
expect(scheduled_jobs.size).to be(4)

scheduled_jobs.each do |job|
expect(job).to be_a_kind_of(Rufus::Scheduler::CronJob)
Expand All @@ -313,6 +314,13 @@
message = MiqQueue.where(:class_name => class_name, :method_name => "purge_all_timer").first
expect(message).to have_attributes(:role => "database_operations", :zone => nil)
end
when %w(database_operations database_maintenance_reindex_schedule)
expect(job.original).to eq(@database_maintenance[:reindex_schedule])
expect(MiqQueue.count).to eq(3)
@database_maintenance[:reindex_tables].each do |class_name|
message = MiqQueue.where(:class_name => class_name, :method_name => "reindex").first
expect(message).to have_attributes(:role => "database_operations", :zone => nil)
end
else
raise_unexpected_job_error(job)
end
Expand All @@ -328,7 +336,7 @@

it "queues the right items" do
scheduled_jobs = @schedule_worker.schedules_for_database_operations_role
expect(scheduled_jobs.size).to be(3)
expect(scheduled_jobs.size).to be(4)

scheduled_jobs.each do |job|
expect(job).to be_kind_of(Rufus::Scheduler::CronJob)
Expand All @@ -355,6 +363,13 @@
message = MiqQueue.where(:class_name => class_name, :method_name => "purge_all_timer").first
expect(message).to have_attributes(:role => "database_operations", :zone => nil)
end
when %w(database_operations database_maintenance_reindex_schedule)
expect(job.original).to eq(@database_maintenance[:reindex_schedule])
expect(MiqQueue.count).to eq(3)
@database_maintenance[:reindex_tables].each do |class_name|
message = MiqQueue.where(:class_name => class_name, :method_name => "reindex").first
expect(message).to have_attributes(:role => "database_operations", :zone => nil)
end
else
raise_unexpected_job_error(job)
end
Expand Down