Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1148E1875F for ; Tue, 9 Feb 2016 17:27:48 +0000 (UTC) Received: (qmail 6247 invoked by uid 500); 9 Feb 2016 17:27:47 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 6079 invoked by uid 500); 9 Feb 2016 17:27:47 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 5884 invoked by uid 99); 9 Feb 2016 17:27:47 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Feb 2016 17:27:47 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 80766E6991; Tue, 9 Feb 2016 17:27:47 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: misty@apache.org To: commits@hbase.apache.org Date: Tue, 09 Feb 2016 17:27:49 -0000 Message-Id: In-Reply-To: <93201ed227144eab9c2a5ace07d2cd4b@git.apache.org> References: <93201ed227144eab9c2a5ace07d2cd4b@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [03/51] [partial] hbase-site git commit: Published site at 7bb68b9031591cf378954a0eb8f71a8b9be01f9c. http://git-wip-us.apache.org/repos/asf/hbase-site/blob/358717f6/devapidocs/src-html/org/apache/hadoop/hbase/wal/WALKey.html ---------------------------------------------------------------------- diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/wal/WALKey.html b/devapidocs/src-html/org/apache/hadoop/hbase/wal/WALKey.html index fa2326f..26033db 100644 --- a/devapidocs/src-html/org/apache/hadoop/hbase/wal/WALKey.html +++ b/devapidocs/src-html/org/apache/hadoop/hbase/wal/WALKey.html @@ -38,641 +38,630 @@ 030import java.util.TreeMap; 031import java.util.UUID; 032import java.util.concurrent.CountDownLatch; -033import java.util.concurrent.TimeUnit; -034 -035import org.apache.hadoop.hbase.regionserver.MultiVersionConcurrencyControl; -036import org.apache.hadoop.hbase.util.ByteStringer; -037import org.apache.commons.logging.Log; -038import org.apache.commons.logging.LogFactory; +033 +034import org.apache.commons.logging.Log; +035import org.apache.commons.logging.LogFactory; +036import org.apache.hadoop.hbase.HBaseInterfaceAudience; +037import org.apache.hadoop.hbase.HConstants; +038import org.apache.hadoop.hbase.TableName; 039import org.apache.hadoop.hbase.classification.InterfaceAudience; -040import org.apache.hadoop.hbase.exceptions.TimeoutIOException; -041import org.apache.hadoop.hbase.HBaseInterfaceAudience; -042import org.apache.hadoop.hbase.HConstants; -043import org.apache.hadoop.hbase.TableName; -044import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos; -045import org.apache.hadoop.hbase.protobuf.generated.WALProtos.FamilyScope; -046import org.apache.hadoop.hbase.protobuf.generated.WALProtos.ScopeType; -047import org.apache.hadoop.hbase.regionserver.SequenceId; -048import org.apache.hadoop.hbase.util.Bytes; -049import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; -050 -051import com.google.common.annotations.VisibleForTesting; -052import com.google.protobuf.ByteString; -053 -054// imports for things that haven't moved from regionserver.wal yet. -055import org.apache.hadoop.hbase.regionserver.wal.CompressionContext; -056import org.apache.hadoop.hbase.regionserver.wal.WALCellCodec; -057 -058/** -059 * A Key for an entry in the change log. -060 * -061 * The log intermingles edits to many tables and rows, so each log entry -062 * identifies the appropriate table and row. Within a table and row, they're -063 * also sorted. -064 * -065 * <p>Some Transactional edits (START, COMMIT, ABORT) will not have an -066 * associated row. -067 * -068 * Note that protected members marked @InterfaceAudience.Private are only protected -069 * to support the legacy HLogKey class, which is in a different package. -070 * -071 * <p> -072 */ -073// TODO: Key and WALEdit are never used separately, or in one-to-many relation, for practical -074// purposes. They need to be merged into WALEntry. -075// TODO: Cleanup. We have logSeqNum and then WriteEntry, both are sequence id'ing. Fix. -076@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.REPLICATION) -077public class WALKey implements SequenceId, Comparable<WALKey> { -078 private static final Log LOG = LogFactory.getLog(WALKey.class); -079 -080 @InterfaceAudience.Private // For internal use only. -081 public MultiVersionConcurrencyControl getMvcc() { -082 return mvcc; -083 } -084 -085 /** -086 * Will block until a write entry has been assigned by they WAL subsystem. -087 * @return A WriteEntry gotten from local WAL subsystem. Must be completed by calling -088 * {@link MultiVersionConcurrencyControl#complete(MultiVersionConcurrencyControl.WriteEntry)} -089 * or -090 * {@link MultiVersionConcurrencyControl#complete(MultiVersionConcurrencyControl.WriteEntry)} -091 * @see #setWriteEntry(MultiVersionConcurrencyControl.WriteEntry) -092 */ -093 @InterfaceAudience.Private // For internal use only. -094 public MultiVersionConcurrencyControl.WriteEntry getWriteEntry() throws InterruptedIOException { -095 try { -096 this.seqNumAssignedLatch.await(); -097 } catch (InterruptedException ie) { -098 // If interrupted... clear out our entry else we can block up mvcc. -099 MultiVersionConcurrencyControl mvcc = getMvcc(); -100 LOG.debug("mvcc=" + mvcc + ", writeEntry=" + this.writeEntry); -101 if (mvcc != null) { -102 if (this.writeEntry != null) { -103 mvcc.complete(this.writeEntry); -104 } -105 } -106 InterruptedIOException iie = new InterruptedIOException(); -107 iie.initCause(ie); -108 throw iie; -109 } -110 return this.writeEntry; -111 } -112 -113 @InterfaceAudience.Private // For internal use only. -114 public void setWriteEntry(MultiVersionConcurrencyControl.WriteEntry writeEntry) { -115 this.writeEntry = writeEntry; -116 this.seqNumAssignedLatch.countDown(); -117 } -118 -119 // should be < 0 (@see HLogKey#readFields(DataInput)) -120 // version 2 supports WAL compression -121 // public members here are only public because of HLogKey -122 @InterfaceAudience.Private -123 protected enum Version { -124 UNVERSIONED(0), -125 // Initial number we put on WALKey when we introduced versioning. -126 INITIAL(-1), -127 // Version -2 introduced a dictionary compression facility. Only this -128 // dictionary-based compression is available in version -2. -129 COMPRESSED(-2); -130 -131 public final int code; -132 static final Version[] byCode; -133 static { -134 byCode = Version.values(); -135 for (int i = 0; i < byCode.length; i++) { -136 if (byCode[i].code != -1 * i) { -137 throw new AssertionError("Values in this enum should be descending by one"); -138 } -139 } -140 } -141 -142 Version(int code) { -143 this.code = code; -144 } -145 -146 public boolean atLeast(Version other) { -147 return code <= other.code; -148 } -149 -150 public static Version fromCode(int code) { -151 return byCode[code * -1]; -152 } -153 } -154 -155 /* -156 * This is used for reading the log entries created by the previous releases -157 * (0.94.11) which write the clusters information to the scopes of WALEdit. -158 */ -159 private static final String PREFIX_CLUSTER_KEY = "."; -160 -161 -162 // visible for deprecated HLogKey -163 @InterfaceAudience.Private -164 protected static final Version VERSION = Version.COMPRESSED; -165 -166 /** Used to represent when a particular wal key doesn't know/care about the sequence ordering. */ -167 public static final long NO_SEQUENCE_ID = -1; +040import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos; +041import org.apache.hadoop.hbase.protobuf.generated.WALProtos.FamilyScope; +042import org.apache.hadoop.hbase.protobuf.generated.WALProtos.ScopeType; +043import org.apache.hadoop.hbase.regionserver.MultiVersionConcurrencyControl; +044import org.apache.hadoop.hbase.regionserver.SequenceId; +045// imports for things that haven't moved from regionserver.wal yet. +046import org.apache.hadoop.hbase.regionserver.wal.CompressionContext; +047import org.apache.hadoop.hbase.regionserver.wal.WALCellCodec; +048import org.apache.hadoop.hbase.util.ByteStringer; +049import org.apache.hadoop.hbase.util.Bytes; +050import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; +051 +052import com.google.common.annotations.VisibleForTesting; +053import com.google.protobuf.ByteString; +054 +055/** +056 * A Key for an entry in the WAL. +057 * +058 * The log intermingles edits to many tables and rows, so each log entry +059 * identifies the appropriate table and row. Within a table and row, they're +060 * also sorted. +061 * +062 * <p>Some Transactional edits (START, COMMIT, ABORT) will not have an associated row. +063 * +064 * Note that protected members marked @InterfaceAudience.Private are only protected +065 * to support the legacy HLogKey class, which is in a different package. +066 */ +067// TODO: Key and WALEdit are never used separately, or in one-to-many relation, for practical +068// purposes. They need to be merged into WALEntry. +069@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.REPLICATION) +070public class WALKey implements SequenceId, Comparable<WALKey> { +071 private static final Log LOG = LogFactory.getLog(WALKey.class); +072 private final CountDownLatch sequenceIdAssignedLatch = new CountDownLatch(1); +073 /** +074 * Used to represent when a particular wal key doesn't know/care about the sequence ordering. +075 */ +076 public static final long NO_SEQUENCE_ID = -1; +077 +078 @InterfaceAudience.Private // For internal use only. +079 public MultiVersionConcurrencyControl getMvcc() { +080 return mvcc; +081 } +082 +083 /** +084 * Use it to complete mvcc transaction. This WALKey was part of +085 * (the transaction is started when you call append; see the comment on FSHLog#append). To +086 * complete call +087 * {@link MultiVersionConcurrencyControl#complete(MultiVersionConcurrencyControl.WriteEntry)} +088 * or {@link MultiVersionConcurrencyControl#complete(MultiVersionConcurrencyControl.WriteEntry)} +089 * @return A WriteEntry gotten from local WAL subsystem. +090 * @see #setWriteEntry(MultiVersionConcurrencyControl.WriteEntry) +091 */ +092 @InterfaceAudience.Private // For internal use only. +093 public MultiVersionConcurrencyControl.WriteEntry getWriteEntry() throws InterruptedIOException { +094 try { +095 this.sequenceIdAssignedLatch.await(); +096 } catch (InterruptedException ie) { +097 MultiVersionConcurrencyControl mvcc = getMvcc(); +098 if (LOG.isDebugEnabled()) { +099 LOG.debug("mvcc=" + mvcc + ", writeEntry=" + this.writeEntry); +100 } +101 InterruptedIOException iie = new InterruptedIOException(); +102 iie.initCause(ie); +103 throw iie; +104 } +105 return this.writeEntry; +106 } +107 +108 @InterfaceAudience.Private // For internal use only. +109 public void setWriteEntry(MultiVersionConcurrencyControl.WriteEntry writeEntry) { +110 if (this.writeEntry != null) { +111 throw new RuntimeException("Non-null!!!"); +112 } +113 this.writeEntry = writeEntry; +114 // Set our sequenceid now using WriteEntry. +115 if (this.writeEntry != null) { +116 this.sequenceId = this.writeEntry.getWriteNumber(); +117 } +118 this.sequenceIdAssignedLatch.countDown(); +119 } +120 +121 // REMOVE!!!! No more Writables!!!! +122 // Should be < 0 (@see HLogKey#readFields(DataInput)) +123 // version 2 supports WAL compression +124 // public members here are only public because of HLogKey +125 @InterfaceAudience.Private +126 protected enum Version { +127 UNVERSIONED(0), +128 // Initial number we put on WALKey when we introduced versioning. +129 INITIAL(-1), +130 // Version -2 introduced a dictionary compression facility. Only this +131 // dictionary-based compression is available in version -2. +132 COMPRESSED(-2); +133 +134 public final int code; +135 static final Version[] byCode; +136 static { +137 byCode = Version.values(); +138 for (int i = 0; i < byCode.length; i++) { +139 if (byCode[i].code != -1 * i) { +140 throw new AssertionError("Values in this enum should be descending by one"); +141 } +142 } +143 } +144 +145 Version(int code) { +146 this.code = code; +147 } +148 +149 public boolean atLeast(Version other) { +150 return code <= other.code; +151 } +152 +153 public static Version fromCode(int code) { +154 return byCode[code * -1]; +155 } +156 } +157 +158 /* +159 * This is used for reading the log entries created by the previous releases +160 * (0.94.11) which write the clusters information to the scopes of WALEdit. +161 */ +162 private static final String PREFIX_CLUSTER_KEY = "."; +163 +164 +165 // visible for deprecated HLogKey +166 @InterfaceAudience.Private +167 protected static final Version VERSION = Version.COMPRESSED; 168 -169 -170 // visible for deprecated HLogKey -171 @InterfaceAudience.Private -172 protected byte [] encodedRegionName; -173 // visible for deprecated HLogKey -174 @InterfaceAudience.Private -175 protected TableName tablename; -176 // visible for deprecated HLogKey -177 @InterfaceAudience.Private -178 protected long logSeqNum; -179 private long origLogSeqNum = 0; -180 private CountDownLatch seqNumAssignedLatch = new CountDownLatch(1); -181 // Time at which this edit was written. -182 // visible for deprecated HLogKey -183 @InterfaceAudience.Private -184 protected long writeTime; +169 // visible for deprecated HLogKey +170 @InterfaceAudience.Private +171 protected byte [] encodedRegionName; +172 // visible for deprecated HLogKey +173 @InterfaceAudience.Private +174 protected TableName tablename; +175 /** +176 * SequenceId for this edit. Set post-construction at write-to-WAL time. Until then it is +177 * NO_SEQUENCE_ID. Change it so multiple threads can read it -- e.g. access is synchronized. +178 */ +179 private long sequenceId; +180 +181 /** +182 * Used during WAL replay; the sequenceId of the edit when it came into the system. +183 */ +184 private long origLogSeqNum = 0; 185 -186 // The first element in the list is the cluster id on which the change has originated +186 // Time at which this edit was written. 187 // visible for deprecated HLogKey 188 @InterfaceAudience.Private -189 protected List<UUID> clusterIds; +189 protected long writeTime; 190 -191 private NavigableMap<byte[], Integer> scopes; -192 -193 private long nonceGroup = HConstants.NO_NONCE; -194 private long nonce = HConstants.NO_NONCE; -195 private MultiVersionConcurrencyControl mvcc; -196 private MultiVersionConcurrencyControl.WriteEntry writeEntry; -197 public static final List<UUID> EMPTY_UUIDS = Collections.unmodifiableList(new ArrayList<UUID>()); -198 -199 // visible for deprecated HLogKey -200 @InterfaceAudience.Private -201 protected CompressionContext compressionContext; -202 -203 public WALKey() { -204 init(null, null, 0L, HConstants.LATEST_TIMESTAMP, -205 new ArrayList<UUID>(), HConstants.NO_NONCE, HConstants.NO_NONCE, null); -206 } -207 -208 @VisibleForTesting -209 public WALKey(final byte[] encodedRegionName, final TableName tablename, -210 long logSeqNum, -211 final long now, UUID clusterId) { -212 List<UUID> clusterIds = new ArrayList<UUID>(); -213 clusterIds.add(clusterId); -214 init(encodedRegionName, tablename, logSeqNum, now, clusterIds, -215 HConstants.NO_NONCE, HConstants.NO_NONCE, null); -216 } -217 -218 public WALKey(final byte[] encodedRegionName, final TableName tablename) { -219 this(encodedRegionName, tablename, System.currentTimeMillis()); -220 } -221 -222 public WALKey(final byte[] encodedRegionName, final TableName tablename, final long now) { -223 init(encodedRegionName, -224 tablename, -225 NO_SEQUENCE_ID, -226 now, -227 EMPTY_UUIDS, -228 HConstants.NO_NONCE, -229 HConstants.NO_NONCE, -230 null); -231 } -232 -233 public WALKey(final byte[] encodedRegionName, -234 final TableName tablename, -235 final long now, -236 MultiVersionConcurrencyControl mvcc) { -237 init(encodedRegionName, -238 tablename, -239 NO_SEQUENCE_ID, -240 now, -241 EMPTY_UUIDS, +191 // The first element in the list is the cluster id on which the change has originated +192 // visible for deprecated HLogKey +193 @InterfaceAudience.Private +194 protected List<UUID> clusterIds; +195 +196 private NavigableMap<byte[], Integer> scopes; +197 +198 private long nonceGroup = HConstants.NO_NONCE; +199 private long nonce = HConstants.NO_NONCE; +200 private MultiVersionConcurrencyControl mvcc; +201 /** +202 * Set in a way visible to multiple threads; e.g. synchronized getter/setters. +203 */ +204 private MultiVersionConcurrencyControl.WriteEntry writeEntry; +205 public static final List<UUID> EMPTY_UUIDS = Collections.unmodifiableList(new ArrayList<UUID>()); +206 +207 // visible for deprecated HLogKey +208 @InterfaceAudience.Private +209 protected CompressionContext compressionContext; +210 +211 public WALKey() { +212 init(null, null, 0L, HConstants.LATEST_TIMESTAMP, +213 new ArrayList<UUID>(), HConstants.NO_NONCE, HConstants.NO_NONCE, null); +214 } +215 +216 @VisibleForTesting +217 public WALKey(final byte[] encodedRegionName, final TableName tablename, +218 long logSeqNum, +219 final long now, UUID clusterId) { +220 List<UUID> clusterIds = new ArrayList<UUID>(); +221 clusterIds.add(clusterId); +222 init(encodedRegionName, tablename, logSeqNum, now, clusterIds, +223 HConstants.NO_NONCE, HConstants.NO_NONCE, null); +224 } +225 +226 /** +227 * @deprecated Remove. Useless. +228 */ +229 @Deprecated // REMOVE +230 public WALKey(final byte[] encodedRegionName, final TableName tablename) { +231 this(encodedRegionName, tablename, System.currentTimeMillis()); +232 } +233 +234 // TODO: Fix being able to pass in sequenceid. +235 public WALKey(final byte[] encodedRegionName, final TableName tablename, final long now) { +236 init(encodedRegionName, +237 tablename, +238 NO_SEQUENCE_ID, +239 now, +240 EMPTY_UUIDS, +241 HConstants.NO_NONCE, 242 HConstants.NO_NONCE, -243 HConstants.NO_NONCE, -244 mvcc); -245 } -246 -247 /** -248 * Create the log key for writing to somewhere. -249 * We maintain the tablename mainly for debugging purposes. -250 * A regionName is always a sub-table object. -251 * <p>Used by log splitting and snapshots. -252 * -253 * @param encodedRegionName Encoded name of the region as returned by -254 * <code>HRegionInfo#getEncodedNameAsBytes()</code>. -255 * @param tablename - name of table -256 * @param logSeqNum - log sequence number -257 * @param now Time at which this edit was written. -258 * @param clusterIds the clusters that have consumed the change(used in Replication) -259 */ -260 public WALKey(final byte[] encodedRegionName, -261 final TableName tablename, -262 long logSeqNum, -263 final long now, -264 List<UUID> clusterIds, -265 long nonceGroup, -266 long nonce, -267 MultiVersionConcurrencyControl mvcc) { -268 init(encodedRegionName, tablename, logSeqNum, now, clusterIds, nonceGroup, nonce, mvcc); -269 } -270 -271 /** -272 * Create the log key for writing to somewhere. -273 * We maintain the tablename mainly for debugging purposes. -274 * A regionName is always a sub-table object. -275 * -276 * @param encodedRegionName Encoded name of the region as returned by -277 * <code>HRegionInfo#getEncodedNameAsBytes()</code>. -278 * @param tablename -279 * @param now Time at which this edit was written. -280 * @param clusterIds the clusters that have consumed the change(used in Replication) -281 * @param nonceGroup -282 * @param nonce -283 * @param mvcc mvcc control used to generate sequence numbers and control read/write points -284 */ -285 public WALKey(final byte[] encodedRegionName, final TableName tablename, -286 final long now, List<UUID> clusterIds, long nonceGroup, -287 final long nonce, final MultiVersionConcurrencyControl mvcc) { -288 init(encodedRegionName, tablename, NO_SEQUENCE_ID, now, clusterIds, nonceGroup, nonce, mvcc); -289 } -290 -291 /** -292 * Create the log key for writing to somewhere. -293 * We maintain the tablename mainly for debugging purposes. -294 * A regionName is always a sub-table object. -295 * -296 * @param encodedRegionName Encoded name of the region as returned by -297 * <code>HRegionInfo#getEncodedNameAsBytes()</code>. -298 * @param tablename -299 * @param logSeqNum -300 * @param nonceGroup -301 * @param nonce -302 */ -303 public WALKey(final byte[] encodedRegionName, -304 final TableName tablename, -305 long logSeqNum, -306 long nonceGroup, -307 long nonce, -308 final MultiVersionConcurrencyControl mvcc) { -309 init(encodedRegionName, -310 tablename, -311 logSeqNum, -312 EnvironmentEdgeManager.currentTime(), -313 EMPTY_UUIDS, -314 nonceGroup, -315 nonce, -316 mvcc); -317 } -318 -319 @InterfaceAudience.Private -320 protected void init(final byte[] encodedRegionName, -321 final TableName tablename, -322 long logSeqNum, -323 final long now, -324 List<UUID> clusterIds, -325 long nonceGroup, -326 long nonce, -327 MultiVersionConcurrencyControl mvcc) { -328 this.logSeqNum = logSeqNum; -329 this.writeTime = now; -330 this.clusterIds = clusterIds; -331 this.encodedRegionName = encodedRegionName; -332 this.tablename = tablename; -333 this.nonceGroup = nonceGroup; -334 this.nonce = nonce; -335 this.mvcc = mvcc; -336 } -337 -338 /** -339 * @param compressionContext Compression context to use -340 */ -341 public void setCompressionContext(CompressionContext compressionContext) { -342 this.compressionContext = compressionContext; -343 } -344 -345 /** @return encoded region name */ -346 public byte [] getEncodedRegionName() { -347 return encodedRegionName; -348 } -349 -350 /** @return table name */ -351 public TableName getTablename() { -352 return tablename; -353 } -354 -355 /** @return log sequence number */ -356 public long getLogSeqNum() { -357 return this.logSeqNum; -358 } -359 -360 /** -361 * Allow that the log sequence id to be set post-construction -362 * Only public for org.apache.hadoop.hbase.regionserver.wal.FSWALEntry -363 * @param sequence +243 null); +244 } +245 +246 public WALKey(final byte[] encodedRegionName, +247 final TableName tablename, +248 final long now, +249 MultiVersionConcurrencyControl mvcc) { +250 init(encodedRegionName, +251 tablename, +252 NO_SEQUENCE_ID, +253 now, +254 EMPTY_UUIDS, +255 HConstants.NO_NONCE, +256 HConstants.NO_NONCE, +257 mvcc); +258 } +259 +260 /** +261 * Create the log key for writing to somewhere. +262 * We maintain the tablename mainly for debugging purposes. +263 * A regionName is always a sub-table object. +264 * <p>Used by log splitting and snapshots. +265 * +266 * @param encodedRegionName Encoded name of the region as returned by +267 * <code>HRegionInfo#getEncodedNameAsBytes()</code>. +268 * @param tablename - name of table +269 * @param logSeqNum - log sequence number +270 * @param now Time at which this edit was written. +271 * @param clusterIds the clusters that have consumed the change(used in Replication) +272 */ +273 // TODO: Fix being able to pass in sequenceid. +274 public WALKey(final byte[] encodedRegionName, +275 final TableName tablename, +276 long logSeqNum, +277 final long now, +278 List<UUID> clusterIds, +279 long nonceGroup, +280 long nonce, +281 MultiVersionConcurrencyControl mvcc) { +282 init(encodedRegionName, tablename, logSeqNum, now, clusterIds, nonceGroup, nonce, mvcc); +283 } +284 +285 /** +286 * Create the log key for writing to somewhere. +287 * We maintain the tablename mainly for debugging purposes. +288 * A regionName is always a sub-table object. +289 * +290 * @param encodedRegionName Encoded name of the region as returned by +291 * <code>HRegionInfo#getEncodedNameAsBytes()</code>. +292 * @param tablename +293 * @param now Time at which this edit was written. +294 * @param clusterIds the clusters that have consumed the change(used in Replication) +295 * @param nonceGroup +296 * @param nonce +297 * @param mvcc mvcc control used to generate sequence numbers and control read/write points +298 */ +299 public WALKey(final byte[] encodedRegionName, final TableName tablename, +300 final long now, List<UUID> clusterIds, long nonceGroup, +301 final long nonce, final MultiVersionConcurrencyControl mvcc) { +302 init(encodedRegionName, tablename, NO_SEQUENCE_ID, now, clusterIds, nonceGroup, nonce, mvcc); +303 } +304 +305 /** +306 * Create the log key for writing to somewhere. +307 * We maintain the tablename mainly for debugging purposes. +308 * A regionName is always a sub-table object. +309 * +310 * @param encodedRegionName Encoded name of the region as returned by +311 * <code>HRegionInfo#getEncodedNameAsBytes()</code>. +312 * @param tablename +313 * @param logSeqNum +314 * @param nonceGroup +315 * @param nonce +316 */ +317 // TODO: Fix being able to pass in sequenceid. +318 public WALKey(final byte[] encodedRegionName, +319 final TableName tablename, +320 long logSeqNum, +321 long nonceGroup, +322 long nonce, +323 final MultiVersionConcurrencyControl mvcc) { +324 init(encodedRegionName, +325 tablename, +326 logSeqNum, +327 EnvironmentEdgeManager.currentTime(), +328 EMPTY_UUIDS, +329 nonceGroup, +330 nonce, +331 mvcc); +332 } +333 +334 @InterfaceAudience.Private +335 protected void init(final byte[] encodedRegionName, +336 final TableName tablename, +337 long logSeqNum, +338 final long now, +339 List<UUID> clusterIds, +340 long nonceGroup, +341 long nonce, +342 MultiVersionConcurrencyControl mvcc) { +343 this.sequenceId = logSeqNum; +344 this.writeTime = now; +345 this.clusterIds = clusterIds; +346 this.encodedRegionName = encodedRegionName; +347 this.tablename = tablename; +348 this.nonceGroup = nonceGroup; +349 this.nonce = nonce; +350 this.mvcc = mvcc; +351 if (logSeqNum != NO_SEQUENCE_ID) { +352 setSequenceId(logSeqNum); +353 } +354 } +355 +356 // For HLogKey and deserialization. DO NOT USE. See setWriteEntry below. +357 @InterfaceAudience.Private +358 protected void setSequenceId(long sequenceId) { +359 this.sequenceId = sequenceId; +360 } +361 +362 /** +363 * @param compressionContext Compression context to use 364 */ -365 @InterfaceAudience.Private -366 public void setLogSeqNum(final long sequence) { -367 this.logSeqNum = sequence; +365 public void setCompressionContext(CompressionContext compressionContext) { +366 this.compressionContext = compressionContext; +367 } 368 -369 } -370 -371 /** -372 * Used to set original seq Id for WALKey during wal replay -373 * @param seqId -374 */ -375 public void setOrigLogSeqNum(final long seqId) { -376 this.origLogSeqNum = seqId; +369 /** @return encoded region name */ +370 public byte [] getEncodedRegionName() { +371 return encodedRegionName; +372 } +373 +374 /** @return table name */ +375 public TableName getTablename() { +376 return tablename; 377 } -378 -379 /** -380 * Return a positive long if current WALKey is created from a replay edit -381 * @return original sequence number of the WALEdit -382 */ -383 public long getOrigLogSeqNum() { -384 return this.origLogSeqNum; +378 +379 /** @return log sequence number +380 * @deprecated Use {@link #getSequenceId()} +381 */ +382 @Deprecated +383 public long getLogSeqNum() { +384 return getSequenceId(); 385 } -386 +386 387 /** -388 * Wait for sequence number to be assigned &amp; return the assigned value -389 * @return long the new assigned sequence number -390 * @throws IOException -391 */ -392 @Override -393 public long getSequenceId() throws IOException { -394 return getSequenceId(-1); -395 } -396 -397 /** -398 * Wait for sequence number to be assigned &amp; return the assigned value. -399 * @param maxWaitForSeqId maximum time to wait in milliseconds for sequenceid -400 * @return long the new assigned sequence number -401 * @throws IOException -402 */ -403 public long getSequenceId(final long maxWaitForSeqId) throws IOException { -404 // TODO: This implementation waiting on a latch is problematic because if a higher level -405 // determines we should stop or abort, there is no global list of all these blocked WALKeys -406 // waiting on a sequence id; they can't be cancelled... interrupted. See getNextSequenceId. -407 // -408 // UPDATE: I think we can remove the timeout now we are stamping all walkeys with sequenceid, -409 // even those that have failed (previously we were not... so they would just hang out...). -410 // St.Ack 20150910 -411 try { -412 if (maxWaitForSeqId < 0) { -413 this.seqNumAssignedLatch.await(); -414 } else if (!this.seqNumAssignedLatch.await(maxWaitForSeqId, TimeUnit.MILLISECONDS)) { -415 throw new TimeoutIOException("Failed to get sequenceid after " + maxWaitForSeqId + -416 "ms; WAL system stuck or has gone away?"); -417 } -418 } catch (InterruptedException ie) { -419 LOG.warn("Thread interrupted waiting for next log sequence number"); -420 InterruptedIOException iie = new InterruptedIOException(); -421 iie.initCause(ie); -422 throw iie; -423 } -424 return this.logSeqNum; -425 } -426 -427 /** -428 * @return the write time -429 */ -430 public long getWriteTime() { -431 return this.writeTime; -432 } -433 -434 public NavigableMap<byte[], Integer> getScopes() { -435 return scopes; -436 } -437 -438 /** @return The nonce group */ -439 public long getNonceGroup() { -440 return nonceGroup; -441 } -442 -443 /** @return The nonce */ -444 public long getNonce() { -445 return nonce; -446 } -447 -448 public void setScopes(NavigableMap<byte[], Integer> scopes) { -449 this.scopes = scopes; -450 } -451 -452 public void readOlderScopes(NavigableMap<byte[], Integer> scopes) { -453 if (scopes != null) { -454 Iterator<Map.Entry<byte[], Integer>> iterator = scopes.entrySet() -455 .iterator(); -456 while (iterator.hasNext()) { -457 Map.Entry<byte[], Integer> scope = iterator.next(); -458 String key = Bytes.toString(scope.getKey()); -459 if (key.startsWith(PREFIX_CLUSTER_KEY)) { -460 addClusterId(UUID.fromString(key.substring(PREFIX_CLUSTER_KEY -461 .length()))); -462 iterator.remove(); -463 } -464 } -465 if (scopes.size() > 0) { -466 this.scopes = scopes; -467 } -468 } -469 } -470 -471 /** -472 * Marks that the cluster with the given clusterId has consumed the change -473 */ -474 public void addClusterId(UUID clusterId) { -475 if (!clusterIds.contains(clusterId)) { -476 clusterIds.add(clusterId); -477 } -478 } -479 -480 /** -481 * @return the set of cluster Ids that have consumed the change -482 */ -483 public List<UUID> getClusterIds() { -484 return clusterIds; -485 } -486 -487 /** -488 * @return the cluster id on which the change has originated. It there is no such cluster, it -489 * returns DEFAULT_CLUSTER_ID (cases where replication is not enabled) -490 */ -491 public UUID getOriginatingClusterId(){ -492 return clusterIds.isEmpty() ? HConstants.DEFAULT_CLUSTER_ID : clusterIds.get(0); -493 } -494 -495 @Override -496 public String toString() { -497 return tablename + "/" + Bytes.toString(encodedRegionName) + "/" + -498 logSeqNum; -499 } -500 -501 /** -502 * Produces a string map for this key. Useful for programmatic use and -503 * manipulation of the data stored in an WALKey, for example, printing -504 * as JSON. -505 * -506 * @return a Map containing data from this key -507 */ -508 public Map<String, Object> toStringMap() { -509 Map<String, Object> stringMap = new HashMap<String, Object>(); -510 stringMap.put("table", tablename); -511 stringMap.put("region", Bytes.toStringBinary(encodedRegionName)); -512 stringMap.put("sequence", logSeqNum); -513 return stringMap; -514 } -515 -516 @Override -517 public boolean equals(Object obj) { -518 if (this == obj) { -519 return true; -520 } -521 if (obj == null || getClass() != obj.getClass()) { -522 return false; -523 } -524 return compareTo((WALKey)obj) == 0; -525 } -526 -527 @Override -528 public int hashCode() { -529 int result = Bytes.hashCode(this.encodedRegionName); -530 result ^= this.logSeqNum; -531 result ^= this.writeTime; -532 return result; -533 } -534 -535 @Override -536 public int compareTo(WALKey o) { -537 int result = Bytes.compareTo(this.encodedRegionName, o.encodedRegionName); -538 if (result == 0) { -539 if (this.logSeqNum < o.logSeqNum) { -540 result = -1; -541 } else if (this.logSeqNum > o.logSeqNum) { -542 result = 1; -543 } -544 if (result == 0) { -545 if (this.writeTime < o.writeTime) { -546 result = -1; -547 } else if (this.writeTime > o.writeTime) { -548 return 1; -549 } -550 } -551 } -552 // why isn't cluster id accounted for? -553 return result; -554 } -555 -556 /** -557 * Drop this instance's tablename byte array and instead -558 * hold a reference to the provided tablename. This is not -559 * meant to be a general purpose setter - it's only used -560 * to collapse references to conserve memory. -561 */ -562 void internTableName(TableName tablename) { -563 // We should not use this as a setter - only to swap -564 // in a new reference to the same table name. -565 assert tablename.equals(this.tablename); -566 this.tablename = tablename; -567 } -568 -569 /** -570 * Drop this instance's region name byte array and instead -571 * hold a reference to the provided region name. This is not -572 * meant to be a general purpose setter - it's only used -573 * to collapse references to conserve memory. -574 */ -575 void internEncodedRegionName(byte []encodedRegionName) { -576 // We should not use this as a setter - only to swap -577 // in a new reference to the same table name. -578 assert Bytes.equals(this.encodedRegionName, encodedRegionName); -579 this.encodedRegionName = encodedRegionName; -580 } -581 -582 public org.apache.hadoop.hbase.protobuf.generated.WALProtos.WALKey.Builder getBuilder( -583 WALCellCodec.ByteStringCompressor compressor) throws IOException { -584 org.apache.hadoop.hbase.protobuf.generated.WALProtos.WALKey.Builder builder = -585 org.apache.hadoop.hbase.protobuf.generated.WALProtos.WALKey.newBuilder(); -586 if (compressionContext == null) { -587 builder.setEncodedRegionName(ByteStringer.wrap(this.encodedRegionName)); -588 builder.setTableName(ByteStringer.wrap(this.tablename.getName())); -589 } else { -590 builder.setEncodedRegionName(compressor.compress(this.encodedRegionName, -591 compressionContext.regionDict)); -592 builder.setTableName(compressor.compress(this.tablename.getName(), -593 compressionContext.tableDict)); +388 * Used to set original sequenceId for WALKey during WAL replay +389 */ +390 public void setOrigLogSeqNum(final long sequenceId) { +391 this.origLogSeqNum = sequenceId; +392 } +393 +394 /** +395 * Return a positive long if current WALKey is created from a replay edit; a replay edit is an +396 * edit that came in when replaying WALs of a crashed server. +397 * @return original sequence number of the WALEdit +398 */ +399 public long getOrigLogSeqNum() { +400 return this.origLogSeqNum; +401 } +402 +403 /** +404 * SequenceId is only available post WAL-assign. Calls before this will get you a +405 * {@link #NO_SEQUENCE_ID}. See the comment on FSHLog#append and #getWriteNumber in this method +406 * for more on when this sequence