Skip to content

Commit

Permalink
Issue #4284 , binary compatibility issue was fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii0lomakin committed Jun 8, 2015
1 parent cecc1fc commit 2a004c4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand All @@ -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;

Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -140,7 +141,7 @@ public void create(long fileId, OBinarySerializer<K> keySerializer, OBinarySeria

openFile(atomicOperation, fileId);

this.fileId = fileId;
this.fileId = OAbstractWriteCache.checkFileIdCompatibility(fileId, storage.getId());
this.name = resolveTreeName(fileId, atomicOperation);

initAfterCreate(atomicOperation);
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}

0 comments on commit 2a004c4

Please sign in to comment.