Skip to content

Commit

Permalink
F #6029: Extend BACKUP state to include increment_flatten action
Browse files Browse the repository at this point in the history
This prevents a race condition on when flatten and backup actions are triggered
simultaneously.

(cherry picked from commit e6c7c51)
  • Loading branch information
rsmontero committed Feb 14, 2023
1 parent 03c28c1 commit db3b920
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
40 changes: 40 additions & 0 deletions src/image/ImageManagerProtocol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,16 @@ void ImageManager::_increment_flatten(unique_ptr<image_msg_t> msg)
int uid = image->get_uid();
int gid = image->get_gid();

auto ids = image->get_running_ids();
auto first = ids.cbegin();

int vm_id = -1;

if (first != ids.cend())
{
vm_id = *first;
}

if (msg->status() == "SUCCESS")
{
auto& increments = image->increments();
Expand Down Expand Up @@ -945,6 +955,36 @@ void ImageManager::_increment_flatten(unique_ptr<image_msg_t> msg)

Quotas::ds_del(uid, gid, &quotas);
}

/* ---------------------------------------------------------------------- */
/* Update VM state to RUNNING/POWEROFF after increment_flatten */
/* ---------------------------------------------------------------------- */
if ( vm_id == -1 )
{
return;
}

VirtualMachinePool* vmpool = Nebula::instance().get_vmpool();

if (auto vm = vmpool->get(vm_id))
{
switch(vm->get_lcm_state())
{
case VirtualMachine::BACKUP:
vm->set_state(VirtualMachine::RUNNING);
break;

case VirtualMachine::BACKUP_POWEROFF:
vm->set_state(VirtualMachine::POWEROFF);
vm->set_state(VirtualMachine::LCM_INIT);
break;

default:
return;
}

vmpool->update(vm.get());
}
}

/* -------------------------------------------------------------------------- */
Expand Down
21 changes: 17 additions & 4 deletions src/lcm/LifeCycleStates.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2870,10 +2870,9 @@ void LifeCycleManager::trigger_backup_success(int vid)

backups.last_backup_clear();

vmpool->update(vm.get());

if (delete_ids.size() > 0) // FULL & backups > keep_last
if (delete_ids.size() > 0)
{
// FULL & backups > keep_last
ostringstream oss;

oss << "Removing backup snapshots:";
Expand All @@ -2885,15 +2884,29 @@ void LifeCycleManager::trigger_backup_success(int vid)

vm->log("LCM", Log::INFO, oss.str());
}
else if (keep_last > 0 && increments > keep_last) // INCREMENTAL & increments > keep_last
else if (keep_last > 0 && increments > keep_last)
{
// INCREMENTAL & increments > keep_last
ostringstream oss;

oss << "Removing " << increments - keep_last << " backup increments";

vm->log("LCM", Log::INFO, oss.str());

//Rollback state to prevent backup operations while increment_flatten
if ( vm->get_lcm_state() == VirtualMachine::RUNNING)
{
vm->set_state(VirtualMachine::BACKUP);
}
else
{
vm->set_state(VirtualMachine::ACTIVE);
vm->set_state(VirtualMachine::BACKUP_POWEROFF);
}
}

vmpool->update(vm.get());

vm.reset();

/* ------------------------------------------------------------------ */
Expand Down

0 comments on commit db3b920

Please sign in to comment.