Permalink
Browse files

minor refactoring

  • Loading branch information...
Maysam Yabandeh
Maysam Yabandeh committed May 24, 2012
1 parent aa23ddc commit 49cadfe18adc6be563352e368430298d05e75413
@@ -506,20 +506,22 @@ public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e)
}
}
+ public static final long INVALID_READ = -2;
+ public static final long LOST_TC = -1;
@dgomezferro

dgomezferro May 24, 2012

Contributor

I don't think this is the right place for this constants.

//In the new implementation, I need direct access to commit timestamp and the logic for deciding
// the committed version is more complex. Therefero, this function replaces validRead.
// validRead could still be used if only validity of the version matters, like in tests
public long commitTimestamp(long transaction, long startTimestamp) throws IOException {
if (aborted.contains(transaction))
- return -2;//invalid read
+ return INVALID_READ;//invalid read
long commitTimestamp = committed.getCommit(transaction);
if (commitTimestamp != -1 && commitTimestamp > startTimestamp)
- return -2;//invalid read
+ return INVALID_READ;//invalid read
if (commitTimestamp != -1 && commitTimestamp <= startTimestamp)
return commitTimestamp;
if (hasConnectionTimestamp && transaction > connectionTimestamp)
- return transaction <= largestDeletedTimestamp ? -1 : -2;
+ return transaction <= largestDeletedTimestamp ? -1 : INVALID_READ;
@dgomezferro

dgomezferro May 24, 2012

Contributor

use LOST_TC

//TODO: it works only if it runs one transaction at a time
if (transaction <= largestDeletedTimestamp)
return -1;//committed but the tc is lost
@dgomezferro

dgomezferro May 24, 2012

Contributor

use LOST_TC

@@ -536,12 +538,12 @@ public long commitTimestamp(long transaction, long startTimestamp) throws IOExce
if (!cb.isAClearAnswer())
//TODO: throw a proper exception
throw new IOException("Either abort or retry the transaction");
- return cb.isCommitted() ? cb.commitTimestamp() : -2;
+ return cb.isCommitted() ? cb.commitTimestamp() : INVALID_READ;
}
public boolean validRead(long transaction, long startTimestamp) throws IOException {
@dgomezferro

dgomezferro May 24, 2012

Contributor

validRead() is not used anywhere, remove it, and adapt the test that was testing this to test the new function (checking the new return status as well)

long Tc = commitTimestamp(transaction, startTimestamp);
- return (Tc != -2);
+ return (Tc != INVALID_READ);
}
/**
@@ -87,12 +87,13 @@ public Result get(TransactionState transactionState, final Get get) throws IOExc
final Get tsget = new Get(get.getRow());
TimeRange timeRange = get.getTimeRange();
- final long eldest = IsolationLevel.checkForWriteWriteConflicts ? -1 : //-1 means no eldest, i.e., do not worry about it
+ final long NO_ELDEST = -1;//-1 means no eldest, i.e., do not worry about it
+ final long eldest = IsolationLevel.checkForWriteWriteConflicts ? NO_ELDEST :
transactionState.tsoclient.getEldest();//if we do not check for ww conflicts, we should take elders into account
int nVersions = (int) (versionsAvg + CACHE_VERSIONS_OVERHEAD);
long startTime = 0;
long endTime = Math.min(timeRange.getMax(), readTimestamp + 1);
- if (eldest == -1 || eldest >= endTime) {//-1 means no eldest
+ if (eldest == NO_ELDEST || eldest >= endTime) {
tsget.setTimeRange(startTime, endTime).setMaxVersions(nVersions);
} else {//either from 0, or eldest, fetch all
startTime = eldest;
@@ -338,13 +339,13 @@ private void filter(TransactionState state, Result unfilteredResult, long startT
if (mostRecentKeyValueWithLostTc != null) continue;//if it is an elder and we have already seen one
//with lost Tc, then it was in failedEdler as well.
long Tc = state.tsoclient.commitTimestamp(Ts, startTimestamp);
- if (Tc == -2) continue;//invalid read
+ if (Tc == TSOClient.INVALID_READ) continue;//invalid read
if (IsolationLevel.checkForWriteWriteConflicts) {//then everything is in order, and the first version is enough
addIfItIsNotADelete(kv, filteredList);
pickedOneForLastColumn = true;
continue;
}
- if (Tc == -1) // means valid read with lost Tc
+ if (Tc == TSOClient.LOST_TC) // means valid read with lost Tc
//Case 2: Normal value with lost Tc
mostRecentKeyValueWithLostTc = kv; //Note: a value with lost Tc could also be a failedElder,
//so do this check after failedEdler check

0 comments on commit 49cadfe

Please sign in to comment.