diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/SequenceIdAccounting.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/SequenceIdAccounting.java
index e14ce0c..f289f6d 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/SequenceIdAccounting.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/wal/SequenceIdAccounting.java
@@ -27,6 +27,8 @@ import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
+
+import org.apache.commons.collections4.MapUtils;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.ImmutableByteArray;
@@ -109,9 +111,9 @@ class SequenceIdAccounting {
/**
* Returns the lowest unflushed sequence id for the region.
- * @param encodedRegionName
+ * @param encodedRegionName the region name
* @return Lowest outstanding unflushed sequenceid for encodedRegionName. Will
- * return {@link HConstants#NO_SEQNUM} when none.
+ * return {@link HConstants#NO_SEQNUM} when none.
*/
long getLowestSequenceId(final byte[] encodedRegionName) {
synchronized (this.tieLock) {
@@ -124,8 +126,8 @@ class SequenceIdAccounting {
}
/**
- * @param encodedRegionName
- * @param familyName
+ * @param encodedRegionName the region name
+ * @param familyName the family name
* @return Lowest outstanding unflushed sequenceid for encodedRegionname and
* familyName. Returned sequenceid may be for an edit currently being
* flushed.
@@ -154,7 +156,7 @@ class SequenceIdAccounting {
/**
* Reset the accounting of highest sequenceid by regionname.
* @return Return the previous accounting Map of regions to the last sequence id written into
- * each.
+ * each.
*/
Map resetHighest() {
Map old = this.highestSequenceIds;
@@ -166,9 +168,9 @@ class SequenceIdAccounting {
* We've been passed a new sequenceid for the region. Set it as highest seen for this region and
* if we are to record oldest, or lowest sequenceids, save it as oldest seen if nothing
* currently older.
- * @param encodedRegionName
- * @param families
- * @param sequenceid
+ * @param encodedRegionName region name
+ * @param families the set of families
+ * @param sequenceid the sequence ID
* @param lowest Whether to keep running account of oldest sequence id.
*/
void update(byte[] encodedRegionName, Set families, long sequenceid,
@@ -240,12 +242,11 @@ class SequenceIdAccounting {
}
/**
- * @param src
* @return New Map that has same keys as src but instead of a Map for a value, it
* instead has found the smallest sequence id and it returns that as the value instead.
*/
private > Map flattenToLowestSequenceId(Map src) {
- if (src == null || src.isEmpty()) {
+ if (MapUtils.isEmpty(src)) {
return null;
}
Map tgt = new HashMap<>();
@@ -262,15 +263,15 @@ class SequenceIdAccounting {
* @param encodedRegionName Region to flush.
* @param families Families to flush. May be a subset of all families in the region.
* @return Returns {@link HConstants#NO_SEQNUM} if we are flushing the whole region OR if
- * we are flushing a subset of all families but there are no edits in those families not
- * being flushed; in other words, this is effectively same as a flush of all of the region
- * though we were passed a subset of regions. Otherwise, it returns the sequence id of the
- * oldest/lowest outstanding edit.
+ * we are flushing a subset of all families but there are no edits in those families not
+ * being flushed; in other words, this is effectively same as a flush of all of the region
+ * though we were passed a subset of regions. Otherwise, it returns the sequence id of the
+ * oldest/lowest outstanding edit.
*/
Long startCacheFlush(final byte[] encodedRegionName, final Set families) {
Map familytoSeq = new HashMap<>();
- for (byte[] familyName : families){
- familytoSeq.put(familyName,HConstants.NO_SEQNUM);
+ for (byte[] familyName : families) {
+ familytoSeq.put(familyName, HConstants.NO_SEQNUM);
}
return startCacheFlush(encodedRegionName,familytoSeq);
}
@@ -288,7 +289,7 @@ class SequenceIdAccounting {
for (Map.Entry entry : familyToSeq.entrySet()) {
ImmutableByteArray familyNameWrapper = ImmutableByteArray.wrap((byte[]) entry.getKey());
Long seqId = null;
- if(entry.getValue() == HConstants.NO_SEQNUM) {
+ if (entry.getValue() == HConstants.NO_SEQNUM) {
seqId = m.remove(familyNameWrapper);
} else {
seqId = m.replace(familyNameWrapper, entry.getValue());
@@ -300,7 +301,7 @@ class SequenceIdAccounting {
oldSequenceIds.put(familyNameWrapper, seqId);
}
}
- if (oldSequenceIds != null && !oldSequenceIds.isEmpty()) {
+ if (MapUtils.isNotEmpty(oldSequenceIds)) {
if (this.flushingSequenceIds.put(encodedRegionName, oldSequenceIds) != null) {
LOG.warn("Flushing Map not cleaned up for " + Bytes.toString(encodedRegionName) +
", sequenceid=" + oldSequenceIds);
@@ -325,7 +326,7 @@ class SequenceIdAccounting {
// were no appends after last flush, so why are we starting flush? Maybe we should
// assert not empty. Less rigorous, but safer, alternative is telling the caller to stop.
// For now preserve old logic.
- LOG.warn("Couldn't find oldest sequenceid for " + Bytes.toString(encodedRegionName));
+ LOG.warn("Could not find oldest sequenceid for " + Bytes.toString(encodedRegionName));
}
return lowestUnflushedInRegion;
}
@@ -389,15 +390,11 @@ class SequenceIdAccounting {
unflushed = flattenToLowestSequenceId(this.lowestUnflushedSequenceIds);
}
for (Map.Entry e : sequenceids.entrySet()) {
- long oldestFlushing = Long.MAX_VALUE;
- long oldestUnflushed = Long.MAX_VALUE;
- if (flushing != null && flushing.containsKey(e.getKey())) {
- oldestFlushing = flushing.get(e.getKey());
- }
- if (unflushed != null && unflushed.containsKey(e.getKey())) {
- oldestUnflushed = unflushed.get(e.getKey());
- }
- long min = Math.min(oldestFlushing, oldestUnflushed);
+ byte[] key = e.getKey();
+ Long oldestFlushing = MapUtils.getObject(flushing, key, Long.MAX_VALUE);
+ Long oldestUnflushed = MapUtils.getObject(unflushed, key, Long.MAX_VALUE);
+
+ long min = Math.min(oldestFlushing.longValue(), oldestUnflushed.longValue());
if (min <= e.getValue()) {
return false;
}