Skip to content
This repository has been archived by the owner on Jul 15, 2019. It is now read-only.

Commit

Permalink
minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Maysam Yabandeh committed May 24, 2012
1 parent 49cadfe commit 5637cf7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
9 changes: 2 additions & 7 deletions src/main/java/com/yahoo/omid/client/TSOClient.java
Expand Up @@ -521,10 +521,10 @@ public long commitTimestamp(long transaction, long startTimestamp) throws IOExce
return commitTimestamp;

if (hasConnectionTimestamp && transaction > connectionTimestamp)
return transaction <= largestDeletedTimestamp ? -1 : INVALID_READ;
return transaction <= largestDeletedTimestamp ? LOST_TC : INVALID_READ;
//TODO: it works only if it runs one transaction at a time
if (transaction <= largestDeletedTimestamp)
return -1;//committed but the tc is lost
return LOST_TC;//committed but the tc is lost

Statistics.partialReport(Statistics.Tag.ASKTSO, 1);
askedTSO++;
Expand All @@ -541,11 +541,6 @@ public long commitTimestamp(long transaction, long startTimestamp) throws IOExce
return cb.isCommitted() ? cb.commitTimestamp() : INVALID_READ;
}

public boolean validRead(long transaction, long startTimestamp) throws IOException {
long Tc = commitTimestamp(transaction, startTimestamp);
return (Tc != INVALID_READ);
}

/**
* When a message is received, handle it based on its type
*/
Expand Down
14 changes: 10 additions & 4 deletions src/test/java/com/yahoo/omid/tso/TestReadAlgorithm.java
Expand Up @@ -28,6 +28,7 @@
import com.yahoo.omid.tso.messages.CommittedTransactionReport;
import com.yahoo.omid.tso.messages.TimestampRequest;
import com.yahoo.omid.tso.messages.TimestampResponse;
import com.yahoo.omid.client.TSOClient;

public class TestReadAlgorithm extends TSOTestBase {

Expand Down Expand Up @@ -57,14 +58,19 @@ public void testReadAlgorithm() throws Exception {
TimestampResponse tr4 = secondClientHandler.receiveMessage(TimestampResponse.class);

// Transaction half aborted
assertFalse(secondClientHandler.validRead(tr3.timestamp, tr4.timestamp));
assertFalse(validRead(secondClientHandler, tr3.timestamp, tr4.timestamp));

// Transaction committed after start timestamp
assertFalse(secondClientHandler.validRead(tr2.timestamp, tr1.timestamp));
assertFalse(validRead(secondClientHandler, tr2.timestamp, tr1.timestamp));

// Transaction committed before start timestamp
assertTrue(secondClientHandler.validRead(tr2.timestamp, tr4.timestamp));
assertTrue(validRead(secondClientHandler, tr2.timestamp, tr4.timestamp));

}

private boolean validRead(TestClientHandler handler, long transaction, long startTimestamp) throws Exception {
long Tc = handler.commitTimestamp(transaction, startTimestamp);
return (Tc != TSOClient.INVALID_READ);
}

}
}

0 comments on commit 5637cf7

Please sign in to comment.