commit b9d30334d0a142dd368692352bf6412cd36b0d52 Author: Enis Soztutar Date: Sat Aug 6 00:32:20 2016 -0700 HBASE-16477 Remove Writable interface and related code from WALEdit/WALKey diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALEdit.java hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALEdit.java index d5a4a75..f963388 100644 --- hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALEdit.java +++ hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALEdit.java @@ -18,13 +18,8 @@ */ package org.apache.hadoop.hbase.regionserver.wal; -import java.io.DataInput; -import java.io.DataOutput; import java.io.IOException; import java.util.ArrayList; -import java.util.NavigableMap; -import java.util.TreeMap; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.hbase.classification.InterfaceAudience; @@ -33,7 +28,6 @@ import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HBaseInterfaceAudience; import org.apache.hadoop.hbase.KeyValue; -import org.apache.hadoop.hbase.KeyValueUtil; import org.apache.hadoop.hbase.codec.Codec; import org.apache.hadoop.hbase.io.HeapSize; import org.apache.hadoop.hbase.protobuf.generated.WALProtos; @@ -43,8 +37,6 @@ import org.apache.hadoop.hbase.protobuf.generated.WALProtos.RegionEventDescripto import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.ClassSize; import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; -import org.apache.hadoop.io.Writable; - import com.google.common.annotations.VisibleForTesting; @@ -84,7 +76,7 @@ import com.google.common.annotations.VisibleForTesting; */ @InterfaceAudience.LimitedPrivate({ HBaseInterfaceAudience.REPLICATION, HBaseInterfaceAudience.COPROC }) -public class WALEdit implements Writable, HeapSize { +public class WALEdit implements HeapSize { private static final Log LOG = LogFactory.getLog(WALEdit.class); // TODO: Get rid of this; see HBASE-8457 @@ -100,22 +92,12 @@ public class WALEdit implements Writable, HeapSize { @VisibleForTesting public static final byte [] BULK_LOAD = Bytes.toBytes("HBASE::BULK_LOAD"); - private final int VERSION_2 = -1; private final boolean isReplay; private ArrayList cells = null; public static final WALEdit EMPTY_WALEDIT = new WALEdit(); - // Only here for legacy writable deserialization - /** - * @deprecated Legacy - */ - @Deprecated - private NavigableMap scopes; - - private CompressionContext compressionContext; - public WALEdit() { this(false); } @@ -162,10 +144,6 @@ public class WALEdit implements Writable, HeapSize { return this.isReplay; } - public void setCompressionContext(final CompressionContext compressionContext) { - this.compressionContext = compressionContext; - } - public WALEdit add(Cell cell) { this.cells.add(cell); return this; @@ -195,74 +173,6 @@ public class WALEdit implements Writable, HeapSize { this.cells = cells; } - public NavigableMap getAndRemoveScopes() { - NavigableMap result = scopes; - scopes = null; - return result; - } - - @Override - public void readFields(DataInput in) throws IOException { - cells.clear(); - if (scopes != null) { - scopes.clear(); - } - int versionOrLength = in.readInt(); - // TODO: Change version when we protobuf. Also, change way we serialize KV! Pb it too. - if (versionOrLength == VERSION_2) { - // this is new style WAL entry containing multiple KeyValues. - int numEdits = in.readInt(); - for (int idx = 0; idx < numEdits; idx++) { - if (compressionContext != null) { - this.add(KeyValueCompression.readKV(in, compressionContext)); - } else { - this.add(KeyValueUtil.create(in)); - } - } - int numFamilies = in.readInt(); - if (numFamilies > 0) { - if (scopes == null) { - scopes = new TreeMap(Bytes.BYTES_COMPARATOR); - } - for (int i = 0; i < numFamilies; i++) { - byte[] fam = Bytes.readByteArray(in); - int scope = in.readInt(); - scopes.put(fam, scope); - } - } - } else { - // this is an old style WAL entry. The int that we just - // read is actually the length of a single KeyValue - this.add(KeyValueUtil.create(versionOrLength, in)); - } - } - - @Override - public void write(DataOutput out) throws IOException { - LOG.warn("WALEdit is being serialized to writable - only expected in test code"); - out.writeInt(VERSION_2); - out.writeInt(cells.size()); - // We interleave the two lists for code simplicity - for (Cell cell : cells) { - // This is not used in any of the core code flows so it is just fine to convert to KV - KeyValue kv = KeyValueUtil.ensureKeyValue(cell); - if (compressionContext != null) { - KeyValueCompression.writeKV(out, kv, compressionContext); - } else{ - KeyValueUtil.write(kv, out); - } - } - if (scopes == null) { - out.writeInt(0); - } else { - out.writeInt(scopes.size()); - for (byte[] key : scopes.keySet()) { - Bytes.writeByteArray(out, key); - out.writeInt(scopes.get(key)); - } - } - } - /** * Reads WALEdit from cells. * @param cellDecoder Cell decoder. @@ -284,11 +194,6 @@ public class WALEdit implements Writable, HeapSize { for (Cell cell : cells) { ret += CellUtil.estimatedHeapSizeOf(cell); } - if (scopes != null) { - ret += ClassSize.TREEMAP; - ret += ClassSize.align(scopes.size() * ClassSize.MAP_ENTRY); - // TODO this isn't quite right, need help here - } return ret; } @@ -301,9 +206,6 @@ public class WALEdit implements Writable, HeapSize { sb.append(cell); sb.append("; "); } - if (scopes != null) { - sb.append(" scopes: " + scopes.toString()); - } sb.append(">]"); return sb.toString(); } diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WAL.java hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WAL.java index 93b0045..a9eb184 100644 --- hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WAL.java +++ hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WAL.java @@ -281,7 +281,6 @@ public interface WAL { * Compression context */ public void setCompressionContext(CompressionContext compressionContext) { - edit.setCompressionContext(compressionContext); key.setCompressionContext(compressionContext); } diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALKey.java hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALKey.java index fa7dc85..2bac2ad 100644 --- hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALKey.java +++ hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALKey.java @@ -23,7 +23,6 @@ import java.io.InterruptedIOException; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.NavigableMap; @@ -59,8 +58,6 @@ import com.google.protobuf.ByteString; * identifies the appropriate table and row. Within a table and row, they're * also sorted. * - * Note that protected members marked @InterfaceAudience.Private are only protected - * to support the legacy HLogKey class, which is in a different package. */ // TODO: Key and WALEdit are never used separately, or in one-to-many relation, for practical // purposes. They need to be merged into WALEntry. @@ -116,60 +113,9 @@ public class WALKey implements SequenceId, Comparable { this.sequenceIdAssignedLatch.countDown(); } - // REMOVE!!!! No more Writables!!!! - // Should be < 0 (@see HLogKey#readFields(DataInput)) - // version 2 supports WAL compression - // public members here are only public because of HLogKey - @InterfaceAudience.Private - protected enum Version { - UNVERSIONED(0), - // Initial number we put on WALKey when we introduced versioning. - INITIAL(-1), - // Version -2 introduced a dictionary compression facility. Only this - // dictionary-based compression is available in version -2. - COMPRESSED(-2); - - public final int code; - static final Version[] byCode; - static { - byCode = Version.values(); - for (int i = 0; i < byCode.length; i++) { - if (byCode[i].code != -1 * i) { - throw new AssertionError("Values in this enum should be descending by one"); - } - } - } - - Version(int code) { - this.code = code; - } - - public boolean atLeast(Version other) { - return code <= other.code; - } - - public static Version fromCode(int code) { - return byCode[code * -1]; - } - } - - /* - * This is used for reading the log entries created by the previous releases - * (0.94.11) which write the clusters information to the scopes of WALEdit. - */ - private static final String PREFIX_CLUSTER_KEY = "."; - + private byte [] encodedRegionName; - // visible for deprecated HLogKey - @InterfaceAudience.Private - protected static final Version VERSION = Version.COMPRESSED; - - // visible for deprecated HLogKey - @InterfaceAudience.Private - protected byte [] encodedRegionName; - // visible for deprecated HLogKey - @InterfaceAudience.Private - protected TableName tablename; + private TableName tablename; /** * SequenceId for this edit. Set post-construction at write-to-WAL time. Until then it is * NO_SEQUENCE_ID. Change it so multiple threads can read it -- e.g. access is synchronized. @@ -181,15 +127,11 @@ public class WALKey implements SequenceId, Comparable { */ private long origLogSeqNum = 0; - // Time at which this edit was written. - // visible for deprecated HLogKey - @InterfaceAudience.Private - protected long writeTime; + /** Time at which this edit was written. */ + private long writeTime; - // The first element in the list is the cluster id on which the change has originated - // visible for deprecated HLogKey - @InterfaceAudience.Private - protected List clusterIds; + /** The first element in the list is the cluster id on which the change has originated */ + private List clusterIds; private NavigableMap replicationScope; @@ -202,9 +144,7 @@ public class WALKey implements SequenceId, Comparable { private MultiVersionConcurrencyControl.WriteEntry writeEntry; public static final List EMPTY_UUIDS = Collections.unmodifiableList(new ArrayList()); - // visible for deprecated HLogKey - @InterfaceAudience.Private - protected CompressionContext compressionContext; + private CompressionContext compressionContext; public WALKey() { init(null, null, 0L, HConstants.LATEST_TIMESTAMP, @@ -416,7 +356,7 @@ public class WALKey implements SequenceId, Comparable { this.replicationScope = replicationScope; } - // For HLogKey and deserialization. DO NOT USE. See setWriteEntry below. + // For deserialization. DO NOT USE. See setWriteEntry below. @InterfaceAudience.Private protected void setSequenceId(long sequenceId) { this.sequenceId = sequenceId; @@ -505,25 +445,6 @@ public class WALKey implements SequenceId, Comparable { } } - public void readOlderScopes(NavigableMap scopes) { - if (scopes != null) { - Iterator> iterator = scopes.entrySet() - .iterator(); - while (iterator.hasNext()) { - Map.Entry scope = iterator.next(); - String key = Bytes.toString(scope.getKey()); - if (key.startsWith(PREFIX_CLUSTER_KEY)) { - addClusterId(UUID.fromString(key.substring(PREFIX_CLUSTER_KEY - .length()))); - iterator.remove(); - } - } - if (scopes.size() > 0) { - this.replicationScope = scopes; - } - } - } - /** * Marks that the cluster with the given clusterId has consumed the change */