hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject [1/3] hbase git commit: HBASE-15158 Change order in which we do write pipeline operations; do all under row locks
Date Mon, 08 Feb 2016 06:56:47 GMT
Repository: hbase
Updated Branches:
  refs/heads/master dfd8a31a1 -> ec92a8a70


http://git-wip-us.apache.org/repos/asf/hbase/blob/ec92a8a7/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSWALEntry.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSWALEntry.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSWALEntry.java
index 5fe2061..86a3c3d 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSWALEntry.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/FSWALEntry.java
@@ -127,10 +127,7 @@ class FSWALEntry extends Entry {
       }
     }
 
-    // This has to stay in this order
-    WALKey key = getKey();
-    key.setLogSeqNum(regionSequenceId);
-    key.setWriteEntry(we);
+    getKey().setWriteEntry(we);
     return regionSequenceId;
   }
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/ec92a8a7/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogKey.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogKey.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogKey.java
index c094ced..7c40323 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogKey.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/HLogKey.java
@@ -166,7 +166,7 @@ public class HLogKey extends WALKey implements Writable {
           this.tablename.getName().length, out,
           compressionContext.tableDict);
     }
-    out.writeLong(this.logSeqNum);
+    out.writeLong(getSequenceId());
     out.writeLong(this.writeTime);
     // Don't need to write the clusters information as we are using protobufs from 0.95
     // Writing only the first clusterId for testing the legacy read
@@ -213,7 +213,7 @@ public class HLogKey extends WALKey implements Writable {
       tablenameBytes = Compressor.readCompressed(in, compressionContext.tableDict);
     }
 
-    this.logSeqNum = in.readLong();
+    setSequenceId(in.readLong());
     this.writeTime = in.readLong();
 
     this.clusterIds.clear();

