seyed8453 / cloudsim

Automatically exported from code.google.com/p/cloudsim
0 stars 0 forks source link

Abrupt termination of the simulation caused by VmAllocationPolicySimple #5

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Playing with migrations, I've found a bug in the code of the class
VmAllocationPolicySimple. The method in question is
allocateHostForVm(Vm vm, Host host) -- lines 232 to 248 in the
attached version of the file.

The new code follows. As you can see, there's a comment explaining why
I added four lines of code between the invocation to getVmTable() and
the call to Log.formatLine().

The bug would cause an abrupt termination of the simulation when a VM
created with this method would try to be destroyed. The execution
would fail in the method deallocateHostForVm(Vm vm) -- line 125 in the
attached version of the file.

********************************************************************************
public boolean allocateHostForVm(Vm vm, Host host) {
   if (host.vmCreate(vm)) { //if vm has been succesfully created in the host
      getVmTable().put(vm.getUid(), host);
      // I believe the following four lines were missing in the original
      // coding of this method. Notice that when a VM is allocated in
      // the method allocateHostForVm(vm), the two lines that modify the
      // number of used and free PEs are indeed present.
      int requiredPes = vm.getPesNumber();
      int idx = getHostList().indexOf(host);
      getUsedPes().put(vm.getUid(), requiredPes);
      getFreePes().set(idx, getFreePes().get(idx) - requiredPes);
      Log.formatLine("%.2f: VM #" + vm.getId() + " has been allocated to
the host #" + host.getId(), CloudSim.clock());
      return true;
   }

   return false;
}
********************************************************************************

Original issue reported on code.google.com by rodrigo.calheiros on 18 Jul 2011 at 12:36

GoogleCodeExporter commented 8 years ago
The four lines were added to the method allocateHostForVm(Vm,Host).

Original comment by rodrigo.calheiros on 15 Dec 2011 at 4:11