use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber in project orientdb by orientechnologies.
the class ONullBucketTest method testAddRemoveValue.
public void testAddRemoveValue() throws IOException {
OByteBufferPool bufferPool = new OByteBufferPool(1024);
ByteBuffer buffer = bufferPool.acquireDirect(true);
OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
cachePointer.incrementReferrer();
OCacheEntry cacheEntry = new OCacheEntry(0, 0, cachePointer, false);
cacheEntry.acquireExclusiveLock();
ONullBucket<String> bucket = new ONullBucket<String>(cacheEntry, null, OStringSerializer.INSTANCE, true);
bucket.setValue(new OSBTreeValue<String>(false, -1, "test"));
bucket.removeValue();
OSBTreeValue<String> treeValue = bucket.getValue();
Assert.assertNull(treeValue);
cacheEntry.releaseExclusiveLock();
cachePointer.decrementReferrer();
}
use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber in project orientdb by orientechnologies.
the class SBTreeLeafBucketTest method testInitialization.
public void testInitialization() throws Exception {
OByteBufferPool bufferPool = OByteBufferPool.instance();
ByteBuffer buffer = bufferPool.acquireDirect(true);
OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
cachePointer.incrementReferrer();
OCacheEntry cacheEntry = new OCacheEntry(0, 0, cachePointer, false);
cacheEntry.acquireExclusiveLock();
OSBTreeBucket<Long, OIdentifiable> treeBucket = new OSBTreeBucket<Long, OIdentifiable>(cacheEntry, true, OLongSerializer.INSTANCE, null, OLinkSerializer.INSTANCE, null);
Assert.assertEquals(treeBucket.size(), 0);
Assert.assertTrue(treeBucket.isLeaf());
treeBucket = new OSBTreeBucket<Long, OIdentifiable>(cacheEntry, OLongSerializer.INSTANCE, null, OLinkSerializer.INSTANCE, null);
Assert.assertEquals(treeBucket.size(), 0);
Assert.assertTrue(treeBucket.isLeaf());
Assert.assertEquals(treeBucket.getLeftSibling(), -1);
Assert.assertEquals(treeBucket.getRightSibling(), -1);
cacheEntry.releaseExclusiveLock();
cachePointer.decrementReferrer();
}
use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber in project orientdb by orientechnologies.
the class SBTreeLeafBucketTest method testSetRightSibling.
public void testSetRightSibling() throws Exception {
OByteBufferPool bufferPool = OByteBufferPool.instance();
ByteBuffer buffer = bufferPool.acquireDirect(true);
OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
cachePointer.incrementReferrer();
OCacheEntry cacheEntry = new OCacheEntry(0, 0, cachePointer, false);
cacheEntry.acquireExclusiveLock();
OSBTreeBucket<Long, OIdentifiable> treeBucket = new OSBTreeBucket<Long, OIdentifiable>(cacheEntry, true, OLongSerializer.INSTANCE, null, OLinkSerializer.INSTANCE, null);
treeBucket.setRightSibling(123);
Assert.assertEquals(treeBucket.getRightSibling(), 123);
cacheEntry.releaseExclusiveLock();
cachePointer.decrementReferrer();
}
use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber in project orientdb by orientechnologies.
the class SBTreeLeafBucketTest method testSearch.
public void testSearch() throws Exception {
long seed = System.currentTimeMillis();
System.out.println("testSearch seed : " + seed);
TreeSet<Long> keys = new TreeSet<Long>();
Random random = new Random(seed);
while (keys.size() < 2 * OSBTreeBucket.MAX_PAGE_SIZE_BYTES / OLongSerializer.LONG_SIZE) {
keys.add(random.nextLong());
}
OByteBufferPool bufferPool = OByteBufferPool.instance();
ByteBuffer buffer = bufferPool.acquireDirect(true);
OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, new OLogSequenceNumber(0, 0), 0, 0);
OCacheEntry cacheEntry = new OCacheEntry(0, 0, cachePointer, false);
cacheEntry.acquireExclusiveLock();
cachePointer.incrementReferrer();
OSBTreeBucket<Long, OIdentifiable> treeBucket = new OSBTreeBucket<Long, OIdentifiable>(cacheEntry, true, OLongSerializer.INSTANCE, null, OLinkSerializer.INSTANCE, null);
int index = 0;
Map<Long, Integer> keyIndexMap = new HashMap<Long, Integer>();
for (Long key : keys) {
if (!treeBucket.addEntry(index, new OSBTreeBucket.SBTreeEntry<Long, OIdentifiable>(-1, -1, key, new OSBTreeValue<OIdentifiable>(false, -1, new ORecordId(index, index))), true))
break;
keyIndexMap.put(key, index);
index++;
}
Assert.assertEquals(treeBucket.size(), keyIndexMap.size());
for (Map.Entry<Long, Integer> keyIndexEntry : keyIndexMap.entrySet()) {
int bucketIndex = treeBucket.find(keyIndexEntry.getKey());
Assert.assertEquals(bucketIndex, (int) keyIndexEntry.getValue());
}
cacheEntry.releaseExclusiveLock();
cachePointer.decrementReferrer();
}
use of com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber in project orientdb by orientechnologies.
the class LocalPaginatedStorageIncrementalSync method incrementalSyncIteration.
private void incrementalSyncIteration(String buildDirectory) throws Exception {
OLogSequenceNumber startLSN = ((OAbstractPaginatedStorage) originalDB.getStorage()).getWALInstance().end();
final Random rnd = new Random();
int created = 0;
int updated = 0;
int deleted = 0;
while (created + updated + deleted < 10000) {
final int operation = rnd.nextInt(3);
switch(operation) {
case 0:
createRecord(rnd);
created++;
break;
case 1:
if (updateRecord(rnd))
updated++;
break;
case 2:
if (deleteRecord(rnd))
deleted++;
break;
}
}
System.out.println("Created " + created);
System.out.println("Updated " + updated);
System.out.println("Deleted " + deleted);
final File changesFile = new File(buildDirectory, LocalPaginatedStorageIncrementalSync.class.getSimpleName() + ".dt");
if (changesFile.exists()) {
Assert.assertTrue(changesFile.delete());
}
RandomAccessFile dataFile = new RandomAccessFile(changesFile, "rw");
try {
FileChannel channel = dataFile.getChannel();
final OutputStream outputStream = Channels.newOutputStream(channel);
final OutputStream bufferedOutputStream = new BufferedOutputStream(outputStream);
((OAbstractPaginatedStorage) originalDB.getStorage()).recordsChangedAfterLSN(startLSN, bufferedOutputStream, new HashSet<String>(), null);
bufferedOutputStream.close();
dataFile.close();
dataFile = new RandomAccessFile(changesFile, "rw");
channel = dataFile.getChannel();
final InputStream inputStream = Channels.newInputStream(channel);
final BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
replicateDelta(syncDB, bufferedInputStream);
} finally {
dataFile.close();
}
assertDatabasesAreInSynch();
Assert.assertTrue(changesFile.delete());
}
Aggregations