Skip to content

CLOUDSTACK-8698: Retrieve a new device ID, if needed - #660

Merged
asfgit merged 1 commit into
apache:masterfrom
mike-tutkowski:CLOUDSTACK-8698
Aug 6, 2015
Merged

asfgit merged 1 commit into
apache:masterfrom
mike-tutkowski:CLOUDSTACK-8698

Conversation

@mike-tutkowski

Copy link
Copy Markdown
Member

@asfbot

asfbot commented Aug 5, 2015

Copy link
Copy Markdown

cloudstack-pull-rats #216 SUCCESS
This pull request looks good

@asfbot

asfbot commented Aug 5, 2015

Copy link
Copy Markdown

cloudstack-pull-requests #913 SUCCESS
This pull request looks good

@asfbot

asfbot commented Aug 5, 2015

Copy link
Copy Markdown

cloudstack-pull-analysis #149 ABORTED

@yadvr

yadvr commented Aug 6, 2015

Copy link
Copy Markdown
Member

LGTM @mike-tutkowski can this cause any side effect on any hypervisor/storage permutation?

@anshul1886

Copy link
Copy Markdown

LGTM

@mike-tutkowski

Copy link
Copy Markdown
Member Author

@bhaisaab I don't think there's any issue with the hypervisor matrix. What was happening was a NPE was being thrown in one scenario when trying to attach a volume to a stopped VM (regardless of hypervisor type, but in the case when the storage was not zone wide).

Thanks!

@karuturi

karuturi commented Aug 6, 2015

Copy link
Copy Markdown
Member

Even after e5ffcab and this change, race condition is possible right? Let us say the hypervisor takes time to attach and another attach command came in before this is completed.

I think its better to persist the devidceId in the table(will set it back to null if something fails) as soon as we generate it and also synchronising the code in getDeviceId() function using GlobalLock

@mike-tutkowski

Copy link
Copy Markdown
Member Author

I don't think there's a race condition anymore (it was fixed by my initial commit (not this code)).

The attach code is run in serial for the VM in question. For example, if multiple attaches come in for the VM, they are serialized and so any race condition is avoided.

The original problem was that the device ID was selected before passing the work to the job queue. If multiple attach commands came in simultaneously, we could pick the same device ID multiple times (so the second attach would fail).

@mike-tutkowski

Copy link
Copy Markdown
Member Author

The reason we could pick multiple same device IDs is because the ID is not written to the DB until late in the attach process (after a successful attach on the hypervisor side).

That being the case, if you started multiple attaches around the same time, they would pick up the same device ID and the second attach would fail.

@karuturi

karuturi commented Aug 6, 2015

Copy link
Copy Markdown
Member

if we dont persist the deviceId at the time of generation, as you said multiple calls around the same time will still get the same id and the attach would fail (which would bring back the original problem).

which is why I think, its better to persist the deviceId as soon as we generate and move the generation of deviceID logic to GlobalLlock.

something like:

-        deviceId = getDeviceId(vmId, deviceId);
+        GlobalLock lock =GlobalLock.getInternLock("Get-DeviceId-VM-" + vmId);
+        try {
+            if (lock.lock(120)) {
+                try {
+                    deviceId = getDeviceId(vmId, deviceId);
+                    _volsDao.updateDeviceId(volumeId, vmId, deviceId);
+                } finally {
+                    lock.unlock();
+                }
+            }
+        } finally {
+            lock.releaseRef();
+        }
-        return attachVolumeToVM(command.getVirtualMachineId(), command.getId(), command.getDeviceId());
+        try {
+            return attachVolumeToVM(command.getVirtualMachineId(), command.getId(), command.getDeviceId());
+        } catch(Exception e) {
+            _volsDao.updateDeviceId(command.getId(), null, null);
+            throw e;
+        }

@mike-tutkowski

Copy link
Copy Markdown
Member Author

So, the way we got around the issue of occasionally acquiring the same device ID was to move the retrieve-device-ID logic from the API layer (which can be called in parallel) to the attach logic in the job queue (which will serialize these kinds of calls to the same VM).

In other words, we no longer have an issue of acquiring the same device ID.

This particular bug is around us forgetting to call "acquire device ID" in the attach logic for one use case.

@karuturi

karuturi commented Aug 6, 2015

Copy link
Copy Markdown
Member

ok. There are lot of ifs in that part of the code which makes it difficult to read. I will have to try it to understand fully for which I dont have time now. So, I would 👍 I will get back if I have any questions.

@mike-tutkowski

Copy link
Copy Markdown
Member Author

Sounds good, @karuturi I'll go ahead and check the code in. Thanks for the comments.

@asfgit
asfgit merged commit b1905c2 into apache:master Aug 6, 2015
asfgit pushed a commit that referenced this pull request Aug 6, 2015
* pr/#660:
  CLOUDSTACK-8698: Retrieve a new device ID, if needed

Signed-off-by: Mike Tutkowski (mike.tutkowski@solidfire.com)
Signed-off-by: Mike Tutkowski <mike.tutkowski@solidfire.com>
@mike-tutkowski
mike-tutkowski deleted the CLOUDSTACK-8698 branch August 6, 2015 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants