Skip to content

Commit

Permalink
Issue #4496 first version of update method.
Browse files Browse the repository at this point in the history
  • Loading branch information
laa committed Jul 15, 2015
1 parent 8bc78dd commit f57aab6
Show file tree
Hide file tree
Showing 5 changed files with 247 additions and 180 deletions.
Expand Up @@ -166,6 +166,7 @@ public enum OGlobalConfiguration {
PAGINATED_STORAGE_LOWEST_FREELIST_BOUNDARY("storage.lowestFreeListBound", "The minimal amount of free space (in kb)"
+ " in page which is tracked in paginated storage", Integer.class, 16),

@Deprecated
STORAGE_USE_CRC32_FOR_EACH_RECORD("storage.cluster.usecrc32",
"Indicates whether crc32 should be used for each record to check record integrity.", Boolean.class, false),

Expand Down
Expand Up @@ -2077,7 +2077,6 @@ private byte[] checkAndIncrementVersion(final OCluster iCluster, final ORecordId

// DOCUMENT UPDATE, NO VERSION CONTROL, NO VERSION UPDATE
case -2:
iDatabaseVersion.setCounter(-2);
break;

default:
Expand Down
Expand Up @@ -208,6 +208,39 @@ public long add(long pageIndex, int recordPosition) throws IOException {
}
}

public void update(long clusterPosition, OClusterPositionMapBucket.PositionEntry entry) throws IOException {
OAtomicOperation atomicOperation = startAtomicOperation();

acquireExclusiveLock();
try {
long pageIndex = clusterPosition / OClusterPositionMapBucket.MAX_ENTRIES;
int index = (int) (clusterPosition % OClusterPositionMapBucket.MAX_ENTRIES);

if (pageIndex >= getFilledUpTo(atomicOperation, fileId))
throw new OStorageException("Passed in cluster position " + clusterPosition
+ " is outside of range of cluster-position map.");

final OCacheEntry cacheEntry = loadPage(atomicOperation, fileId, pageIndex, false);
cacheEntry.acquireExclusiveLock();
try {
final OClusterPositionMapBucket bucket = new OClusterPositionMapBucket(cacheEntry, getChangesTree(atomicOperation,
cacheEntry));
bucket.set(index, entry);
} finally {
cacheEntry.releaseExclusiveLock();
releasePage(atomicOperation, cacheEntry);
}

endAtomicOperation(false, null);
} catch (Exception e) {
endAtomicOperation(true, e);
throw new OStorageException("Error of update of mapping between logical adn physical record position.", e);
} finally {
releaseExclusiveLock();
}

}

public OClusterPositionMapBucket.PositionEntry get(final long clusterPosition) throws IOException {
atomicOperationsManager.acquireReadLock(this);
try {
Expand Down
Expand Up @@ -25,6 +25,7 @@
import com.orientechnologies.common.serialization.types.OByteSerializer;
import com.orientechnologies.common.serialization.types.OIntegerSerializer;
import com.orientechnologies.common.serialization.types.OLongSerializer;
import com.orientechnologies.orient.core.exception.OStorageException;
import com.orientechnologies.orient.core.storage.cache.OCacheEntry;
import com.orientechnologies.orient.core.storage.impl.local.paginated.base.ODurablePage;
import com.orientechnologies.orient.core.storage.impl.local.paginated.wal.OWALChangesTree;
Expand Down Expand Up @@ -76,6 +77,19 @@ public PositionEntry get(int index) {
return readEntry(position);
}

public void set(int index, PositionEntry entry) throws IOException {
int size = getIntValue(SIZE_OFFSET);

if (index >= size)
throw new OStorageException("Provided index " + index + " is out of range.");

final int position = entryPosition(index);
if (getByteValue(position) != FILLED)
throw new OStorageException("Provided index " + index + " points to removed entry.");

updateEntry(position, entry);
}

private int entryPosition(int index) {
return index * ENTRY_SIZE + POSITIONS_OFFSET;
}
Expand Down Expand Up @@ -116,6 +130,15 @@ private PositionEntry readEntry(int position) {
return new PositionEntry(pageIndex, pagePosition);
}

private void updateEntry(int position, PositionEntry entry) throws IOException {
position += OByteSerializer.BYTE_SIZE;

setLongValue(position, entry.pageIndex);
position += OLongSerializer.LONG_SIZE;

setIntValue(position, entry.recordPosition);
}

public boolean exists(int index) {
int size = getIntValue(SIZE_OFFSET);
if (index >= size)
Expand Down

0 comments on commit f57aab6

Please sign in to comment.