From d682eeec4132b7719c696f5c9987095dfc1ca100 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Czern=C3=BD?= Date: Mon, 28 Feb 2022 17:02:56 +0100 Subject: [PATCH] M #-: Fsck fix `RETIME != 0` for running VMs (#1817) --- src/onedb/fsck/history.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/onedb/fsck/history.rb b/src/onedb/fsck/history.rb index 87dac399a9..7575baeb99 100644 --- a/src/onedb/fsck/history.rb +++ b/src/onedb/fsck/history.rb @@ -111,6 +111,33 @@ module OneDBFsck @showback_delete.add(row[:vid]) end end + + # Query to select history elements that have: + # - etime = 0 + # - is last seq + # - VM is RUNNING + # If RETIME != 0, change it to 0 + @db.fetch('SELECT * ' \ + 'FROM history ' \ + 'WHERE (etime = 0 AND vid IN ' \ + '(SELECT oid FROM vm_pool WHERE state=3) AND ' \ + 'seq = (SELECT MAX(seq) FROM history AS subhistory ' \ + 'WHERE history.vid=subhistory.vid))') do |row| + history_doc = nokogiri_doc(row[:body]) + retime = history_doc.root.at_xpath('RETIME') + + if retime.text.to_i != 0 + log_error("History for VM #{row[:vid]} seq # #{row[:seq]} "\ + "has RETIME = #{retime.text}, but it's still running") + + retime.content = '0' + + row[:body] = history_doc.root.to_s + + history_fix.push(row) + @showback_delete.add(row[:vid]) + end + end end # Fix the broken history records