mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-21 14:50:08 +03:00
M #-: onedb fsck check history seqence id (#3237)
* It looks like `onedb purge-history` sometimes fails to delete some history records. * Delete all history records with SEQ greater then VM/HISTORY_RECORDS/HISTORY/SEQ, which should be the last record (cherry picked from commit a3c47764686404edba7b86b50ad8efdfc8f3edf0)
This commit is contained in:
parent
21dbf2a81f
commit
48506a7e0e
@ -13,6 +13,8 @@ module OneDBFsck
|
||||
|
||||
check_history_retime
|
||||
|
||||
check_history_seq
|
||||
|
||||
log_error('Removing possibly corrupted records from VM showback '\
|
||||
"please run 'oneshowback calculate` to recalculate "\
|
||||
'the showback') unless @showback_delete.empty?
|
||||
@ -144,6 +146,26 @@ module OneDBFsck
|
||||
end
|
||||
end
|
||||
|
||||
def check_history_seq
|
||||
@history_delete = {}
|
||||
|
||||
# Query to select history elements with max seq
|
||||
@db.fetch('SELECT vid, MAX(seq) AS max_seq ' \
|
||||
'FROM history ' \
|
||||
'GROUP BY vid') do |row|
|
||||
# Skip iteration if VM doesn't have last seq, it should never happen
|
||||
last_seq = @vms_last_history[row[:vid]]
|
||||
next if last_seq.nil?
|
||||
|
||||
if row[:max_seq] != last_seq
|
||||
log_error("VM #{row[:vid]} history last seq # #{last_seq} "\
|
||||
"doesn't match last seq in DB # #{row[:max_seq]}")
|
||||
|
||||
@history_delete[row[:vid]] = [last_seq + 1, row[:max_seq]]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Fix the broken history records
|
||||
def fix_history
|
||||
# DATA: FIX: update history records with fixed data
|
||||
@ -155,6 +177,12 @@ module OneDBFsck
|
||||
end
|
||||
end
|
||||
|
||||
@db.transaction do
|
||||
@history_delete.each do |vid, seq|
|
||||
@db[:history].where(:vid => vid, :seq => seq[0]..seq[1]).delete
|
||||
end
|
||||
end
|
||||
|
||||
@db.transaction do
|
||||
@showback_delete.each do |vid|
|
||||
@db[:vm_showback].where(:vmid => vid).delete
|
||||
|
@ -8,6 +8,7 @@ module OneDBFsck
|
||||
cluster_vnc = @data_vm[:vnc] = {}
|
||||
|
||||
@vms_ports = {}
|
||||
@vms_last_history = Hash.new
|
||||
|
||||
# DATA: Aggregate information of the RUNNING vms
|
||||
@db.fetch("SELECT oid,body FROM vm_pool WHERE state<>6") do |row|
|
||||
@ -18,6 +19,10 @@ module OneDBFsck
|
||||
state = vm_doc.root.at_xpath('STATE').text.to_i
|
||||
lcm_state = vm_doc.root.at_xpath('LCM_STATE').text.to_i
|
||||
|
||||
# Get last history record
|
||||
seq = vm_doc.root.at_xpath('HISTORY_RECORDS/HISTORY[last()]/SEQ').text.to_i rescue nil
|
||||
@vms_last_history[row[:oid]] = seq unless seq.nil?
|
||||
|
||||
# DATA: VNC ports per cluster
|
||||
cid = vm_doc.root.at_xpath("HISTORY_RECORDS/HISTORY[last()]/CID").text.to_i rescue nil
|
||||
port = vm_doc.root.at_xpath('TEMPLATE/GRAPHICS[translate(TYPE,"vnc","VNC")="VNC"]/PORT').text.to_i rescue nil
|
||||
|
Loading…
x
Reference in New Issue
Block a user