Permalink
Browse files

Merge pull request #2 from yahoo/readWrite

Read write
  • Loading branch information...
2 parents f11407d + 91a1bcc commit 059201e62fffc565c27b3ee446b3cf3c45c95af5 Maysam Yabandeh committed May 25, 2012
Showing with 1,446 additions and 1,581 deletions.
  1. +18 −6 src/main/java/com/yahoo/omid/Statistics.java
  2. +19 −29 src/main/java/com/yahoo/omid/client/ColumnFamilyAndQuantifier.java
  3. +2 −1 src/main/java/com/yahoo/omid/client/CommitCallback.java
  4. +23 −23 src/main/java/com/yahoo/omid/client/MinVersionsFilter.java
  5. +22 −20 src/main/java/com/yahoo/omid/client/MinVersionsSingleColumnFilter.java
  6. +11 −11 src/main/java/com/yahoo/omid/client/SyncCommitCallback.java
  7. +143 −167 src/main/java/com/yahoo/omid/client/TSOClient.java
  8. +2 −3 src/main/java/com/yahoo/omid/client/TransactionManager.java
  9. +49 −238 src/main/java/com/yahoo/omid/client/TransactionalTable.java
  10. +87 −87 src/main/java/com/yahoo/omid/client/regionserver/Compacter.java
  11. +41 −41 src/main/java/com/yahoo/omid/tso/ClientHandler.java
  12. +5 −5 src/main/java/com/yahoo/omid/tso/CompacterHandler.java
  13. +12 −1 src/main/java/com/yahoo/omid/tso/Elder.java
  14. +21 −20 src/main/java/com/yahoo/omid/tso/Elders.java
  15. +67 −89 src/main/java/com/yahoo/omid/tso/RowKey.java
  16. +254 −234 src/main/java/com/yahoo/omid/tso/TSOHandler.java
  17. +53 −53 src/main/java/com/yahoo/omid/tso/Timestamp.java
  18. +30 −30 src/main/java/com/yahoo/omid/tso/messages/AbortedTransactionReport.java
  19. +78 −78 src/main/java/com/yahoo/omid/tso/messages/CommitRequest.java
  20. +75 −81 src/main/java/com/yahoo/omid/tso/messages/CommitResponse.java
  21. +104 −104 src/main/java/com/yahoo/omid/tso/messages/CommittedTransactionReport.java
  22. +15 −15 src/main/java/com/yahoo/omid/tso/messages/EldestUpdate.java
  23. +18 −18 src/main/java/com/yahoo/omid/tso/messages/FailedElderReport.java
  24. +36 −36 src/main/java/com/yahoo/omid/tso/messages/FullAbortReport.java
  25. +31 −31 src/main/java/com/yahoo/omid/tso/messages/LargestDeletedTimestampReport.java
  26. +15 −15 src/main/java/com/yahoo/omid/tso/messages/ReincarnationReport.java
  27. +4 −0 src/main/java/com/yahoo/omid/tso/persistence/LoggerProtocol.java
  28. +1 −1 src/main/native/Makefile
  29. +200 −137 src/test/java/com/yahoo/omid/TestIsolationLevels.java
  30. +0 −1 src/test/java/com/yahoo/omid/tso/TestCommit.java
  31. +0 −2 src/test/java/com/yahoo/omid/tso/TestCommitReport.java
  32. +10 −4 src/test/java/com/yahoo/omid/tso/TestReadAlgorithm.java
