ODatabaseDocumentTx test_db = new ODatabaseDocumentTx("plocal:" + buildDir + "/testLocalPaginatedStorageLinkBagCrashRestore");
test_db.open("admin", "admin");
long minTs = Long.MAX_VALUE;
OStorage baseStorage = base_db.getStorage();
OPhysicalPosition[] physicalPositions = baseStorage.ceilingPhysicalPositions(defaultClusterId, new OPhysicalPosition(
OClusterPositionFactory.INSTANCE.valueOf(0)));
int recordsRestored = 0;
int recordsTested = 0;
while (physicalPositions.length > 0) {
final ORecordId rid = new ORecordId(defaultClusterId);
for (OPhysicalPosition physicalPosition : physicalPositions) {
rid.clusterPosition = physicalPosition.clusterPosition;
ODatabaseRecordThreadLocal.INSTANCE.set(base_db);
ODocument baseDocument = base_db.load(rid);
baseDocument.setLazyLoad(false);
ODatabaseRecordThreadLocal.INSTANCE.set(test_db);
ODocument testDocument = test_db.load(rid);
testDocument.setLazyLoad(false);
if (testDocument == null) {
ODatabaseRecordThreadLocal.INSTANCE.set(base_db);
if (((Long) baseDocument.field("ts")) < minTs)
minTs = baseDocument.field("ts");
} else {
long baseTs;
long testTs;
ODatabaseRecordThreadLocal.INSTANCE.set(base_db);
baseTs = baseDocument.field("ts");
ODatabaseRecordThreadLocal.INSTANCE.set(test_db);
testTs = testDocument.field("ts");
boolean equals = baseTs == testTs;
if (equals) {
Set<ORID> baseRids = new HashSet<ORID>();
ODatabaseRecordThreadLocal.INSTANCE.set(base_db);
ORidBag baseRidBag = baseDocument.field("ridBag");
for (OIdentifiable baseIdentifiable : baseRidBag)
baseRids.add(baseIdentifiable.getIdentity());
Set<ORID> testRids = new HashSet<ORID>();
ODatabaseRecordThreadLocal.INSTANCE.set(test_db);
ORidBag testRidBag = testDocument.field("ridBag");
for (OIdentifiable testIdentifiable : testRidBag)
testRids.add(testIdentifiable.getIdentity());
equals = baseRids.equals(testRids);
}
if (!equals)
if (((Long) baseDocument.field("ts")) < minTs)
minTs = baseDocument.field("ts");
else
recordsRestored++;
}
recordsTested++;
if (recordsTested % 10000 == 0)
System.out.println(recordsTested + " were tested, " + recordsRestored + " were restored ...");
}
physicalPositions = baseStorage.higherPhysicalPositions(defaultClusterId, physicalPositions[physicalPositions.length - 1]);
}
System.out.println(recordsRestored + " records were restored. Total records " + recordsTested
+ ". Max interval for lost records " + (lastTs - minTs));