diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Append.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Append.java index cb78d43d04c..89ea082135b 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Append.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Append.java @@ -17,19 +17,17 @@ */ package org.apache.hadoop.hbase.client; -import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.NavigableMap; import java.util.UUID; - import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.KeyValue; -import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.hbase.security.access.Permission; import org.apache.hadoop.hbase.security.visibility.CellVisibility; import org.apache.hadoop.hbase.util.Bytes; +import org.apache.yetus.audience.InterfaceAudience; /** * Performs Append operations on a single row. @@ -142,6 +140,12 @@ public class Append extends Mutation { return this; } + @Override + public Append setTimestamp(long timestamp) { + super.setTimestamp(timestamp); + return this; + } + @Override public Append setAttribute(String name, byte[] value) { return (Append) super.setAttribute(name, value); diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Delete.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Delete.java index 27116a5187f..2d296fb3939 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Delete.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Delete.java @@ -24,15 +24,14 @@ import java.util.List; import java.util.Map; import java.util.NavigableMap; import java.util.UUID; - import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.KeyValue; -import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.hbase.security.access.Permission; import org.apache.hadoop.hbase.security.visibility.CellVisibility; import org.apache.hadoop.hbase.util.Bytes; +import org.apache.yetus.audience.InterfaceAudience; /** * Used to perform Delete operations on a single row. @@ -294,26 +293,10 @@ public class Delete extends Mutation implements Comparable { return this; } - /** - * Set the timestamp of the delete. - * - * @param timestamp - */ - public Delete setTimestamp(long timestamp) { - if (timestamp < 0) { - throw new IllegalArgumentException("Timestamp cannot be negative. ts=" + timestamp); - } - this.ts = timestamp; - return this; - } - @Override - public Map toMap(int maxCols) { - // we start with the fingerprint map and build on top of it. - Map map = super.toMap(maxCols); - // why is put not doing this? - map.put("ts", this.ts); - return map; + public Delete setTimestamp(long timestamp) { + super.setTimestamp(timestamp); + return this; } @Override diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Increment.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Increment.java index d9cfea7ac7b..2f8dd26f640 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Increment.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Increment.java @@ -24,16 +24,15 @@ import java.util.Map; import java.util.NavigableMap; import java.util.TreeMap; import java.util.UUID; - import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.KeyValue; -import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.hbase.io.TimeRange; import org.apache.hadoop.hbase.security.access.Permission; import org.apache.hadoop.hbase.security.visibility.CellVisibility; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.ClassSize; +import org.apache.yetus.audience.InterfaceAudience; /** * Used to perform Increment operations on a single row. @@ -151,7 +150,13 @@ public class Increment extends Mutation implements Comparable { tr = new TimeRange(minStamp, maxStamp); return this; } - + + @Override + public Increment setTimestamp(long timestamp) { + super.setTimestamp(timestamp); + return this; + } + /** * @param returnResults True (default) if the increment operation should return the results. A * client that is not interested in the result can save network bandwidth setting this diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Mutation.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Mutation.java index 4ba499f1978..ba8f6cc2a08 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Mutation.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Mutation.java @@ -28,7 +28,6 @@ import java.util.Map; import java.util.NavigableMap; import java.util.TreeMap; import java.util.UUID; - import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellScannable; import org.apache.hadoop.hbase.CellScanner; @@ -46,14 +45,15 @@ import org.apache.hadoop.hbase.security.access.AccessControlUtil; import org.apache.hadoop.hbase.security.access.Permission; import org.apache.hadoop.hbase.security.visibility.CellVisibility; import org.apache.hadoop.hbase.security.visibility.VisibilityConstants; +import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.hbase.util.ClassSize; +import org.apache.yetus.audience.InterfaceAudience; + import org.apache.hadoop.hbase.shaded.com.google.common.collect.ArrayListMultimap; import org.apache.hadoop.hbase.shaded.com.google.common.collect.ListMultimap; import org.apache.hadoop.hbase.shaded.com.google.common.io.ByteArrayDataInput; import org.apache.hadoop.hbase.shaded.com.google.common.io.ByteArrayDataOutput; import org.apache.hadoop.hbase.shaded.com.google.common.io.ByteStreams; -import org.apache.hadoop.hbase.util.Bytes; -import org.apache.hadoop.hbase.util.ClassSize; -import org.apache.yetus.audience.InterfaceAudience; @InterfaceAudience.Public public abstract class Mutation extends OperationWithAttributes implements Row, CellScannable, @@ -215,6 +215,7 @@ public abstract class Mutation extends OperationWithAttributes implements Row, C if (getTTL() != Long.MAX_VALUE) { map.put("ttl", getTTL()); } + map.put("ts", this.ts); return map; } @@ -523,6 +524,153 @@ public abstract class Mutation extends OperationWithAttributes implements Row, C return 0L; } + /** + * Set the timestamp of the delete. + */ + public Mutation setTimestamp(long timestamp) { + if (timestamp < 0) { + throw new IllegalArgumentException("Timestamp cannot be negative. ts=" + timestamp); + } + this.ts = timestamp; + return this; + } + + /** + * A convenience method to determine if this object's familyMap contains + * a value assigned to the given family & qualifier. + * Both given arguments must match the KeyValue object to return true. + * + * @param family column family + * @param qualifier column qualifier + * @return returns true if the given family and qualifier already has an + * existing KeyValue object in the family map. + */ + public boolean has(byte [] family, byte [] qualifier) { + return has(family, qualifier, this.ts, HConstants.EMPTY_BYTE_ARRAY, true, true); + } + + /** + * A convenience method to determine if this object's familyMap contains + * a value assigned to the given family, qualifier and timestamp. + * All 3 given arguments must match the KeyValue object to return true. + * + * @param family column family + * @param qualifier column qualifier + * @param ts timestamp + * @return returns true if the given family, qualifier and timestamp already has an + * existing KeyValue object in the family map. + */ + public boolean has(byte [] family, byte [] qualifier, long ts) { + return has(family, qualifier, ts, HConstants.EMPTY_BYTE_ARRAY, false, true); + } + + /** + * A convenience method to determine if this object's familyMap contains + * a value assigned to the given family, qualifier and timestamp. + * All 3 given arguments must match the KeyValue object to return true. + * + * @param family column family + * @param qualifier column qualifier + * @param value value to check + * @return returns true if the given family, qualifier and value already has an + * existing KeyValue object in the family map. + */ + public boolean has(byte [] family, byte [] qualifier, byte [] value) { + return has(family, qualifier, this.ts, value, true, false); + } + + /** + * A convenience method to determine if this object's familyMap contains + * the given value assigned to the given family, qualifier and timestamp. + * All 4 given arguments must match the KeyValue object to return true. + * + * @param family column family + * @param qualifier column qualifier + * @param ts timestamp + * @param value value to check + * @return returns true if the given family, qualifier timestamp and value + * already has an existing KeyValue object in the family map. + */ + public boolean has(byte [] family, byte [] qualifier, long ts, byte [] value) { + return has(family, qualifier, ts, value, false, false); + } + + /** + * Returns a list of all KeyValue objects with matching column family and qualifier. + * + * @param family column family + * @param qualifier column qualifier + * @return a list of KeyValue objects with the matching family and qualifier, + * returns an empty list if one doesn't exist for the given family. + */ + public List get(byte[] family, byte[] qualifier) { + List filteredList = new ArrayList<>(); + for (Cell cell: getCellList(family)) { + if (CellUtil.matchingQualifier(cell, qualifier)) { + filteredList.add(cell); + } + } + return filteredList; + } + + /* + * Private method to determine if this object's familyMap contains + * the given value assigned to the given family, qualifier and timestamp + * respecting the 2 boolean arguments + * + * @param family + * @param qualifier + * @param ts + * @param value + * @param ignoreTS + * @param ignoreValue + * @return returns true if the given family, qualifier timestamp and value + * already has an existing KeyValue object in the family map. + */ + protected boolean has(byte[] family, byte[] qualifier, long ts, byte[] value, + boolean ignoreTS, boolean ignoreValue) { + List list = getCellList(family); + if (list.isEmpty()) { + return false; + } + // Boolean analysis of ignoreTS/ignoreValue. + // T T => 2 + // T F => 3 (first is always true) + // F T => 2 + // F F => 1 + if (!ignoreTS && !ignoreValue) { + for (Cell cell : list) { + if (CellUtil.matchingFamily(cell, family) && + CellUtil.matchingQualifier(cell, qualifier) && + CellUtil.matchingValue(cell, value) && + cell.getTimestamp() == ts) { + return true; + } + } + } else if (ignoreValue && !ignoreTS) { + for (Cell cell : list) { + if (CellUtil.matchingFamily(cell, family) && CellUtil.matchingQualifier(cell, qualifier) + && cell.getTimestamp() == ts) { + return true; + } + } + } else if (!ignoreValue && ignoreTS) { + for (Cell cell : list) { + if (CellUtil.matchingFamily(cell, family) && CellUtil.matchingQualifier(cell, qualifier) + && CellUtil.matchingValue(cell, value)) { + return true; + } + } + } else { + for (Cell cell : list) { + if (CellUtil.matchingFamily(cell, family) && + CellUtil.matchingQualifier(cell, qualifier)) { + return true; + } + } + } + return false; + } /** * @param row Row to check diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Put.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Put.java index 94c6a987a8c..47349b3e893 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Put.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Put.java @@ -27,18 +27,17 @@ import java.util.Map; import java.util.NavigableMap; import java.util.TreeMap; import java.util.UUID; - import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.HConstants; -import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.IndividualBytesFieldCell; +import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.Tag; -import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.hbase.io.HeapSize; import org.apache.hadoop.hbase.security.access.Permission; import org.apache.hadoop.hbase.security.visibility.CellVisibility; import org.apache.hadoop.hbase.util.Bytes; +import org.apache.yetus.audience.InterfaceAudience; /** * Used to perform Put operations for a single row. @@ -326,141 +325,10 @@ public class Put extends Mutation implements HeapSize, Comparable { return this; } - /** - * A convenience method to determine if this object's familyMap contains - * a value assigned to the given family & qualifier. - * Both given arguments must match the KeyValue object to return true. - * - * @param family column family - * @param qualifier column qualifier - * @return returns true if the given family and qualifier already has an - * existing KeyValue object in the family map. - */ - public boolean has(byte [] family, byte [] qualifier) { - return has(family, qualifier, this.ts, HConstants.EMPTY_BYTE_ARRAY, true, true); - } - - /** - * A convenience method to determine if this object's familyMap contains - * a value assigned to the given family, qualifier and timestamp. - * All 3 given arguments must match the KeyValue object to return true. - * - * @param family column family - * @param qualifier column qualifier - * @param ts timestamp - * @return returns true if the given family, qualifier and timestamp already has an - * existing KeyValue object in the family map. - */ - public boolean has(byte [] family, byte [] qualifier, long ts) { - return has(family, qualifier, ts, HConstants.EMPTY_BYTE_ARRAY, false, true); - } - - /** - * A convenience method to determine if this object's familyMap contains - * a value assigned to the given family, qualifier and timestamp. - * All 3 given arguments must match the KeyValue object to return true. - * - * @param family column family - * @param qualifier column qualifier - * @param value value to check - * @return returns true if the given family, qualifier and value already has an - * existing KeyValue object in the family map. - */ - public boolean has(byte [] family, byte [] qualifier, byte [] value) { - return has(family, qualifier, this.ts, value, true, false); - } - - /** - * A convenience method to determine if this object's familyMap contains - * the given value assigned to the given family, qualifier and timestamp. - * All 4 given arguments must match the KeyValue object to return true. - * - * @param family column family - * @param qualifier column qualifier - * @param ts timestamp - * @param value value to check - * @return returns true if the given family, qualifier timestamp and value - * already has an existing KeyValue object in the family map. - */ - public boolean has(byte [] family, byte [] qualifier, long ts, byte [] value) { - return has(family, qualifier, ts, value, false, false); - } - - /* - * Private method to determine if this object's familyMap contains - * the given value assigned to the given family, qualifier and timestamp - * respecting the 2 boolean arguments - * - * @param family - * @param qualifier - * @param ts - * @param value - * @param ignoreTS - * @param ignoreValue - * @return returns true if the given family, qualifier timestamp and value - * already has an existing KeyValue object in the family map. - */ - private boolean has(byte[] family, byte[] qualifier, long ts, byte[] value, - boolean ignoreTS, boolean ignoreValue) { - List list = getCellList(family); - if (list.isEmpty()) { - return false; - } - // Boolean analysis of ignoreTS/ignoreValue. - // T T => 2 - // T F => 3 (first is always true) - // F T => 2 - // F F => 1 - if (!ignoreTS && !ignoreValue) { - for (Cell cell : list) { - if (CellUtil.matchingFamily(cell, family) && - CellUtil.matchingQualifier(cell, qualifier) && - CellUtil.matchingValue(cell, value) && - cell.getTimestamp() == ts) { - return true; - } - } - } else if (ignoreValue && !ignoreTS) { - for (Cell cell : list) { - if (CellUtil.matchingFamily(cell, family) && CellUtil.matchingQualifier(cell, qualifier) - && cell.getTimestamp() == ts) { - return true; - } - } - } else if (!ignoreValue && ignoreTS) { - for (Cell cell : list) { - if (CellUtil.matchingFamily(cell, family) && CellUtil.matchingQualifier(cell, qualifier) - && CellUtil.matchingValue(cell, value)) { - return true; - } - } - } else { - for (Cell cell : list) { - if (CellUtil.matchingFamily(cell, family) && - CellUtil.matchingQualifier(cell, qualifier)) { - return true; - } - } - } - return false; - } - - /** - * Returns a list of all KeyValue objects with matching column family and qualifier. - * - * @param family column family - * @param qualifier column qualifier - * @return a list of KeyValue objects with the matching family and qualifier, - * returns an empty list if one doesn't exist for the given family. - */ - public List get(byte[] family, byte[] qualifier) { - List filteredList = new ArrayList<>(); - for (Cell cell: getCellList(family)) { - if (CellUtil.matchingQualifier(cell, qualifier)) { - filteredList.add(cell); - } - } - return filteredList; + @Override + public Put setTimestamp(long timestamp) { + super.setTimestamp(timestamp); + return this; } @Override diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/fs/HFileSystem.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/fs/HFileSystem.java index f7eb02b4d19..c48d9d679f5 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/fs/HFileSystem.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/fs/HFileSystem.java @@ -117,7 +117,7 @@ public class HFileSystem extends FilterFileSystem { /** * Wrap a FileSystem object within a HFileSystem. The noChecksumFs and - * writefs are both set to be the same specified fs. + * writefs are both set to be the same specified fs. * Do not verify hbase-checksums while reading data from filesystem. * @param fs Set the noChecksumFs and writeFs to this specified filesystem. */