@@ -21,12 +21,16 @@
import java.util.Map;
import java.util.EnumMap;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
/**
* To collect statistics
* @author maysam
*
*/
public class Statistics {
+ private static final Log LOG = LogFactory.getLog(Statistics.class);
public enum Tag {
VSN_PER_HBASE_GET,//number of returned version per hbase get operation
VSN_PER_CLIENT_GET,//number of returned version per client get operation
@@ -53,13 +57,17 @@ static protected History getHistory(Tag tag, Map<Tag, History> map) {
}
static public void partialReport(Tag tag, int value) {
+ if(!LOG.isDebugEnabled())
+ return;
synchronized (histories) {
History tmpHistory = getHistory(tag, partialChanges);
tmpHistory.total += value;
}
}
static public void partialReportOver(Tag tag) {
+ if(!LOG.isDebugEnabled())
+ return;
synchronized (histories) {
History tmpHistory = getHistory(tag, partialChanges);
if (tmpHistory.total == 0)
@@ -72,6 +80,8 @@ static public void partialReportOver(Tag tag) {
}
static public void fullReport(Tag tag, int value) {
+ if(!LOG.isDebugEnabled())
+ return;
synchronized (histories) {
if (value == 0)
return;
@@ -83,7 +93,7 @@ static public void fullReport(Tag tag, int value) {
static long lastReportTime = System.currentTimeMillis();
static final long reportInterval = 2000;
- static public boolean skipReport() {
+ static private boolean skipReport() {
long currentTimeMillis = System.currentTimeMillis();
if (currentTimeMillis - lastReportTime > reportInterval) {
lastReportTime = currentTimeMillis;
@@ -92,18 +102,20 @@ static public boolean skipReport() {
return true;
}
static public void println() {
+ if(!LOG.isDebugEnabled())
+ return;
synchronized (histories) {
if (skipReport())
return;
- System.out.print("Statistics: ");
+ StringBuffer tobelogged = new StringBuffer("Statistics: ");
for (Map.Entry<Tag, History> entry : histories.entrySet()) {
Tag tag = entry.getKey();
History history = entry.getValue();
- System.out.print(tag + "Cnt " + history.cnt + " ");
- System.out.print(tag + "Sum " + history.total + " ");
- System.out.print(tag + "Avg " + (float) history.total / history.cnt + " ");
+ tobelogged.append(tag + "Cnt " + history.cnt + " ");
+ tobelogged.append(tag + "Sum " + history.total + " ");
+ tobelogged.append(tag + "Avg " + (float) history.total / history.cnt + " ");
}
- System.out.println();
+ LOG.debug(tobelogged);
}
}
}
@@ -16,6 +16,8 @@
package com.yahoo.omid.client;
+import java.util.Arrays;
+
//A wrapper for both column family and the qualifier
//Make it easier to be used in maps and hash maps
public class ColumnFamilyAndQuantifier {
@@ -27,36 +29,24 @@
qualifier = q;
}
@Override
- public boolean equals(Object o) {
- if (o instanceof ColumnFamilyAndQuantifier) {
- ColumnFamilyAndQuantifier other = (ColumnFamilyAndQuantifier) o;
- if (family.length != other.family.length || qualifier.length != other.qualifier.length)
- return false;
- for (int i = 0; i < family.length; i++)
- if (family[i] != other.family[i])
- return false;
- for (int i = 0; i < qualifier.length; i++)
- if (qualifier[i] != other.qualifier[i])
- return false;
- return true;
- }
- return false;
+ public boolean equals(Object o) {
+ if (o instanceof ColumnFamilyAndQuantifier) {
+ ColumnFamilyAndQuantifier other = (ColumnFamilyAndQuantifier) o;
+ if (family.length != other.family.length || qualifier.length != other.qualifier.length)
+ return false;
+ return (Arrays.equals(family, other.family) && Arrays.equals(qualifier, other.qualifier));
}
+ return false;
+ }
@Override
- public int hashCode() {
- if (hash != null)
- return hash;
- int h = 0;
- h = computeHash(h, family);
- h = computeHash(h, qualifier);
- hash = h;
- return h;
- }
- private int computeHash(int hash, byte[] larray) {
- hash += larray.length;
- for (int i = 0; i < larray.length; i++) {
- hash += larray[i];
- }
- return hash;
+ public int hashCode() {
+ if (hash != null)
+ return hash;
+ final int prime = 31;
+ int h = 1;
+ h = prime * h + Arrays.hashCode(family);
+ h = prime * h + Arrays.hashCode(qualifier);
+ hash = h;
+ return h;
}
}
@@ -18,8 +18,9 @@
import com.yahoo.omid.client.TSOClient.Result;
import com.yahoo.omid.tso.RowKey;
+import java.util.ArrayList;
public interface CommitCallback extends Callback {
- public void complete(Result res, long commitTimestamp, RowKey[] wwRows);
+ public void complete(Result res, long commitTimestamp, ArrayList<RowKey> rowsWithWriteWriteConflict);
}
@@ -74,33 +74,33 @@ private void setIncludedVersions(ColumnFamilyAndQuantifier column, int versions)
}
@Override
- public ReturnCode filterKeyValue(KeyValue v) {
- long version = v.getTimestamp();
- if (version >= endTime)
- return ReturnCode.SKIP;
- ColumnFamilyAndQuantifier column = new ColumnFamilyAndQuantifier(v.getFamily(), v.getQualifier());
- int includedVersions = getIncludedVersions(column);
- if (includedVersions < minVersions || version > startTime) {
- includedVersions++;
- setIncludedVersions(column, includedVersions);
- return ReturnCode.INCLUDE;
- }
- return ReturnCode.NEXT_COL;
+ public ReturnCode filterKeyValue(KeyValue v) {
+ long version = v.getTimestamp();
+ if (version >= endTime)
+ return ReturnCode.SKIP;
+ ColumnFamilyAndQuantifier column = new ColumnFamilyAndQuantifier(v.getFamily(), v.getQualifier());
+ int includedVersions = getIncludedVersions(column);
+ if (includedVersions < minVersions || version > startTime) {
+ includedVersions++;
+ setIncludedVersions(column, includedVersions);
+ return ReturnCode.INCLUDE;
}
+ return ReturnCode.NEXT_COL;
+ }
@Override
- public void readFields(DataInput in) throws IOException {
- this.startTime = in.readLong();
- this.endTime = in.readLong();
- this.minVersions = in.readInt();
- init();
- }
+ public void readFields(DataInput in) throws IOException {
+ this.startTime = in.readLong();
+ this.endTime = in.readLong();
+ this.minVersions = in.readInt();
+ init();
+ }
@Override
- public void write(DataOutput out) throws IOException {
- out.writeLong(this.startTime);
- out.writeLong(this.endTime);
- out.writeInt(this.minVersions);
- }
+ public void write(DataOutput out) throws IOException {
+ out.writeLong(this.startTime);
+ out.writeLong(this.endTime);
+ out.writeInt(this.minVersions);
+ }
}
@@ -28,6 +28,8 @@
/**
* Filter that sets both minTimestamp and minVersions
* Assumes that there is only one column in the output
+ * This filter is more optimized than MinVersionsFilter if
+ * we know that the get asks for a single column qualifier
* @maysam
*/
public class MinVersionsSingleColumnFilter extends FilterBase {
@@ -59,30 +61,30 @@ private void init() {
}
@Override
- public ReturnCode filterKeyValue(KeyValue v) {
- long version = v.getTimestamp();
- if (version >= endTime)
- return ReturnCode.SKIP;
- if (includedVersions < minVersions || version > startTime) {
- includedVersions++;
- return ReturnCode.INCLUDE;
- }
- return ReturnCode.NEXT_COL;
+ public ReturnCode filterKeyValue(KeyValue v) {
+ long version = v.getTimestamp();
+ if (version >= endTime)
+ return ReturnCode.SKIP;
+ if (includedVersions < minVersions || version > startTime) {
+ includedVersions++;
+ return ReturnCode.INCLUDE;
}
+ return ReturnCode.NEXT_COL;
+ }
@Override
- public void readFields(DataInput in) throws IOException {
- this.startTime = in.readLong();
- this.endTime = in.readLong();
- this.minVersions = in.readInt();
- init();
- }
+ public void readFields(DataInput in) throws IOException {
+ this.startTime = in.readLong();
+ this.endTime = in.readLong();
+ this.minVersions = in.readInt();
+ init();
+ }
@Override
- public void write(DataOutput out) throws IOException {
- out.writeLong(this.startTime);
- out.writeLong(this.endTime);
- out.writeInt(this.minVersions);
- }
+ public void write(DataOutput out) throws IOException {
+ out.writeLong(this.startTime);
+ out.writeLong(this.endTime);
+ out.writeInt(this.minVersions);
+ }
}
@@ -18,11 +18,12 @@
import com.yahoo.omid.client.TSOClient.Result;
import com.yahoo.omid.tso.RowKey;
+import java.util.ArrayList;
public class SyncCommitCallback extends SyncCallbackBase implements CommitCallback {
private Result result;
private long commitTimestamp;
- private RowKey[] wwRows;
+ private ArrayList<RowKey> rowsWithWriteWriteConflict;//rows with write-write conflict
public Result getResult() {
return result;
@@ -33,19 +34,18 @@ public long getCommitTimestamp() {
}
public boolean isElder() {
- return wwRows != null && wwRows.length != 0;
+ return rowsWithWriteWriteConflict != null && rowsWithWriteWriteConflict.size() != 0;
}
- public RowKey[] getWWRows() {
- return wwRows;
+ public ArrayList<RowKey> getWWRows() {
+ return rowsWithWriteWriteConflict;
}
- synchronized
- public void complete(Result res, long commitTimestamp, RowKey[] wwRows) {
- this.result = res;
- this.commitTimestamp = commitTimestamp;
- this.wwRows = wwRows;
- countDown();
- }
+ synchronized public void complete(Result res, long commitTimestamp, ArrayList<RowKey> rowsWithWriteWriteConflict) {
+ this.result = res;
+ this.commitTimestamp = commitTimestamp;
+ this.rowsWithWriteWriteConflict = rowsWithWriteWriteConflict;
+ countDown();
+ }
}
Oops, something went wrong.

0 comments on commit 059201e

Please sign in to comment.