Permalink
Browse files

Replay the transaction pages into the FSM map

  • Loading branch information...
justinsb committed Dec 11, 2013
1 parent 4a62229 commit 65034e556dcc1cdd2ada109065a954506bf9c93f
@@ -58,27 +58,27 @@ private MmapPageStore(MappedByteBuffer buffer, boolean uniqueKeys) {
private FreeSpaceMap recoverFreeSpaceMap(MasterPage latest) {
int transactionPageId = latest.getTransactionPageId();
List<TransactionPage> history = Lists.newArrayList();
FreeSpaceMap.SnapshotPage fsmSnapshot = null;
List<PageRecord> history = Lists.newArrayList();
PageRecord fsmSnapshot = null;
if (transactionPageId != 0) {
TransactionPage transactionPage = (TransactionPage) fetchPage(null, transactionPageId).page;
TransactionPage current = transactionPage;
PageRecord current = fetchPage(null, transactionPageId);
while (true) {
TransactionPage transactionPage = (TransactionPage) current.page;
history.add(current);
if (current.getFreeSpaceSnapshotId() != 0) {
fsmSnapshot = (FreeSpaceMap.SnapshotPage) fetchPage(null, current.getFreeSpaceSnapshotId()).page;
if (transactionPage.getFreeSpaceSnapshotId() != 0) {
fsmSnapshot = fetchPage(null, transactionPage.getFreeSpaceSnapshotId());
break;
}
int previousTransactionPageId = current.getPreviousTransactionPageId();
int previousTransactionPageId = transactionPage.getPreviousTransactionPageId();
if (previousTransactionPageId == 0) {
break;
}
TransactionPage previousTransaction = (TransactionPage) fetchPage(null, previousTransactionPageId).page;
assert (previousTransaction != null);
PageRecord previous = fetchPage(null, previousTransactionPageId);
assert (previous != null);
current = previous;
}
Collections.reverse(history);
@@ -91,8 +91,8 @@ private FreeSpaceMap recoverFreeSpaceMap(MasterPage latest) {
fsm = FreeSpaceMap.createFromSnapshot(fsmSnapshot);
}
for (TransactionPage txn : history) {
fsm.replay(txn);
for (PageRecord txnRecord : history) {
fsm.replay(txnRecord);
}
return fsm;
@@ -8,6 +8,7 @@
import com.cloudata.keyvalue.btree.EntryListener;
import com.cloudata.keyvalue.btree.Page;
import com.cloudata.keyvalue.btree.PageStore;
import com.cloudata.keyvalue.btree.PageStore.PageRecord;
import com.cloudata.keyvalue.btree.Transaction;
import com.cloudata.keyvalue.btree.TransactionPage;
import com.cloudata.keyvalue.btree.WriteTransaction;
@@ -27,7 +28,9 @@ private FreeSpaceMap(SnapshotPage snapshot) {
this.freeRanges = snapshot.deserialize();
}
public void replay(TransactionPage txn) {
public void replay(PageRecord txnRecord) {
TransactionPage txn = (TransactionPage) txnRecord.page;
for (int i = 0; i < txn.getFreedCount(); i++) {
int start = txn.getFreedStart(i);
int size = txn.getFreedLength(i);
@@ -41,14 +44,22 @@ public void replay(TransactionPage txn) {
freeRanges.remove(start, size);
}
// The free space map can't include the transaction itself
freeRanges.remove(txnRecord.space.start, txnRecord.space.length);
}
public static FreeSpaceMap createEmpty(int start, int end) {
return new FreeSpaceMap(start, end);
}
public static FreeSpaceMap createFromSnapshot(SnapshotPage snapshot) {
return new FreeSpaceMap(snapshot);
public static FreeSpaceMap createFromSnapshot(PageRecord snapshotRecord) {
FreeSpaceMap fsm = new FreeSpaceMap((SnapshotPage) snapshotRecord.page);
// Note: The snapshot _does_ include the FSM snapshot page :-)
// fsm.freeRanges.remove(snapshotRecord.space.start, snapshotRecord.space.length);
return fsm;
}
// public void reclaimSpace(TransactionPage t) {

0 comments on commit 65034e5

Please sign in to comment.