From d44c862ee70c6bdecfab668a4bdf4fb0854fa6a8 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Tue, 22 Nov 2016 17:09:39 +0000 Subject: [PATCH] ciao-controller: Update internal state after DB state Ensure consistency by only updating the internal state of the datastore after the datebase state has been updated. Signed-off-by: Rob Bradford --- ciao-controller/internal/datastore/datastore.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ciao-controller/internal/datastore/datastore.go b/ciao-controller/internal/datastore/datastore.go index 867515b53..ca3f8409a 100644 --- a/ciao-controller/internal/datastore/datastore.go +++ b/ciao-controller/internal/datastore/datastore.go @@ -1503,12 +1503,6 @@ func (ds *Datastore) CreateStorageAttachment(instanceID string, blockID string, Ephemeral: ephemeral, } - // add it to our links map - ds.attachLock.Lock() - ds.attachments[a.ID] = a - ds.instanceVolumes[link] = a.ID - ds.attachLock.Unlock() - err := ds.db.createStorageAttachment(a) if err != nil { return types.StorageAttachment{}, fmt.Errorf("error creating storage attachment: %v", err) @@ -1528,6 +1522,12 @@ func (ds *Datastore) CreateStorageAttachment(instanceID string, blockID string, return types.StorageAttachment{}, fmt.Errorf("error creating storage attachment: %v", err) } + // add it to our links map + ds.attachLock.Lock() + ds.attachments[a.ID] = a + ds.instanceVolumes[link] = a.ID + ds.attachLock.Unlock() + return a, nil }