Skip to content

Commit

Permalink
Issue #2874, cluster with wal tests are fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
laa committed Mar 17, 2015
1 parent f1b4f6c commit 66fa31d
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 17 deletions.
Expand Up @@ -588,11 +588,11 @@ public boolean deleteRecord(long clusterPosition) throws IOException {

atomicOperation = storage.getAtomicOperationsManager().getCurrentOperation();
do {
final OCacheEntry cacheEntry = loadPage(atomicOperation, fileId, pageIndex, false, diskCache);
OCacheEntry cacheEntry = loadPage(atomicOperation, fileId, pageIndex, false, diskCache);
cacheEntry.acquireExclusiveLock();
int initialFreePageIndex;
try {
final OClusterPage localPage = new OClusterPage(cacheEntry, false, getChangesTree(atomicOperation, cacheEntry));
OClusterPage localPage = new OClusterPage(cacheEntry, false, getChangesTree(atomicOperation, cacheEntry));
initialFreePageIndex = calculateFreePageIndex(localPage);

if (localPage.isDeleted(recordPosition)) {
Expand All @@ -601,11 +601,18 @@ public boolean deleteRecord(long clusterPosition) throws IOException {
else
throw new OStorageException("Content of record " + new ORecordId(id, clusterPosition) + " was broken.");
} else if (removedContentSize == 0) {
cacheEntry.releaseExclusiveLock();
releasePage(atomicOperation, cacheEntry, diskCache);

atomicOperation = startAtomicOperation();
localPage.setChangesTree(getChangesTree(atomicOperation, cacheEntry));
lockTillAtomicOperationCompletes();

cacheEntry = loadPage(atomicOperation, fileId, pageIndex, false, diskCache);
cacheEntry.acquireExclusiveLock();

localPage = new OClusterPage(cacheEntry, false, getChangesTree(atomicOperation, cacheEntry));

operationStarted = true;
lockTillAtomicOperationCompletes();
}

byte[] content = localPage.getRecordBinaryValue(recordPosition, 0, localPage.getRecordSize(recordPosition));
Expand Down
Expand Up @@ -286,6 +286,9 @@ public void commitChanges(ODiskCache diskCache, OWriteAheadLog writeAheadLog) th
if (cacheEntry == null) {
assert filePageChanges.isNew;
do {
if (cacheEntry != null)
diskCache.release(cacheEntry);

cacheEntry = diskCache.allocateNewPage(fileId);
} while (cacheEntry.getPageIndex() != pageIndex);
}
Expand Down
Expand Up @@ -87,10 +87,6 @@ public ODurablePage(OCacheEntry cacheEntry, OWALChangesTree changesTree) {
this.changesTree = changesTree;
}

public void setChangesTree(OWALChangesTree changesTree) {
this.changesTree = changesTree;
}

public static OLogSequenceNumber getLogSequenceNumberFromPage(ODirectMemoryPointer dataPointer) {
final long segment = OLongSerializer.INSTANCE.deserializeFromDirectMemory(dataPointer, WAL_SEGMENT_OFFSET + PAGE_PADDING);
final long position = OLongSerializer.INSTANCE.deserializeFromDirectMemory(dataPointer, WAL_POSITION_OFFSET + PAGE_PADDING);
Expand Down
Expand Up @@ -62,14 +62,6 @@ public int toStream(final byte[] content, int offset) {
public int fromStream(final byte[] content, int offset) {
offset = super.fromStream(content, offset);

final long position = OLongSerializer.INSTANCE.deserializeNative(content, offset);
offset += OLongSerializer.LONG_SIZE;

final long segment = OLongSerializer.INSTANCE.deserializeNative(content, offset);
offset += OLongSerializer.LONG_SIZE;

lsn = new OLogSequenceNumber(segment, position);

changesTree = new OWALChangesTree();
offset = changesTree.fromStream(offset, content);

Expand Down
Expand Up @@ -335,6 +335,8 @@ public int fromStream(int offset, byte[] stream) {
public int toStream(int offset, byte[] stream) {
OIntegerSerializer.INSTANCE.serializeNative(serializedSize, stream, offset);
offset += OIntegerSerializer.INT_SIZE;
if (root == null)
return offset;

offset = toStream(root, offset, stream);

Expand Down
Expand Up @@ -172,7 +172,8 @@ public void testAddOneBigRecord() throws IOException {
public void testAddManySmallRecords() throws IOException {
final int records = 10000;

long seed = System.currentTimeMillis();
long seed = 1426587095601L;
System.currentTimeMillis();
MersenneTwisterFast mersenneTwisterFast = new MersenneTwisterFast(seed);
System.out.println("testAddManySmallRecords seed : " + seed);

Expand Down
Expand Up @@ -397,6 +397,9 @@ private void restoreClusterFromWAL() throws IOException {
OCacheEntry cacheEntry = testDiskCache.load(fileId, pageIndex, true);
if (cacheEntry == null) {
do {
if (cacheEntry != null)
diskCache.release(cacheEntry);

cacheEntry = testDiskCache.allocateNewPage(fileId);
} while (cacheEntry.getPageIndex() != pageIndex);
}
Expand Down

0 comments on commit 66fa31d

Please sign in to comment.