Repository: hbase Updated Branches: refs/heads/branch-2 db4939168 -> c77778dd1
HBASE-19426 Move has() and setTimestamp() to Mutation (Chia-Ping Tsai) Signed-off-by: Chia-Ping Tsai <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/c77778dd Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/c77778dd Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/c77778dd Branch: refs/heads/branch-2 Commit: c77778dd13694005bb2e328dad93c9ca2e64a2ad Parents: db49391 Author: Michael Stack <[email protected]> Authored: Tue Dec 5 09:40:28 2017 -0800 Committer: Michael Stack <[email protected]> Committed: Tue Dec 5 09:42:13 2017 -0800 ---------------------------------------------------------------------- .../org/apache/hadoop/hbase/client/Append.java | 10 +- .../org/apache/hadoop/hbase/client/Delete.java | 23 +-- .../apache/hadoop/hbase/client/Increment.java | 11 +- .../apache/hadoop/hbase/client/Mutation.java | 156 ++++++++++++++++++- .../org/apache/hadoop/hbase/client/Put.java | 144 +---------------- .../org/apache/hadoop/hbase/fs/HFileSystem.java | 2 +- 6 files changed, 177 insertions(+), 169 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/c77778dd/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Append.java ---------------------------------------------------------------------- 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 cb78d43..89ea082 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. @@ -143,6 +141,12 @@ public class Append extends Mutation { } @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); } http://git-wip-us.apache.org/repos/asf/hbase/blob/c77778dd/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Delete.java ---------------------------------------------------------------------- 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 27116a5..2d296fb 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,29 +293,13 @@ public class Delete extends Mutation implements Comparable<Row> { return this; } - /** - * Set the timestamp of the delete. - * - * @param timestamp - */ + @Override public Delete setTimestamp(long timestamp) { - if (timestamp < 0) { - throw new IllegalArgumentException("Timestamp cannot be negative. ts=" + timestamp); - } - this.ts = timestamp; + super.setTimestamp(timestamp); return this; } @Override - public Map<String, Object> toMap(int maxCols) { - // we start with the fingerprint map and build on top of it. - Map<String, Object> map = super.toMap(maxCols); - // why is put not doing this? - map.put("ts", this.ts); - return map; - } - - @Override public Delete setAttribute(String name, byte[] value) { return (Delete) super.setAttribute(name, value); } http://git-wip-us.apache.org/repos/asf/hbase/blob/c77778dd/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Increment.java ---------------------------------------------------------------------- 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 d9cfea7..2f8dd26 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<Row> { 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 http://git-wip-us.apache.org/repos/asf/hbase/blob/c77778dd/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Mutation.java ---------------------------------------------------------------------- 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 4ba499f..ba8f6cc 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<Cell> get(byte[] family, byte[] qualifier) { + List<Cell> 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<Cell> 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 http://git-wip-us.apache.org/repos/asf/hbase/blob/c77778dd/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Put.java ---------------------------------------------------------------------- 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 94c6a98..47349b3 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<Row> { 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<Cell> 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<Cell> get(byte[] family, byte[] qualifier) { - List<Cell> 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 http://git-wip-us.apache.org/repos/asf/hbase/blob/c77778dd/hbase-server/src/main/java/org/apache/hadoop/hbase/fs/HFileSystem.java ---------------------------------------------------------------------- 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 f7eb02b..c48d9d6 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. */
