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

Fix #1624, Synchronization issue on mapStorageCapacity #1625

Merged
merged 4 commits into from
Mar 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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