Василец Дмитрий
2009-Jan-15 15:15 UTC
[Ovirt-devel] ovirt-server patch for error 'Attempted to update a stale object'
patch for error 'Attempted to update a stale object' diff --git a/src/task-omatic/task_vm.rb b/src/task-omatic/task_vm.rb index c187287..fddc594 100644 --- a/src/task-omatic/task_vm.rb +++ b/src/task-omatic/task_vm.rb @@ -196,8 +196,18 @@ def create_vm_xml(name, uuid, memAllocated, memUsed, vcpus, bootDevice, end def setVmState(vm, state) - vm.state = state - vm.save! + attempts = 0 + begin + vm.state = state + vm.save! + rescue ActiveRecord::StaleObjectError + puts "error with stale object" + if attempts < 3 + attempts += 1 + vm.reload + retry + end + end end def setVmVncPort(vm, domain)
Ian Main
2009-Jan-15 23:09 UTC
[Ovirt-devel] ovirt-server patch for error 'Attempted to update a stale object'
On Thu, 15 Jan 2009 18:15:10 +0300 ??????? ??????? <d.vasilets at peterhost.ru> wrote:> patch for error 'Attempted to update a stale object' > > diff --git a/src/task-omatic/task_vm.rb b/src/task-omatic/task_vm.rb > index c187287..fddc594 100644 > --- a/src/task-omatic/task_vm.rb > +++ b/src/task-omatic/task_vm.rb > @@ -196,8 +196,18 @@ def create_vm_xml(name, uuid, memAllocated, > memUsed, vcpus, bootDevice, > end > > def setVmState(vm, state) > - vm.state = state > - vm.save! > + attempts = 0 > + begin > + vm.state = state > + vm.save! > + rescue ActiveRecord::StaleObjectError > + puts "error with stale object" > + if attempts < 3 > + attempts += 1 > + vm.reload > + retry > + end > + end > endInteresting. I know when doing certain long operations it can fail; never considered catching that and doing a retry. I'll push a similar patch shortly. I may just remove the puts and I'm not sure how many attempts we want to make? Anyway I'll play with it. Thanks! Ian