use of com.orientechnologies.orient.core.storage.OPhysicalPosition in project orientdb by orientechnologies.
the class LocalPaginatedClusterTest method testHideHalfRecordsAndAddAnotherHalfAgain.
public void testHideHalfRecordsAndAddAnotherHalfAgain() throws IOException {
final int records = 10000;
long seed = System.currentTimeMillis();
Random mersenneTwisterFast = new Random(seed);
System.out.println("testHideHalfRecordsAndAddAnotherHalfAgain 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(3 * OClusterPage.MAX_RECORD_SIZE) + 1;
byte[] bigRecord = new byte[recordSize];
mersenneTwisterFast.nextBytes(bigRecord);
final OPhysicalPosition physicalPosition = paginatedCluster.createRecord(bigRecord, recordVersion, (byte) 2, null);
positionRecordMap.put(physicalPosition.clusterPosition, bigRecord);
}
int hiddenRecords = 0;
Assert.assertEquals(records, paginatedCluster.getEntries());
Iterator<Long> positionIterator = positionRecordMap.keySet().iterator();
while (positionIterator.hasNext()) {
long clusterPosition = positionIterator.next();
if (mersenneTwisterFast.nextBoolean()) {
Assert.assertTrue(paginatedCluster.hideRecord(clusterPosition));
hiddenRecords++;
Assert.assertEquals(paginatedCluster.getEntries(), records - hiddenRecords);
positionIterator.remove();
}
}
Assert.assertEquals(paginatedCluster.getEntries(), records - hiddenRecords);
for (int i = 0; i < records / 2; i++) {
int recordSize = mersenneTwisterFast.nextInt(3 * OClusterPage.MAX_RECORD_SIZE) + 1;
byte[] bigRecord = new byte[recordSize];
mersenneTwisterFast.nextBytes(bigRecord);
final OPhysicalPosition physicalPosition = paginatedCluster.createRecord(bigRecord, recordVersion, (byte) 2, null);
positionRecordMap.put(physicalPosition.clusterPosition, bigRecord);
}
Assert.assertEquals(paginatedCluster.getEntries(), (long) (1.5 * records - hiddenRecords));
}
use of com.orientechnologies.orient.core.storage.OPhysicalPosition in project orientdb by orientechnologies.
the class LocalPaginatedClusterTest method testGetPhysicalPosition.
public void testGetPhysicalPosition() throws IOException {
final int records = 10000;
long seed = System.currentTimeMillis();
Random mersenneTwisterFast = new Random(seed);
System.out.println("testGetPhysicalPosition seed : " + seed);
Set<OPhysicalPosition> positions = new HashSet<OPhysicalPosition>();
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);
recordVersion++;
final OPhysicalPosition physicalPosition = paginatedCluster.createRecord(record, recordVersion, (byte) i, null);
positions.add(physicalPosition);
}
Set<OPhysicalPosition> removedPositions = new HashSet<OPhysicalPosition>();
for (OPhysicalPosition position : positions) {
OPhysicalPosition physicalPosition = new OPhysicalPosition();
physicalPosition.clusterPosition = position.clusterPosition;
physicalPosition = paginatedCluster.getPhysicalPosition(physicalPosition);
Assert.assertEquals(physicalPosition.clusterPosition, position.clusterPosition);
Assert.assertEquals(physicalPosition.recordType, position.recordType);
Assert.assertEquals(physicalPosition.recordSize, position.recordSize);
if (mersenneTwisterFast.nextBoolean()) {
paginatedCluster.deleteRecord(position.clusterPosition);
removedPositions.add(position);
}
}
for (OPhysicalPosition position : positions) {
OPhysicalPosition physicalPosition = new OPhysicalPosition();
physicalPosition.clusterPosition = position.clusterPosition;
physicalPosition = paginatedCluster.getPhysicalPosition(physicalPosition);
if (removedPositions.contains(position))
Assert.assertNull(physicalPosition);
else {
Assert.assertEquals(physicalPosition.clusterPosition, position.clusterPosition);
Assert.assertEquals(physicalPosition.recordType, position.recordType);
Assert.assertEquals(physicalPosition.recordSize, position.recordSize);
}
}
}
use of com.orientechnologies.orient.core.storage.OPhysicalPosition in project orientdb by orientechnologies.
the class LocalPaginatedClusterTest method testUpdateManySmallRecords.
public void testUpdateManySmallRecords() throws IOException {
final int records = 10000;
long seed = System.currentTimeMillis();
Random mersenneTwisterFast = new Random(seed);
System.out.println("testUpdateManySmallRecords seed : " + seed);
Map<Long, byte[]> positionRecordMap = new HashMap<Long, byte[]>();
Set<Long> updatedPositions = new HashSet<Long>();
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 newRecordVersion = 0;
newRecordVersion = recordVersion;
newRecordVersion++;
for (long clusterPosition : positionRecordMap.keySet()) {
if (mersenneTwisterFast.nextBoolean()) {
int recordSize = mersenneTwisterFast.nextInt(OClusterPage.MAX_RECORD_SIZE - 1) + 1;
byte[] smallRecord = new byte[recordSize];
mersenneTwisterFast.nextBytes(smallRecord);
paginatedCluster.updateRecord(clusterPosition, smallRecord, newRecordVersion, (byte) 3);
positionRecordMap.put(clusterPosition, smallRecord);
updatedPositions.add(clusterPosition);
}
}
for (Map.Entry<Long, byte[]> entry : positionRecordMap.entrySet()) {
ORawBuffer rawBuffer = paginatedCluster.readRecord(entry.getKey(), false);
Assert.assertNotNull(rawBuffer);
Assert.assertEquals(rawBuffer.buffer, entry.getValue());
if (updatedPositions.contains(entry.getKey())) {
Assert.assertEquals(rawBuffer.version, newRecordVersion);
Assert.assertEquals(rawBuffer.recordType, 3);
} else {
Assert.assertEquals(rawBuffer.version, recordVersion);
Assert.assertEquals(rawBuffer.recordType, 2);
}
}
}
use of com.orientechnologies.orient.core.storage.OPhysicalPosition in project orientdb by orientechnologies.
the class ClusterDebugInfoTest method testThreePagesRecordDebugInfo.
@Test
public void testThreePagesRecordDebugInfo() throws IOException {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:ClusterDebugInfoTest");
db.create();
try {
OStorage storage = db.getStorage();
int defaultId = storage.getDefaultClusterId();
OPaginatedCluster cluster = (OPaginatedCluster) storage.getClusterById(defaultId);
int size = OGlobalConfiguration.DISK_CACHE_PAGE_SIZE.getValueAsInteger();
byte[] content = new byte[(size + size) * 1024];
OStorageOperationResult<OPhysicalPosition> result = storage.createRecord(new ORecordId(defaultId), content, 0, (byte) 'b', OPERATION_MODE.SYNCHRONOUS.ordinal(), null);
OPaginatedClusterDebug debug = cluster.readDebug(result.getResult().clusterPosition);
Assert.assertEquals(debug.clusterPosition, result.getResult().clusterPosition);
Assert.assertNotEquals(debug.contentSize, 0);
Assert.assertFalse(debug.empty);
Assert.assertEquals(debug.pages.size(), 3);
Assert.assertNotEquals(debug.pages.get(0).pageIndex, -1);
Assert.assertNotEquals(debug.pages.get(0).inPagePosition, -1);
Assert.assertNotEquals(debug.pages.get(0).inPageSize, -1);
Assert.assertNotNull(debug.pages.get(0).content);
Assert.assertNotEquals(debug.pages.get(1).pageIndex, -1);
Assert.assertNotEquals(debug.pages.get(1).inPagePosition, -1);
Assert.assertNotEquals(debug.pages.get(1).inPageSize, -1);
Assert.assertNotNull(debug.pages.get(1).content);
Assert.assertNotEquals(debug.pages.get(2).pageIndex, -1);
Assert.assertNotEquals(debug.pages.get(2).inPagePosition, -1);
Assert.assertNotEquals(debug.pages.get(2).inPageSize, -1);
Assert.assertNotNull(debug.pages.get(2).content);
} finally {
db.drop();
}
}
use of com.orientechnologies.orient.core.storage.OPhysicalPosition in project orientdb by orientechnologies.
the class ClusterDebugInfoTest method testOnePageRecordDebugInfo.
@Test
public void testOnePageRecordDebugInfo() throws IOException {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:ClusterDebugInfoTest");
db.create();
try {
OStorage storage = db.getStorage();
int defaultId = storage.getDefaultClusterId();
OPaginatedCluster cluster = (OPaginatedCluster) storage.getClusterById(defaultId);
int size = OGlobalConfiguration.DISK_CACHE_PAGE_SIZE.getValueAsInteger();
int half = size / 2;
byte[] content = new byte[half * 1024];
OStorageOperationResult<OPhysicalPosition> result = storage.createRecord(new ORecordId(defaultId), content, 0, (byte) 'b', OPERATION_MODE.SYNCHRONOUS.ordinal(), null);
OPaginatedClusterDebug debug = cluster.readDebug(result.getResult().clusterPosition);
Assert.assertEquals(debug.clusterPosition, result.getResult().clusterPosition);
Assert.assertNotEquals(debug.contentSize, 0);
Assert.assertFalse(debug.empty);
Assert.assertEquals(debug.pages.size(), 1);
Assert.assertNotEquals(debug.pages.get(0).pageIndex, -1);
Assert.assertNotEquals(debug.pages.get(0).inPagePosition, -1);
Assert.assertNotEquals(debug.pages.get(0).inPageSize, -1);
Assert.assertNotNull(debug.pages.get(0).content);
} finally {
db.drop();
}
}
Aggregations