use of com.orientechnologies.orient.core.storage.OPhysicalPosition in project orientdb by orientechnologies.
the class LocalPaginatedClusterTest method testDeleteRecordAndAddNewOnItsPlace.
public void testDeleteRecordAndAddNewOnItsPlace() throws IOException {
byte[] smallRecord = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
int recordVersion = 0;
recordVersion++;
recordVersion++;
OPhysicalPosition physicalPosition = paginatedCluster.createRecord(smallRecord, recordVersion, (byte) 1, null);
Assert.assertEquals(physicalPosition.clusterPosition, 0);
paginatedCluster.deleteRecord(physicalPosition.clusterPosition);
recordVersion = 0;
Assert.assertEquals(recordVersion, 0);
physicalPosition = paginatedCluster.createRecord(smallRecord, recordVersion, (byte) 1, null);
Assert.assertEquals(physicalPosition.clusterPosition, 1);
Assert.assertEquals(physicalPosition.recordVersion, recordVersion);
}
use of com.orientechnologies.orient.core.storage.OPhysicalPosition in project orientdb by orientechnologies.
the class LocalPaginatedClusterTest method testUpdateOneSmallRecord.
public void testUpdateOneSmallRecord() throws IOException {
byte[] smallRecord = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
int recordVersion = 0;
recordVersion++;
recordVersion++;
OPhysicalPosition physicalPosition = paginatedCluster.createRecord(smallRecord, recordVersion, (byte) 1, null);
Assert.assertEquals(physicalPosition.clusterPosition, 0);
recordVersion++;
smallRecord = new byte[] { 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3 };
paginatedCluster.updateRecord(physicalPosition.clusterPosition, smallRecord, recordVersion, (byte) 2);
ORawBuffer rawBuffer = paginatedCluster.readRecord(physicalPosition.clusterPosition, false);
Assert.assertNotNull(rawBuffer);
Assert.assertEquals(rawBuffer.version, recordVersion);
Assert.assertEquals(rawBuffer.buffer, smallRecord);
Assert.assertEquals(rawBuffer.recordType, 2);
}
use of com.orientechnologies.orient.core.storage.OPhysicalPosition in project orientdb by orientechnologies.
the class LocalPaginatedClusterTest method testResurrectRecord.
public void testResurrectRecord() throws IOException {
byte[] smallRecord = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
int recordVersion = 0;
OPhysicalPosition physicalPosition = paginatedCluster.createRecord(smallRecord, recordVersion, (byte) 1, null);
Assert.assertEquals(physicalPosition.clusterPosition, 0);
Assert.assertEquals(paginatedCluster.getRecordStatus(physicalPosition.clusterPosition), OPaginatedCluster.RECORD_STATUS.PRESENT);
for (int i = 0; i < 1000; ++i) {
smallRecord = new byte[] { 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3 };
try {
paginatedCluster.recycleRecord(physicalPosition.clusterPosition);
Assert.fail("it must be not possible to resurrect a non deleted record");
} catch (OPaginatedClusterException e) {
// OK
}
Assert.assertEquals(paginatedCluster.getRecordStatus(physicalPosition.clusterPosition), OPaginatedCluster.RECORD_STATUS.PRESENT);
paginatedCluster.deleteRecord(physicalPosition.clusterPosition);
Assert.assertEquals(paginatedCluster.getRecordStatus(physicalPosition.clusterPosition), OPaginatedCluster.RECORD_STATUS.REMOVED);
ORawBuffer rawBuffer = paginatedCluster.readRecord(physicalPosition.clusterPosition, false);
Assert.assertNull(rawBuffer);
paginatedCluster.recycleRecord(physicalPosition.clusterPosition);
Assert.assertEquals(paginatedCluster.getRecordStatus(physicalPosition.clusterPosition), OPaginatedCluster.RECORD_STATUS.ALLOCATED);
final OPhysicalPosition pos = paginatedCluster.createRecord(smallRecord, 1, ODocument.RECORD_TYPE, new OPhysicalPosition(physicalPosition.clusterPosition));
Assert.assertEquals(pos.clusterPosition, physicalPosition.clusterPosition);
rawBuffer = paginatedCluster.readRecord(physicalPosition.clusterPosition, false);
Assert.assertNotNull(rawBuffer);
Assert.assertEquals(rawBuffer.version, recordVersion + 1);
Assert.assertEquals(rawBuffer.buffer, smallRecord);
Assert.assertEquals(rawBuffer.recordType, ODocument.RECORD_TYPE);
// UPDATE 10 TIMES WITH A GROWING CONTENT TO STIMULATE DEFRAG AND CHANGE OF PAGES
for (int k = 0; k < 10; ++k) {
final byte[] updatedRecord = new byte[10 * k];
for (int j = 0; j < updatedRecord.length; ++j) {
updatedRecord[j] = (byte) j;
}
paginatedCluster.updateRecord(physicalPosition.clusterPosition, updatedRecord, recordVersion, (byte) 4);
}
}
}
use of com.orientechnologies.orient.core.storage.OPhysicalPosition in project orientdb by orientechnologies.
the class LocalPaginatedStorageIncrementalSync method assertDatabasesAreInSynch.
private void assertDatabasesAreInSynch() throws Exception {
originalDB.activateOnCurrentThread();
final long originalRecords = originalDB.countClass("Sample");
syncDB.activateOnCurrentThread();
final long syncRecords = syncDB.countClass("Sample");
Assert.assertEquals(originalRecords, syncRecords);
originalDB.activateOnCurrentThread();
OSchema schema = originalDB.getMetadata().getSchema();
OClass clazz = schema.getClass("Sample");
int[] clusterIds = clazz.getClusterIds();
for (int clusterId : clusterIds) {
final OStorage originalStorage = originalDB.getStorage();
final OStorage syncedStorage = syncDB.getStorage();
final long[] db1Range = originalStorage.getClusterDataRange(clusterId);
final long[] db2Range = syncedStorage.getClusterDataRange(clusterId);
Assert.assertEquals(db1Range, db2Range);
final ORecordId rid = new ORecordId(clusterId);
OPhysicalPosition[] physicalPositions = originalStorage.ceilingPhysicalPositions(clusterId, new OPhysicalPosition(0));
while (physicalPositions.length > 0) {
for (OPhysicalPosition physicalPosition : physicalPositions) {
rid.setClusterPosition(physicalPosition.clusterPosition);
final ORawBuffer originalBuffer = originalStorage.readRecord(rid, null, true, false, null).getResult();
final ORawBuffer syncBuffer = syncedStorage.readRecord(rid, null, true, false, null).getResult();
Assert.assertEquals(originalBuffer.recordType, syncBuffer.recordType);
Assert.assertEquals(originalBuffer.version, syncBuffer.version);
Assert.assertEquals(originalBuffer.buffer, syncBuffer.buffer);
}
physicalPositions = originalStorage.higherPhysicalPositions(clusterId, physicalPositions[physicalPositions.length - 1]);
}
}
}
use of com.orientechnologies.orient.core.storage.OPhysicalPosition in project orientdb by orientechnologies.
the class LocalPaginatedClusterTest method testForwardIteration.
public void testForwardIteration() throws IOException {
final int records = 10000;
long seed = System.currentTimeMillis();
Random mersenneTwisterFast = new Random(seed);
System.out.println("testForwardIteration 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 = 0;
OPhysicalPosition[] positions = paginatedCluster.ceilingPositions(physicalPosition);
Assert.assertTrue(positions.length > 0);
int counter = 0;
for (long testedPosition : positionRecordMap.keySet()) {
Assert.assertTrue(positions.length > 0);
Assert.assertEquals(positions[0].clusterPosition, testedPosition);
OPhysicalPosition positionToFind = positions[0];
positions = paginatedCluster.higherPositions(positionToFind);
counter++;
}
Assert.assertEquals(paginatedCluster.getEntries(), counter);
Assert.assertEquals(paginatedCluster.getFirstPosition(), (long) positionRecordMap.firstKey());
Assert.assertEquals(paginatedCluster.getLastPosition(), (long) positionRecordMap.lastKey());
}
Aggregations