Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
Fix #1624, Synchronization issue on mapStorageCapacity (#1625)
Browse files Browse the repository at this point in the history
  • Loading branch information
PHILO-HE committed Mar 13, 2018
1 parent 792734e commit 4cd6921
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -398,23 +398,23 @@ public void insertAccessCountTable(

public void insertUpdateStoragesTable(StorageCapacity[] storages)
throws MetaStoreException {
mapStorageCapacity = null;
try {
storageDao.insertUpdateStoragesTable(storages);
} catch (Exception e) {
throw new MetaStoreException(e);
}
updateCache();
}

public void insertUpdateStoragesTable(List<StorageCapacity> storages)
throws MetaStoreException {
mapStorageCapacity = null;
try {
storageDao.insertUpdateStoragesTable(
storages.toArray(new StorageCapacity[storages.size()]));
} catch (Exception e) {
throw new MetaStoreException(e);
}
updateCache();
}

public void insertUpdateStoragesTable(StorageCapacity storage)
Expand All @@ -429,8 +429,10 @@ public Map<String, StorageCapacity> getStorageCapacity() throws MetaStoreExcepti

Map<String, StorageCapacity> ret = new HashMap<>();
if (mapStorageCapacity != null) {
for (String key : mapStorageCapacity.keySet()) {
ret.put(key, mapStorageCapacity.get(key));
synchronized (storageDao) {
for (String key : mapStorageCapacity.keySet()) {
ret.put(key, mapStorageCapacity.get(key));
}
}
}
return ret;
Expand Down Expand Up @@ -508,12 +510,12 @@ private void updateCache() throws MetaStoreException {
mapStoragePolicyNameId.put(mapStoragePolicyIdName.get(key), key);
}
}
if (mapStorageCapacity == null) {
try {
try {
synchronized (storageDao) {
mapStorageCapacity = storageDao.getStorageTablesItem();
} catch (Exception e) {
throw new MetaStoreException(e);
}
} catch (Exception e) {
throw new MetaStoreException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void testInsertStoragesTable() throws Exception {
Assert.assertTrue(storageCapacity1.equals(storage1));
Assert.assertTrue(storageCapacity2.equals(storage2));
Assert.assertTrue(metaStore.updateStoragesTable("Flash", 123456L, 4562233L));
Assert.assertTrue(metaStore.getStorageCapacity("Flash").getCapacity() == 12343333L);
Assert.assertTrue(metaStore.getStorageCapacity("Flash").getCapacity() == 123456L);
}

@Test
Expand Down

0 comments on commit 4cd6921

Please sign in to comment.