From 2a004c4b73a8609cf941b54707f6e23ff7cbea22 Mon Sep 17 00:00:00 2001 From: laa Date: Mon, 8 Jun 2015 13:22:49 +0300 Subject: [PATCH] Issue #4284 , binary compatibility issue was fixed. --- .../index/hashindex/local/cache/O2QCache.java | 33 +++++-------------- .../local/OSBTreeBonsaiLocal.java | 4 ++- .../storage/cache/OAbstractWriteCache.java | 8 +++++ 3 files changed, 20 insertions(+), 25 deletions(-) diff --git a/core/src/main/java/com/orientechnologies/orient/core/index/hashindex/local/cache/O2QCache.java b/core/src/main/java/com/orientechnologies/orient/core/index/hashindex/local/cache/O2QCache.java index b1c6db2b362..8eeba3bf052 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/index/hashindex/local/cache/O2QCache.java +++ b/core/src/main/java/com/orientechnologies/orient/core/index/hashindex/local/cache/O2QCache.java @@ -25,6 +25,7 @@ import com.orientechnologies.common.exception.OException; import com.orientechnologies.orient.core.exception.OAllCacheEntriesAreUsedException; import com.orientechnologies.orient.core.exception.OStorageException; +import com.orientechnologies.orient.core.storage.cache.OAbstractWriteCache; import com.orientechnologies.orient.core.storage.cache.OWriteCache; import com.orientechnologies.orient.core.storage.impl.local.paginated.base.ODurablePage; @@ -140,7 +141,7 @@ public long openFile(final String fileName, OWriteCache writeCache) throws IOExc @Override public void openFile(long fileId, OWriteCache writeCache) throws IOException { - fileId = checkFileIdCompatibilty(fileId, writeCache.getId()); + fileId = OAbstractWriteCache.checkFileIdCompatibility(fileId, writeCache.getId()); cacheLock.acquireReadLock(); Lock fileLock; @@ -164,7 +165,7 @@ public void openFile(long fileId, OWriteCache writeCache) throws IOException { @Override public void openFile(String fileName, long fileId, OWriteCache writeCache) throws IOException { - fileId = checkFileIdCompatibilty(fileId, writeCache.getId()); + fileId = OAbstractWriteCache.checkFileIdCompatibility(fileId, writeCache.getId()); cacheLock.acquireWriteLock(); try { @@ -188,7 +189,7 @@ public void openFile(String fileName, long fileId, OWriteCache writeCache) throw @Override public void addFile(String fileName, long fileId, OWriteCache writeCache) throws IOException { - fileId = checkFileIdCompatibilty(fileId, writeCache.getId()); + fileId = OAbstractWriteCache.checkFileIdCompatibility(fileId, writeCache.getId()); cacheLock.acquireWriteLock(); try { @@ -227,7 +228,7 @@ public void pinPage(final OCacheEntry cacheEntry) throws IOException { @Override public OCacheEntry load(long fileId, final long pageIndex, final boolean checkPinnedPages, OWriteCache writeCache) throws IOException { - fileId = checkFileIdCompatibilty(fileId, writeCache.getId()); + fileId = OAbstractWriteCache.checkFileIdCompatibility(fileId, writeCache.getId()); final UpdateCacheResult cacheResult = doLoad(fileId, pageIndex, checkPinnedPages, false, writeCache); if (cacheResult == null) @@ -288,7 +289,7 @@ private UpdateCacheResult doLoad(long fileId, long pageIndex, boolean checkPinne @Override public OCacheEntry allocateNewPage(long fileId, OWriteCache writeCache) throws IOException { - fileId = checkFileIdCompatibilty(fileId, writeCache.getId()); + fileId = OAbstractWriteCache.checkFileIdCompatibility(fileId, writeCache.getId()); UpdateCacheResult cacheResult; @@ -375,7 +376,7 @@ public void clear() { @Override public void truncateFile(long fileId, OWriteCache writeCache) throws IOException { Lock fileLock; - fileId = checkFileIdCompatibilty(fileId, writeCache.getId()); + fileId = OAbstractWriteCache.checkFileIdCompatibility(fileId, writeCache.getId()); cacheLock.acquireReadLock(); try { @@ -430,7 +431,7 @@ private void clearFile(long fileId) { @Override public void closeFile(long fileId, boolean flush, OWriteCache writeCache) throws IOException { - fileId = checkFileIdCompatibilty(fileId, writeCache.getId()); + fileId = OAbstractWriteCache.checkFileIdCompatibility(fileId, writeCache.getId()); Lock fileLock; cacheLock.acquireReadLock(); @@ -452,7 +453,7 @@ public void closeFile(long fileId, boolean flush, OWriteCache writeCache) throws @Override public void deleteFile(long fileId, OWriteCache writeCache) throws IOException { - fileId = checkFileIdCompatibilty(fileId, writeCache.getId()); + fileId = OAbstractWriteCache.checkFileIdCompatibility(fileId, writeCache.getId()); Lock fileLock; @@ -933,20 +934,4 @@ private UpdateCacheResult(boolean removeColdPages, OCacheEntry cacheEntry) { this.cacheEntry = cacheEntry; } } - - private int storageId(long fileId) { - return (int) (fileId >>> 32); - } - - private long composeFileId(long fileId, int storageId) { - return (((long) storageId) << 32) | fileId; - } - - private long checkFileIdCompatibilty(long fileId, int storageId) { - if (storageId(fileId) == 0) { - return composeFileId(fileId, storageId); - } - - return fileId; - } } diff --git a/core/src/main/java/com/orientechnologies/orient/core/index/sbtreebonsai/local/OSBTreeBonsaiLocal.java b/core/src/main/java/com/orientechnologies/orient/core/index/sbtreebonsai/local/OSBTreeBonsaiLocal.java index cba83057639..c629cf089b5 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/index/sbtreebonsai/local/OSBTreeBonsaiLocal.java +++ b/core/src/main/java/com/orientechnologies/orient/core/index/sbtreebonsai/local/OSBTreeBonsaiLocal.java @@ -44,6 +44,7 @@ import com.orientechnologies.orient.core.index.sbtree.local.OSBTree; import com.orientechnologies.orient.core.index.sbtree.local.OSBTreeException; import com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory; +import com.orientechnologies.orient.core.storage.cache.OAbstractWriteCache; import com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage; import com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation; import com.orientechnologies.orient.core.storage.impl.local.paginated.base.ODurableComponent; @@ -140,7 +141,7 @@ public void create(long fileId, OBinarySerializer keySerializer, OBinarySeria openFile(atomicOperation, fileId); - this.fileId = fileId; + this.fileId = OAbstractWriteCache.checkFileIdCompatibility(fileId, storage.getId()); this.name = resolveTreeName(fileId, atomicOperation); initAfterCreate(atomicOperation); @@ -483,6 +484,7 @@ public void delete() { } public void load(long fileId, OBonsaiBucketPointer rootBucketPointer) { + fileId = OAbstractWriteCache.checkFileIdCompatibility(fileId, storage.getId()); Lock lock = fileLockManager.acquireExclusiveLock(fileId); try { this.rootBucketPointer = rootBucketPointer; diff --git a/core/src/main/java/com/orientechnologies/orient/core/storage/cache/OAbstractWriteCache.java b/core/src/main/java/com/orientechnologies/orient/core/storage/cache/OAbstractWriteCache.java index d9c4c4b5764..6d598bcff09 100755 --- a/core/src/main/java/com/orientechnologies/orient/core/storage/cache/OAbstractWriteCache.java +++ b/core/src/main/java/com/orientechnologies/orient/core/storage/cache/OAbstractWriteCache.java @@ -16,4 +16,12 @@ public static int extractStorageId(long fileId) { return (int) (fileId >>> 32); } + public static long checkFileIdCompatibility(long fileId, int storageId) { + if (extractStorageId(fileId) == 0) { + return composeFileId((int) fileId, storageId); + } + + return fileId; + } + }