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 85bc843efaa..df89fb16d30 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 @@ -23,7 +23,6 @@ import com.orientechnologies.common.directmemory.OPointer; import com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OLogSequenceNumber; import java.nio.ByteBuffer; -import java.nio.ByteOrder; import java.util.concurrent.atomic.AtomicIntegerFieldUpdater; import java.util.concurrent.atomic.AtomicLongFieldUpdater; import java.util.concurrent.locks.ReentrantReadWriteLock; @@ -44,7 +43,7 @@ public final class OCachePointer { } private static final int WRITERS_OFFSET = 32; - private static final int READERS_MASK = 0xFFFFFFFF; + private static final long READERS_MASK = 0xFFFFFFFFL; private final ReentrantReadWriteLock readWriteLock = new ReentrantReadWriteLock(); @@ -232,16 +231,6 @@ public OPointer getPointer() { return pointer; } - public ByteBuffer getBufferDuplicate() { - if (pointer == null) { - return null; - } - final ByteBuffer duplicate = - pointer.getNativeByteBuffer().duplicate().order(ByteOrder.nativeOrder()); - duplicate.rewind(); - return duplicate; - } - public void acquireExclusiveLock() { readWriteLock.writeLock().lock(); version++; diff --git a/core/src/test/java/com/orientechnologies/orient/core/storage/index/hashindex/local/cache/WOWCacheTestIT.java b/core/src/test/java/com/orientechnologies/orient/core/storage/index/hashindex/local/cache/WOWCacheTestIT.java index 7accc8943cb..12c453e105f 100755 --- a/core/src/test/java/com/orientechnologies/orient/core/storage/index/hashindex/local/cache/WOWCacheTestIT.java +++ b/core/src/test/java/com/orientechnologies/orient/core/storage/index/hashindex/local/cache/WOWCacheTestIT.java @@ -376,14 +376,13 @@ public void testDataUpdate() throws Exception { final OCachePointer cachePointer = wowCache.load(fileId, pageIndex, new OModifiableBoolean(), false); cachePointer.acquireExclusiveLock(); - ByteBuffer buffer = cachePointer.getBufferDuplicate(); + ByteBuffer buffer = cachePointer.getBuffer(); assert buffer != null; Assert.assertEquals( new OLogSequenceNumber(0, 0), ODurablePage.getLogSequenceNumberFromPage(buffer)); - buffer.position(ODurablePage.NEXT_FREE_POSITION); - buffer.put(data); + buffer.put(ODurablePage.NEXT_FREE_POSITION, data); cachePointer.releaseExclusiveLock(); wowCache.store(fileId, pageIndex, cachePointer); @@ -396,11 +395,9 @@ public void testDataUpdate() throws Exception { OCachePointer cachePointer = wowCache.load(fileId, pageIndex, new OModifiableBoolean(), true); byte[] dataTwo = new byte[8]; - ByteBuffer buffer = cachePointer.getBufferDuplicate(); + ByteBuffer buffer = cachePointer.getBuffer(); assert buffer != null; - - buffer.position(ODurablePage.NEXT_FREE_POSITION); - buffer.get(dataTwo); + buffer.get(ODurablePage.NEXT_FREE_POSITION, dataTwo); cachePointer.decrementReadersReferrer(); Assert.assertArrayEquals(dataTwo, dataOne); @@ -420,11 +417,10 @@ public void testDataUpdate() throws Exception { wowCache.load(fileId, pageIndex, new OModifiableBoolean(), true); cachePointer.acquireExclusiveLock(); - ByteBuffer buffer = cachePointer.getBufferDuplicate(); + ByteBuffer buffer = cachePointer.getBuffer(); assert buffer != null; - buffer.position(ODurablePage.NEXT_FREE_POSITION); - buffer.put(data); + buffer.put(ODurablePage.NEXT_FREE_POSITION, data); cachePointer.releaseExclusiveLock(); wowCache.store(fileId, pageIndex, cachePointer); @@ -436,11 +432,10 @@ public void testDataUpdate() throws Exception { byte[] dataOne = entry.getValue(); OCachePointer cachePointer = wowCache.load(fileId, pageIndex, new OModifiableBoolean(), true); byte[] dataTwo = new byte[8]; - ByteBuffer buffer = cachePointer.getBufferDuplicate(); + ByteBuffer buffer = cachePointer.getBuffer(); assert buffer != null; - buffer.position(ODurablePage.NEXT_FREE_POSITION); - buffer.get(dataTwo); + buffer.get(ODurablePage.NEXT_FREE_POSITION, dataTwo); cachePointer.decrementReadersReferrer(); Assert.assertArrayEquals(dataTwo, dataOne); @@ -529,17 +524,16 @@ public void testDataUpdateEncrypted() throws Exception { final OCachePointer cachePointer = wowCache.load(fileId, pageIndex, new OModifiableBoolean(), verifyChecksums); - ByteBuffer bufferDuplicate = cachePointer.getBufferDuplicate(); + ByteBuffer bufferDuplicate = cachePointer.getBuffer(); assert bufferDuplicate != null; Assert.assertEquals( new OLogSequenceNumber(0, 0), ODurablePage.getLogSequenceNumberFromPage(bufferDuplicate)); cachePointer.acquireExclusiveLock(); - ByteBuffer buffer = cachePointer.getBufferDuplicate(); + ByteBuffer buffer = cachePointer.getBuffer(); - buffer.position(ODurablePage.NEXT_FREE_POSITION); - buffer.put(data); + buffer.put(ODurablePage.NEXT_FREE_POSITION, data); cachePointer.releaseExclusiveLock(); @@ -553,11 +547,10 @@ public void testDataUpdateEncrypted() throws Exception { OCachePointer cachePointer = wowCache.load(fileId, pageIndex, new OModifiableBoolean(), true); byte[] dataTwo = new byte[8]; - ByteBuffer buffer = cachePointer.getBufferDuplicate(); + ByteBuffer buffer = cachePointer.getBuffer(); assert buffer != null; - buffer.position(ODurablePage.NEXT_FREE_POSITION); - buffer.get(dataTwo); + buffer.get(ODurablePage.NEXT_FREE_POSITION, dataTwo); cachePointer.decrementReadersReferrer(); Assert.assertArrayEquals(dataTwo, dataOne); @@ -577,11 +570,10 @@ public void testDataUpdateEncrypted() throws Exception { wowCache.load(fileId, pageIndex, new OModifiableBoolean(), true); cachePointer.acquireExclusiveLock(); - ByteBuffer buffer = cachePointer.getBufferDuplicate(); + ByteBuffer buffer = cachePointer.getBuffer(); assert buffer != null; - buffer.position(ODurablePage.NEXT_FREE_POSITION); - buffer.put(data); + buffer.put(ODurablePage.NEXT_FREE_POSITION, data); cachePointer.releaseExclusiveLock(); @@ -594,11 +586,10 @@ public void testDataUpdateEncrypted() throws Exception { byte[] dataOne = entry.getValue(); OCachePointer cachePointer = wowCache.load(fileId, pageIndex, new OModifiableBoolean(), true); byte[] dataTwo = new byte[8]; - ByteBuffer buffer = cachePointer.getBufferDuplicate(); + ByteBuffer buffer = cachePointer.getBuffer(); assert buffer != null; - buffer.position(ODurablePage.NEXT_FREE_POSITION); - buffer.get(dataTwo); + buffer.get(ODurablePage.NEXT_FREE_POSITION, dataTwo); cachePointer.decrementReadersReferrer(); Assert.assertArrayEquals(dataTwo, dataOne); @@ -685,11 +676,10 @@ public void testChecksumFailure() throws IOException { final OCachePointer cachePointer = wowCache.load(fileId, 0, new OModifiableBoolean(), false); cachePointer.acquireExclusiveLock(); - final ByteBuffer buffer = cachePointer.getBufferDuplicate(); + final ByteBuffer buffer = cachePointer.getBuffer(); assert buffer != null; - buffer.position(ODurablePage.NEXT_FREE_POSITION); - buffer.put(new byte[buffer.remaining()]); + buffer.put(ODurablePage.NEXT_FREE_POSITION, new byte[buffer.remaining()]); cachePointer.releaseExclusiveLock(); wowCache.store(fileId, 0, cachePointer); @@ -725,11 +715,10 @@ public void testMagicFailure() throws IOException { final OCachePointer cachePointer = wowCache.load(fileId, 0, new OModifiableBoolean(), false); cachePointer.acquireExclusiveLock(); - final ByteBuffer buffer = cachePointer.getBufferDuplicate(); + final ByteBuffer buffer = cachePointer.getBuffer(); assert buffer != null; - buffer.position(ODurablePage.NEXT_FREE_POSITION); - buffer.put(new byte[buffer.remaining()]); + buffer.put(ODurablePage.NEXT_FREE_POSITION, new byte[buffer.remaining()]); cachePointer.releaseExclusiveLock(); wowCache.store(fileId, 0, cachePointer); @@ -763,11 +752,10 @@ public void testNoChecksumVerificationIfNotRequested() throws IOException { final OCachePointer cachePointer = wowCache.load(fileId, 0, new OModifiableBoolean(), false); cachePointer.acquireExclusiveLock(); - final ByteBuffer buffer = cachePointer.getBufferDuplicate(); + final ByteBuffer buffer = cachePointer.getBuffer(); assert buffer != null; - buffer.position(ODurablePage.NEXT_FREE_POSITION); - buffer.put(new byte[buffer.remaining()]); + buffer.put(ODurablePage.NEXT_FREE_POSITION, new byte[buffer.remaining()]); cachePointer.releaseExclusiveLock(); wowCache.store(fileId, 0, cachePointer); @@ -798,11 +786,10 @@ public void testNoChecksumFailureIfVerificationTurnedOff() throws IOException { final OCachePointer cachePointer = wowCache.load(fileId, 0, new OModifiableBoolean(), true); cachePointer.acquireExclusiveLock(); - final ByteBuffer buffer = cachePointer.getBufferDuplicate(); + final ByteBuffer buffer = cachePointer.getBuffer(); assert buffer != null; - buffer.position(ODurablePage.NEXT_FREE_POSITION); - buffer.put(new byte[buffer.remaining()]); + buffer.put(ODurablePage.NEXT_FREE_POSITION, new byte[buffer.remaining()]); cachePointer.releaseExclusiveLock(); wowCache.store(fileId, 0, cachePointer); @@ -833,11 +820,10 @@ public void testNoChecksumFailureIfVerificationTurnedOffOnLoad() throws IOExcept final OCachePointer cachePointer = wowCache.load(fileId, 0, new OModifiableBoolean(), true); cachePointer.acquireExclusiveLock(); - final ByteBuffer buffer = cachePointer.getBufferDuplicate(); + final ByteBuffer buffer = cachePointer.getBuffer(); assert buffer != null; - buffer.position(ODurablePage.NEXT_FREE_POSITION); - buffer.put(new byte[buffer.remaining()]); + buffer.put(ODurablePage.NEXT_FREE_POSITION, new byte[buffer.remaining()]); cachePointer.releaseExclusiveLock(); wowCache.store(fileId, 0, cachePointer); @@ -868,11 +854,10 @@ public void testNoChecksumFailureIfNoChecksumProvided() throws IOException { final OCachePointer cachePointer = wowCache.load(fileId, 0, new OModifiableBoolean(), true); cachePointer.acquireExclusiveLock(); - final ByteBuffer buffer = cachePointer.getBufferDuplicate(); + final ByteBuffer buffer = cachePointer.getBuffer(); assert buffer != null; - buffer.position(ODurablePage.NEXT_FREE_POSITION); - buffer.put(new byte[buffer.remaining()]); + buffer.put(ODurablePage.NEXT_FREE_POSITION, new byte[buffer.remaining()]); cachePointer.releaseExclusiveLock(); wowCache.store(fileId, 0, cachePointer);