http://git-wip-us.apache.org/repos/asf/hbase/blob/ec92a8a7/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALUtil.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALUtil.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALUtil.java
index c89a466..f268422 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALUtil.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/WALUtil.java
@@ -37,9 +37,9 @@ import org.apache.hadoop.hbase.wal.WALKey;
 import com.google.protobuf.TextFormat;
 
 /**
- * Helper methods to ease Region Server integration with the write ahead log.
+ * Helper methods to ease Region Server integration with the Write Ahead Log (WAL).
  * Note that methods in this class specifically should not require access to anything
- * other than the API found in {@link WAL}.
+ * other than the API found in {@link WAL}. For internal use only.
  */
 @InterfaceAudience.Private
 public class WALUtil {
@@ -51,86 +51,108 @@ public class WALUtil {
 
   /**
    * Write the marker that a compaction has succeeded and is about to be committed.
-   * This provides info to the HMaster to allow it to recover the compaction if
-   * this regionserver dies in the middle (This part is not yet implemented). It also prevents
-   * the compaction from finishing if this regionserver has already lost its lease on the
log.
+   * This provides info to the HMaster to allow it to recover the compaction if this regionserver
+   * dies in the middle. It also prevents the compaction from finishing if this regionserver
has
+   * already lost its lease on the log.
+   *
+   * <p>This write is for internal use only. Not for external client consumption.
    * @param mvcc Used by WAL to get sequence Id for the waledit.
    */
-  public static long writeCompactionMarker(WAL wal, HTableDescriptor htd, HRegionInfo hri,
+  public static WALKey writeCompactionMarker(WAL wal, HTableDescriptor htd, HRegionInfo hri,
       final CompactionDescriptor c, MultiVersionConcurrencyControl mvcc)
   throws IOException {
-    long trx = writeMarker(wal, htd, hri, WALEdit.createCompaction(hri, c), mvcc, true);
+    WALKey walKey = writeMarker(wal, htd, hri, WALEdit.createCompaction(hri, c), mvcc);
     if (LOG.isTraceEnabled()) {
       LOG.trace("Appended compaction marker " + TextFormat.shortDebugString(c));
     }
-    return trx;
+    return walKey;
   }
 
   /**
    * Write a flush marker indicating a start / abort or a complete of a region flush
+   *
+   * <p>This write is for internal use only. Not for external client consumption.
    */
-  public static long writeFlushMarker(WAL wal, HTableDescriptor htd, HRegionInfo hri,
+  public static WALKey writeFlushMarker(WAL wal, HTableDescriptor htd, HRegionInfo hri,
       final FlushDescriptor f, boolean sync, MultiVersionConcurrencyControl mvcc)
   throws IOException {
-    long trx = writeMarker(wal, htd, hri, WALEdit.createFlushWALEdit(hri, f), mvcc, sync);
+    WALKey walKey =
+      doFullAppendTransaction(wal, htd, hri, WALEdit.createFlushWALEdit(hri, f), mvcc, sync);
     if (LOG.isTraceEnabled()) {
       LOG.trace("Appended flush marker " + TextFormat.shortDebugString(f));
     }
-    return trx;
+    return walKey;
   }
 
   /**
-   * Write a region open marker indicating that the region is opened
+   * Write a region open marker indicating that the region is opened.
+   * This write is for internal use only. Not for external client consumption.
    */
-  public static long writeRegionEventMarker(WAL wal, HTableDescriptor htd, HRegionInfo hri,
+  public static WALKey writeRegionEventMarker(WAL wal, HTableDescriptor htd, HRegionInfo
hri,
       final RegionEventDescriptor r, final MultiVersionConcurrencyControl mvcc)
   throws IOException {
-    long trx = writeMarker(wal, htd, hri, WALEdit.createRegionEventWALEdit(hri, r), mvcc,
true);
+    WALKey walKey = writeMarker(wal, htd, hri, WALEdit.createRegionEventWALEdit(hri, r),
mvcc);
     if (LOG.isTraceEnabled()) {
       LOG.trace("Appended region event marker " + TextFormat.shortDebugString(r));
     }
-    return trx;
+    return walKey;
   }
 
   /**
    * Write a log marker that a bulk load has succeeded and is about to be committed.
-   *
-   * @param wal        The log to write into.
-   * @param htd        A description of the table that we are bulk loading into.
-   * @param hri       A description of the region in the table that we are bulk loading into.
+   * This write is for internal use only. Not for external client consumption.
+   * @param wal The log to write into.
+   * @param htd A description of the table that we are bulk loading into.
+   * @param hri A description of the region in the table that we are bulk loading into.
    * @param desc A protocol buffers based description of the client's bulk loading request
-   * @return txid of this transaction or if nothing to do, the last txid
+   * @return walKey with sequenceid filled out for this bulk load marker
    * @throws IOException We will throw an IOException if we can not append to the HLog.
    */
-  public static long writeBulkLoadMarkerAndSync(final WAL wal, final HTableDescriptor htd,
+  public static WALKey writeBulkLoadMarkerAndSync(final WAL wal, final HTableDescriptor htd,
       final HRegionInfo hri, final WALProtos.BulkLoadDescriptor desc,
       final MultiVersionConcurrencyControl mvcc)
   throws IOException {
-    long trx = writeMarker(wal, htd, hri, WALEdit.createBulkLoadEvent(hri, desc), mvcc, true);
+    WALKey walKey = writeMarker(wal, htd, hri, WALEdit.createBulkLoadEvent(hri, desc), mvcc);
     if (LOG.isTraceEnabled()) {
       LOG.trace("Appended Bulk Load marker " + TextFormat.shortDebugString(desc));
     }
-    return trx;
+    return walKey;
   }
 
-  private static long writeMarker(final WAL wal, final HTableDescriptor htd, final HRegionInfo
hri,
-      final WALEdit edit, final MultiVersionConcurrencyControl mvcc, final boolean sync)
+  private static WALKey writeMarker(final WAL wal, final HTableDescriptor htd,
+      final HRegionInfo hri, final WALEdit edit, final MultiVersionConcurrencyControl mvcc)
+  throws IOException {
+    // If sync == true in below, then timeout is not used; safe to pass UNSPECIFIED_TIMEOUT
+    return doFullAppendTransaction(wal, htd, hri, edit, mvcc, true);
+  }
+
+  /**
+   * A 'full' WAL transaction involves starting an mvcc transaction followed by an append,
+   * an optional sync, and then a call to complete the mvcc transaction. This method does
it all.
+   * Good for case of adding a single edit or marker to the WAL.
+   *
+   * <p>This write is for internal use only. Not for external client consumption.
+   * @return WALKey that was added to the WAL.
+   */
+  public static WALKey doFullAppendTransaction(final WAL wal, final HTableDescriptor htd,
+      final HRegionInfo hri, final WALEdit edit, final MultiVersionConcurrencyControl mvcc,
+      final boolean sync)
   throws IOException {
     // TODO: Pass in current time to use?
-    WALKey key =
-      new HLogKey(hri.getEncodedNameAsBytes(), hri.getTable(), System.currentTimeMillis(),
mvcc);
-    // Add it to the log but the false specifies that we don't need to add it to the memstore
+    WALKey walKey =
+      new WALKey(hri.getEncodedNameAsBytes(), hri.getTable(), System.currentTimeMillis(),
mvcc);
     long trx = MultiVersionConcurrencyControl.NONE;
     try {
-      trx = wal.append(htd, hri, key, edit, false);
-      if (sync) wal.sync(trx);
-    } finally {
-      // If you get hung here, is it a real WAL or a mocked WAL? If the latter, you need
to
-      // trip the latch that is inside in getWriteEntry up in your mock. See down in the
append
-      // called from onEvent in FSHLog.
-      MultiVersionConcurrencyControl.WriteEntry we = key.getWriteEntry();
-      if (mvcc != null && we != null) mvcc.complete(we);
+      trx = wal.append(htd, hri, walKey, edit, false);
+      if (sync) {
+        wal.sync(trx);
+      }
+      // Call complete only here because these are markers only. They are not for clients
to read.
+      mvcc.complete(walKey.getWriteEntry());
+    } catch (IOException ioe) {
+      mvcc.complete(walKey.getWriteEntry());
+      throw ioe;
     }
-    return trx;
+    return walKey;
   }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/hbase/blob/ec92a8a7/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALKey.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALKey.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALKey.java
index 4091a82..09096fe 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALKey.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/wal/WALKey.java
@@ -30,52 +30,50 @@ import java.util.NavigableMap;
 import java.util.TreeMap;
 import java.util.UUID;
 import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
 
-import org.apache.hadoop.hbase.regionserver.MultiVersionConcurrencyControl;
-import org.apache.hadoop.hbase.util.ByteStringer;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.hadoop.hbase.classification.InterfaceAudience;
-import org.apache.hadoop.hbase.exceptions.TimeoutIOException;
 import org.apache.hadoop.hbase.HBaseInterfaceAudience;
 import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.classification.InterfaceAudience;
 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos;
 import org.apache.hadoop.hbase.protobuf.generated.WALProtos.FamilyScope;
 import org.apache.hadoop.hbase.protobuf.generated.WALProtos.ScopeType;
+import org.apache.hadoop.hbase.regionserver.MultiVersionConcurrencyControl;
 import org.apache.hadoop.hbase.regionserver.SequenceId;
+// imports for things that haven't moved from regionserver.wal yet.
+import org.apache.hadoop.hbase.regionserver.wal.CompressionContext;
+import org.apache.hadoop.hbase.regionserver.wal.WALCellCodec;
+import org.apache.hadoop.hbase.util.ByteStringer;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.protobuf.ByteString;
 
-// imports for things that haven't moved from regionserver.wal yet.
-import org.apache.hadoop.hbase.regionserver.wal.CompressionContext;
-import org.apache.hadoop.hbase.regionserver.wal.WALCellCodec;
-
 /**
- * A Key for an entry in the change log.
+ * A Key for an entry in the WAL.
  *
  * The log intermingles edits to many tables and rows, so each log entry
  * identifies the appropriate table and row.  Within a table and row, they're
  * also sorted.
  *
- * <p>Some Transactional edits (START, COMMIT, ABORT) will not have an
- * associated row.
+ * <p>Some Transactional edits (START, COMMIT, ABORT) will not have an associated row.
  *
  * Note that protected members marked @InterfaceAudience.Private are only protected
  * to support the legacy HLogKey class, which is in a different package.
- * 
- * <p>
  */
 // TODO: Key and WALEdit are never used separately, or in one-to-many relation, for practical
 //       purposes. They need to be merged into WALEntry.
-// TODO: Cleanup. We have logSeqNum and then WriteEntry, both are sequence id'ing. Fix.
 @InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.REPLICATION)
 public class WALKey implements SequenceId, Comparable<WALKey> {
   private static final Log LOG = LogFactory.getLog(WALKey.class);
+  private final CountDownLatch sequenceIdAssignedLatch = new CountDownLatch(1);
+  /**
+   * Used to represent when a particular wal key doesn't know/care about the sequence ordering.
+   */
+  public static final long NO_SEQUENCE_ID = -1;
 
   @InterfaceAudience.Private // For internal use only.
   public MultiVersionConcurrencyControl getMvcc() {
@@ -83,25 +81,22 @@ public class WALKey implements SequenceId, Comparable<WALKey> {
   }
 
   /**
-   * Will block until a write entry has been assigned by they WAL subsystem.
-   * @return A WriteEntry gotten from local WAL subsystem. Must be completed by calling
-   *     {@link MultiVersionConcurrencyControl#complete(MultiVersionConcurrencyControl.WriteEntry)}
-   *     or
-   *     {@link MultiVersionConcurrencyControl#complete(MultiVersionConcurrencyControl.WriteEntry)}
+   * Use it to complete mvcc transaction. This WALKey was part of
+   * (the transaction is started when you call append; see the comment on FSHLog#append).
To
+   * complete call
+   * {@link MultiVersionConcurrencyControl#complete(MultiVersionConcurrencyControl.WriteEntry)}
+   * or {@link MultiVersionConcurrencyControl#complete(MultiVersionConcurrencyControl.WriteEntry)}
+   * @return A WriteEntry gotten from local WAL subsystem.
    * @see #setWriteEntry(MultiVersionConcurrencyControl.WriteEntry)
    */
   @InterfaceAudience.Private // For internal use only.
   public MultiVersionConcurrencyControl.WriteEntry getWriteEntry() throws InterruptedIOException
{
     try {
-      this.seqNumAssignedLatch.await();
+      this.sequenceIdAssignedLatch.await();
     } catch (InterruptedException ie) {
-      // If interrupted... clear out our entry else we can block up mvcc.
       MultiVersionConcurrencyControl mvcc = getMvcc();
-      LOG.debug("mvcc=" + mvcc + ", writeEntry=" + this.writeEntry);
-      if (mvcc != null) {
-        if (this.writeEntry != null) {
-          mvcc.complete(this.writeEntry);
-        }
+      if (LOG.isDebugEnabled()) {
+        LOG.debug("mvcc=" + mvcc + ", writeEntry=" + this.writeEntry);
       }
       InterruptedIOException iie = new InterruptedIOException();
       iie.initCause(ie);
@@ -112,11 +107,19 @@ public class WALKey implements SequenceId, Comparable<WALKey>
{
 
   @InterfaceAudience.Private // For internal use only.
   public void setWriteEntry(MultiVersionConcurrencyControl.WriteEntry writeEntry) {
+    if (this.writeEntry != null) {
+      throw new RuntimeException("Non-null!!!");
+    }
     this.writeEntry = writeEntry;
-    this.seqNumAssignedLatch.countDown();
+    // Set our sequenceid now using WriteEntry.
+    if (this.writeEntry != null) {
+      this.sequenceId = this.writeEntry.getWriteNumber();
+    }
+    this.sequenceIdAssignedLatch.countDown();
   }
 
-  // should be < 0 (@see HLogKey#readFields(DataInput))
+  // 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
@@ -163,21 +166,23 @@ public class WALKey implements SequenceId, Comparable<WALKey>
{
   @InterfaceAudience.Private
   protected static final Version VERSION = Version.COMPRESSED;
 
-  /** Used to represent when a particular wal key doesn't know/care about the sequence ordering.
*/
-  public static final long NO_SEQUENCE_ID = -1;
-
-
   // visible for deprecated HLogKey
   @InterfaceAudience.Private
   protected byte [] encodedRegionName;
   // visible for deprecated HLogKey
   @InterfaceAudience.Private
   protected TableName tablename;
-  // visible for deprecated HLogKey
-  @InterfaceAudience.Private
-  protected long logSeqNum;
+  /**
+   * 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.
+   */
+  private long sequenceId;
+
+  /**
+   * Used during WAL replay; the sequenceId of the edit when it came into the system.
+   */
   private long origLogSeqNum = 0;
-  private CountDownLatch seqNumAssignedLatch = new CountDownLatch(1);
+
   // Time at which this edit was written.
   // visible for deprecated HLogKey
   @InterfaceAudience.Private
@@ -193,6 +198,9 @@ public class WALKey implements SequenceId, Comparable<WALKey> {
   private long nonceGroup = HConstants.NO_NONCE;
   private long nonce = HConstants.NO_NONCE;
   private MultiVersionConcurrencyControl mvcc;
+  /**
+   * Set in a way visible to multiple threads; e.g. synchronized getter/setters.
+   */
   private MultiVersionConcurrencyControl.WriteEntry writeEntry;
   public static final List<UUID> EMPTY_UUIDS = Collections.unmodifiableList(new ArrayList<UUID>());
 
@@ -215,10 +223,15 @@ public class WALKey implements SequenceId, Comparable<WALKey>
{
         HConstants.NO_NONCE, HConstants.NO_NONCE, null);
   }
 
+  /**
+   * @deprecated Remove. Useless.
+   */
+  @Deprecated // REMOVE
   public WALKey(final byte[] encodedRegionName, final TableName tablename) {
     this(encodedRegionName, tablename, System.currentTimeMillis());
   }
 
+  // TODO: Fix being able to pass in sequenceid.
   public WALKey(final byte[] encodedRegionName, final TableName tablename, final long now)
{
     init(encodedRegionName,
         tablename,
@@ -257,6 +270,7 @@ public class WALKey implements SequenceId, Comparable<WALKey> {
    * @param now               Time at which this edit was written.
    * @param clusterIds        the clusters that have consumed the change(used in Replication)
    */
+  // TODO: Fix being able to pass in sequenceid.
   public WALKey(final byte[] encodedRegionName,
                 final TableName tablename,
                 long logSeqNum,
@@ -300,6 +314,7 @@ public class WALKey implements SequenceId, Comparable<WALKey> {
    * @param nonceGroup
    * @param nonce
    */
+  // TODO: Fix being able to pass in sequenceid.
   public WALKey(final byte[] encodedRegionName,
                 final TableName tablename,
                 long logSeqNum,
@@ -325,7 +340,7 @@ public class WALKey implements SequenceId, Comparable<WALKey> {
                       long nonceGroup,
                       long nonce,
                       MultiVersionConcurrencyControl mvcc) {
-    this.logSeqNum = logSeqNum;
+    this.sequenceId = logSeqNum;
     this.writeTime = now;
     this.clusterIds = clusterIds;
     this.encodedRegionName = encodedRegionName;
@@ -333,6 +348,15 @@ public class WALKey implements SequenceId, Comparable<WALKey> {
     this.nonceGroup = nonceGroup;
     this.nonce = nonce;
     this.mvcc = mvcc;
+    if (logSeqNum != NO_SEQUENCE_ID) {
+      setSequenceId(logSeqNum);
+    }
+  }
+
+  // For HLogKey and deserialization. DO NOT USE. See setWriteEntry below.
+  @InterfaceAudience.Private
+  protected void setSequenceId(long sequenceId) {
+    this.sequenceId = sequenceId;
   }
 
   /**
@@ -352,32 +376,24 @@ public class WALKey implements SequenceId, Comparable<WALKey>
{
     return tablename;
   }
 
-  /** @return log sequence number */
-  public long getLogSeqNum() {
-    return this.logSeqNum;
-  }
-
-  /**
-   * Allow that the log sequence id to be set post-construction
-   * Only public for org.apache.hadoop.hbase.regionserver.wal.FSWALEntry
-   * @param sequence
+  /** @return log sequence number
+   * @deprecated Use {@link #getSequenceId()}
    */
-  @InterfaceAudience.Private
-  public void setLogSeqNum(final long sequence) {
-    this.logSeqNum = sequence;
-
+  @Deprecated
+  public long getLogSeqNum() {
+    return getSequenceId();
   }
 
   /**
-   * Used to set original seq Id for WALKey during wal replay
-   * @param seqId
+   * Used to set original sequenceId for WALKey during WAL replay
    */
-  public void setOrigLogSeqNum(final long seqId) {
-    this.origLogSeqNum = seqId;
+  public void setOrigLogSeqNum(final long sequenceId) {
+    this.origLogSeqNum = sequenceId;
   }
   
   /**
-   * Return a positive long if current WALKey is created from a replay edit
+   * Return a positive long if current WALKey is created from a replay edit; a replay edit
is an
+   * edit that came in when replaying WALs of a crashed server.
    * @return original sequence number of the WALEdit
    */
   public long getOrigLogSeqNum() {
@@ -385,43 +401,14 @@ public class WALKey implements SequenceId, Comparable<WALKey>
{
   }
   
   /**
-   * Wait for sequence number to be assigned &amp; return the assigned value
+   * SequenceId is only available post WAL-assign. Calls before this will get you a
+   * {@link #NO_SEQUENCE_ID}. See the comment on FSHLog#append and #getWriteNumber in this
method
+   * for more on when this sequenceId comes available.
    * @return long the new assigned sequence number
-   * @throws IOException
    */
   @Override
-  public long getSequenceId() throws IOException {
-    return getSequenceId(-1);
-  }
-
-  /**
-   * Wait for sequence number to be assigned &amp; return the assigned value.
-   * @param maxWaitForSeqId maximum time to wait in milliseconds for sequenceid
-   * @return long the new assigned sequence number
-   * @throws IOException
-   */
-  public long getSequenceId(final long maxWaitForSeqId) throws IOException {
-    // TODO: This implementation waiting on a latch is problematic because if a higher level
-    // determines we should stop or abort, there is no global list of all these blocked WALKeys
-    // waiting on a sequence id; they can't be cancelled... interrupted. See getNextSequenceId.
-    //
-    // UPDATE: I think we can remove the timeout now we are stamping all walkeys with sequenceid,
-    // even those that have failed (previously we were not... so they would just hang out...).
-    // St.Ack 20150910
-    try {
-      if (maxWaitForSeqId < 0) {
-        this.seqNumAssignedLatch.await();
-      } else if (!this.seqNumAssignedLatch.await(maxWaitForSeqId, TimeUnit.MILLISECONDS))
{
-        throw new TimeoutIOException("Failed to get sequenceid after " + maxWaitForSeqId
+
-          "ms; WAL system stuck or has gone away?");
-      }
-    } catch (InterruptedException ie) {
-      LOG.warn("Thread interrupted waiting for next log sequence number");
-      InterruptedIOException iie = new InterruptedIOException();
-      iie.initCause(ie);
-      throw iie;
-    }
-    return this.logSeqNum;
+  public long getSequenceId() {
+    return this.sequenceId;
   }
 
   /**
@@ -495,7 +482,7 @@ public class WALKey implements SequenceId, Comparable<WALKey> {
   @Override
   public String toString() {
     return tablename + "/" + Bytes.toString(encodedRegionName) + "/" +
-      logSeqNum;
+      sequenceId;
   }
 
   /**
@@ -509,7 +496,7 @@ public class WALKey implements SequenceId, Comparable<WALKey> {
     Map<String, Object> stringMap = new HashMap<String, Object>();
     stringMap.put("table", tablename);
     stringMap.put("region", Bytes.toStringBinary(encodedRegionName));
-    stringMap.put("sequence", logSeqNum);
+    stringMap.put("sequence", getSequenceId());
     return stringMap;
   }
 
@@ -527,7 +514,7 @@ public class WALKey implements SequenceId, Comparable<WALKey> {
   @Override
   public int hashCode() {
     int result = Bytes.hashCode(this.encodedRegionName);
-    result ^= this.logSeqNum;
+    result ^= getSequenceId();
     result ^= this.writeTime;
     return result;
   }
@@ -536,9 +523,11 @@ public class WALKey implements SequenceId, Comparable<WALKey> {
   public int compareTo(WALKey o) {
     int result = Bytes.compareTo(this.encodedRegionName, o.encodedRegionName);
     if (result == 0) {
-      if (this.logSeqNum < o.logSeqNum) {
+      long sid = getSequenceId();
+      long otherSid = o.getSequenceId();
+      if (sid < otherSid) {
         result = -1;
-      } else if (this.logSeqNum  > o.logSeqNum) {
+      } else if (sid  > otherSid) {
         result = 1;
       }
       if (result == 0) {
@@ -592,7 +581,7 @@ public class WALKey implements SequenceId, Comparable<WALKey> {
       builder.setTableName(compressor.compress(this.tablename.getName(),
           compressionContext.tableDict));
     }
-    builder.setLogSequenceNumber(this.logSeqNum);
+    builder.setLogSequenceNumber(getSequenceId());
     builder.setWriteTime(writeTime);
     if (this.origLogSeqNum > 0) {
       builder.setOrigSequenceNumber(this.origLogSeqNum);
@@ -658,10 +647,10 @@ public class WALKey implements SequenceId, Comparable<WALKey>
{
         this.scopes.put(family, scope.getScopeType().getNumber());
       }
     }
-    this.logSeqNum = walKey.getLogSequenceNumber();
+    setSequenceId(walKey.getLogSequenceNumber());
     this.writeTime = walKey.getWriteTime();
     if(walKey.hasOrigSequenceNumber()) {
       this.origLogSeqNum = walKey.getOrigSequenceNumber();
     }
   }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/hbase/blob/ec92a8a7/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
index 60bc155..7add8a9 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
@@ -4765,12 +4765,12 @@ public class TestHRegion {
     durabilityTest(method, Durability.ASYNC_WAL, Durability.USE_DEFAULT, 5000, true, false,
true);
 
     // expect skip wal cases
-    durabilityTest(method, Durability.SYNC_WAL, Durability.SKIP_WAL, 0, true, false, false);
-    durabilityTest(method, Durability.FSYNC_WAL, Durability.SKIP_WAL, 0, true, false, false);
-    durabilityTest(method, Durability.ASYNC_WAL, Durability.SKIP_WAL, 0, true, false, false);
-    durabilityTest(method, Durability.SKIP_WAL, Durability.SKIP_WAL, 0, true, false, false);
-    durabilityTest(method, Durability.USE_DEFAULT, Durability.SKIP_WAL, 0, true, false, false);
-    durabilityTest(method, Durability.SKIP_WAL, Durability.USE_DEFAULT, 0, true, false, false);
+    durabilityTest(method, Durability.SYNC_WAL, Durability.SKIP_WAL, 0, false, false, false);
+    durabilityTest(method, Durability.FSYNC_WAL, Durability.SKIP_WAL, 0, false, false, false);
+    durabilityTest(method, Durability.ASYNC_WAL, Durability.SKIP_WAL, 0, false, false, false);
+    durabilityTest(method, Durability.SKIP_WAL, Durability.SKIP_WAL, 0, false, false, false);
+    durabilityTest(method, Durability.USE_DEFAULT, Durability.SKIP_WAL, 0, false, false,
false);
+    durabilityTest(method, Durability.SKIP_WAL, Durability.USE_DEFAULT, 0, false, false,
false);
 
   }
 


Mime
View raw message