From 26e644842241c48af69cad5dad28bfc90768bf89 Mon Sep 17 00:00:00 2001 From: Alejandro Huertas Date: Mon, 27 May 2019 14:52:03 +0200 Subject: [PATCH] B #3269: onedb purge-done eat too much RAM * Divide the function between delete VMs and history records * Delete in group of 1000 VMs --- src/onedb/onedb_live.rb | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/onedb/onedb_live.rb b/src/onedb/onedb_live.rb index c04977371cd..3210a1d06de 100644 --- a/src/onedb/onedb_live.rb +++ b/src/onedb/onedb_live.rb @@ -205,6 +205,27 @@ def purge_history(options = {}) end end + def purge_object(object, id, last_id, pool, start_time, end_time) + count = 0 + + pool.each do |obj| + if count % 1000 == 0 && count > 0 + sleep(10) + count = 0 + end + + print percentage_line(obj.id, last_id, true) + + time = obj["ETIME"].to_i + + next unless time >= start_time && time < end_time + + delete(object, "#{id} = #{obj.id}", false) + + count += 1 + end + end + def purge_done_vm(options = {}) vmpool = OpenNebula::VirtualMachinePool.new(client) vmpool.info(OpenNebula::Pool::INFO_ALL, @@ -219,18 +240,15 @@ def purge_done_vm(options = {}) start_time = ops[:start_time].to_i end_time = ops[:end_time].to_i + last_id = vmpool["/VM_POOL/VM[last()]/ID"] - last_id = vmpool["/VM_POOL/VM[last()]/ID"] + puts "Deleting VMs from VM_POOL" - vmpool.each do |vm| - print percentage_line(vm.id, last_id, true) + purge_object('vm_pool', 'oid', last_id, vmpool, start_time, end_time) - time = vm["ETIME"].to_i - next unless time >= start_time && time < end_time + puts "Deleting history records" - delete("vm_pool", "oid = #{vm.id}", false) - delete("history", "vid = #{vm.id}", false) - end + purge_object('history', 'vid', last_id, vmpool, start_time, end_time) end def check_expr(object, expr)