Skip to content

Commit

Permalink
B OpenNebula#3269: onedb purge-done eat too much RAM
Browse files Browse the repository at this point in the history
    * Divide the function between delete VMs and history records
    * Delete in group of 1000 VMs
  • Loading branch information
Alejandro Huertas committed May 27, 2019
1 parent d00b00a commit 26e6448
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions src/onedb/onedb_live.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand 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)
Expand Down

0 comments on commit 26e6448

Please sign in to comment.