Skip to content

Commit

Permalink
implement restoreObject to use restricted storage first then public
Browse files Browse the repository at this point in the history
  • Loading branch information
elmiomar committed Jan 4, 2024
1 parent 9208922 commit d64e1d8
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@
*/
public class HybridPDRDatasetRestorer extends PDRDatasetRestorer {
BagStorage restrictedLtstore = null;
HeadBagCacheManager hbcm = null;
long smszlim = 100000000L; // 100 MB
Logger log = null;

/**
* create the restorer
Expand Down Expand Up @@ -152,7 +149,8 @@ public boolean doesNotExist(String id) throws StorageVolumeException, CacheManag
}

/**
* restore the identified object to the CacheVolume associated with the given Reservation
* restore the identified object to the CacheVolume associated with the given Reservation,
* first trying the restricted storage, then the public storage.
* @param id the storage-independent identifier for the data object
* @param resv the reservation for space in a CacheVolume where the object should be restored to.
* @param name the name to assign to the object within the volume.
Expand All @@ -165,13 +163,23 @@ public boolean doesNotExist(String id) throws StorageVolumeException, CacheManag
*/
@Override
public void restoreObject(String id, Reservation resv, String name, JSONObject metadata)
throws RestorationException, StorageVolumeException, JSONException {

try {
restoreObjectFromStore(id, resv, name, metadata, restrictedLtstore);
} catch (ObjectNotFoundException ex) {
super.restoreObject(id, resv, name, metadata);
}
}

private void restoreObjectFromStore(String id, Reservation resv, String name, JSONObject metadata, BagStorage store)
throws RestorationException, StorageVolumeException, JSONException
{
String[] idparts = parseId(id);
String headbag = null;
JSONObject cachemd = null;
try {
headbag = ltstore.findHeadBagFor(idparts[0], idparts[2]);
headbag = store.findHeadBagFor(idparts[0], idparts[2]);
cachemd = getCacheMDFromHeadBag(headbag, idparts[1]);
}
catch (ResourceNotFoundException ex) {
Expand All @@ -198,7 +206,7 @@ public void restoreObject(String id, Reservation resv, String name, JSONObject m

InputStream bstrm = null;
try {
bstrm = ltstore.openFile(srcbag);
bstrm = store.openFile(srcbag);
ZipBagUtils.OpenEntry ntry = ZipBagUtils.openDataFile(bstrm, bagname, idparts[1]);
resv.saveAs(ntry.stream, id, name, cachemd);
log.info("Cached "+id);
Expand Down Expand Up @@ -656,7 +664,7 @@ private JSONObject getCacheMDFromHeadBag(String headbag, String filepath)
String bagname = headbag.substring(0, headbag.length()-4);

try {
CacheObject hbo = hbcm.getObject(headbag);
CacheObject hbo = this.hbcm.getObject(headbag);
InputStream is = hbo.volume.getStream(headbag);
try {
JSONObject cmpmd = ZipBagUtils.getFileMetadata(filepath, is, bagname);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,42 @@ public void testGetChecksum() throws StorageVolumeException, CacheManagementExce
}
catch (ObjectNotFoundException ex) { /* Success! */ }
}

@Test
public void testRestoreObject() throws CacheManagementException, StorageVolumeException, JSONException {
assertTrue(! cache.isCached("mds1491/trial1.json"));
Reservation resv = cache.reserveSpace(70, PDRCacheRoles.ROLE_SMALL_OBJECTS);
rstr.restoreObject("mds1491/trial1.json", resv, "mds1491/trial1.json", null);
assertTrue(cache.isCached("mds1491/trial1.json"));
assertEquals("foobar", resv.getVolumeName());
assertTrue((new File(tempf.getRoot(),
"data/"+resv.getVolumeName()+"/mds1491/trial1.json")).exists());

assertTrue(! cache.isCached("mds1491/trial3/trial3a.json#1"));
resv = cache.reserveSpace(70, PDRCacheRoles.ROLE_OLD_VERSIONS);
rstr.restoreObject("mds1491/trial3/trial3a.json#1", resv, "mds1491/trial3/trial3a-v1.json", null);
assertTrue(cache.isCached("mds1491/trial3/trial3a.json#1"));
assertEquals("old", resv.getVolumeName());
assertTrue((new File(tempf.getRoot(),
"data/"+resv.getVolumeName()+"/mds1491/trial3/trial3a-v1.json")).exists());

assertTrue(! cache.isCached("mds1491/trial3/trial3a.json#1.1.0"));
resv = cache.reserveSpace(553, PDRCacheRoles.ROLE_GENERAL_PURPOSE);
rstr.restoreObject("mds1491/trial3/trial3a.json#1.1.0", resv, "mds1491/trial3/trial3a-X.json", null);
assertTrue(cache.isCached("mds1491/trial3/trial3a.json#1.1.0"));
assertEquals("cranky", resv.getVolumeName());
assertTrue((new File(tempf.getRoot(),
"data/"+resv.getVolumeName()+"/mds1491/trial3/trial3a-X.json")).exists());

assertTrue(! cache.isCached("67C783D4BA814C8EE05324570681708A1899/NMRRVocab20171102.rdf"));
assertTrue(! cache.isCached("67C783D4BA814C8EE05324570681708A1899/NMRRVocab20171102.rdf.sha256"));
resv = cache.reserveSpace(64);
rstr.restoreObject("67C783D4BA814C8EE05324570681708A1899/NMRRVocab20171102.rdf.sha256",
resv, "NMRRVocab20171102.rdf.sha256", null);
assertTrue(cache.isCached("67C783D4BA814C8EE05324570681708A1899/NMRRVocab20171102.rdf.sha256"));
assertTrue(! cache.isCached("67C783D4BA814C8EE05324570681708A1899/NMRRVocab20171102.rdf"));
assertTrue((new File(tempf.getRoot(),
"data/"+resv.getVolumeName()+"/NMRRVocab20171102.rdf.sha256")).exists());
}
}

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
af229ea5e0b42b7cb26dc77a83250d2fd22391685e5c11c53c4bf4971bf6f64b
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
48c574d43d229bd70376cb6f086fbc314cd81be4a4a8ef77861ee80014110681

0 comments on commit d64e1d8

Please sign in to comment.