diff --git a/core/src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALEdit.java b/core/src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALEdit.java index 8d2facd..4fcefe8 100644 --- a/core/src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALEdit.java +++ b/core/src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALEdit.java @@ -25,6 +25,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.util.ClassSize; import org.apache.hadoop.io.Writable; @@ -68,12 +69,18 @@ public class WALEdit implements Writable { private final int VERSION_2 = -1; private List kvs = new ArrayList(); + private List scopes = new ArrayList(); public WALEdit() { } public void add(KeyValue kv) { + this.add(kv, HConstants.REPLICATION_SCOPE_LOCAL); + } + + public void add(KeyValue kv, int scope) { this.kvs.add(kv); + this.scopes.add(scope); } public boolean isEmpty() { @@ -88,24 +95,28 @@ public class WALEdit implements Writable { return kvs; } - public void readFields(DataInput in) throws IOException { - - // ignore any old state in case caller is recycling an instance of this object. - kvs = new ArrayList(); + public List getScopes() { + return scopes; + } + public void readFields(DataInput in) throws IOException { int versionOrLength = in.readInt(); - if (versionOrLength == VERSION_2) { // this is new style HLog entry containing multiple KeyValues. int numEdits = in.readInt(); + // Set it to the right size since we know it + kvs = new ArrayList(numEdits); + scopes = new ArrayList(numEdits); for (int idx = 0; idx < numEdits; idx++) { KeyValue kv = new KeyValue(); kv.readFields(in); - this.add(kv); + this.add(kv, in.readInt()); } } else { // this is an old style HLog entry. The int that we just - // read is actually the length of a single KeyValye. + // read is actually the length of a single KeyValue. + kvs = new ArrayList(0); + scopes = new ArrayList(0); KeyValue kv = new KeyValue(); kv.readFields(versionOrLength, in); this.add(kv); @@ -116,19 +127,21 @@ public class WALEdit implements Writable { public void write(DataOutput out) throws IOException { out.writeInt(VERSION_2); out.writeInt(kvs.size()); - for (KeyValue kv : kvs) { - kv.write(out); + // We interleave the two lists for code simplicity + for (int i = 0; i < kvs.size(); i++) { + kvs.get(i).write(out); + out.writeInt(scopes.get(i)); } } public long heapSize() { - long size = ClassSize.align(ClassSize.OBJECT + - ClassSize.REFERENCE + - ClassSize.ARRAYLIST); + long size = 2 * ClassSize.align(ClassSize.OBJECT + + ClassSize.REFERENCE + + ClassSize.ARRAYLIST); for (KeyValue kv : kvs) { size += kv.heapSize(); } - + size += scopes.size() * ClassSize.INTEGER; return size; } @@ -136,8 +149,10 @@ public class WALEdit implements Writable { StringBuilder sb = new StringBuilder(); sb.append("[#edits: " + kvs.size() + " = <"); - for (KeyValue kv : kvs) { - sb.append(kv.toString()); + for (int i = 0; i < kvs.size(); i++) { + sb.append(kvs.get(i).toString()); + sb.append(", scope="); + sb.append(scopes.get(i)); sb.append("; "); } sb.append(">]");