From 23e878d8c1beb761bc49e4d880df364a347c7441 Mon Sep 17 00:00:00 2001 From: laa Date: Thu, 6 Dec 2018 09:10:49 +0200 Subject: [PATCH] CHM removed from OByteBufferPool --- .../common/directmemory/OByteBufferPool.java | 98 +++------ .../common/directmemory/OPointer.java | 16 +- .../common/util/OQuarto.java | 38 ++++ .../core/storage/cache/OCachePointer.java | 56 +++-- .../core/storage/cache/local/OWOWCache.java | 138 ++++++------ .../memory/ODirectMemoryOnlyDiskCache.java | 187 ++++++++-------- .../directmemory/OByteBufferPoolTest.java | 140 +++++------- .../local/twoq/ReadWriteDiskCacheTest.java | 48 +++-- .../impl/local/paginated/ClusterPageTest.java | 204 +++++++++--------- .../cache/AbstractLRUListTestTemplate.java | 138 ++++++------ .../index/sbtree/local/ONullBucketTest.java | 18 +- .../sbtree/local/SBTreeLeafBucketTest.java | 118 +++++----- .../sbtree/local/SBTreeNonLeafBucketTest.java | 14 +- .../sbtree/local/SBTreeValuePageTest.java | 14 +- .../local/OSBTreeBonsaiLeafBucketTest.java | 89 ++++---- .../local/OSBTreeBonsaiNonLeafBucketTest.java | 14 +- 16 files changed, 680 insertions(+), 650 deletions(-) create mode 100755 core/src/main/java/com/orientechnologies/common/util/OQuarto.java diff --git a/core/src/main/java/com/orientechnologies/common/directmemory/OByteBufferPool.java b/core/src/main/java/com/orientechnologies/common/directmemory/OByteBufferPool.java index 679fed6a764..a9811dbae0d 100755 --- a/core/src/main/java/com/orientechnologies/common/directmemory/OByteBufferPool.java +++ b/core/src/main/java/com/orientechnologies/common/directmemory/OByteBufferPool.java @@ -37,7 +37,7 @@ * * @see ODirectMemoryAllocator */ -public class OByteBufferPool implements OByteBufferPoolMXBean { +public final class OByteBufferPool implements OByteBufferPoolMXBean { /** * Whether we should track memory leaks during application execution */ @@ -56,7 +56,6 @@ public class OByteBufferPool implements OByteBufferPoolMXBean { /** * @return Singleton instance - * @param contextConfiguration */ public static OByteBufferPool instance(OContextConfiguration contextConfiguration) { final OByteBufferPool instance = INSTANCE_HOLDER.get(); @@ -71,7 +70,7 @@ public static OByteBufferPool instance(OContextConfiguration contextConfiguratio bufferSize = OGlobalConfiguration.DISK_CACHE_PAGE_SIZE.getValueAsInteger(); } - final OByteBufferPool newInstance = new OByteBufferPool(bufferSize * 1024); + final OByteBufferPool newInstance = new OByteBufferPool(bufferSize * 1024); if (INSTANCE_HOLDER.compareAndSet(null, newInstance)) { return newInstance; } @@ -87,7 +86,7 @@ public static OByteBufferPool instance(OContextConfiguration contextConfiguratio /** * {@link ByteBuffer}s can not be extended, so to keep mapping between pointers and buffers we use concurrent hash map. */ - private final ConcurrentHashMap bufferPointerMapping = new ConcurrentHashMap<>(); + private final ConcurrentHashMap pointerMapping = new ConcurrentHashMap<>(); /** * Pool of already allocated pages. @@ -133,7 +132,7 @@ public OByteBufferPool(int pageSize, ODirectMemoryAllocator allocator, int poolS * * @return Direct memory buffer instance. */ - public ByteBuffer acquireDirect(boolean clear) { + public final OPointer acquireDirect(boolean clear) { OPointer pointer; pointer = pointersPool.poll(); @@ -151,39 +150,39 @@ public ByteBuffer acquireDirect(boolean clear) { final ByteBuffer buffer = pointer.getNativeByteBuffer(); buffer.position(0); - bufferPointerMapping.put(wrapBuffer(buffer), wrapPointer(pointer)); - return buffer; + if (TRACK) { + pointerMapping.put(pointer, generatePointer()); + } + + return pointer; } /** * Put buffer which is not used any more back to the pool or frees direct memory if pool is full. * - * @param buffer Not used instance of buffer. + * @param pointer Not used instance of buffer. * * @see OGlobalConfiguration#DIRECT_MEMORY_POOL_LIMIT */ - public void release(ByteBuffer buffer) { - final PointerHolder holder = bufferPointerMapping.remove(wrapBuffer(buffer)); - - if (holder == null) { - throw new IllegalArgumentException(String.format("Buffer %X is not acquired", System.identityHashCode(buffer))); + public final void release(OPointer pointer) { + if (TRACK) { + pointerMapping.remove(pointer); } long poolSize = pointersPoolSize.incrementAndGet(); if (poolSize > this.poolSize) { pointersPoolSize.decrementAndGet(); - allocator.deallocate(holder.pointer); + allocator.deallocate(pointer); } else { - pointersPool.add(holder.pointer); + pointersPool.add(pointer); } - } /** * @inheritDoc */ @Override - public int getPoolSize() { + public final int getPoolSize() { return pointersPoolSize.get(); } @@ -193,10 +192,10 @@ public int getPoolSize() { public void checkMemoryLeaks() { boolean detected = false; if (TRACK) { - for (Map.Entry entry : bufferPointerMapping.entrySet()) { + for (Map.Entry entry : pointerMapping.entrySet()) { OLogManager.instance() - .errorNoDb(this, "DIRECT-TRACK: unreleased direct memory buffer `%X` detected.", entry.getValue().allocation, - System.identityHashCode(entry.getKey().byteBuffer)); + .errorNoDb(this, "DIRECT-TRACK: unreleased direct memory pointer `%X` detected.", entry.getValue().allocation, + System.identityHashCode(entry.getKey())); detected = true; } } @@ -215,68 +214,25 @@ public void clear() { pointersPool.clear(); pointersPoolSize.set(0); - if (!TRACK && !bufferPointerMapping.isEmpty()) { - final String message = - "There are not released allocations in " + "ByteBufferPool which may indicate presence of memory leaks in database!!" - + "Start JVM with system property" + OGlobalConfiguration.DIRECT_MEMORY_TRACK_MODE.getKey() - + " = true for more details"; - - OLogManager.instance().warnNoDb(this, message); - } - - for (PointerHolder holder : bufferPointerMapping.values()) { - allocator.deallocate(holder.pointer); - } - - bufferPointerMapping.clear(); - } - - /** - * Holder which is used to compare byte buffers by object's identity not by content - */ - private static final class ByteBufferHolder { - private final ByteBuffer byteBuffer; - - ByteBufferHolder(ByteBuffer byteBuffer) { - this.byteBuffer = byteBuffer; - } - - @Override - public int hashCode() { - return System.identityHashCode(byteBuffer); + for (OPointer pointer : pointerMapping.keySet()) { + allocator.deallocate(pointer); } - @Override - public boolean equals(Object obj) { - if (!(obj instanceof ByteBufferHolder)) - return false; - - return ((ByteBufferHolder) obj).byteBuffer == this.byteBuffer; - } + pointerMapping.clear(); } /** - * Holder which contains direct memory pointer and if memory tracking is enabled stack trace for the first allocation. + * Holder which contains if memory tracking is enabled stack trace for the first allocation. */ - private static final class PointerHolder { - private final OPointer pointer; + private static final class PointerTracker { private final Exception allocation; - PointerHolder(OPointer pointer, Exception allocation) { - this.pointer = pointer; + PointerTracker(Exception allocation) { this.allocation = allocation; } } - private ByteBufferHolder wrapBuffer(ByteBuffer byteBuffer) { - return new ByteBufferHolder(byteBuffer); - } - - private PointerHolder wrapPointer(OPointer pointer) { - if (TRACK) { - return new PointerHolder(pointer, new Exception()); - } else { - return new PointerHolder(pointer, null); - } + private PointerTracker generatePointer() { + return new PointerTracker(new Exception()); } } diff --git a/core/src/main/java/com/orientechnologies/common/directmemory/OPointer.java b/core/src/main/java/com/orientechnologies/common/directmemory/OPointer.java index 38bb0f82554..20f2742f60f 100755 --- a/core/src/main/java/com/orientechnologies/common/directmemory/OPointer.java +++ b/core/src/main/java/com/orientechnologies/common/directmemory/OPointer.java @@ -5,11 +5,12 @@ import java.nio.ByteBuffer; import java.util.Objects; -public class OPointer { - private final Pointer pointer; - private final int size; +public final class OPointer { + private final Pointer pointer; + private final int size; + private ByteBuffer byteBuffer; - public OPointer(Pointer pointer, int size) { + OPointer(Pointer pointer, int size) { this.pointer = pointer; this.size = size; } @@ -19,7 +20,12 @@ public void clear() { } public ByteBuffer getNativeByteBuffer() { - return pointer.getByteBuffer(0, size); + if (byteBuffer != null) { + return byteBuffer; + } + + byteBuffer = pointer.getByteBuffer(0, size); + return byteBuffer; } Pointer getNativePointer() { diff --git a/core/src/main/java/com/orientechnologies/common/util/OQuarto.java b/core/src/main/java/com/orientechnologies/common/util/OQuarto.java new file mode 100755 index 00000000000..f7df644ca4a --- /dev/null +++ b/core/src/main/java/com/orientechnologies/common/util/OQuarto.java @@ -0,0 +1,38 @@ +package com.orientechnologies.common.util; + +import java.util.Objects; + +public final class OQuarto { + public final T1 one; + public final T2 two; + public final T3 three; + public final T4 four; + + public OQuarto(T1 one, T2 two, T3 three, T4 four) { + this.one = one; + this.two = two; + this.three = three; + this.four = four; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + OQuarto oQuarto = (OQuarto) o; + return Objects.equals(one, oQuarto.one) && Objects.equals(two, oQuarto.two) && Objects.equals(three, oQuarto.three) && Objects + .equals(four, oQuarto.four); + } + + @Override + public int hashCode() { + return Objects.hash(one, two, three, four); + } + + @Override + public String toString() { + return "OQuarto{" + "one=" + one + ", two=" + two + ", three=" + three + ", four=" + four + '}'; + } +} diff --git a/core/src/main/java/com/orientechnologies/orient/core/storage/cache/OCachePointer.java b/core/src/main/java/com/orientechnologies/orient/core/storage/cache/OCachePointer.java index 7716c8ee125..8d13cc5f1e3 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/storage/cache/OCachePointer.java +++ b/core/src/main/java/com/orientechnologies/orient/core/storage/cache/OCachePointer.java @@ -20,6 +20,7 @@ package com.orientechnologies.orient.core.storage.cache; import com.orientechnologies.common.directmemory.OByteBufferPool; +import com.orientechnologies.common.directmemory.OPointer; import com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber; import java.nio.ByteBuffer; @@ -32,7 +33,7 @@ * @author Andrey Lomakin (a.lomakin-at-orientdb.com) * @since 05.08.13 */ -public class OCachePointer { +public final class OCachePointer { private static final int WRITERS_OFFSET = 32; private static final int READERS_MASK = 0xFFFFFFFF; @@ -45,7 +46,7 @@ public class OCachePointer { private volatile WritersListener writersListener; - private final ByteBuffer buffer; + private final OPointer pointer; private final OByteBufferPool bufferPool; private long version; @@ -55,8 +56,8 @@ public class OCachePointer { private OLogSequenceNumber endLSN; - public OCachePointer(final ByteBuffer buffer, final OByteBufferPool bufferPool, final long fileId, final long pageIndex) { - this.buffer = buffer; + public OCachePointer(final OPointer pointer, final OByteBufferPool bufferPool, final long fileId, final long pageIndex) { + this.pointer = pointer; this.bufferPool = bufferPool; this.fileId = fileId; @@ -90,8 +91,9 @@ public void incrementReadersReferrer() { final WritersListener wl = writersListener; if (wl != null) { - if (writers > 0 && readers == 1) + if (writers > 0 && readers == 1) { wl.removeOnlyWriters(fileId, pageIndex); + } } incrementReferrer(); @@ -116,8 +118,9 @@ public void decrementReadersReferrer() { final WritersListener wl = writersListener; if (wl != null) { - if (writers > 0 && readers == 0) + if (writers > 0 && readers == 0) { wl.addOnlyWriters(fileId, pageIndex); + } } decrementReferrer(); @@ -158,8 +161,9 @@ public void decrementWritersReferrer() { final WritersListener wl = writersListener; if (wl != null) { - if (readers == 0 && writers == 0) + if (readers == 0 && writers == 0) { wl.removeOnlyWriters(fileId, pageIndex); + } } decrementReferrer(); @@ -180,24 +184,33 @@ public void incrementReferrer() { public void decrementReferrer() { final int rf = referrersCount.decrementAndGet(); - if (rf == 0 && buffer != null) { - bufferPool.release(buffer); + if (rf == 0 && pointer != null) { + bufferPool.release(pointer); } - if (rf < 0) + if (rf < 0) { throw new IllegalStateException("Invalid direct memory state, number of referrers cannot be negative " + rf); + } } public ByteBuffer getBuffer() { - return buffer; + if (pointer == null) { + return null; + } + + return pointer.getNativeByteBuffer(); + } + + public OPointer getPointer() { + return pointer; } public ByteBuffer getBufferDuplicate() { - if (buffer == null) { + if (pointer == null) { return null; } - return buffer.duplicate().order(ByteOrder.nativeOrder()); + return pointer.getNativeByteBuffer().duplicate().order(ByteOrder.nativeOrder()); } public void acquireExclusiveLock() { @@ -205,7 +218,6 @@ public void acquireExclusiveLock() { version++; } - public long getVersion() { return version; } @@ -222,32 +234,31 @@ public void releaseSharedLock() { readWriteLock.readLock().unlock(); } - @SuppressWarnings("BooleanMethodIsAlwaysInverted") public boolean tryAcquireSharedLock() { return readWriteLock.readLock().tryLock(); } @Override public boolean equals(Object o) { - if (this == o) + if (this == o) { return true; - if (o == null || getClass() != o.getClass()) + } + if (o == null || getClass() != o.getClass()) { return false; + } OCachePointer that = (OCachePointer) o; - buffer.position(0); - that.buffer.position(0); - - if (!buffer.equals(that.buffer)) + if (!pointer.equals(that.pointer)) { return false; + } return true; } @Override public int hashCode() { - return buffer != null ? buffer.hashCode() : 0; + return pointer != null ? pointer.hashCode() : 0; } @Override @@ -260,7 +271,6 @@ private static long composeReadersWriters(int readers, int writers) { } private static int getReaders(long readersWriters) { - //noinspection PointlessBitwiseExpression return (int) (readersWriters & READERS_MASK); } diff --git a/core/src/main/java/com/orientechnologies/orient/core/storage/cache/local/OWOWCache.java b/core/src/main/java/com/orientechnologies/orient/core/storage/cache/local/OWOWCache.java index 01a65e88dad..64c00def40c 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/storage/cache/local/OWOWCache.java +++ b/core/src/main/java/com/orientechnologies/orient/core/storage/cache/local/OWOWCache.java @@ -26,6 +26,7 @@ import com.orientechnologies.common.concur.lock.OPartitionedLockManager; import com.orientechnologies.common.concur.lock.OReadersWriterSpinLock; import com.orientechnologies.common.directmemory.OByteBufferPool; +import com.orientechnologies.common.directmemory.OPointer; import com.orientechnologies.common.exception.OException; import com.orientechnologies.common.io.OIOUtils; import com.orientechnologies.common.log.OLogManager; @@ -35,7 +36,7 @@ import com.orientechnologies.common.thread.OScheduledThreadPoolExecutorWithLogging; import com.orientechnologies.common.thread.OThreadPoolExecutorWithLogging; import com.orientechnologies.common.types.OModifiableBoolean; -import com.orientechnologies.common.util.OTriple; +import com.orientechnologies.common.util.OQuarto; import com.orientechnologies.common.util.OUncaughtExceptionHandler; import com.orientechnologies.orient.core.command.OCommandOutputListener; import com.orientechnologies.orient.core.config.OGlobalConfiguration; @@ -404,8 +405,8 @@ public final class OWOWCache extends OAbstractWriteCache implements OWriteCache, private final boolean printCacheStatistics; private final int statisticsPrintInterval; - private long lastFlushTs = -1; - private long backroundExclusiveFlushBoundary = -1; + private long lastFlushTs = -1; + private long backgroundExclusiveFlushBoundary = -1; private long lsnPagesFlushIntervalSum = 0; private int lsnPagesFlushIntervalCount = 0; @@ -858,7 +859,8 @@ public long addFile(final String fileName, long fileId) throws IOException { throw new OStorageException("File with name '" + fileName + "'' already exists in storage '" + storageName + "'"); } else { throw new OStorageException( - "File with given name '" + fileName + "' already exists but has different id " + existingFileId + " vs. proposed " + fileId); + "File with given name '" + fileName + "' already exists but has different id " + existingFileId + " vs. proposed " + + fileId); } } @@ -1117,7 +1119,7 @@ public OCachePointer[] load(final long fileId, final long startPageIndex, final pageKeys = new PageKey[] { startPageKey }; } - final OCachePointer pagePointers[]; + final OCachePointer[] pagePointers; try { //load requested page and preload requested amount of pages pagePointers = loadFileContent(intId, startPageIndex, pageCount, verifyChecksums); @@ -1191,14 +1193,16 @@ public OCachePointer[] load(final long fileId, final long startPageIndex, final } for (long index = startAllocationIndex; index <= stopAllocationIndex; index++) { - final ByteBuffer buffer = bufferPool.acquireDirect(true); + final OPointer pointer = bufferPool.acquireDirect(true); + final ByteBuffer buffer = pointer.getNativeByteBuffer(); + buffer.putLong(MAGIC_NUMBER_OFFSET, MAGIC_NUMBER_WITHOUT_CHECKSUM); if (initNewPage) { fileClassic.allocateSpace(buffer); } buffer.rewind(); - final OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, fileId, index); + final OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, fileId, index); //item only in write cache till we will not return //it to read cache so we increment exclusive size by one //otherwise call of write listener inside pointer may set exclusive size to negative value @@ -1605,13 +1609,14 @@ private void checkFileStoredPages(final OCommandOutputListener commandOutputList final byte[] data = new byte[pageSize]; - ByteBuffer byteBuffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); try { + ByteBuffer byteBuffer = pointer.getNativeByteBuffer(); fileClassic.read(pos, byteBuffer, true); byteBuffer.rewind(); byteBuffer.get(data); } finally { - bufferPool.release(byteBuffer); + bufferPool.release(pointer); } final long magicNumber = OLongSerializer.INSTANCE.deserializeNative(data, MAGIC_NUMBER_OFFSET); @@ -1619,7 +1624,8 @@ private void checkFileStoredPages(final OCommandOutputListener commandOutputList if (magicNumber != MAGIC_NUMBER_WITH_CHECKSUM && magicNumber != MAGIC_NUMBER_WITHOUT_CHECKSUM) { magicNumberIncorrect = true; if (commandOutputListener != null) { - commandOutputListener.onMessage("Error: Magic number for page " + (pos / pageSize) + " in file '" + fileName + "' does not match!\n"); + commandOutputListener + .onMessage("Error: Magic number for page " + (pos / pageSize) + " in file '" + fileName + "' does not match!\n"); } fileIsCorrect = false; } @@ -1634,7 +1640,8 @@ private void checkFileStoredPages(final OCommandOutputListener commandOutputList if (storedCRC32 != calculatedCRC32) { checkSumIncorrect = true; if (commandOutputListener != null) { - commandOutputListener.onMessage("Error: Checksum for page " + (pos / pageSize) + " in file '" + fileName + "' is incorrect!\n"); + commandOutputListener + .onMessage("Error: Checksum for page " + (pos / pageSize) + " in file '" + fileName + "' is incorrect!\n"); } fileIsCorrect = false; } @@ -1882,7 +1889,6 @@ private void readNameIdMapV2() throws IOException, InterruptedException { long localFileCounter = -1; - //noinspection resource nameIdMapHolder.position(0); NameFileIdEntry nameFileIdEntry; @@ -1942,7 +1948,6 @@ private void readNameIdMapV1() throws IOException, InterruptedException { long localFileCounter = -1; - //noinspection resource nameIdMapHolder.position(0); NameFileIdEntry nameFileIdEntry; @@ -2183,18 +2188,19 @@ private OCachePointer[] loadFileContent(final int intId, final long startPageInd try { if (pageCount == 1) { - final ByteBuffer buffer = bufferPool.acquireDirect(false); + final OPointer pointer = bufferPool.acquireDirect(false); + final ByteBuffer buffer = pointer.getNativeByteBuffer(); assert buffer.position() == 0; fileClassic.read(firstPageStartPosition, buffer, false); if (verifyChecksums && (checksumMode == OChecksumMode.StoreAndVerify || checksumMode == OChecksumMode.StoreAndThrow || checksumMode == OChecksumMode.StoreAndSwitchReadOnlyMode)) { - verifyMagicAndChecksum(buffer, fileId, startPageIndex, null); + verifyMagicAndChecksum(buffer, pointer, fileId, startPageIndex, null); } buffer.position(0); - final OCachePointer dataPointer = new OCachePointer(buffer, bufferPool, fileId, startPageIndex); + final OCachePointer dataPointer = new OCachePointer(pointer, bufferPool, fileId, startPageIndex); pagesRead = 1; return new OCachePointer[] { dataPointer }; } @@ -2202,25 +2208,27 @@ private OCachePointer[] loadFileContent(final int intId, final long startPageInd final long maxPageCount = (fileClassic.getFileSize() - firstPageStartPosition) / pageSize; final int realPageCount = Math.min((int) maxPageCount, pageCount); + final OPointer[] pointers = new OPointer[realPageCount]; final ByteBuffer[] buffers = new ByteBuffer[realPageCount]; - for (int i = 0; i < buffers.length; i++) { - buffers[i] = bufferPool.acquireDirect(false); - assert buffers[i].position() == 0; + for (int i = 0; i < pointers.length; i++) { + final OPointer pointer = bufferPool.acquireDirect(false); + pointers[i] = pointer; + buffers[i] = pointer.getNativeByteBuffer(); } fileClassic.read(firstPageStartPosition, buffers, false); if (verifyChecksums && (checksumMode == OChecksumMode.StoreAndVerify || checksumMode == OChecksumMode.StoreAndThrow || checksumMode == OChecksumMode.StoreAndSwitchReadOnlyMode)) { - for (int i = 0; i < buffers.length; ++i) { - verifyMagicAndChecksum(buffers[i], fileId, startPageIndex + i, buffers); + for (int i = 0; i < pointers.length; ++i) { + verifyMagicAndChecksum(buffers[i], pointers[i], fileId, startPageIndex + i, pointers); } } - final OCachePointer[] dataPointers = new OCachePointer[buffers.length]; - for (int n = 0; n < buffers.length; n++) { + final OCachePointer[] dataPointers = new OCachePointer[pointers.length]; + for (int n = 0; n < pointers.length; n++) { buffers[n].position(0); - dataPointers[n] = new OCachePointer(buffers[n], bufferPool, fileId, startPageIndex + n); + dataPointers[n] = new OCachePointer(pointers[n], bufferPool, fileId, startPageIndex + n); } pagesRead = dataPointers.length; @@ -2265,8 +2273,8 @@ private void addMagicAndChecksum(final ByteBuffer buffer) { } } - private void verifyMagicAndChecksum(final ByteBuffer buffer, final long fileId, final long pageIndex, - final ByteBuffer[] buffersToRelease) { + private void verifyMagicAndChecksum(final ByteBuffer buffer, final OPointer pointer, final long fileId, final long pageIndex, + final OPointer[] pointersToRelease) { assert buffer.order() == ByteOrder.nativeOrder(); buffer.position(MAGIC_NUMBER_OFFSET); @@ -2277,10 +2285,10 @@ private void verifyMagicAndChecksum(final ByteBuffer buffer, final long fileId, OLogManager.instance().error(this, "%s", null, message); if (checksumMode == OChecksumMode.StoreAndThrow) { - if (buffersToRelease == null) { - bufferPool.release(buffer); + if (pointersToRelease == null) { + bufferPool.release(pointer); } else { - for (final ByteBuffer bufferToRelease : buffersToRelease) { + for (final OPointer bufferToRelease : pointersToRelease) { bufferPool.release(bufferToRelease); } } @@ -2306,11 +2314,11 @@ private void verifyMagicAndChecksum(final ByteBuffer buffer, final long fileId, final String message = "Checksum verification failed for page `" + pageIndex + "` of `" + fileNameById(fileId) + "`."; OLogManager.instance().error(this, "%s", null, message); if (checksumMode == OChecksumMode.StoreAndThrow) { - if (buffersToRelease == null) { - bufferPool.release(buffer); + if (pointersToRelease == null) { + bufferPool.release(pointer); } else { - for (final ByteBuffer bufferToRelease : buffersToRelease) { - bufferPool.release(bufferToRelease); + for (final OPointer pointerToRelease : pointersToRelease) { + bufferPool.release(pointerToRelease); } } @@ -2799,14 +2807,14 @@ public void run() { ewcSize = exclusiveWriteCacheSize.get(); - if (ewcSize >= chunkSize && backgroundExclusiveInterval >= backroundExclusiveFlushBoundary) { + if (ewcSize >= chunkSize && backgroundExclusiveInterval >= backgroundExclusiveFlushBoundary) { final long backgroundTs = System.nanoTime(); final int backgroundPages = flushExclusiveWriteCache(null, (long) (0.1 * exclusiveWriteCacheMaxSize)); if (backgroundPages > 0) { final long endTs = System.nanoTime(); - backroundExclusiveFlushBoundary = 9 * (endTs - backgroundTs); + backgroundExclusiveFlushBoundary = 9 * (endTs - backgroundTs); } lastFlushTs = startTs; @@ -2900,7 +2908,7 @@ private int flushWriteCacheFromMinLSN(long segStart, long segEnd, int pagesFlush int flushedPages = 0; int copiedPages = 0; - final ArrayList> chunk = new ArrayList<>(pagesFlushLimit); + final ArrayList> chunk = new ArrayList<>(pagesFlushLimit); long currentSegment = segStart; @@ -2969,13 +2977,15 @@ private int flushWriteCacheFromMinLSN(long segStart, long segEnd, int pagesFlush final long version; final OLogSequenceNumber fullLogLSN; - final ByteBuffer copy = bufferPool.acquireDirect(false); + final OPointer directPointer = bufferPool.acquireDirect(false); + final ByteBuffer copy = directPointer.getNativeByteBuffer(); try { version = pointer.getVersion(); final ByteBuffer buffer = pointer.getBufferDuplicate(); fullLogLSN = pointer.getEndLSN(); + assert buffer != null; buffer.position(0); copy.position(0); @@ -2994,7 +3004,7 @@ private int flushWriteCacheFromMinLSN(long segStart, long segEnd, int pagesFlush copy.position(0); - chunk.add(new OTriple<>(version, copy, pointer)); + chunk.add(new OQuarto<>(version, copy, directPointer, pointer)); if (chunk.size() >= pagesFlushLimit || chunk.size() >= chunkSize) { flushedPages += flushPagesChunk(chunk, maxFullLogLSN); @@ -3035,8 +3045,8 @@ private int flushWriteCacheFromMinLSN(long segStart, long segEnd, int pagesFlush return flushedPages; } - private int flushPagesChunk(final ArrayList> chunk, OLogSequenceNumber fullLogLSN) - throws InterruptedException, IOException { + private int flushPagesChunk(final ArrayList> chunk, + OLogSequenceNumber fullLogLSN) throws InterruptedException, IOException { if (chunk.isEmpty()) { return 0; @@ -3071,18 +3081,22 @@ private int flushPagesChunk(final ArrayList quarto = chunk.get(i); + final ByteBuffer buffer = quarto.two; addMagicAndChecksum(buffer); buffer.position(0); buffers[i] = buffer; + directPointers[i] = quarto.three; } - final OTriple firstChunk = chunk.get(0); + final OQuarto firstChunk = chunk.get(0); - final OCachePointer firstCachePointer = firstChunk.getValue().getValue(); + final OCachePointer firstCachePointer = firstChunk.four; final long firstFileId = firstCachePointer.getFileId(); final long firstPageIndex = firstCachePointer.getPageIndex(); @@ -3094,15 +3108,15 @@ private int flushPagesChunk(final ArrayList triple : chunk) { - final OCachePointer pointer = triple.getValue().getValue(); + for (final OQuarto triple : chunk) { + final OCachePointer pointer = triple.four; final PageKey pageKey = new PageKey(internalFileId(pointer.getFileId()), pointer.getPageIndex()); - final long version = triple.getKey(); + final long version = triple.one; final Lock lock = lockManager.acquireExclusiveLock(pageKey); try { @@ -3157,7 +3171,7 @@ private int flushExclusiveWriteCache(CountDownLatch latch, long pagesToFlush) th final long ewcSize = exclusiveWriteCacheSize.get(); pagesToFlush = Math.min(Math.max(pagesToFlush, chunkSize), ewcSize); - final ArrayList> chunk = new ArrayList<>(chunkSize); + final ArrayList> chunk = new ArrayList<>(chunkSize); if (latch != null && ewcSize <= exclusiveWriteCacheMaxSize) { latch.countDown(); @@ -3193,13 +3207,16 @@ private int flushExclusiveWriteCache(CountDownLatch latch, long pagesToFlush) th } else { if (pointer.tryAcquireSharedLock()) { final OLogSequenceNumber fullLSN; - final ByteBuffer copy = bufferPool.acquireDirect(false); + + final OPointer directPointer = bufferPool.acquireDirect(false); + final ByteBuffer copy = directPointer.getNativeByteBuffer(); try { version = pointer.getVersion(); final ByteBuffer buffer = pointer.getBufferDuplicate(); fullLSN = pointer.getEndLSN(); + assert buffer != null; buffer.position(0); copy.position(0); @@ -3219,22 +3236,20 @@ private int flushExclusiveWriteCache(CountDownLatch latch, long pagesToFlush) th copy.position(0); if (chunk.isEmpty()) { - chunk.add(new OTriple<>(version, copy, pointer)); + chunk.add(new OQuarto<>(version, copy, directPointer, pointer)); } else { if (lastFileId != pointer.getFileId() || lastPageIndex != pointer.getPageIndex() - 1) { - if (!chunk.isEmpty()) { - flushedPages += flushPagesChunk(chunk, maxFullLogLSN); + flushedPages += flushPagesChunk(chunk, maxFullLogLSN); - if (latch != null && exclusiveWriteCacheSize.get() <= exclusiveWriteCacheMaxSize) { - latch.countDown(); - } + if (latch != null && exclusiveWriteCacheSize.get() <= exclusiveWriteCacheMaxSize) { + latch.countDown(); } maxFullLogLSN = null; - chunk.add(new OTriple<>(version, copy, pointer)); + chunk.add(new OQuarto<>(version, copy, directPointer, pointer)); } else { - chunk.add(new OTriple<>(version, copy, pointer)); + chunk.add(new OQuarto<>(version, copy, directPointer, pointer)); } } @@ -3309,16 +3324,19 @@ public Void call() throws Exception { try { final ByteBuffer buffer = pagePointer.getBufferDuplicate(); - final ByteBuffer copy = bufferPool.acquireDirect(false); + final OPointer directPointer = bufferPool.acquireDirect(false); try { + final ByteBuffer copy = directPointer.getNativeByteBuffer(); + + assert buffer != null; buffer.position(0); copy.put(buffer); final OLogSequenceNumber endLSN = pagePointer.getEndLSN(); flushPage(pageKey.fileId, pageKey.pageIndex, copy, endLSN); } finally { - bufferPool.release(copy); + bufferPool.release(directPointer); } removeFromDirtyPages(pageKey); diff --git a/core/src/main/java/com/orientechnologies/orient/core/storage/memory/ODirectMemoryOnlyDiskCache.java b/core/src/main/java/com/orientechnologies/orient/core/storage/memory/ODirectMemoryOnlyDiskCache.java index 46f7032312b..36170be130e 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/storage/memory/ODirectMemoryOnlyDiskCache.java +++ b/core/src/main/java/com/orientechnologies/orient/core/storage/memory/ODirectMemoryOnlyDiskCache.java @@ -21,6 +21,7 @@ package com.orientechnologies.orient.core.storage.memory; import com.orientechnologies.common.directmemory.OByteBufferPool; +import com.orientechnologies.common.directmemory.OPointer; import com.orientechnologies.common.types.OModifiableBoolean; import com.orientechnologies.common.util.OCommonConst; import com.orientechnologies.orient.core.command.OCommandOutputListener; @@ -39,8 +40,6 @@ import com.orientechnologies.orient.core.storage.impl.local.statistic.OPerformanceStatisticManager; import com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic; -import java.io.IOException; -import java.nio.ByteBuffer; import java.nio.file.Path; import java.util.HashMap; import java.util.Map; @@ -57,7 +56,7 @@ * @author Andrey Lomakin (a.lomakin-at-orientdb.com) * @since 6/24/14 */ -public class ODirectMemoryOnlyDiskCache extends OAbstractWriteCache implements OReadCache, OWriteCache { +public final class ODirectMemoryOnlyDiskCache extends OAbstractWriteCache implements OReadCache, OWriteCache { private final Lock metadataLock = new ReentrantLock(); private final Map fileNameIdMap = new HashMap<>(); @@ -81,12 +80,12 @@ public class ODirectMemoryOnlyDiskCache extends OAbstractWriteCache implements O * {@inheritDoc} */ @Override - public Path getRootDirectory() { + public final Path getRootDirectory() { return null; } @Override - public long addFile(String fileName, OWriteCache writeCache) { + public final long addFile(String fileName, OWriteCache writeCache) { metadataLock.lock(); try { Integer fileId = fileNameIdMap.get(fileName); @@ -112,12 +111,13 @@ public long addFile(String fileName, OWriteCache writeCache) { } @Override - public long fileIdByName(String fileName) { + public final long fileIdByName(String fileName) { metadataLock.lock(); try { Integer fileId = fileNameIdMap.get(fileName); - if (fileId != null) + if (fileId != null) { return fileId; + } } finally { metadataLock.unlock(); } @@ -126,17 +126,17 @@ public long fileIdByName(String fileName) { } @Override - public int internalFileId(long fileId) { + public final int internalFileId(long fileId) { return extractFileId(fileId); } @Override - public long externalFileId(int fileId) { + public final long externalFileId(int fileId) { return composeFileId(id, fileId); } @Override - public long bookFileId(String fileName) { + public final long bookFileId(String fileName) { metadataLock.lock(); try { counter++; @@ -147,28 +147,30 @@ public long bookFileId(String fileName) { } @Override - public void addBackgroundExceptionListener(OBackgroundExceptionListener listener) { + public final void addBackgroundExceptionListener(OBackgroundExceptionListener listener) { } @Override - public void removeBackgroundExceptionListener(OBackgroundExceptionListener listener) { + public final void removeBackgroundExceptionListener(OBackgroundExceptionListener listener) { } @Override - public void checkCacheOverflow() throws InterruptedException { + public final void checkCacheOverflow() { } @Override - public long addFile(String fileName, long fileId, OWriteCache writeCache) { + public final long addFile(String fileName, long fileId, OWriteCache writeCache) { int intId = extractFileId(fileId); metadataLock.lock(); try { - if (files.containsKey(intId)) + if (files.containsKey(intId)) { throw new OStorageException("File with id " + intId + " already exists."); + } - if (fileNameIdMap.containsKey(fileName)) + if (fileNameIdMap.containsKey(fileName)) { throw new OStorageException(fileName + " already exists."); + } files.put(intId, new MemoryFile(id, intId)); fileNameIdMap.put(fileName, intId); @@ -181,13 +183,14 @@ public long addFile(String fileName, long fileId, OWriteCache writeCache) { } @Override - public OCacheEntry loadForWrite(long fileId, long pageIndex, boolean checkPinnedPages, OWriteCache writeCache, int pageCount, - boolean verifyChecksums, OLogSequenceNumber startLSN) throws IOException { + public final OCacheEntry loadForWrite(long fileId, long pageIndex, boolean checkPinnedPages, OWriteCache writeCache, + int pageCount, boolean verifyChecksums, OLogSequenceNumber startLSN) { final OCacheEntry cacheEntry = doLoad(fileId, pageIndex); - if (cacheEntry == null) + if (cacheEntry == null) { return null; + } cacheEntry.acquireExclusiveLock(); @@ -195,13 +198,14 @@ public OCacheEntry loadForWrite(long fileId, long pageIndex, boolean checkPinned } @Override - public OCacheEntry loadForRead(long fileId, long pageIndex, boolean checkPinnedPages, OWriteCache writeCache, int pageCount, - boolean verifyChecksums) throws IOException { + public final OCacheEntry loadForRead(long fileId, long pageIndex, boolean checkPinnedPages, OWriteCache writeCache, int pageCount, + boolean verifyChecksums) { final OCacheEntry cacheEntry = doLoad(fileId, pageIndex); - if (cacheEntry == null) + if (cacheEntry == null) { return null; + } cacheEntry.acquireSharedLock(); @@ -221,8 +225,9 @@ private OCacheEntry doLoad(long fileId, long pageIndex) { final MemoryFile memoryFile = getFile(intId); final OCacheEntry cacheEntry = memoryFile.loadPage(pageIndex); - if (cacheEntry == null) + if (cacheEntry == null) { return null; + } //noinspection SynchronizationOnLocalVariableOrMethodParameter synchronized (cacheEntry) { @@ -238,12 +243,12 @@ private OCacheEntry doLoad(long fileId, long pageIndex) { } @Override - public void pinPage(OCacheEntry cacheEntry, OWriteCache writeCache) { + public final void pinPage(OCacheEntry cacheEntry, OWriteCache writeCache) { } @Override - public OCacheEntry allocateNewPage(long fileId, OWriteCache writeCache, boolean verifyChecksums, OLogSequenceNumber startLSN, - boolean initPage) { + public final OCacheEntry allocateNewPage(long fileId, OWriteCache writeCache, boolean verifyChecksums, + OLogSequenceNumber startLSN, boolean initPage) { final OSessionStoragePerformanceStatistic sessionStoragePerformanceStatistic = performanceStatisticManager .getSessionPerformanceStatistic(); @@ -274,27 +279,28 @@ public OCacheEntry allocateNewPage(long fileId, OWriteCache writeCache, boolean private MemoryFile getFile(int fileId) { final MemoryFile memoryFile = files.get(fileId); - if (memoryFile == null) + if (memoryFile == null) { throw new OStorageException("File with id " + fileId + " does not exist"); + } return memoryFile; } @Override - public void releaseFromWrite(OCacheEntry cacheEntry, OWriteCache writeCache) { + public final void releaseFromWrite(OCacheEntry cacheEntry, OWriteCache writeCache) { cacheEntry.releaseExclusiveLock(); doRelease(cacheEntry); } @Override - public void releaseFromRead(OCacheEntry cacheEntry, OWriteCache writeCache) { + public final void releaseFromRead(OCacheEntry cacheEntry, OWriteCache writeCache) { cacheEntry.releaseSharedLock(); doRelease(cacheEntry); } - private void doRelease(OCacheEntry cacheEntry) { + private static void doRelease(OCacheEntry cacheEntry) { //noinspection SynchronizationOnLocalVariableOrMethodParameter synchronized (cacheEntry) { cacheEntry.decrementUsages(); @@ -304,7 +310,7 @@ private void doRelease(OCacheEntry cacheEntry) { } @Override - public long getFilledUpTo(long fileId) { + public final long getFilledUpTo(long fileId) { int intId = extractFileId(fileId); final MemoryFile memoryFile = getFile(intId); @@ -312,40 +318,43 @@ public long getFilledUpTo(long fileId) { } @Override - public void flush(long fileId) { + public final void flush(long fileId) { } @Override - public void close(long fileId, boolean flush) { + public final void close(long fileId, boolean flush) { } @Override - public void deleteFile(long fileId) { + public final void deleteFile(long fileId) { int intId = extractFileId(fileId); metadataLock.lock(); try { final String fileName = fileIdNameMap.remove(intId); - if (fileName == null) + if (fileName == null) { return; + } fileNameIdMap.remove(fileName); MemoryFile file = files.remove(intId); - if (file != null) + if (file != null) { file.clear(); + } } finally { metadataLock.unlock(); } } @Override - public void renameFile(long fileId, String newFileName) { + public final void renameFile(long fileId, String newFileName) { int intId = extractFileId(fileId); metadataLock.lock(); try { String fileName = fileIdNameMap.get(intId); - if (fileName == null) + if (fileName == null) { return; + } fileNameIdMap.remove(fileName); @@ -357,12 +366,12 @@ public void renameFile(long fileId, String newFileName) { } @Override - public void replaceFileContentWith(long fileId, Path newContentFile) throws IOException { + public final void replaceFileContentWith(long fileId, Path newContentFile) { throw new UnsupportedOperationException("replacing file content is not supported for memory storage"); } @Override - public void truncateFile(long fileId) { + public final void truncateFile(long fileId) { int intId = extractFileId(fileId); final MemoryFile file = getFile(intId); @@ -370,25 +379,26 @@ public void truncateFile(long fileId) { } @Override - public void flush() { + public final void flush() { } @Override - public long[] close() { + public final long[] close() { return new long[0]; } @Override - public void clear() { + public final void clear() { delete(); } @Override - public long[] delete() { + public final long[] delete() { metadataLock.lock(); try { - for (MemoryFile file : files.values()) + for (MemoryFile file : files.values()) { file.clear(); + } files.clear(); fileIdNameMap.clear(); @@ -401,7 +411,7 @@ public long[] delete() { } @Override - public void deleteStorage(OWriteCache writeCache) throws IOException { + public final void deleteStorage(OWriteCache writeCache) { delete(); } @@ -409,7 +419,8 @@ public void deleteStorage(OWriteCache writeCache) throws IOException { * {@inheritDoc} */ @Override - public void closeStorage(OWriteCache writeCache) throws IOException { + public final void closeStorage(OWriteCache writeCache) { + //noinspection ResultOfMethodCallIgnored close(); } @@ -417,28 +428,29 @@ public void closeStorage(OWriteCache writeCache) throws IOException { * {@inheritDoc} */ @Override - public void loadCacheState(OWriteCache writeCache) { + public final void loadCacheState(OWriteCache writeCache) { } /** * {@inheritDoc} */ @Override - public void storeCacheState(OWriteCache writeCache) { + public final void storeCacheState(OWriteCache writeCache) { } @Override - public OPageDataVerificationError[] checkStoredPages(OCommandOutputListener commandOutputListener) { + public final OPageDataVerificationError[] checkStoredPages(OCommandOutputListener commandOutputListener) { return OCommonConst.EMPTY_PAGE_DATA_VERIFICATION_ARRAY; } @Override - public boolean exists(String name) { + public final boolean exists(String name) { metadataLock.lock(); try { final Integer fileId = fileNameIdMap.get(name); - if (fileId == null) + if (fileId == null) { return false; + } final MemoryFile memoryFile = files.get(fileId); return memoryFile != null; @@ -448,7 +460,7 @@ public boolean exists(String name) { } @Override - public boolean exists(long fileId) { + public final boolean exists(long fileId) { int intId = extractFileId(fileId); metadataLock.lock(); @@ -461,7 +473,7 @@ public boolean exists(long fileId) { } @Override - public String fileNameById(long fileId) { + public final String fileNameById(long fileId) { int intId = extractFileId(fileId); metadataLock.lock(); @@ -473,7 +485,7 @@ public String fileNameById(long fileId) { } @Override - public String nativeFileNameById(long fileId) { + public final String nativeFileNameById(long fileId) { return fileNameById(fileId); } @@ -506,17 +518,17 @@ private OCacheEntry addNewPage() { long index; do { - if (content.isEmpty()) + if (content.isEmpty()) { index = 0; - else { + } else { long lastIndex = content.lastKey(); index = lastIndex + 1; } final OByteBufferPool bufferPool = OByteBufferPool.instance(null); - final ByteBuffer buffer = bufferPool.acquireDirect(true); + final OPointer pointer = bufferPool.acquireDirect(true); - final OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, id, index); + final OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, id, index); cachePointer.incrementReferrer(); cacheEntry = new OCacheEntryImpl(composeFileId(storageId, id), index, cachePointer); @@ -538,8 +550,9 @@ private OCacheEntry addNewPage() { private long size() { clearLock.readLock().lock(); try { - if (content.isEmpty()) + if (content.isEmpty()) { return 0; + } try { return content.lastKey() + 1; @@ -574,22 +587,24 @@ private void clear() { clearLock.writeLock().unlock(); } - if (thereAreNotReleased) + if (thereAreNotReleased) { throw new IllegalStateException("Some cache entries were not released. Storage may be in invalid state."); + } } } @Override - public long getUsedMemory() { + public final long getUsedMemory() { long totalPages = 0; - for (MemoryFile file : files.values()) + for (MemoryFile file : files.values()) { totalPages += file.getUsedMemory(); + } return totalPages * pageSize; } @Override - public boolean checkLowDiskSpace() throws IOException { + public final boolean checkLowDiskSpace() { return true; } @@ -597,26 +612,26 @@ public boolean checkLowDiskSpace() throws IOException { * Not implemented because has no sense */ @Override - public void addPageIsBrokenListener(OPageIsBrokenListener listener) { + public final void addPageIsBrokenListener(OPageIsBrokenListener listener) { } /** * Not implemented because has no sense */ @Override - public void removePageIsBrokenListener(OPageIsBrokenListener listener) { + public final void removePageIsBrokenListener(OPageIsBrokenListener listener) { } @Override - public void addLowDiskSpaceListener(OLowDiskSpaceListener listener) { + public final void addLowDiskSpaceListener(OLowDiskSpaceListener listener) { } @Override - public void removeLowDiskSpaceListener(OLowDiskSpaceListener listener) { + public final void removeLowDiskSpaceListener(OLowDiskSpaceListener listener) { } @Override - public long loadFile(String fileName) { + public final long loadFile(String fileName) { metadataLock.lock(); try { Integer fileId = fileNameIdMap.get(fileName); @@ -632,60 +647,60 @@ public long loadFile(String fileName) { } @Override - public long addFile(String fileName) { + public final long addFile(String fileName) { return addFile(fileName, null); } @Override - public long addFile(String fileName, long fileId) { + public final long addFile(String fileName, long fileId) { return addFile(fileName, fileId, null); } @Override - public void store(long fileId, long pageIndex, OCachePointer dataPointer) { + public final void store(long fileId, long pageIndex, OCachePointer dataPointer) { throw new UnsupportedOperationException(); } @Override - public void makeFuzzyCheckpoint(long segmentId) throws IOException { + public final void makeFuzzyCheckpoint(long segmentId) { } @Override - public void flushTillSegment(long segmentId) { + public final void flushTillSegment(long segmentId) { } @Override - public Long getMinimalNotFlushedSegment() { + public final Long getMinimalNotFlushedSegment() { throw new UnsupportedOperationException(); } @Override - public void updateDirtyPagesTable(OCachePointer pointer, OLogSequenceNumber startLSN) { + public final void updateDirtyPagesTable(OCachePointer pointer, OLogSequenceNumber startLSN) { } @Override - public OCachePointer[] load(long fileId, long startPageIndex, int pageCount, boolean addNewPages, boolean initNewPage, + public final OCachePointer[] load(long fileId, long startPageIndex, int pageCount, boolean addNewPages, boolean initNewPage, OModifiableBoolean cacheHit, boolean verifyChecksums) { throw new UnsupportedOperationException(); } @Override - public long getExclusiveWriteCachePagesSize() { + public final long getExclusiveWriteCachePagesSize() { return 0; } @Override - public void truncateFile(long fileId, OWriteCache writeCache) throws IOException { + public final void truncateFile(long fileId, OWriteCache writeCache) { truncateFile(fileId); } @Override - public int getId() { + public final int getId() { return id; } @Override - public Map files() { + public final Map files() { final Map result = new HashMap<>(); metadataLock.lock(); @@ -706,7 +721,7 @@ public Map files() { * @inheritDoc */ @Override - public int pageSize() { + public final int pageSize() { return pageSize; } @@ -714,7 +729,7 @@ public int pageSize() { * @inheritDoc */ @Override - public boolean fileIdsAreEqual(long firsId, long secondId) { + public final boolean fileIdsAreEqual(long firsId, long secondId) { final int firstIntId = extractFileId(firsId); final int secondIntId = extractFileId(secondId); @@ -722,17 +737,17 @@ public boolean fileIdsAreEqual(long firsId, long secondId) { } @Override - public String restoreFileById(long fileId) throws IOException { + public final String restoreFileById(long fileId) { return null; } @Override - public void closeFile(long fileId, boolean flush, OWriteCache writeCache) { + public final void closeFile(long fileId, boolean flush, OWriteCache writeCache) { close(fileId, flush); } @Override - public void deleteFile(long fileId, OWriteCache writeCache) throws IOException { + public final void deleteFile(long fileId, OWriteCache writeCache) { deleteFile(fileId); } } diff --git a/core/src/test/java/com/orientechnologies/common/directmemory/OByteBufferPoolTest.java b/core/src/test/java/com/orientechnologies/common/directmemory/OByteBufferPoolTest.java index a74bf0bb22c..2513596b303 100755 --- a/core/src/test/java/com/orientechnologies/common/directmemory/OByteBufferPoolTest.java +++ b/core/src/test/java/com/orientechnologies/common/directmemory/OByteBufferPoolTest.java @@ -33,23 +33,23 @@ public void testByteBufferAllocationZeroPool() { final ODirectMemoryAllocator allocator = new ODirectMemoryAllocator(); final OByteBufferPool byteBufferPool = new OByteBufferPool(42, allocator, 0); - final ByteBuffer bufferOne = byteBufferPool.acquireDirect(false); - Assert.assertEquals(42, bufferOne.capacity()); + final OPointer pointerOne = byteBufferPool.acquireDirect(false); + Assert.assertEquals(42, pointerOne.getNativeByteBuffer().capacity()); Assert.assertEquals(42, allocator.getMemoryConsumption()); Assert.assertEquals(0, byteBufferPool.getPoolSize()); - final ByteBuffer bufferTwo = byteBufferPool.acquireDirect(true); - Assert.assertEquals(42, bufferTwo.capacity()); + final OPointer pointerTwo = byteBufferPool.acquireDirect(true); + Assert.assertEquals(42, pointerTwo.getNativeByteBuffer().capacity()); Assert.assertEquals(84, allocator.getMemoryConsumption()); - assertBufferIsClear(bufferTwo); + assertBufferIsClear(pointerTwo.getNativeByteBuffer()); - byteBufferPool.release(bufferOne); + byteBufferPool.release(pointerOne); Assert.assertEquals(0, byteBufferPool.getPoolSize()); Assert.assertEquals(42, allocator.getMemoryConsumption()); - byteBufferPool.release(bufferTwo); + byteBufferPool.release(pointerTwo); Assert.assertEquals(0, byteBufferPool.getPoolSize()); Assert.assertEquals(0, allocator.getMemoryConsumption()); @@ -62,120 +62,89 @@ public void testByteBufferAllocationTwoPagesPool() { final ODirectMemoryAllocator allocator = new ODirectMemoryAllocator(); final OByteBufferPool byteBufferPool = new OByteBufferPool(42, allocator, 2); - ByteBuffer bufferOne = byteBufferPool.acquireDirect(false); + OPointer pointerOne = byteBufferPool.acquireDirect(false); - Assert.assertEquals(42, bufferOne.capacity()); + Assert.assertEquals(42, pointerOne.getNativeByteBuffer().capacity()); Assert.assertEquals(0, byteBufferPool.getPoolSize()); Assert.assertEquals(42, allocator.getMemoryConsumption()); - ByteBuffer bufferTwo = byteBufferPool.acquireDirect(true); - Assert.assertEquals(42, bufferTwo.capacity()); + OPointer pointerTwo = byteBufferPool.acquireDirect(true); + Assert.assertEquals(42, pointerTwo.getNativeByteBuffer().capacity()); Assert.assertEquals(0, byteBufferPool.getPoolSize()); Assert.assertEquals(84, allocator.getMemoryConsumption()); - assertBufferIsClear(bufferTwo); + assertBufferIsClear(pointerTwo.getNativeByteBuffer()); - ByteBuffer bufferThree = byteBufferPool.acquireDirect(false); + OPointer pointerThree = byteBufferPool.acquireDirect(false); - Assert.assertEquals(42, bufferThree.capacity()); + Assert.assertEquals(42, pointerThree.getNativeByteBuffer().capacity()); Assert.assertEquals(0, byteBufferPool.getPoolSize()); Assert.assertEquals(126, allocator.getMemoryConsumption()); - byteBufferPool.release(bufferOne); + byteBufferPool.release(pointerOne); Assert.assertEquals(1, byteBufferPool.getPoolSize()); Assert.assertEquals(126, allocator.getMemoryConsumption()); - byteBufferPool.release(bufferTwo); + byteBufferPool.release(pointerTwo); Assert.assertEquals(2, byteBufferPool.getPoolSize()); Assert.assertEquals(126, allocator.getMemoryConsumption()); - byteBufferPool.release(bufferThree); + byteBufferPool.release(pointerThree); Assert.assertEquals(2, byteBufferPool.getPoolSize()); Assert.assertEquals(84, allocator.getMemoryConsumption()); - bufferOne = byteBufferPool.acquireDirect(true); + pointerOne = byteBufferPool.acquireDirect(true); - Assert.assertEquals(42, bufferOne.capacity()); - Assert.assertEquals(0, bufferOne.position()); + Assert.assertEquals(42, pointerOne.getNativeByteBuffer().capacity()); Assert.assertEquals(1, byteBufferPool.getPoolSize()); Assert.assertEquals(84, allocator.getMemoryConsumption()); - assertBufferIsClear(bufferOne); + assertBufferIsClear(pointerOne.getNativeByteBuffer()); - bufferTwo = byteBufferPool.acquireDirect(true); + pointerTwo = byteBufferPool.acquireDirect(true); - Assert.assertEquals(42, bufferTwo.capacity()); - Assert.assertEquals(0, bufferTwo.position()); + Assert.assertEquals(42, pointerTwo.getNativeByteBuffer().capacity()); Assert.assertEquals(0, byteBufferPool.getPoolSize()); Assert.assertEquals(84, allocator.getMemoryConsumption()); - assertBufferIsClear(bufferTwo); + assertBufferIsClear(pointerTwo.getNativeByteBuffer()); - bufferThree = byteBufferPool.acquireDirect(false); + pointerThree = byteBufferPool.acquireDirect(false); - Assert.assertEquals(42, bufferThree.capacity()); - Assert.assertEquals(0, bufferThree.position()); + Assert.assertEquals(42, pointerThree.getNativeByteBuffer().capacity()); Assert.assertEquals(0, byteBufferPool.getPoolSize()); Assert.assertEquals(126, allocator.getMemoryConsumption()); - byteBufferPool.release(bufferThree); + byteBufferPool.release(pointerThree); Assert.assertEquals(1, byteBufferPool.getPoolSize()); Assert.assertEquals(126, allocator.getMemoryConsumption()); - bufferThree = byteBufferPool.acquireDirect(true); + pointerThree = byteBufferPool.acquireDirect(true); - Assert.assertEquals(42, bufferThree.capacity()); - Assert.assertEquals(0, bufferThree.position()); + Assert.assertEquals(42, pointerThree.getNativeByteBuffer().capacity()); Assert.assertEquals(0, byteBufferPool.getPoolSize()); Assert.assertEquals(126, allocator.getMemoryConsumption()); - assertBufferIsClear(bufferThree); + assertBufferIsClear(pointerThree.getNativeByteBuffer()); - byteBufferPool.release(bufferThree); + byteBufferPool.release(pointerThree); Assert.assertEquals(1, byteBufferPool.getPoolSize()); Assert.assertEquals(126, allocator.getMemoryConsumption()); - byteBufferPool.release(bufferOne); + byteBufferPool.release(pointerOne); Assert.assertEquals(2, byteBufferPool.getPoolSize()); Assert.assertEquals(126, allocator.getMemoryConsumption()); - try { - byteBufferPool.release(bufferThree); - Assert.fail(); - } catch (IllegalArgumentException e) { - Assert.assertTrue(true); - } - Assert.assertEquals(2, byteBufferPool.getPoolSize()); Assert.assertEquals(126, allocator.getMemoryConsumption()); - byteBufferPool.release(bufferTwo); - - Assert.assertEquals(2, byteBufferPool.getPoolSize()); - Assert.assertEquals(84, allocator.getMemoryConsumption()); - - try { - byteBufferPool.release(bufferTwo); - Assert.fail(); - } catch (IllegalArgumentException e) { - Assert.assertTrue(true); - } - - Assert.assertEquals(2, byteBufferPool.getPoolSize()); - Assert.assertEquals(84, allocator.getMemoryConsumption()); - - try { - byteBufferPool.release(bufferOne); - Assert.fail(); - } catch (IllegalArgumentException e) { - Assert.assertTrue(true); - } + byteBufferPool.release(pointerTwo); Assert.assertEquals(2, byteBufferPool.getPoolSize()); Assert.assertEquals(84, allocator.getMemoryConsumption()); @@ -222,11 +191,10 @@ private void assertBufferIsClear(ByteBuffer bufferTwo) { } private static final class Allocator implements Callable { - private final OByteBufferPool pool; - private final ThreadLocalRandom random = ThreadLocalRandom.current(); - private final AtomicBoolean stop; - private long allocatedSize; - private List allocatedBuffers = new ArrayList<>(); + private final OByteBufferPool pool; + private final ThreadLocalRandom random = ThreadLocalRandom.current(); + private final AtomicBoolean stop; + private final List allocatedPointers = new ArrayList<>(); private Allocator(OByteBufferPool pool, AtomicBoolean stop) { this.pool = pool; @@ -234,36 +202,36 @@ private Allocator(OByteBufferPool pool, AtomicBoolean stop) { } @Override - public Void call() throws Exception { + public Void call() { try { while (!stop.get()) { - if (allocatedBuffers.size() < 500) { - ByteBuffer buffer = pool.acquireDirect(false); - allocatedBuffers.add(buffer); - } else if (allocatedBuffers.size() < 1000) { + if (allocatedPointers.size() < 500) { + OPointer pointer = pool.acquireDirect(false); + allocatedPointers.add(pointer); + } else if (allocatedPointers.size() < 1000) { if (random.nextDouble() <= 0.5) { - ByteBuffer buffer = pool.acquireDirect(false); - allocatedBuffers.add(buffer); + OPointer pointer = pool.acquireDirect(false); + allocatedPointers.add(pointer); } else { - final int bufferToRemove = random.nextInt(allocatedBuffers.size()); - final ByteBuffer buffer = allocatedBuffers.remove(bufferToRemove); - pool.release(buffer); + final int bufferToRemove = random.nextInt(allocatedPointers.size()); + final OPointer pointer = allocatedPointers.remove(bufferToRemove); + pool.release(pointer); } } else { if (random.nextDouble() <= 0.4) { - ByteBuffer buffer = pool.acquireDirect(false); - allocatedBuffers.add(buffer); + OPointer pointer = pool.acquireDirect(false); + allocatedPointers.add(pointer); } else { - final int bufferToRemove = random.nextInt(allocatedBuffers.size()); - final ByteBuffer buffer = allocatedBuffers.remove(bufferToRemove); - pool.release(buffer); + final int bufferToRemove = random.nextInt(allocatedPointers.size()); + final OPointer pointer = allocatedPointers.remove(bufferToRemove); + pool.release(pointer); } } } - System.out.println("Allocated buffers " + allocatedBuffers.size()); - for (ByteBuffer buffer : allocatedBuffers) { - pool.release(buffer); + System.out.println("Allocated buffers " + allocatedPointers.size()); + for (OPointer pointer : allocatedPointers) { + pool.release(pointer); } } catch (Exception | Error e) { e.printStackTrace(); diff --git a/core/src/test/java/com/orientechnologies/orient/core/storage/cache/local/twoq/ReadWriteDiskCacheTest.java b/core/src/test/java/com/orientechnologies/orient/core/storage/cache/local/twoq/ReadWriteDiskCacheTest.java index 996d953e3a4..589fbba5589 100755 --- a/core/src/test/java/com/orientechnologies/orient/core/storage/cache/local/twoq/ReadWriteDiskCacheTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/storage/cache/local/twoq/ReadWriteDiskCacheTest.java @@ -2,6 +2,7 @@ import com.orientechnologies.common.collection.closabledictionary.OClosableLinkedContainer; import com.orientechnologies.common.directmemory.OByteBufferPool; +import com.orientechnologies.common.directmemory.OPointer; import com.orientechnologies.common.serialization.types.OIntegerSerializer; import com.orientechnologies.common.serialization.types.OLongSerializer; import com.orientechnologies.common.serialization.types.OStringSerializer; @@ -191,8 +192,7 @@ private void closeBufferAndDeleteFile() throws IOException { private void initBuffer() throws IOException, InterruptedException { writeAheadLog = new OCASDiskWriteAheadLog(storageName, storagePath, storagePath, 12_000, 128, Integer.MAX_VALUE, - Integer.MAX_VALUE, - 25, true, Locale.US, -1, 1024L * 1024 * 1024, 1000, true, false, true, 10); + Integer.MAX_VALUE, 25, true, Locale.US, -1, 1024L * 1024 * 1024, 1000, true, false, true, 10); writeBuffer = new OWOWCache(PAGE_SIZE, BUFFER_POOL, writeAheadLog, -1, 10, WRITE_CACHE_MAX_SIZE, storagePath, storageName, OStringSerializer.INSTANCE, files, 1, OChecksumMode.StoreAndThrow, false, true, 10); @@ -232,7 +232,7 @@ public void testAddFourItems() throws IOException { final OByteBufferPool bufferPool = OByteBufferPool.instance(null); for (int i = 0; i < 4; i++) { - OCacheEntry entry = generateEntry(fileId, i, entries[i].getCachePointer().getBufferDuplicate(), bufferPool); + OCacheEntry entry = generateEntry(fileId, i, entries[i].getCachePointer().getPointer(), bufferPool); Assert.assertEquals(a1in.get(entry.getFileId(), entry.getPageIndex()), entry); } @@ -285,6 +285,7 @@ public void testAddFourItemsInFourDifferentFiles() throws IOException { final ByteBuffer buffer = entries[i].getCachePointer().getBufferDuplicate(); + assert buffer != null; buffer.position(systemOffset); buffer.put(new byte[] { (byte) i, 1, 2, (byte) (seed + n), 4, 5, 6, (byte) (i + n) }); @@ -370,6 +371,7 @@ public void testAddFourItemsInFourDifferentFilesCloseAndOpen() throws Exception final ByteBuffer buffer = entries[i].getCachePointer().getBufferDuplicate(); + assert buffer != null; buffer.position(systemOffset); buffer.put(new byte[] { (byte) i, 1, 2, (byte) (seed + n), 4, 5, 6, (byte) (i + n) }); @@ -441,6 +443,7 @@ public void testFrequentlyReadItemsAreMovedInAm() throws Exception { } final ByteBuffer buffer = entries[i].getCachePointer().getBufferDuplicate(); + assert buffer != null; buffer.position(systemOffset); buffer.put(new byte[] { (byte) i, 1, 2, seed, 4, 5, 6, (byte) i }); @@ -475,7 +478,7 @@ public void testFrequentlyReadItemsAreMovedInAm() throws Exception { final OByteBufferPool bufferPool = OByteBufferPool.instance(null); for (int i = 2; i < 4; i++) { - OCacheEntry lruEntry = generateEntry(fileId, i, entries[i].getCachePointer().getBufferDuplicate(), bufferPool); + OCacheEntry lruEntry = generateEntry(fileId, i, entries[i].getCachePointer().getPointer(), bufferPool); Assert.assertEquals(am.get(fileId, i), lruEntry); } @@ -485,7 +488,7 @@ public void testFrequentlyReadItemsAreMovedInAm() throws Exception { } for (int i = 6; i < 8; i++) { - OCacheEntry lruEntry = generateEntry(fileId, i, entries[i].getCachePointer().getBufferDuplicate(), bufferPool); + OCacheEntry lruEntry = generateEntry(fileId, i, entries[i].getCachePointer().getPointer(), bufferPool); Assert.assertEquals(a1in.get(fileId, i), lruEntry); } } @@ -515,6 +518,7 @@ public void testFrequentlyAddItemsAreMovedInAm() throws Exception { } final ByteBuffer buffer = entries[i].getCachePointer().getBufferDuplicate(); + assert buffer != null; buffer.position(systemOffset); buffer.put(new byte[] { (byte) i, 1, 2, seed, 4, 5, 6, (byte) i }); setLsn(buffer, new OLogSequenceNumber(1, i)); @@ -532,7 +536,7 @@ public void testFrequentlyAddItemsAreMovedInAm() throws Exception { OByteBufferPool bufferPool = OByteBufferPool.instance(null); for (int i = 6; i < 10; i++) { - OCacheEntry lruEntry = generateEntry(fileId, i, entries[i].getCachePointer().getBufferDuplicate(), bufferPool); + OCacheEntry lruEntry = generateEntry(fileId, i, entries[i].getCachePointer().getPointer(), bufferPool); Assert.assertEquals(a1in.get(fileId, i), lruEntry); } @@ -551,7 +555,7 @@ public void testFrequentlyAddItemsAreMovedInAm() throws Exception { Assert.assertEquals(a1out.size(), 2); for (int i = 4; i < 6; i++) { - OCacheEntry lruEntry = generateEntry(fileId, i, entries[i].getCachePointer().getBufferDuplicate(), bufferPool); + OCacheEntry lruEntry = generateEntry(fileId, i, entries[i].getCachePointer().getPointer(), bufferPool); Assert.assertEquals(am.get(fileId, i), lruEntry); } @@ -561,7 +565,7 @@ public void testFrequentlyAddItemsAreMovedInAm() throws Exception { } for (int i = 8; i < 10; i++) { - OCacheEntry lruEntry = generateEntry(fileId, i, entries[i].getCachePointer().getBufferDuplicate(), bufferPool); + OCacheEntry lruEntry = generateEntry(fileId, i, entries[i].getCachePointer().getPointer(), bufferPool); Assert.assertEquals(a1in.get(fileId, i), lruEntry); } @@ -587,6 +591,7 @@ public void testReadFourItems() throws IOException { } final ByteBuffer buffer = entries[i].getCachePointer().getBufferDuplicate(); + assert buffer != null; buffer.position(systemOffset); buffer.put(new byte[] { (byte) i, 1, 2, seed, 4, 5, 6, (byte) i }); setLsn(buffer, new OLogSequenceNumber(1, i)); @@ -615,7 +620,7 @@ public void testReadFourItems() throws IOException { OByteBufferPool bufferPool = OByteBufferPool.instance(null); for (int i = 0; i < 4; i++) { - OCacheEntry entry = generateEntry(fileId, i, entries[i].getCachePointer().getBufferDuplicate(), bufferPool); + OCacheEntry entry = generateEntry(fileId, i, entries[i].getCachePointer().getPointer(), bufferPool); Assert.assertEquals(a1in.get(entry.getFileId(), entry.getPageIndex()), entry); } @@ -636,6 +641,7 @@ public void testPrefetchPagesInA1inQueue() throws Exception { } final ByteBuffer buffer = cacheEntry.getCachePointer().getBufferDuplicate(); + assert buffer != null; buffer.position(systemOffset); buffer.put(userData); @@ -702,6 +708,7 @@ public void testPrefetchPagesInA1inAmQueue() throws Exception { } final ByteBuffer buffer = cacheEntry.getCachePointer().getBufferDuplicate(); + assert buffer != null; buffer.position(systemOffset); buffer.put(userData); @@ -786,6 +793,7 @@ public void testPrefetchPagesInPinnedPages() throws Exception { } final ByteBuffer buffer = cacheEntry.getCachePointer().getBufferDuplicate(); + assert buffer != null; buffer.position(systemOffset); buffer.put(userData); @@ -889,7 +897,7 @@ public void testLoadAndLockForReadShouldHitCache() throws Exception { Assert.assertEquals(a1out.size(), 0); final OByteBufferPool bufferPool = OByteBufferPool.instance(null); - final OCacheEntry entry = generateEntry(fileId, 0, cacheEntry.getCachePointer().getBufferDuplicate(), bufferPool); + final OCacheEntry entry = generateEntry(fileId, 0, cacheEntry.getCachePointer().getPointer(), bufferPool); Assert.assertEquals(a1in.size(), 1); Assert.assertEquals(a1in.get(entry.getFileId(), entry.getPageIndex()), entry); @@ -909,6 +917,7 @@ public void testCloseFileShouldFlushData() throws Exception { Assert.assertEquals(entries[i].getPageIndex(), i); } ByteBuffer buffer = entries[i].getCachePointer().getBufferDuplicate(); + assert buffer != null; buffer.position(systemOffset); buffer.put(new byte[] { (byte) i, 1, 2, seed, 4, 5, 6, (byte) i }); @@ -924,7 +933,7 @@ public void testCloseFileShouldFlushData() throws Exception { final OByteBufferPool bufferPool = OByteBufferPool.instance(null); for (int i = 0; i < 4; i++) { - OCacheEntry entry = generateEntry(fileId, i, entries[i].getCachePointer().getBufferDuplicate(), bufferPool); + OCacheEntry entry = generateEntry(fileId, i, entries[i].getCachePointer().getPointer(), bufferPool); Assert.assertEquals(a1in.get(entry.getFileId(), entry.getPageIndex()), entry); } @@ -953,6 +962,7 @@ public void testDeleteFileShouldDeleteFileFromHardDrive() throws Exception { } final ByteBuffer buffer = entries[i].getCachePointer().getBufferDuplicate(); + assert buffer != null; buffer.position(systemOffset); content[i] = new byte[8]; buffer.get(content[i]); @@ -984,6 +994,7 @@ public void testFileContentReplacement() throws IOException { cachePointer.acquireExclusiveLock(); final Random random = new Random(seed); final ByteBuffer buffer = cachePointer.getBufferDuplicate(); + assert buffer != null; Assert.assertTrue(buffer.limit() > systemOffset); for (int i = systemOffset; i < buffer.limit(); ++i) buffer.put(i, (byte) random.nextInt()); @@ -1015,6 +1026,7 @@ public void testFileContentReplacement() throws IOException { verificationCachePointer.acquireSharedLock(); final Random verificationRandom = new Random(seed); final ByteBuffer verificationBuffer = verificationCachePointer.getBufferDuplicate(); + assert verificationBuffer != null; Assert.assertTrue(verificationBuffer.limit() > systemOffset); for (int i = systemOffset; i < verificationBuffer.limit(); ++i) Assert.assertEquals("at " + i, (byte) verificationRandom.nextInt(), verificationBuffer.get(i)); @@ -1038,6 +1050,7 @@ public void testFlushData() throws Exception { } final ByteBuffer buffer = entries[i].getCachePointer().getBufferDuplicate(); + assert buffer != null; buffer.position(systemOffset); buffer.put(new byte[] { (byte) i, 1, 2, seed, 4, 5, (byte) j, (byte) i }); @@ -1054,8 +1067,8 @@ public void testFlushData() throws Exception { final OByteBufferPool bufferPool = OByteBufferPool.instance(null); for (int i = 0; i < 4; i++) { - final ByteBuffer buffer = entries[i].getCachePointer().getBufferDuplicate(); - OCacheEntry entry = generateEntry(fileId, i, buffer, bufferPool); + final OPointer pointer = entries[i].getCachePointer().getPointer(); + OCacheEntry entry = generateEntry(fileId, i, pointer, bufferPool); Assert.assertEquals(a1in.get(entry.getFileId(), entry.getPageIndex()), entry); } @@ -1084,6 +1097,7 @@ public void testIfNotEnoughSpaceOldPagesShouldBeMovedToA1Out() throws Exception } final ByteBuffer buffer = entries[i].getCachePointer().getBufferDuplicate(); + assert buffer != null; buffer.position(systemOffset); buffer.put(new byte[] { (byte) i, 1, 2, seed, 4, 5, 6, 7 }); @@ -1103,7 +1117,7 @@ public void testIfNotEnoughSpaceOldPagesShouldBeMovedToA1Out() throws Exception final OByteBufferPool bufferPool = OByteBufferPool.instance(null); for (int i = 2; i < 6; i++) { - OCacheEntry entry = generateEntry(fileId, i, entries[i].getCachePointer().getBufferDuplicate(), bufferPool); + OCacheEntry entry = generateEntry(fileId, i, entries[i].getCachePointer().getPointer(), bufferPool); Assert.assertEquals(a1in.get(entry.getFileId(), entry.getPageIndex()), entry); } @@ -1129,6 +1143,7 @@ public void testIfAllPagesAreUsedExceptionShouldBeThrown() throws Exception { } ByteBuffer buffer = entries[i].getCachePointer().getBufferDuplicate(); + assert buffer != null; buffer.position(systemOffset); buffer.put(new byte[] { (byte) i, 1, 2, seed, 4, 5, 6, 7 }); @@ -1136,6 +1151,7 @@ public void testIfAllPagesAreUsedExceptionShouldBeThrown() throws Exception { readBuffer.loadForWrite(fileId, i - 4, false, writeBuffer, 0, true, null); buffer = entries[i - 4].getCachePointer().getBufferDuplicate(); + assert buffer != null; buffer.position(systemOffset); buffer.put(new byte[] { (byte) (i - 4), 1, 2, seed, 4, 5, 6, 7 }); } @@ -1171,8 +1187,8 @@ private void assertFile(long pageIndex, byte[] value, OLogSequenceNumber lsn, St fileClassic.close(); } - private OCacheEntry generateEntry(long fileId, long pageIndex, ByteBuffer buffer, OByteBufferPool bufferPool) { - return new OCacheEntryImpl(fileId, pageIndex, new OCachePointer(buffer, bufferPool, fileId, pageIndex)); + private OCacheEntry generateEntry(long fileId, long pageIndex, OPointer pointer, OByteBufferPool bufferPool) { + return new OCacheEntryImpl(fileId, pageIndex, new OCachePointer(pointer, bufferPool, fileId, pageIndex)); } private OCacheEntry generateRemovedEntry(long fileId, long pageIndex) { diff --git a/core/src/test/java/com/orientechnologies/orient/core/storage/impl/local/paginated/ClusterPageTest.java b/core/src/test/java/com/orientechnologies/orient/core/storage/impl/local/paginated/ClusterPageTest.java index fa6674f0d71..24d202a7770 100755 --- a/core/src/test/java/com/orientechnologies/orient/core/storage/impl/local/paginated/ClusterPageTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/storage/impl/local/paginated/ClusterPageTest.java @@ -1,6 +1,7 @@ package com.orientechnologies.orient.core.storage.impl.local.paginated; import com.orientechnologies.common.directmemory.OByteBufferPool; +import com.orientechnologies.common.directmemory.OPointer; import com.orientechnologies.orient.core.record.ORecordVersionHelper; import com.orientechnologies.orient.core.storage.cache.OCacheEntry; import com.orientechnologies.orient.core.storage.cache.OCacheEntryImpl; @@ -33,16 +34,16 @@ public class ClusterPageTest { @Test public void testAddOneRecord() throws Exception { OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); - ByteBuffer directBuffer = bufferPool.acquireDirect(true); - OCachePointer directCachePointer = new OCachePointer(directBuffer, bufferPool, 0, 0); + OPointer directPointer = bufferPool.acquireDirect(true); + OCachePointer directCachePointer = new OCachePointer(directPointer, bufferPool, 0, 0); directCachePointer.incrementReferrer(); OCacheEntry directCacheEntry = new OCacheEntryImpl(0, 0, directCachePointer); @@ -54,7 +55,7 @@ public void testAddOneRecord() throws Exception { addOneRecord(localPage); addOneRecord(directLocalPage); - assertChangesTracking(localPage, directBuffer, bufferPool); + assertChangesTracking(localPage, directPointer, bufferPool); } finally { cacheEntry.releaseExclusiveLock(); directCacheEntry.releaseExclusiveLock(); @@ -86,16 +87,16 @@ private void addOneRecord(OClusterPage localPage) throws IOException { @Test public void testAddThreeRecords() throws Exception { OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); - ByteBuffer directBuffer = bufferPool.acquireDirect(true); - OCachePointer directCachePointer = new OCachePointer(directBuffer, bufferPool, 0, 0); + OPointer directPointer = bufferPool.acquireDirect(true); + OCachePointer directCachePointer = new OCachePointer(directPointer, bufferPool, 0, 0); directCachePointer.incrementReferrer(); OCacheEntry directCacheEntry = new OCacheEntryImpl(0, 0, directCachePointer); @@ -108,7 +109,7 @@ public void testAddThreeRecords() throws Exception { addThreeRecords(localPage); addThreeRecords(directLocalPage); - assertChangesTracking(localPage, directBuffer, bufferPool); + assertChangesTracking(localPage, directPointer, bufferPool); } finally { cacheEntry.releaseExclusiveLock(); directCacheEntry.releaseExclusiveLock(); @@ -159,16 +160,16 @@ private void addThreeRecords(OClusterPage localPage) throws IOException { @Test public void testAddFullPage() throws Exception { OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); - ByteBuffer directBuffer = bufferPool.acquireDirect(true); - OCachePointer directCachePointer = new OCachePointer(directBuffer, bufferPool, 0, 0); + OPointer directPointer = bufferPool.acquireDirect(true); + OCachePointer directCachePointer = new OCachePointer(directPointer, bufferPool, 0, 0); directCachePointer.incrementReferrer(); OCacheEntry directCacheEntry = new OCacheEntryImpl(0, 0, directCachePointer); @@ -181,7 +182,7 @@ public void testAddFullPage() throws Exception { addFullPage(localPage); addFullPage(directLocalPage); - assertChangesTracking(localPage, directBuffer, bufferPool); + assertChangesTracking(localPage, directPointer, bufferPool); } finally { cacheEntry.releaseExclusiveLock(); directCacheEntry.releaseExclusiveLock(); @@ -226,16 +227,16 @@ private void addFullPage(OClusterPage localPage) throws IOException { @Test public void testDeleteAddLowerVersion() throws Exception { OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); - ByteBuffer directBuffer = bufferPool.acquireDirect(true); - OCachePointer directCachePointer = new OCachePointer(directBuffer, bufferPool, 0, 0); + OPointer directPointer = bufferPool.acquireDirect(true); + OCachePointer directCachePointer = new OCachePointer(directPointer, bufferPool, 0, 0); directCachePointer.incrementReferrer(); OCacheEntry directCacheEntry = new OCacheEntryImpl(0, 0, directCachePointer); @@ -248,7 +249,7 @@ public void testDeleteAddLowerVersion() throws Exception { deleteAddLowerVersion(localPage); deleteAddLowerVersion(directLocalPage); - assertChangesTracking(localPage, directBuffer, bufferPool); + assertChangesTracking(localPage, directPointer, bufferPool); } finally { cacheEntry.releaseExclusiveLock(); directCacheEntry.releaseExclusiveLock(); @@ -283,16 +284,16 @@ private void deleteAddLowerVersion(OClusterPage localPage) throws IOException { @Test public void testDeleteAddBiggerVersion() throws Exception { OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); - ByteBuffer directBuffer = bufferPool.acquireDirect(true); - OCachePointer directCachePointer = new OCachePointer(directBuffer, bufferPool, 0, 0); + OPointer directPointer = bufferPool.acquireDirect(true); + OCachePointer directCachePointer = new OCachePointer(directPointer, bufferPool, 0, 0); directCachePointer.incrementReferrer(); OCacheEntry directCacheEntry = new OCacheEntryImpl(0, 0, directCachePointer); @@ -304,7 +305,7 @@ public void testDeleteAddBiggerVersion() throws Exception { deleteAddBiggerVersion(localPage); deleteAddBiggerVersion(directLocalPage); - assertChangesTracking(localPage, directBuffer, bufferPool); + assertChangesTracking(localPage, directPointer, bufferPool); } finally { cacheEntry.releaseExclusiveLock(); directCacheEntry.releaseExclusiveLock(); @@ -343,16 +344,16 @@ private void deleteAddBiggerVersion(OClusterPage localPage) throws IOException { @Test public void testDeleteAddEqualVersion() throws Exception { OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool,0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); - ByteBuffer directBuffer = bufferPool.acquireDirect(true); - OCachePointer directCachePointer = new OCachePointer(directBuffer, bufferPool, 0, 0); + OPointer directPointer = bufferPool.acquireDirect(true); + OCachePointer directCachePointer = new OCachePointer(directPointer, bufferPool, 0, 0); directCachePointer.incrementReferrer(); OCacheEntry directCacheEntry = new OCacheEntryImpl(0, 0, directCachePointer); @@ -365,7 +366,7 @@ public void testDeleteAddEqualVersion() throws Exception { deleteAddEqualVersion(localPage); deleteAddEqualVersion(directLocalPage); - assertChangesTracking(localPage, directBuffer, bufferPool); + assertChangesTracking(localPage, directPointer, bufferPool); } finally { cacheEntry.releaseExclusiveLock(); directCacheEntry.releaseExclusiveLock(); @@ -397,16 +398,16 @@ private void deleteAddEqualVersion(OClusterPage localPage) throws IOException { @Test public void testDeleteAddEqualVersionKeepTombstoneVersion() throws Exception { OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); - ByteBuffer directBuffer = bufferPool.acquireDirect(true); - OCachePointer directCachePointer = new OCachePointer(directBuffer, bufferPool, 0, 0); + OPointer directPointer = bufferPool.acquireDirect(true); + OCachePointer directCachePointer = new OCachePointer(directPointer, bufferPool, 0, 0); directCachePointer.incrementReferrer(); OCacheEntry directCacheEntry = new OCacheEntryImpl(0, 0, directCachePointer); @@ -418,7 +419,7 @@ public void testDeleteAddEqualVersionKeepTombstoneVersion() throws Exception { deleteAddEqualVersionKeepTombstoneVersion(localPage); deleteAddEqualVersionKeepTombstoneVersion(directLocalPage); - assertChangesTracking(localPage, directBuffer, bufferPool); + assertChangesTracking(localPage, directPointer, bufferPool); } finally { cacheEntry.releaseExclusiveLock(); directCacheEntry.releaseExclusiveLock(); @@ -450,16 +451,16 @@ private void deleteAddEqualVersionKeepTombstoneVersion(OClusterPage localPage) t @Test public void testDeleteTwoOutOfFour() throws Exception { OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); - ByteBuffer directBuffer = bufferPool.acquireDirect(true); - OCachePointer directCachePointer = new OCachePointer(directBuffer, bufferPool, 0, 0); + OPointer directPointer = bufferPool.acquireDirect(true); + OCachePointer directCachePointer = new OCachePointer(directPointer, bufferPool, 0, 0); directCachePointer.incrementReferrer(); OCacheEntry directCacheEntry = new OCacheEntryImpl(0, 0, directCachePointer); @@ -471,7 +472,7 @@ public void testDeleteTwoOutOfFour() throws Exception { deleteTwoOutOfFour(localPage); deleteTwoOutOfFour(directLocalPage); - assertChangesTracking(localPage, directBuffer, bufferPool); + assertChangesTracking(localPage, directPointer, bufferPool); } finally { cacheEntry.releaseExclusiveLock(); directCacheEntry.releaseExclusiveLock(); @@ -540,16 +541,16 @@ private void deleteTwoOutOfFour(OClusterPage localPage) throws IOException { @Test public void testAddFullPageDeleteAndAddAgain() throws Exception { OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); - ByteBuffer directBuffer = bufferPool.acquireDirect(true); - OCachePointer directCachePointer = new OCachePointer(directBuffer, bufferPool, 0, 0); + OPointer directPointer = bufferPool.acquireDirect(true); + OCachePointer directCachePointer = new OCachePointer(directPointer, bufferPool, 0, 0); directCachePointer.incrementReferrer(); OCacheEntry directCacheEntry = new OCacheEntryImpl(0, 0, directCachePointer); @@ -562,7 +563,7 @@ public void testAddFullPageDeleteAndAddAgain() throws Exception { addFullPageDeleteAndAddAgain(localPage); addFullPageDeleteAndAddAgain(directLocalPage); - assertChangesTracking(localPage, directBuffer, bufferPool); + assertChangesTracking(localPage, directPointer, bufferPool); } finally { cacheEntry.releaseExclusiveLock(); directCacheEntry.releaseExclusiveLock(); @@ -634,16 +635,16 @@ private void addFullPageDeleteAndAddAgain(OClusterPage localPage) throws IOExcep @Test public void testAddBigRecordDeleteAndAddSmallRecords() throws Exception { OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); - ByteBuffer directBuffer = bufferPool.acquireDirect(true); - OCachePointer directCachePointer = new OCachePointer(directBuffer, bufferPool, 0, 0); + OPointer directPointer = bufferPool.acquireDirect(true); + OCachePointer directCachePointer = new OCachePointer(directPointer, bufferPool, 0, 0); directCachePointer.incrementReferrer(); OCacheEntry directCacheEntry = new OCacheEntryImpl(0, 0, directCachePointer); @@ -658,7 +659,7 @@ public void testAddBigRecordDeleteAndAddSmallRecords() throws Exception { addBigRecordDeleteAndAddSmallRecords(seed, localPage); addBigRecordDeleteAndAddSmallRecords(seed, directLocalPage); - assertChangesTracking(localPage, directBuffer, bufferPool); + assertChangesTracking(localPage, directPointer, bufferPool); } finally { cacheEntry.releaseExclusiveLock(); directCacheEntry.releaseExclusiveLock(); @@ -721,16 +722,16 @@ private void addBigRecordDeleteAndAddSmallRecords(long seed, OClusterPage localP @Test public void testFindFirstRecord() throws Exception { OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); - ByteBuffer directBuffer = bufferPool.acquireDirect(true); - OCachePointer directCachePointer = new OCachePointer(directBuffer, bufferPool, 0, 0); + OPointer directPointer = bufferPool.acquireDirect(true); + OCachePointer directCachePointer = new OCachePointer(directPointer, bufferPool, 0, 0); directCachePointer.incrementReferrer(); OCacheEntry directCacheEntry = new OCacheEntryImpl(0, 0, directCachePointer); @@ -744,7 +745,7 @@ public void testFindFirstRecord() throws Exception { findFirstRecord(seed, localPage); findFirstRecord(seed, directLocalPage); - assertChangesTracking(localPage, directBuffer, bufferPool); + assertChangesTracking(localPage, directPointer, bufferPool); } finally { cacheEntry.releaseExclusiveLock(); directCacheEntry.releaseExclusiveLock(); @@ -811,16 +812,16 @@ private void findFirstRecord(long seed, OClusterPage localPage) throws IOExcepti @Test public void testFindLastRecord() throws Exception { OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool,0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); - ByteBuffer directBuffer = bufferPool.acquireDirect(true); - OCachePointer directCachePointer = new OCachePointer(directBuffer, bufferPool, 0, 0); + OPointer directPointer = bufferPool.acquireDirect(true); + OCachePointer directCachePointer = new OCachePointer(directPointer, bufferPool, 0, 0); directCachePointer.incrementReferrer(); OCacheEntry directCacheEntry = new OCacheEntryImpl(0, 0, directCachePointer); @@ -834,7 +835,7 @@ public void testFindLastRecord() throws Exception { findLastRecord(seed, localPage); findLastRecord(seed, directLocalPage); - assertChangesTracking(localPage, directBuffer, bufferPool); + assertChangesTracking(localPage, directPointer, bufferPool); } finally { cacheEntry.releaseExclusiveLock(); directCacheEntry.releaseExclusiveLock(); @@ -898,16 +899,16 @@ private void findLastRecord(long seed, OClusterPage localPage) throws IOExceptio @Test public void testSetGetNextPage() throws Exception { OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); - ByteBuffer directBuffer = bufferPool.acquireDirect(true); - OCachePointer directCachePointer = new OCachePointer(directBuffer, bufferPool, 0, 0); + OPointer directPointer = bufferPool.acquireDirect(true); + OCachePointer directCachePointer = new OCachePointer(directPointer, bufferPool, 0, 0); directCachePointer.incrementReferrer(); OCacheEntry directCacheEntry = new OCacheEntryImpl(0, 0, directCachePointer); @@ -919,7 +920,7 @@ public void testSetGetNextPage() throws Exception { setGetNextPage(localPage); setGetNextPage(directLocalPage); - assertChangesTracking(localPage, directBuffer, bufferPool); + assertChangesTracking(localPage, directPointer, bufferPool); } finally { cacheEntry.releaseExclusiveLock(); directCacheEntry.releaseExclusiveLock(); @@ -937,16 +938,16 @@ private void setGetNextPage(OClusterPage localPage) throws IOException { @Test public void testSetGetPrevPage() throws Exception { OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); - ByteBuffer directBuffer = bufferPool.acquireDirect(true); - OCachePointer directCachePointer = new OCachePointer(directBuffer, bufferPool, 0, 0); + OPointer directPointer = bufferPool.acquireDirect(true); + OCachePointer directCachePointer = new OCachePointer(directPointer, bufferPool, 0, 0); directCachePointer.incrementReferrer(); OCacheEntry directCacheEntry = new OCacheEntryImpl(0, 0, directCachePointer); @@ -958,7 +959,7 @@ public void testSetGetPrevPage() throws Exception { setGetPrevPage(localPage); setGetPrevPage(directLocalPage); - assertChangesTracking(localPage, directBuffer, bufferPool); + assertChangesTracking(localPage, directPointer, bufferPool); } finally { cacheEntry.releaseExclusiveLock(); directCacheEntry.releaseExclusiveLock(); @@ -976,16 +977,16 @@ private void setGetPrevPage(OClusterPage localPage) throws IOException { @Test public void testReplaceOneRecordWithBiggerSize() throws Exception { OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); - ByteBuffer directBuffer = bufferPool.acquireDirect(true); - OCachePointer directCachePointer = new OCachePointer(directBuffer, bufferPool, 0, 0); + OPointer directPointer = bufferPool.acquireDirect(true); + OCachePointer directCachePointer = new OCachePointer(directPointer, bufferPool, 0, 0); directCachePointer.incrementReferrer(); OCacheEntry directCacheEntry = new OCacheEntryImpl(0, 0, directCachePointer); @@ -998,7 +999,7 @@ public void testReplaceOneRecordWithBiggerSize() throws Exception { replaceOneRecordWithBiggerSize(localPage); replaceOneRecordWithBiggerSize(directLocalPage); - assertChangesTracking(localPage, directBuffer, bufferPool); + assertChangesTracking(localPage, directPointer, bufferPool); } finally { cacheEntry.releaseExclusiveLock(); directCacheEntry.releaseExclusiveLock(); @@ -1036,16 +1037,16 @@ private void replaceOneRecordWithBiggerSize(OClusterPage localPage) throws IOExc @Test public void testReplaceOneRecordWithEqualSize() throws Exception { OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); - ByteBuffer directBuffer = bufferPool.acquireDirect(true); - OCachePointer directCachePointer = new OCachePointer(directBuffer, bufferPool, 0, 0); + OPointer directPointer = bufferPool.acquireDirect(true); + OCachePointer directCachePointer = new OCachePointer(directPointer, bufferPool, 0, 0); directCachePointer.incrementReferrer(); OCacheEntry directCacheEntry = new OCacheEntryImpl(0, 0, directCachePointer); @@ -1057,7 +1058,7 @@ public void testReplaceOneRecordWithEqualSize() throws Exception { replaceOneRecordWithEqualSize(localPage); replaceOneRecordWithEqualSize(directLocalPage); - assertChangesTracking(localPage, directBuffer, bufferPool); + assertChangesTracking(localPage, directPointer, bufferPool); } finally { cacheEntry.releaseExclusiveLock(); directCacheEntry.releaseExclusiveLock(); @@ -1095,16 +1096,16 @@ private void replaceOneRecordWithEqualSize(OClusterPage localPage) throws IOExce @Test public void testReplaceOneRecordWithSmallerSize() throws Exception { OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); - ByteBuffer directBuffer = bufferPool.acquireDirect(true); - OCachePointer directCachePointer = new OCachePointer(directBuffer, bufferPool, 0, 0); + OPointer directPointer = bufferPool.acquireDirect(true); + OCachePointer directCachePointer = new OCachePointer(directPointer, bufferPool, 0, 0); directCachePointer.incrementReferrer(); OCacheEntry directCacheEntry = new OCacheEntryImpl(0, 0, directCachePointer); @@ -1117,7 +1118,7 @@ public void testReplaceOneRecordWithSmallerSize() throws Exception { replaceOneRecordWithSmallerSize(localPage); replaceOneRecordWithSmallerSize(directLocalPage); - assertChangesTracking(localPage, directBuffer, bufferPool); + assertChangesTracking(localPage, directPointer, bufferPool); } finally { cacheEntry.releaseExclusiveLock(); directCacheEntry.releaseExclusiveLock(); @@ -1155,16 +1156,16 @@ private void replaceOneRecordWithSmallerSize(OClusterPage localPage) throws IOEx @Test public void testReplaceOneRecordNoVersionUpdate() throws Exception { OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); - ByteBuffer directBuffer = bufferPool.acquireDirect(true); - OCachePointer directCachePointer = new OCachePointer(directBuffer, bufferPool, 0, 0); + OPointer directPointer = bufferPool.acquireDirect(true); + OCachePointer directCachePointer = new OCachePointer(directPointer, bufferPool, 0, 0); directCachePointer.incrementReferrer(); OCacheEntry directCacheEntry = new OCacheEntryImpl(0, 0, directCachePointer); @@ -1176,7 +1177,7 @@ public void testReplaceOneRecordNoVersionUpdate() throws Exception { replaceOneRecordNoVersionUpdate(localPage); replaceOneRecordNoVersionUpdate(directLocalPage); - assertChangesTracking(localPage, directBuffer, bufferPool); + assertChangesTracking(localPage, directPointer, bufferPool); } finally { cacheEntry.releaseExclusiveLock(); directCacheEntry.releaseExclusiveLock(); @@ -1214,16 +1215,16 @@ private void replaceOneRecordNoVersionUpdate(OClusterPage localPage) throws IOEx @Test public void testReplaceOneRecordLowerVersion() throws Exception { OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); - ByteBuffer directBuffer = bufferPool.acquireDirect(true); - OCachePointer directCachePointer = new OCachePointer(directBuffer, bufferPool, 0, 0); + OPointer directPointer = bufferPool.acquireDirect(true); + OCachePointer directCachePointer = new OCachePointer(directPointer, bufferPool, 0, 0); directCachePointer.incrementReferrer(); OCacheEntry directCacheEntry = new OCacheEntryImpl(0, 0, directCachePointer); @@ -1235,7 +1236,7 @@ public void testReplaceOneRecordLowerVersion() throws Exception { replaceOneRecordLowerVersion(localPage); replaceOneRecordLowerVersion(directLocalPage); - assertChangesTracking(localPage, directBuffer, bufferPool); + assertChangesTracking(localPage, directPointer, bufferPool); } finally { cacheEntry.releaseExclusiveLock(); directCacheEntry.releaseExclusiveLock(); @@ -1268,10 +1269,10 @@ private void replaceOneRecordLowerVersion(OClusterPage localPage) throws IOExcep Assert.assertEquals(localPage.getRecordVersion(index), recordVersion); } - private void assertChangesTracking(OClusterPage localPage, ByteBuffer buffer, OByteBufferPool bufferPool) throws IOException { - ByteBuffer restoredBuffer = bufferPool.acquireDirect(true); + private void assertChangesTracking(OClusterPage localPage, OPointer pointer, OByteBufferPool bufferPool) throws IOException { + OPointer restoredPointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(restoredBuffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(restoredPointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); @@ -1282,11 +1283,8 @@ private void assertChangesTracking(OClusterPage localPage, ByteBuffer buffer, OB OWALChanges changes = localPage.getChanges(); restoredPage.restoreChanges(changes); - // Assert.assertEquals(getBytes(restoredBuffer, SYSTEM_OFFSET, OClusterPage.PAGE_SIZE - SYSTEM_OFFSET), - // getBytes(buffer, SYSTEM_OFFSET, OClusterPage.PAGE_SIZE - SYSTEM_OFFSET)); - - assertThat(getBytes(restoredBuffer, SYSTEM_OFFSET, OClusterPage.PAGE_SIZE - SYSTEM_OFFSET)) - .isEqualTo(getBytes(buffer, SYSTEM_OFFSET, OClusterPage.PAGE_SIZE - SYSTEM_OFFSET)); + assertThat(getBytes(restoredPointer.getNativeByteBuffer(), SYSTEM_OFFSET, OClusterPage.PAGE_SIZE - SYSTEM_OFFSET)) + .isEqualTo(getBytes(pointer.getNativeByteBuffer(), SYSTEM_OFFSET, OClusterPage.PAGE_SIZE - SYSTEM_OFFSET)); } finally { cacheEntry.releaseExclusiveLock(); cachePointer.decrementReferrer(); diff --git a/core/src/test/java/com/orientechnologies/orient/core/storage/index/hashindex/local/cache/AbstractLRUListTestTemplate.java b/core/src/test/java/com/orientechnologies/orient/core/storage/index/hashindex/local/cache/AbstractLRUListTestTemplate.java index 7153b614741..58025dca8f5 100755 --- a/core/src/test/java/com/orientechnologies/orient/core/storage/index/hashindex/local/cache/AbstractLRUListTestTemplate.java +++ b/core/src/test/java/com/orientechnologies/orient/core/storage/index/hashindex/local/cache/AbstractLRUListTestTemplate.java @@ -1,6 +1,7 @@ package com.orientechnologies.orient.core.storage.index.hashindex.local.cache; import com.orientechnologies.common.directmemory.OByteBufferPool; +import com.orientechnologies.common.directmemory.OPointer; import com.orientechnologies.orient.core.storage.cache.OCacheEntry; import com.orientechnologies.orient.core.storage.cache.OCacheEntryImpl; import com.orientechnologies.orient.core.storage.cache.OCachePointer; @@ -8,7 +9,6 @@ import org.junit.Assert; import org.junit.Test; -import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Iterator; @@ -23,16 +23,16 @@ public abstract class AbstractLRUListTestTemplate { @Test public void testSingleAdd() { final OByteBufferPool bufferPool = new OByteBufferPool(1); - final ByteBuffer buffer = bufferPool.acquireDirect(true); + final OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); lruList.putToMRU(new OCacheEntryImpl(1, 10, cachePointer)); Iterator entryIterator = lruList.iterator(); Assert.assertTrue(entryIterator.hasNext()); Assert.assertEquals(entryIterator.next(), new OCacheEntryImpl(1, 10, cachePointer)); - bufferPool.release(buffer); + bufferPool.release(pointer); bufferPool.clear(); } @@ -40,11 +40,11 @@ public void testSingleAdd() { public void testAddTwo() { final OByteBufferPool bufferPool = new OByteBufferPool(1); - ByteBuffer bufferOne = bufferPool.acquireDirect(true); - ByteBuffer bufferTwo = bufferPool.acquireDirect(true); + OPointer pointerOne = bufferPool.acquireDirect(true); + OPointer pointerTwo = bufferPool.acquireDirect(true); - OCachePointer cachePointerOne = new OCachePointer(bufferOne, bufferPool, 0, 0); - OCachePointer cachePointerTwo = new OCachePointer(bufferTwo, bufferPool, 0, 0); + OCachePointer cachePointerOne = new OCachePointer(pointerOne, bufferPool, 0, 0); + OCachePointer cachePointerTwo = new OCachePointer(pointerTwo, bufferPool, 0, 0); lruList.putToMRU(new OCacheEntryImpl(1, 10, cachePointerOne)); lruList.putToMRU(new OCacheEntryImpl(1, 20, cachePointerTwo)); @@ -57,8 +57,8 @@ public void testAddTwo() { Assert.assertEquals(entryIterator.next(), new OCacheEntryImpl(1, 20, cachePointerTwo)); Assert.assertEquals(entryIterator.next(), new OCacheEntryImpl(1, 10, cachePointerOne)); - bufferPool.release(bufferOne); - bufferPool.release(bufferTwo); + bufferPool.release(pointerOne); + bufferPool.release(pointerTwo); bufferPool.clear(); } @@ -66,13 +66,13 @@ public void testAddTwo() { public void testAddThree() { final OByteBufferPool bufferPool = new OByteBufferPool(1); - ByteBuffer bufferOne = bufferPool.acquireDirect(true); - ByteBuffer bufferTwo = bufferPool.acquireDirect(true); - ByteBuffer bufferThree = bufferPool.acquireDirect(true); + OPointer pointerOne = bufferPool.acquireDirect(true); + OPointer pointerTwo = bufferPool.acquireDirect(true); + OPointer pointerThree = bufferPool.acquireDirect(true); - OCachePointer cachePointerOne = new OCachePointer(bufferOne, bufferPool, 0, 0); - OCachePointer cachePointerTwo = new OCachePointer(bufferTwo, bufferPool, 0, 0); - OCachePointer cachePointerThree = new OCachePointer(bufferThree, bufferPool, 0, 0); + OCachePointer cachePointerOne = new OCachePointer(pointerOne, bufferPool, 0, 0); + OCachePointer cachePointerTwo = new OCachePointer(pointerTwo, bufferPool, 0, 0); + OCachePointer cachePointerThree = new OCachePointer(pointerThree, bufferPool, 0, 0); lruList.putToMRU(new OCacheEntryImpl(1, 10, cachePointerOne)); lruList.putToMRU(new OCacheEntryImpl(1, 20, cachePointerTwo)); @@ -87,9 +87,9 @@ public void testAddThree() { Assert.assertEquals(entryIterator.next(), new OCacheEntryImpl(1, 20, cachePointerTwo)); Assert.assertEquals(entryIterator.next(), new OCacheEntryImpl(1, 10, cachePointerOne)); - bufferPool.release(bufferOne); - bufferPool.release(bufferTwo); - bufferPool.release(bufferThree); + bufferPool.release(pointerOne); + bufferPool.release(pointerTwo); + bufferPool.release(pointerThree); bufferPool.clear(); } @@ -98,13 +98,13 @@ public void testAddThree() { public void testAddThreePutMiddleToTop() { final OByteBufferPool bufferPool = new OByteBufferPool(1); - ByteBuffer bufferOne = bufferPool.acquireDirect(true); - ByteBuffer bufferTwo = bufferPool.acquireDirect(true); - ByteBuffer bufferThree = bufferPool.acquireDirect(true); + OPointer pointerOne = bufferPool.acquireDirect(true); + OPointer pointerTwo = bufferPool.acquireDirect(true); + OPointer pointerThree = bufferPool.acquireDirect(true); - OCachePointer cachePointerOne = new OCachePointer(bufferOne, bufferPool, 0, 0); - OCachePointer cachePointerTwo = new OCachePointer(bufferTwo, bufferPool, 0, 0); - OCachePointer cachePointerThree = new OCachePointer(bufferThree, bufferPool, 0, 0); + OCachePointer cachePointerOne = new OCachePointer(pointerOne, bufferPool, 0, 0); + OCachePointer cachePointerTwo = new OCachePointer(pointerTwo, bufferPool, 0, 0); + OCachePointer cachePointerThree = new OCachePointer(pointerThree, bufferPool, 0, 0); lruList.putToMRU(new OCacheEntryImpl(1, 10, cachePointerOne)); lruList.putToMRU(new OCacheEntryImpl(1, 20, cachePointerTwo)); @@ -121,9 +121,9 @@ public void testAddThreePutMiddleToTop() { Assert.assertEquals(entryIterator.next(), new OCacheEntryImpl(3, 30, cachePointerThree)); Assert.assertEquals(entryIterator.next(), new OCacheEntryImpl(1, 10, cachePointerOne)); - bufferPool.release(bufferOne); - bufferPool.release(bufferTwo); - bufferPool.release(bufferThree); + bufferPool.release(pointerOne); + bufferPool.release(pointerTwo); + bufferPool.release(pointerThree); bufferPool.clear(); } @@ -132,15 +132,15 @@ public void testAddThreePutMiddleToTop() { public void testAddThreePutMiddleToTopChangePointer() { final OByteBufferPool bufferPool = new OByteBufferPool(1); - ByteBuffer bufferOne = bufferPool.acquireDirect(true); - ByteBuffer bufferTwo = bufferPool.acquireDirect(true); - ByteBuffer bufferThree = bufferPool.acquireDirect(true); - ByteBuffer bufferFour = bufferPool.acquireDirect(true); + OPointer pointerOne = bufferPool.acquireDirect(true); + OPointer pointerTwo = bufferPool.acquireDirect(true); + OPointer pointerThree = bufferPool.acquireDirect(true); + OPointer pointerFour = bufferPool.acquireDirect(true); - OCachePointer cachePointerOne = new OCachePointer(bufferOne, bufferPool, 0, 0); - OCachePointer cachePointerTwo = new OCachePointer(bufferTwo, bufferPool, 0, 0); - OCachePointer cachePointerThree = new OCachePointer(bufferThree, bufferPool, 0, 0); - OCachePointer cachePointerFour = new OCachePointer(bufferFour, bufferPool, 0, 0); + OCachePointer cachePointerOne = new OCachePointer(pointerOne, bufferPool, 0, 0); + OCachePointer cachePointerTwo = new OCachePointer(pointerTwo, bufferPool, 0, 0); + OCachePointer cachePointerThree = new OCachePointer(pointerThree, bufferPool, 0, 0); + OCachePointer cachePointerFour = new OCachePointer(pointerFour, bufferPool, 0, 0); lruList.putToMRU(new OCacheEntryImpl(1, 10, cachePointerOne)); lruList.putToMRU(new OCacheEntryImpl(1, 20, cachePointerTwo)); @@ -157,10 +157,10 @@ public void testAddThreePutMiddleToTopChangePointer() { Assert.assertEquals(entryIterator.next(), new OCacheEntryImpl(3, 30, cachePointerThree)); Assert.assertEquals(entryIterator.next(), new OCacheEntryImpl(1, 10, cachePointerOne)); - bufferPool.release(bufferOne); - bufferPool.release(bufferTwo); - bufferPool.release(bufferThree); - bufferPool.release(bufferFour); + bufferPool.release(pointerOne); + bufferPool.release(pointerTwo); + bufferPool.release(pointerThree); + bufferPool.release(pointerFour); bufferPool.clear(); } @@ -172,9 +172,9 @@ public void testAddElevenPutMiddleToTopChangePointer() { OCachePointer[] cachePointers = new OCachePointer[11]; for (int i = 0; i < 11; i++) { - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - cachePointers[i] = new OCachePointer(buffer, bufferPool,0, 0); + cachePointers[i] = new OCachePointer(pointer, bufferPool, 0, 0); lruList.putToMRU(new OCacheEntryImpl(1, i * 10, cachePointers[i])); } @@ -196,7 +196,7 @@ public void testAddElevenPutMiddleToTopChangePointer() { } for (OCachePointer pointer : cachePointers) { - bufferPool.release(pointer.getBuffer()); + bufferPool.release(pointer.getPointer()); } bufferPool.clear(); @@ -205,9 +205,9 @@ public void testAddElevenPutMiddleToTopChangePointer() { @Test public void testAddOneRemoveLRU() { final OByteBufferPool bufferPool = new OByteBufferPool(1); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointerOne = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointerOne = new OCachePointer(pointer, bufferPool, 0, 0); lruList.putToMRU(new OCacheEntryImpl(1, 10, cachePointerOne)); lruList.removeLRU(); @@ -216,16 +216,16 @@ public void testAddOneRemoveLRU() { Iterator entryIterator = lruList.iterator(); Assert.assertFalse(entryIterator.hasNext()); - bufferPool.release(buffer); + bufferPool.release(pointer); bufferPool.clear(); } @Test public void testRemoveLRUShouldReturnNullIfAllRecordsAreUsed() { final OByteBufferPool bufferPool = new OByteBufferPool(1); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointerOne = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointerOne = new OCachePointer(pointer, bufferPool, 0, 0); OCacheEntry cacheEntry = new OCacheEntryImpl(1, 10, cachePointerOne); lruList.putToMRU(cacheEntry); cacheEntry.incrementUsages(); @@ -234,7 +234,7 @@ public void testRemoveLRUShouldReturnNullIfAllRecordsAreUsed() { Assert.assertNull(removedLRU); - bufferPool.release(buffer); + bufferPool.release(pointer); bufferPool.clear(); } @@ -245,9 +245,9 @@ public void testAddElevenRemoveLRU() { OCachePointer[] cachePointers = new OCachePointer[11]; for (int i = 0; i < 11; i++) { - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - cachePointers[i] = new OCachePointer(buffer, bufferPool, 0, 0); + cachePointers[i] = new OCachePointer(pointer, bufferPool, 0, 0); lruList.putToMRU(new OCacheEntryImpl(1, i * 10, cachePointers[i])); } @@ -263,7 +263,7 @@ public void testAddElevenRemoveLRU() { } for (OCachePointer cachePointer : cachePointers) { - bufferPool.release(cachePointer.getBuffer()); + bufferPool.release(cachePointer.getPointer()); } bufferPool.clear(); @@ -275,9 +275,9 @@ public void testAddElevenRemoveMiddle() { OCachePointer[] cachePointers = new OCachePointer[11]; for (int i = 0; i < 11; i++) { - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - cachePointers[i] = new OCachePointer(buffer, bufferPool, 0, 0); + cachePointers[i] = new OCachePointer(pointer, bufferPool, 0, 0); lruList.putToMRU(new OCacheEntryImpl(1, i * 10, cachePointers[i])); } @@ -296,7 +296,7 @@ public void testAddElevenRemoveMiddle() { } for (OCachePointer cachePointer : cachePointers) { - bufferPool.release(cachePointer.getBuffer()); + bufferPool.release(cachePointer.getPointer()); } bufferPool.clear(); } @@ -308,7 +308,7 @@ public void testAddElevenGetMiddle() { OCachePointer[] cachePointers = new OCachePointer[11]; for (int i = 0; i < 11; i++) { - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer buffer = bufferPool.acquireDirect(true); cachePointers[i] = new OCachePointer(buffer, bufferPool, 0, 0); lruList.putToMRU(new OCacheEntryImpl(1, i * 10, cachePointers[i])); @@ -328,7 +328,7 @@ public void testAddElevenGetMiddle() { } for (OCachePointer cachePointer : cachePointers) { - bufferPool.release(cachePointer.getBuffer()); + bufferPool.release(cachePointer.getPointer()); } bufferPool.clear(); } @@ -339,8 +339,8 @@ public void testAdd9128() { OCachePointer[] cachePointers = new OCachePointer[9128]; for (int i = 0; i < 9128; i++) { - ByteBuffer buffer = bufferPool.acquireDirect(true); - cachePointers[i] = new OCachePointer(buffer, bufferPool, 0, 0); + OPointer pointer = bufferPool.acquireDirect(true); + cachePointers[i] = new OCachePointer(pointer, bufferPool, 0, 0); lruList.putToMRU(new OCacheEntryImpl(1, i * 10, cachePointers[i])); } @@ -353,7 +353,7 @@ public void testAdd9128() { } for (OCachePointer cachePointer : cachePointers) { - bufferPool.release(cachePointer.getBuffer()); + bufferPool.release(cachePointer.getPointer()); } bufferPool.clear(); @@ -365,8 +365,8 @@ public void testAdd9128Get() { OCachePointer[] cachePointers = new OCachePointer[9128]; for (int i = 0; i < 9128; i++) { - ByteBuffer buffer = bufferPool.acquireDirect(true); - cachePointers[i] = new OCachePointer(buffer, bufferPool, 0, 0); + OPointer pointer = bufferPool.acquireDirect(true); + cachePointers[i] = new OCachePointer(pointer, bufferPool, 0, 0); lruList.putToMRU(new OCacheEntryImpl(1, i * 10, cachePointers[i])); } @@ -382,7 +382,7 @@ public void testAdd9128Get() { } for (OCachePointer pointer : cachePointers) { - bufferPool.release(pointer.getBuffer()); + bufferPool.release(pointer.getPointer()); } bufferPool.clear(); @@ -394,8 +394,8 @@ public void testAdd9128Remove4564() { OCachePointer[] cachePointers = new OCachePointer[9128]; for (int i = 0; i < 9128; i++) { - ByteBuffer buffer = bufferPool.acquireDirect(true); - cachePointers[i] = new OCachePointer(buffer, bufferPool, 0, 0); + OPointer pointer = bufferPool.acquireDirect(true); + cachePointers[i] = new OCachePointer(pointer, bufferPool, 0, 0); lruList.putToMRU(new OCacheEntryImpl(1, i * 10, cachePointers[i])); } @@ -411,7 +411,7 @@ public void testAdd9128Remove4564() { } for (OCachePointer cachePointer : cachePointers) { - bufferPool.release(cachePointer.getBuffer()); + bufferPool.release(cachePointer.getPointer()); } bufferPool.clear(); @@ -424,8 +424,8 @@ public void testAdd9128PutLastAndMiddleToTop() { OCachePointer[] cachePointers = new OCachePointer[9128]; for (int i = 0; i < 9128; i++) { - ByteBuffer buffer = bufferPool.acquireDirect(true); - cachePointers[i] = new OCachePointer(buffer, bufferPool, 0, 0); + OPointer pointer = bufferPool.acquireDirect(true); + cachePointers[i] = new OCachePointer(pointer, bufferPool, 0, 0); lruList.putToMRU(new OCacheEntryImpl(1, i * 10, cachePointers[i])); } @@ -448,7 +448,7 @@ public void testAdd9128PutLastAndMiddleToTop() { } for (OCachePointer cachePointer : cachePointers) { - bufferPool.release(cachePointer.getBuffer()); + bufferPool.release(cachePointer.getPointer()); } bufferPool.clear(); diff --git a/core/src/test/java/com/orientechnologies/orient/core/storage/index/sbtree/local/ONullBucketTest.java b/core/src/test/java/com/orientechnologies/orient/core/storage/index/sbtree/local/ONullBucketTest.java index 978bb0181a3..3c6b96434d9 100755 --- a/core/src/test/java/com/orientechnologies/orient/core/storage/index/sbtree/local/ONullBucketTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/storage/index/sbtree/local/ONullBucketTest.java @@ -1,6 +1,7 @@ package com.orientechnologies.orient.core.storage.index.sbtree.local; import com.orientechnologies.common.directmemory.OByteBufferPool; +import com.orientechnologies.common.directmemory.OPointer; import com.orientechnologies.common.serialization.types.OStringSerializer; import com.orientechnologies.orient.core.storage.cache.OCacheEntry; import com.orientechnologies.orient.core.storage.cache.OCacheEntryImpl; @@ -9,7 +10,6 @@ import org.junit.Test; import java.io.IOException; -import java.nio.ByteBuffer; /** * @author Andrey Lomakin (a.lomakin-at-orientdb.com) @@ -19,9 +19,9 @@ public class ONullBucketTest { @Test public void testEmptyBucket() { OByteBufferPool bufferPool = new OByteBufferPool(1024); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); @@ -38,9 +38,9 @@ public void testEmptyBucket() { @Test public void testAddGetValue() throws IOException { OByteBufferPool bufferPool = new OByteBufferPool(1024); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); @@ -60,9 +60,9 @@ public void testAddGetValue() throws IOException { @Test public void testAddRemoveValue() throws IOException { OByteBufferPool bufferPool = new OByteBufferPool(1024); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); @@ -84,9 +84,9 @@ public void testAddRemoveValue() throws IOException { @Test public void testAddRemoveAddValue() throws IOException { OByteBufferPool bufferPool = new OByteBufferPool(1024); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); diff --git a/core/src/test/java/com/orientechnologies/orient/core/storage/index/sbtree/local/SBTreeLeafBucketTest.java b/core/src/test/java/com/orientechnologies/orient/core/storage/index/sbtree/local/SBTreeLeafBucketTest.java index 74f1a845929..6f66382aa02 100755 --- a/core/src/test/java/com/orientechnologies/orient/core/storage/index/sbtree/local/SBTreeLeafBucketTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/storage/index/sbtree/local/SBTreeLeafBucketTest.java @@ -1,6 +1,7 @@ package com.orientechnologies.orient.core.storage.index.sbtree.local; import com.orientechnologies.common.directmemory.OByteBufferPool; +import com.orientechnologies.common.directmemory.OPointer; import com.orientechnologies.common.serialization.types.OLongSerializer; import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.id.ORecordId; @@ -11,7 +12,6 @@ import org.junit.Assert; import org.junit.Test; -import java.nio.ByteBuffer; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -26,20 +26,20 @@ public class SBTreeLeafBucketTest { @Test public void testInitialization() throws Exception { OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); - OSBTreeBucket treeBucket = new OSBTreeBucket(cacheEntry, true, - OLongSerializer.INSTANCE, null, OLinkSerializer.INSTANCE, null); + OSBTreeBucket treeBucket = new OSBTreeBucket<>(cacheEntry, true, OLongSerializer.INSTANCE, null, + OLinkSerializer.INSTANCE, null); Assert.assertEquals(treeBucket.size(), 0); Assert.assertTrue(treeBucket.isLeaf()); - treeBucket = new OSBTreeBucket(cacheEntry, OLongSerializer.INSTANCE, null, OLinkSerializer.INSTANCE, null); + treeBucket = new OSBTreeBucket<>(cacheEntry, OLongSerializer.INSTANCE, null, OLinkSerializer.INSTANCE, null); Assert.assertEquals(treeBucket.size(), 0); Assert.assertTrue(treeBucket.isLeaf()); Assert.assertEquals(treeBucket.getLeftSibling(), -1); @@ -54,7 +54,7 @@ public void testSearch() throws Exception { long seed = System.currentTimeMillis(); System.out.println("testSearch seed : " + seed); - TreeSet keys = new TreeSet(); + TreeSet keys = new TreeSet<>(); Random random = new Random(seed); while (keys.size() < 2 * OSBTreeBucket.MAX_PAGE_SIZE_BYTES / OLongSerializer.LONG_SIZE) { @@ -62,22 +62,23 @@ public void testSearch() throws Exception { } OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); cachePointer.incrementReferrer(); - OSBTreeBucket treeBucket = new OSBTreeBucket(cacheEntry, true, - OLongSerializer.INSTANCE, null, OLinkSerializer.INSTANCE, null); + OSBTreeBucket treeBucket = new OSBTreeBucket<>(cacheEntry, true, OLongSerializer.INSTANCE, null, + OLinkSerializer.INSTANCE, null); int index = 0; - Map keyIndexMap = new HashMap(); + Map keyIndexMap = new HashMap<>(); for (Long key : keys) { - if (!treeBucket.addEntry(index, new OSBTreeBucket.SBTreeEntry(-1, -1, key, - new OSBTreeValue(false, -1, new ORecordId(index, index))), true)) + if (!treeBucket + .addEntry(index, new OSBTreeBucket.SBTreeEntry<>(-1, -1, key, new OSBTreeValue<>(false, -1, new ORecordId(index, index))), + true)) break; keyIndexMap.put(key, index); index++; @@ -99,7 +100,7 @@ public void testUpdateValue() throws Exception { long seed = System.currentTimeMillis(); System.out.println("testUpdateValue seed : " + seed); - TreeSet keys = new TreeSet(); + TreeSet keys = new TreeSet<>(); Random random = new Random(seed); while (keys.size() < 2 * OSBTreeBucket.MAX_PAGE_SIZE_BYTES / OLongSerializer.LONG_SIZE) { @@ -107,22 +108,23 @@ public void testUpdateValue() throws Exception { } OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool,0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); cachePointer.incrementReferrer(); - OSBTreeBucket treeBucket = new OSBTreeBucket(cacheEntry, true, - OLongSerializer.INSTANCE, null, OLinkSerializer.INSTANCE, null); + OSBTreeBucket treeBucket = new OSBTreeBucket<>(cacheEntry, true, OLongSerializer.INSTANCE, null, + OLinkSerializer.INSTANCE, null); - Map keyIndexMap = new HashMap(); + Map keyIndexMap = new HashMap<>(); int index = 0; for (Long key : keys) { - if (!treeBucket.addEntry(index, new OSBTreeBucket.SBTreeEntry(-1, -1, key, - new OSBTreeValue(false, -1, new ORecordId(index, index))), true)) + if (!treeBucket + .addEntry(index, new OSBTreeBucket.SBTreeEntry<>(-1, -1, key, new OSBTreeValue<>(false, -1, new ORecordId(index, index))), + true)) break; keyIndexMap.put(key, index); @@ -141,8 +143,8 @@ public void testUpdateValue() throws Exception { for (Map.Entry keyIndexEntry : keyIndexMap.entrySet()) { OSBTreeBucket.SBTreeEntry entry = treeBucket.getEntry(keyIndexEntry.getValue()); - Assert.assertEquals(entry, new OSBTreeBucket.SBTreeEntry(-1, -1, keyIndexEntry.getKey(), - new OSBTreeValue(false, -1, new ORecordId(keyIndexEntry.getValue() + 5, keyIndexEntry.getValue() + 5)))); + Assert.assertEquals(entry, new OSBTreeBucket.SBTreeEntry<>(-1, -1, keyIndexEntry.getKey(), + new OSBTreeValue<>(false, -1, new ORecordId(keyIndexEntry.getValue() + 5, keyIndexEntry.getValue() + 5)))); Assert.assertEquals(keyIndexEntry.getKey(), treeBucket.getKey(keyIndexEntry.getValue())); } @@ -155,7 +157,7 @@ public void testShrink() throws Exception { long seed = System.currentTimeMillis(); System.out.println("testShrink seed : " + seed); - TreeSet keys = new TreeSet(); + TreeSet keys = new TreeSet<>(); Random random = new Random(seed); while (keys.size() < 2 * OSBTreeBucket.MAX_PAGE_SIZE_BYTES / OLongSerializer.LONG_SIZE) { @@ -163,21 +165,22 @@ public void testShrink() throws Exception { } OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); - OSBTreeBucket treeBucket = new OSBTreeBucket(cacheEntry, true, - OLongSerializer.INSTANCE, null, OLinkSerializer.INSTANCE, null); + OSBTreeBucket treeBucket = new OSBTreeBucket<>(cacheEntry, true, OLongSerializer.INSTANCE, null, + OLinkSerializer.INSTANCE, null); int index = 0; for (Long key : keys) { - if (!treeBucket.addEntry(index, new OSBTreeBucket.SBTreeEntry(-1, -1, key, - new OSBTreeValue(false, -1, new ORecordId(index, index))), true)) + if (!treeBucket + .addEntry(index, new OSBTreeBucket.SBTreeEntry<>(-1, -1, key, new OSBTreeValue<>(false, -1, new ORecordId(index, index))), + true)) break; index++; @@ -189,7 +192,7 @@ public void testShrink() throws Exception { Assert.assertEquals(treeBucket.size(), index / 2); index = 0; - final Map keyIndexMap = new HashMap(); + final Map keyIndexMap = new HashMap<>(); Iterator keysIterator = keys.iterator(); while (keysIterator.hasNext() && index < treeBucket.size()) { @@ -208,8 +211,9 @@ public void testShrink() throws Exception { while (keysIterator.hasNext() && index < originalSize) { Long key = keysIterator.next(); - if (!treeBucket.addEntry(index, new OSBTreeBucket.SBTreeEntry(-1, -1, key, - new OSBTreeValue(false, -1, new ORecordId(index, index))), true)) + if (!treeBucket + .addEntry(index, new OSBTreeBucket.SBTreeEntry<>(-1, -1, key, new OSBTreeValue<>(false, -1, new ORecordId(index, index))), + true)) break; keyIndexMap.put(key, index); @@ -220,8 +224,8 @@ public void testShrink() throws Exception { for (Map.Entry keyIndexEntry : keyIndexMap.entrySet()) { OSBTreeBucket.SBTreeEntry entry = treeBucket.getEntry(keyIndexEntry.getValue()); - Assert.assertEquals(entry, new OSBTreeBucket.SBTreeEntry(-1, -1, keyIndexEntry.getKey(), - new OSBTreeValue(false, -1, new ORecordId(keyIndexEntry.getValue(), keyIndexEntry.getValue())))); + Assert.assertEquals(entry, new OSBTreeBucket.SBTreeEntry<>(-1, -1, keyIndexEntry.getKey(), + new OSBTreeValue<>(false, -1, new ORecordId(keyIndexEntry.getValue(), keyIndexEntry.getValue())))); } Assert.assertEquals(treeBucket.size(), originalSize); @@ -236,7 +240,7 @@ public void testRemove() throws Exception { long seed = System.currentTimeMillis(); System.out.println("testRemove seed : " + seed); - TreeSet keys = new TreeSet(); + TreeSet keys = new TreeSet<>(); Random random = new Random(seed); while (keys.size() < 2 * OSBTreeBucket.MAX_PAGE_SIZE_BYTES / OLongSerializer.LONG_SIZE) { @@ -244,21 +248,22 @@ public void testRemove() throws Exception { } OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool,0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); - OSBTreeBucket treeBucket = new OSBTreeBucket(cacheEntry, true, - OLongSerializer.INSTANCE, null, OLinkSerializer.INSTANCE, null); + OSBTreeBucket treeBucket = new OSBTreeBucket<>(cacheEntry, true, OLongSerializer.INSTANCE, null, + OLinkSerializer.INSTANCE, null); int index = 0; for (Long key : keys) { - if (!treeBucket.addEntry(index, new OSBTreeBucket.SBTreeEntry(-1, -1, key, - new OSBTreeValue(false, -1, new ORecordId(index, index))), true)) + if (!treeBucket + .addEntry(index, new OSBTreeBucket.SBTreeEntry<>(-1, -1, key, new OSBTreeValue<>(false, -1, new ORecordId(index, index))), + true)) break; index++; @@ -276,7 +281,7 @@ public void testRemove() throws Exception { Assert.assertEquals(treeBucket.size(), originalSize - itemsToDelete); - final Map keyIndexMap = new HashMap(); + final Map keyIndexMap = new HashMap<>(); Iterator keysIterator = keys.iterator(); index = 0; @@ -296,8 +301,9 @@ public void testRemove() throws Exception { while (keysIterator.hasNext() && index < originalSize) { Long key = keysIterator.next(); - if (!treeBucket.addEntry(index, new OSBTreeBucket.SBTreeEntry(-1, -1, key, - new OSBTreeValue(false, -1, new ORecordId(index, index))), true)) + if (!treeBucket + .addEntry(index, new OSBTreeBucket.SBTreeEntry<>(-1, -1, key, new OSBTreeValue<>(false, -1, new ORecordId(index, index))), + true)) break; keyIndexMap.put(key, index); @@ -308,8 +314,8 @@ public void testRemove() throws Exception { for (Map.Entry keyIndexEntry : keyIndexMap.entrySet()) { OSBTreeBucket.SBTreeEntry entry = treeBucket.getEntry(keyIndexEntry.getValue()); - Assert.assertEquals(entry, new OSBTreeBucket.SBTreeEntry(-1, -1, keyIndexEntry.getKey(), - new OSBTreeValue(false, -1, new ORecordId(keyIndexEntry.getValue(), keyIndexEntry.getValue())))); + Assert.assertEquals(entry, new OSBTreeBucket.SBTreeEntry<>(-1, -1, keyIndexEntry.getKey(), + new OSBTreeValue<>(false, -1, new ORecordId(keyIndexEntry.getValue(), keyIndexEntry.getValue())))); } Assert.assertEquals(treeBucket.size(), originalSize); @@ -322,16 +328,16 @@ public void testRemove() throws Exception { @Test public void testSetLeftSibling() throws Exception { OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); - OSBTreeBucket treeBucket = new OSBTreeBucket(cacheEntry, true, - OLongSerializer.INSTANCE, null, OLinkSerializer.INSTANCE, null); + OSBTreeBucket treeBucket = new OSBTreeBucket<>(cacheEntry, true, OLongSerializer.INSTANCE, null, + OLinkSerializer.INSTANCE, null); treeBucket.setLeftSibling(123); Assert.assertEquals(treeBucket.getLeftSibling(), 123); @@ -342,16 +348,16 @@ public void testSetLeftSibling() throws Exception { @Test public void testSetRightSibling() throws Exception { OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); - OSBTreeBucket treeBucket = new OSBTreeBucket(cacheEntry, true, - OLongSerializer.INSTANCE, null, OLinkSerializer.INSTANCE, null); + OSBTreeBucket treeBucket = new OSBTreeBucket<>(cacheEntry, true, OLongSerializer.INSTANCE, null, + OLinkSerializer.INSTANCE, null); treeBucket.setRightSibling(123); Assert.assertEquals(treeBucket.getRightSibling(), 123); diff --git a/core/src/test/java/com/orientechnologies/orient/core/storage/index/sbtree/local/SBTreeNonLeafBucketTest.java b/core/src/test/java/com/orientechnologies/orient/core/storage/index/sbtree/local/SBTreeNonLeafBucketTest.java index 0b543d14508..d913efcbbcf 100755 --- a/core/src/test/java/com/orientechnologies/orient/core/storage/index/sbtree/local/SBTreeNonLeafBucketTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/storage/index/sbtree/local/SBTreeNonLeafBucketTest.java @@ -1,6 +1,7 @@ package com.orientechnologies.orient.core.storage.index.sbtree.local; import com.orientechnologies.common.directmemory.OByteBufferPool; +import com.orientechnologies.common.directmemory.OPointer; import com.orientechnologies.common.serialization.types.OLongSerializer; import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.serialization.serializer.binary.impl.OLinkSerializer; @@ -10,7 +11,6 @@ import org.junit.Assert; import org.junit.Test; -import java.nio.ByteBuffer; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -25,9 +25,9 @@ public class SBTreeNonLeafBucketTest { @Test public void testInitialization() throws Exception { final OByteBufferPool bufferPool = OByteBufferPool.instance(null); - final ByteBuffer buffer = bufferPool.acquireDirect(true); + final OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); cachePointer.incrementReferrer(); @@ -60,9 +60,9 @@ public void testSearch() throws Exception { } final OByteBufferPool bufferPool = OByteBufferPool.instance(null); - final ByteBuffer buffer = bufferPool.acquireDirect(true); + final OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); cachePointer.incrementReferrer(); @@ -126,9 +126,9 @@ public void testShrink() throws Exception { } final OByteBufferPool bufferPool = OByteBufferPool.instance(null); - final ByteBuffer buffer = bufferPool.acquireDirect(true); + final OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); diff --git a/core/src/test/java/com/orientechnologies/orient/core/storage/index/sbtree/local/SBTreeValuePageTest.java b/core/src/test/java/com/orientechnologies/orient/core/storage/index/sbtree/local/SBTreeValuePageTest.java index da2b0d7fd9a..61f9890fda9 100755 --- a/core/src/test/java/com/orientechnologies/orient/core/storage/index/sbtree/local/SBTreeValuePageTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/storage/index/sbtree/local/SBTreeValuePageTest.java @@ -1,6 +1,7 @@ package com.orientechnologies.orient.core.storage.index.sbtree.local; import com.orientechnologies.common.directmemory.OByteBufferPool; +import com.orientechnologies.common.directmemory.OPointer; import com.orientechnologies.orient.core.storage.cache.OCacheEntry; import com.orientechnologies.orient.core.storage.cache.OCacheEntryImpl; import com.orientechnologies.orient.core.storage.cache.OCachePointer; @@ -9,7 +10,6 @@ import org.junit.Assert; import org.junit.Test; -import java.nio.ByteBuffer; import java.util.Random; /** @@ -20,9 +20,9 @@ public class SBTreeValuePageTest { @Test public void fillPageDataTest() throws Exception { OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer bufferOne = bufferPool.acquireDirect(true); + OPointer pointerOne = bufferPool.acquireDirect(true); - OCachePointer cachePointerOne = new OCachePointer(bufferOne, bufferPool, 0, 0); + OCachePointer cachePointerOne = new OCachePointer(pointerOne, bufferPool, 0, 0); cachePointerOne.incrementReferrer(); OCacheEntry cacheEntryOne = new OCacheEntryImpl(0, 0, cachePointerOne); @@ -36,8 +36,8 @@ public void fillPageDataTest() throws Exception { int offset = valuePageOne.fillBinaryContent(data, 0); Assert.assertEquals(offset, OSBTreeValuePage.MAX_BINARY_VALUE_SIZE); - ByteBuffer bufferTwo = bufferPool.acquireDirect(true); - OCachePointer cachePointerTwo = new OCachePointer(bufferTwo, bufferPool, 0, 0); + OPointer pointerTwo = bufferPool.acquireDirect(true); + OCachePointer cachePointerTwo = new OCachePointer(pointerTwo, bufferPool, 0, 0); cachePointerTwo.incrementReferrer(); OCacheEntry cacheEntryTwo = new OCacheEntryImpl(0, 0, cachePointerTwo); @@ -70,9 +70,9 @@ public void fillPageDataTest() throws Exception { @Test public void testFreeListPointer() throws Exception { OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); diff --git a/core/src/test/java/com/orientechnologies/orient/core/storage/index/sbtreebonsai/local/OSBTreeBonsaiLeafBucketTest.java b/core/src/test/java/com/orientechnologies/orient/core/storage/index/sbtreebonsai/local/OSBTreeBonsaiLeafBucketTest.java index 1605456fcc9..283265163f9 100755 --- a/core/src/test/java/com/orientechnologies/orient/core/storage/index/sbtreebonsai/local/OSBTreeBonsaiLeafBucketTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/storage/index/sbtreebonsai/local/OSBTreeBonsaiLeafBucketTest.java @@ -1,6 +1,7 @@ package com.orientechnologies.orient.core.storage.index.sbtreebonsai.local; import com.orientechnologies.common.directmemory.OByteBufferPool; +import com.orientechnologies.common.directmemory.OPointer; import com.orientechnologies.common.serialization.types.OLongSerializer; import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.id.ORecordId; @@ -11,7 +12,6 @@ import org.junit.Assert; import org.junit.Test; -import java.nio.ByteBuffer; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -26,21 +26,20 @@ public class OSBTreeBonsaiLeafBucketTest { @Test public void testInitialization() throws Exception { OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); - OSBTreeBonsaiBucket treeBucket = new OSBTreeBonsaiBucket(cacheEntry, 0, true, - OLongSerializer.INSTANCE, OLinkSerializer.INSTANCE, null); + OSBTreeBonsaiBucket treeBucket = new OSBTreeBonsaiBucket<>(cacheEntry, 0, true, OLongSerializer.INSTANCE, + OLinkSerializer.INSTANCE, null); Assert.assertEquals(treeBucket.size(), 0); Assert.assertTrue(treeBucket.isLeaf()); - treeBucket = new OSBTreeBonsaiBucket(cacheEntry, 0, OLongSerializer.INSTANCE, OLinkSerializer.INSTANCE, - null); + treeBucket = new OSBTreeBonsaiBucket<>(cacheEntry, 0, OLongSerializer.INSTANCE, OLinkSerializer.INSTANCE, null); Assert.assertEquals(treeBucket.size(), 0); Assert.assertTrue(treeBucket.isLeaf()); Assert.assertFalse(treeBucket.getLeftSibling().isValid()); @@ -55,7 +54,7 @@ public void testSearch() throws Exception { long seed = System.currentTimeMillis(); System.out.println("testSearch seed : " + seed); - TreeSet keys = new TreeSet(); + TreeSet keys = new TreeSet<>(); Random random = new Random(seed); while (keys.size() < 2 * OSBTreeBonsaiBucket.MAX_BUCKET_SIZE_BYTES / OLongSerializer.LONG_SIZE) { @@ -63,22 +62,22 @@ public void testSearch() throws Exception { } OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); - OSBTreeBonsaiBucket treeBucket = new OSBTreeBonsaiBucket(cacheEntry, 0, true, - OLongSerializer.INSTANCE, OLinkSerializer.INSTANCE, null); + OSBTreeBonsaiBucket treeBucket = new OSBTreeBonsaiBucket<>(cacheEntry, 0, true, OLongSerializer.INSTANCE, + OLinkSerializer.INSTANCE, null); int index = 0; - Map keyIndexMap = new HashMap(); + Map keyIndexMap = new HashMap<>(); for (Long key : keys) { if (!treeBucket.addEntry(index, - new OSBTreeBonsaiBucket.SBTreeEntry(OBonsaiBucketPointer.NULL, OBonsaiBucketPointer.NULL, key, + new OSBTreeBonsaiBucket.SBTreeEntry<>(OBonsaiBucketPointer.NULL, OBonsaiBucketPointer.NULL, key, new ORecordId(index, index)), true)) break; keyIndexMap.put(key, index); @@ -101,7 +100,7 @@ public void testUpdateValue() throws Exception { long seed = System.currentTimeMillis(); System.out.println("testUpdateValue seed : " + seed); - TreeSet keys = new TreeSet(); + TreeSet keys = new TreeSet<>(); Random random = new Random(seed); while (keys.size() < 2 * OSBTreeBonsaiBucket.MAX_BUCKET_SIZE_BYTES / OLongSerializer.LONG_SIZE) { @@ -109,22 +108,22 @@ public void testUpdateValue() throws Exception { } OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool,0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); - OSBTreeBonsaiBucket treeBucket = new OSBTreeBonsaiBucket(cacheEntry, 0, true, - OLongSerializer.INSTANCE, OLinkSerializer.INSTANCE, null); + OSBTreeBonsaiBucket treeBucket = new OSBTreeBonsaiBucket<>(cacheEntry, 0, true, OLongSerializer.INSTANCE, + OLinkSerializer.INSTANCE, null); - Map keyIndexMap = new HashMap(); + Map keyIndexMap = new HashMap<>(); int index = 0; for (Long key : keys) { if (!treeBucket.addEntry(index, - new OSBTreeBonsaiBucket.SBTreeEntry(OBonsaiBucketPointer.NULL, OBonsaiBucketPointer.NULL, key, + new OSBTreeBonsaiBucket.SBTreeEntry<>(OBonsaiBucketPointer.NULL, OBonsaiBucketPointer.NULL, key, new ORecordId(index, index)), true)) break; @@ -155,7 +154,7 @@ public void testShrink() throws Exception { long seed = System.currentTimeMillis(); System.out.println("testShrink seed : " + seed); - TreeSet keys = new TreeSet(); + TreeSet keys = new TreeSet<>(); Random random = new Random(seed); while (keys.size() < 2 * OSBTreeBonsaiBucket.MAX_BUCKET_SIZE_BYTES / OLongSerializer.LONG_SIZE) { @@ -163,21 +162,21 @@ public void testShrink() throws Exception { } OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); cachePointer.incrementReferrer(); - OSBTreeBonsaiBucket treeBucket = new OSBTreeBonsaiBucket(cacheEntry, 0, true, - OLongSerializer.INSTANCE, OLinkSerializer.INSTANCE, null); + OSBTreeBonsaiBucket treeBucket = new OSBTreeBonsaiBucket<>(cacheEntry, 0, true, OLongSerializer.INSTANCE, + OLinkSerializer.INSTANCE, null); int index = 0; for (Long key : keys) { if (!treeBucket.addEntry(index, - new OSBTreeBonsaiBucket.SBTreeEntry(OBonsaiBucketPointer.NULL, OBonsaiBucketPointer.NULL, key, + new OSBTreeBonsaiBucket.SBTreeEntry<>(OBonsaiBucketPointer.NULL, OBonsaiBucketPointer.NULL, key, new ORecordId(index, index)), true)) break; @@ -190,7 +189,7 @@ public void testShrink() throws Exception { Assert.assertEquals(treeBucket.size(), index / 2); index = 0; - final Map keyIndexMap = new HashMap(); + final Map keyIndexMap = new HashMap<>(); Iterator keysIterator = keys.iterator(); while (keysIterator.hasNext() && index < treeBucket.size()) { @@ -210,7 +209,7 @@ public void testShrink() throws Exception { Long key = keysIterator.next(); if (!treeBucket.addEntry(index, - new OSBTreeBonsaiBucket.SBTreeEntry(OBonsaiBucketPointer.NULL, OBonsaiBucketPointer.NULL, key, + new OSBTreeBonsaiBucket.SBTreeEntry<>(OBonsaiBucketPointer.NULL, OBonsaiBucketPointer.NULL, key, new ORecordId(index, index)), true)) break; @@ -239,7 +238,7 @@ public void testRemove() throws Exception { long seed = System.currentTimeMillis(); System.out.println("testRemove seed : " + seed); - TreeSet keys = new TreeSet(); + TreeSet keys = new TreeSet<>(); Random random = new Random(seed); while (keys.size() < 2 * OSBTreeBonsaiBucket.MAX_BUCKET_SIZE_BYTES / OLongSerializer.LONG_SIZE) { @@ -247,21 +246,21 @@ public void testRemove() throws Exception { } OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); - OSBTreeBonsaiBucket treeBucket = new OSBTreeBonsaiBucket(cacheEntry, 0, true, - OLongSerializer.INSTANCE, OLinkSerializer.INSTANCE, null); + OSBTreeBonsaiBucket treeBucket = new OSBTreeBonsaiBucket<>(cacheEntry, 0, true, OLongSerializer.INSTANCE, + OLinkSerializer.INSTANCE, null); int index = 0; for (Long key : keys) { if (!treeBucket.addEntry(index, - new OSBTreeBonsaiBucket.SBTreeEntry(OBonsaiBucketPointer.NULL, OBonsaiBucketPointer.NULL, key, + new OSBTreeBonsaiBucket.SBTreeEntry<>(OBonsaiBucketPointer.NULL, OBonsaiBucketPointer.NULL, key, new ORecordId(index, index)), true)) break; @@ -277,7 +276,7 @@ public void testRemove() throws Exception { Assert.assertEquals(treeBucket.size(), originalSize - itemsToDelete); - final Map keyIndexMap = new HashMap(); + final Map keyIndexMap = new HashMap<>(); Iterator keysIterator = keys.iterator(); index = 0; @@ -298,7 +297,7 @@ public void testRemove() throws Exception { Long key = keysIterator.next(); if (!treeBucket.addEntry(index, - new OSBTreeBonsaiBucket.SBTreeEntry(OBonsaiBucketPointer.NULL, OBonsaiBucketPointer.NULL, key, + new OSBTreeBonsaiBucket.SBTreeEntry<>(OBonsaiBucketPointer.NULL, OBonsaiBucketPointer.NULL, key, new ORecordId(index, index)), true)) break; @@ -325,16 +324,16 @@ public void testRemove() throws Exception { @Test public void testSetLeftSibling() throws Exception { OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); - OSBTreeBonsaiBucket treeBucket = new OSBTreeBonsaiBucket(cacheEntry, 0, true, - OLongSerializer.INSTANCE, OLinkSerializer.INSTANCE, null); + OSBTreeBonsaiBucket treeBucket = new OSBTreeBonsaiBucket<>(cacheEntry, 0, true, OLongSerializer.INSTANCE, + OLinkSerializer.INSTANCE, null); final OBonsaiBucketPointer p = new OBonsaiBucketPointer(123, 8192 * 2); treeBucket.setLeftSibling(p); Assert.assertEquals(treeBucket.getLeftSibling(), p); @@ -346,16 +345,16 @@ public void testSetLeftSibling() throws Exception { @Test public void testSetRightSibling() throws Exception { OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); - OSBTreeBonsaiBucket treeBucket = new OSBTreeBonsaiBucket(cacheEntry, 0, true, - OLongSerializer.INSTANCE, OLinkSerializer.INSTANCE, null); + OSBTreeBonsaiBucket treeBucket = new OSBTreeBonsaiBucket<>(cacheEntry, 0, true, OLongSerializer.INSTANCE, + OLinkSerializer.INSTANCE, null); final OBonsaiBucketPointer p = new OBonsaiBucketPointer(123, 8192 * 2); treeBucket.setRightSibling(p); Assert.assertEquals(treeBucket.getRightSibling(), p); diff --git a/core/src/test/java/com/orientechnologies/orient/core/storage/index/sbtreebonsai/local/OSBTreeBonsaiNonLeafBucketTest.java b/core/src/test/java/com/orientechnologies/orient/core/storage/index/sbtreebonsai/local/OSBTreeBonsaiNonLeafBucketTest.java index d7a6edc56ca..724ad87fbf8 100755 --- a/core/src/test/java/com/orientechnologies/orient/core/storage/index/sbtreebonsai/local/OSBTreeBonsaiNonLeafBucketTest.java +++ b/core/src/test/java/com/orientechnologies/orient/core/storage/index/sbtreebonsai/local/OSBTreeBonsaiNonLeafBucketTest.java @@ -1,6 +1,7 @@ package com.orientechnologies.orient.core.storage.index.sbtreebonsai.local; import com.orientechnologies.common.directmemory.OByteBufferPool; +import com.orientechnologies.common.directmemory.OPointer; import com.orientechnologies.common.serialization.types.OLongSerializer; import com.orientechnologies.orient.core.db.record.OIdentifiable; import com.orientechnologies.orient.core.serialization.serializer.binary.impl.OLinkSerializer; @@ -10,7 +11,6 @@ import org.junit.Assert; import org.junit.Test; -import java.nio.ByteBuffer; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -26,9 +26,9 @@ public class OSBTreeBonsaiNonLeafBucketTest { @Test public void testInitialization() throws Exception { OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock(); @@ -62,9 +62,9 @@ public void testSearch() throws Exception { } OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); @@ -129,9 +129,9 @@ public void testShrink() throws Exception { } OByteBufferPool bufferPool = OByteBufferPool.instance(null); - ByteBuffer buffer = bufferPool.acquireDirect(true); + OPointer pointer = bufferPool.acquireDirect(true); - OCachePointer cachePointer = new OCachePointer(buffer, bufferPool, 0, 0); + OCachePointer cachePointer = new OCachePointer(pointer, bufferPool, 0, 0); cachePointer.incrementReferrer(); OCacheEntry cacheEntry = new OCacheEntryImpl(0, 0, cachePointer); cacheEntry.acquireExclusiveLock();