use of com.orientechnologies.orient.core.storage.OPhysicalPosition in project orientdb by orientechnologies.
the class LocalPaginatedStorageLinkBagCrashRestoreIT method compareDocuments.
private void compareDocuments(long lastTs) {
ODatabaseDocumentTx base_db = new ODatabaseDocumentTx("plocal:" + buildDir + "/baseLocalPaginatedStorageLinkBagCrashRestore");
base_db.open("admin", "admin");
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(0));
int recordsRestored = 0;
int recordsTested = 0;
while (physicalPositions.length > 0) {
final ORecordId rid = new ORecordId(defaultClusterId);
for (OPhysicalPosition physicalPosition : physicalPositions) {
rid.setClusterPosition(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);
if (testDocument == null) {
ODatabaseRecordThreadLocal.INSTANCE.set(base_db);
if (((Long) baseDocument.field("ts")) < minTs)
minTs = baseDocument.field("ts");
} else {
testDocument.setLazyLoad(false);
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 + ". lost records " + (recordsTested - recordsRestored));
long maxInterval = minTs == Long.MAX_VALUE ? 0 : lastTs - minTs;
System.out.println("Lost records max interval (ms) : " + maxInterval);
assertThat(maxInterval).isLessThan(2000);
base_db.activateOnCurrentThread();
base_db.close();
test_db.activateOnCurrentThread();
test_db.close();
}
use of com.orientechnologies.orient.core.storage.OPhysicalPosition in project orientdb by orientechnologies.
the class LocalPaginatedStorageUpdateCrashRestoreIT method compareDocuments.
private void compareDocuments(long lastTs) {
long minTs = Long.MAX_VALUE;
baseDocumentTx.activateOnCurrentThread();
int clusterId = baseDocumentTx.getClusterIdByName("TestClass");
OStorage baseStorage = baseDocumentTx.getStorage();
OPhysicalPosition[] physicalPositions = baseStorage.ceilingPhysicalPositions(clusterId, new OPhysicalPosition(0));
int recordsRestored = 0;
int recordsTested = 0;
while (physicalPositions.length > 0) {
final ORecordId rid = new ORecordId(clusterId);
for (OPhysicalPosition physicalPosition : physicalPositions) {
rid.setClusterPosition(physicalPosition.clusterPosition);
baseDocumentTx.activateOnCurrentThread();
ODocument baseDocument = baseDocumentTx.load(rid);
testDocumentTx.activateOnCurrentThread();
List<ODocument> testDocuments = testDocumentTx.query(new OSQLSynchQuery<ODocument>("select from TestClass where id = " + baseDocument.field("id")));
Assert.assertTrue(!testDocuments.isEmpty());
ODocument testDocument = testDocuments.get(0);
if (testDocument.field("timestamp").equals(baseDocument.field("timestamp")) && testDocument.field("stringValue").equals(baseDocument.field("stringValue"))) {
recordsRestored++;
} else {
if (((Long) baseDocument.field("timestamp")) < minTs)
minTs = baseDocument.field("timestamp");
}
recordsTested++;
if (recordsTested % 10000 == 0)
System.out.println(recordsTested + " were tested, " + recordsRestored + " were restored ...");
}
physicalPositions = baseStorage.higherPhysicalPositions(clusterId, physicalPositions[physicalPositions.length - 1]);
}
System.out.println(recordsRestored + " records were restored. Total records " + recordsTested + ". lost records " + (recordsTested - recordsRestored));
long maxInterval = minTs == Long.MAX_VALUE ? 0 : lastTs - minTs;
System.out.println("Lost records max interval (ms) : " + maxInterval);
assertThat(recordsTested - recordsRestored).isLessThan(120);
assertThat(maxInterval).isLessThan(2000);
}
use of com.orientechnologies.orient.core.storage.OPhysicalPosition in project orientdb by orientechnologies.
the class RemoteProtocolCommandsTest method testRawCreateWithoutIDTest.
@Test
public void testRawCreateWithoutIDTest() {
OClass clazz = this.database.getMetadata().getSchema().createClass("RidCreationTestClass");
OStorage storage = this.database.getStorage();
ODocument doc = new ODocument("RidCreationTestClass");
doc.field("test", "test");
ORecordId bad = new ORecordId(-1, -1);
OStorageOperationResult<OPhysicalPosition> res = storage.createRecord(bad, doc.toStream(), doc.getVersion(), ODocument.RECORD_TYPE, OPERATION_MODE.SYNCHRONOUS.ordinal(), null);
// assertTrue(" the cluster is not valid", bad.clusterId >= 0);
String ids = "";
for (int aId : clazz.getClusterIds()) ids += aId;
assertTrue(" returned id:" + bad.getClusterId() + " shoud be one of:" + ids, Arrays.binarySearch(clazz.getClusterIds(), bad.getClusterId()) >= 0);
}
use of com.orientechnologies.orient.core.storage.OPhysicalPosition in project orientdb by orientechnologies.
the class LocalPaginatedClusterTest method testBackwardIteration.
public void testBackwardIteration() throws IOException {
final int records = 10000;
long seed = System.currentTimeMillis();
Random mersenneTwisterFast = new Random(seed);
System.out.println("testBackwardIteration seed : " + seed);
NavigableMap<Long, byte[]> positionRecordMap = new TreeMap<Long, byte[]>();
int recordVersion = 0;
recordVersion++;
recordVersion++;
for (int i = 0; i < records; i++) {
int recordSize = mersenneTwisterFast.nextInt(2 * OClusterPage.MAX_RECORD_SIZE) + 1;
byte[] record = new byte[recordSize];
mersenneTwisterFast.nextBytes(record);
final OPhysicalPosition physicalPosition = paginatedCluster.createRecord(record, recordVersion, (byte) 2, null);
positionRecordMap.put(physicalPosition.clusterPosition, record);
}
Iterator<Long> positionIterator = positionRecordMap.keySet().iterator();
while (positionIterator.hasNext()) {
long clusterPosition = positionIterator.next();
if (mersenneTwisterFast.nextBoolean()) {
Assert.assertTrue(paginatedCluster.deleteRecord(clusterPosition));
positionIterator.remove();
}
}
OPhysicalPosition physicalPosition = new OPhysicalPosition();
physicalPosition.clusterPosition = Long.MAX_VALUE;
OPhysicalPosition[] positions = paginatedCluster.floorPositions(physicalPosition);
Assert.assertTrue(positions.length > 0);
positionIterator = positionRecordMap.descendingKeySet().iterator();
int counter = 0;
while (positionIterator.hasNext()) {
Assert.assertTrue(positions.length > 0);
long testedPosition = positionIterator.next();
Assert.assertEquals(positions[positions.length - 1].clusterPosition, testedPosition);
OPhysicalPosition positionToFind = positions[positions.length - 1];
positions = paginatedCluster.lowerPositions(positionToFind);
counter++;
}
Assert.assertEquals(paginatedCluster.getEntries(), counter);
Assert.assertEquals(paginatedCluster.getFirstPosition(), (long) positionRecordMap.firstKey());
Assert.assertEquals(paginatedCluster.getLastPosition(), (long) positionRecordMap.lastKey());
}
use of com.orientechnologies.orient.core.storage.OPhysicalPosition in project orientdb by orientechnologies.
the class LocalPaginatedClusterTest method testHideHalfSmallRecords.
public void testHideHalfSmallRecords() throws IOException {
final int records = 10000;
long seed = System.currentTimeMillis();
Random mersenneTwisterFast = new Random(seed);
System.out.println("testHideHalfSmallRecords seed : " + seed);
Map<Long, byte[]> positionRecordMap = new HashMap<Long, byte[]>();
int recordVersion = 0;
recordVersion++;
recordVersion++;
for (int i = 0; i < records; i++) {
int recordSize = mersenneTwisterFast.nextInt(OClusterPage.MAX_RECORD_SIZE - 1) + 1;
byte[] smallRecord = new byte[recordSize];
mersenneTwisterFast.nextBytes(smallRecord);
final OPhysicalPosition physicalPosition = paginatedCluster.createRecord(smallRecord, recordVersion, (byte) 2, null);
positionRecordMap.put(physicalPosition.clusterPosition, smallRecord);
}
int hiddenRecords = 0;
Assert.assertEquals(records, paginatedCluster.getEntries());
Set<Long> hiddenPositions = new HashSet<Long>();
Iterator<Long> positionIterator = positionRecordMap.keySet().iterator();
while (positionIterator.hasNext()) {
long clusterPosition = positionIterator.next();
if (mersenneTwisterFast.nextBoolean()) {
hiddenPositions.add(clusterPosition);
Assert.assertTrue(paginatedCluster.hideRecord(clusterPosition));
hiddenRecords++;
Assert.assertEquals(records - hiddenRecords, paginatedCluster.getEntries());
positionIterator.remove();
}
}
Assert.assertEquals(paginatedCluster.getEntries(), records - hiddenRecords);
for (long deletedPosition : hiddenPositions) {
Assert.assertNull(paginatedCluster.readRecord(deletedPosition, false));
Assert.assertFalse(paginatedCluster.hideRecord(deletedPosition));
}
for (Map.Entry<Long, byte[]> entry : positionRecordMap.entrySet()) {
ORawBuffer rawBuffer = paginatedCluster.readRecord(entry.getKey(), false);
Assert.assertNotNull(rawBuffer);
Assert.assertEquals(rawBuffer.version, recordVersion);
Assert.assertEquals(rawBuffer.buffer, entry.getValue());
Assert.assertEquals(rawBuffer.recordType, 2);
}
}
Aggregations