From 5637cf73a3acb4644fee3ba16b30dc96023b4e4f Mon Sep 17 00:00:00 2001 From: Maysam Yabandeh Date: Thu, 24 May 2012 15:10:28 +0200 Subject: [PATCH] minor refactoring --- src/main/java/com/yahoo/omid/client/TSOClient.java | 9 ++------- .../java/com/yahoo/omid/tso/TestReadAlgorithm.java | 14 ++++++++++---- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/yahoo/omid/client/TSOClient.java b/src/main/java/com/yahoo/omid/client/TSOClient.java index 911e92ad..e8d9e969 100644 --- a/src/main/java/com/yahoo/omid/client/TSOClient.java +++ b/src/main/java/com/yahoo/omid/client/TSOClient.java @@ -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++; @@ -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 */ diff --git a/src/test/java/com/yahoo/omid/tso/TestReadAlgorithm.java b/src/test/java/com/yahoo/omid/tso/TestReadAlgorithm.java index ffb9714b..5b284f44 100644 --- a/src/test/java/com/yahoo/omid/tso/TestReadAlgorithm.java +++ b/src/test/java/com/yahoo/omid/tso/TestReadAlgorithm.java @@ -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 { @@ -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); + } -} \ No newline at end of file +}