From 4cb76aa929c4bd9f9f1f9783ab940a902bfdb166 Mon Sep 17 00:00:00 2001 From: Enis Soztutar Date: Thu, 11 Sep 2014 12:58:04 -0700 Subject: [PATCH] HBASE-11936 IsolationLevel must be attribute of a Query not a Scan (Vladimir Rodionov) --- .../org/apache/hadoop/hbase/client/Get.java | 6 ++++ .../org/apache/hadoop/hbase/client/Query.java | 28 +++++++++++++++ .../org/apache/hadoop/hbase/client/Scan.java | 34 ++++--------------- 3 files changed, 41 insertions(+), 27 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java index 2a872f48b86..8551e16f5cf 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Get.java @@ -482,4 +482,10 @@ public class Get extends Query public Get setReplicaId(int Id) { return (Get) super.setReplicaId(Id); } + + @Override + public Get setIsolationLevel(IsolationLevel level) { + return (Get) super.setIsolationLevel(level); + } + } diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Query.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Query.java index 6706cefef67..357d7b95e91 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Query.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Query.java @@ -34,6 +34,7 @@ import com.google.common.collect.ListMultimap; @InterfaceAudience.Public @InterfaceStability.Evolving public abstract class Query extends OperationWithAttributes { + private static final String ISOLATION_LEVEL = "_isolationlevel_"; protected Filter filter = null; protected int targetReplicaId = -1; protected Consistency consistency = Consistency.STRONG; @@ -143,4 +144,31 @@ public abstract class Query extends OperationWithAttributes { public int getReplicaId() { return this.targetReplicaId; } + + /* + * Set the isolation level for this query. If the + * isolation level is set to READ_UNCOMMITTED, then + * this query will return data from committed and + * uncommitted transactions. If the isolation level + * is set to READ_COMMITTED, then this query will return + * data from committed transactions only. If a isolation + * level is not explicitly set on a Query, then it + * is assumed to be READ_COMMITTED. + * @param level IsolationLevel for this query + */ + public Query setIsolationLevel(IsolationLevel level) { + setAttribute(ISOLATION_LEVEL, level.toBytes()); + return this; + } + /* + * @return The isolation level of this query. + * If no isolation level was set for this query object, + * then it returns READ_COMMITTED. + * @return The IsolationLevel for this query + */ + public IsolationLevel getIsolationLevel() { + byte[] attr = getAttribute(ISOLATION_LEVEL); + return attr == null ? IsolationLevel.READ_COMMITTED : + IsolationLevel.fromBytes(attr); + } } diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Scan.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Scan.java index 734d36f1786..5189139a4c5 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Scan.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/Scan.java @@ -89,7 +89,6 @@ public class Scan extends Query { private static final Log LOG = LogFactory.getLog(Scan.class); private static final String RAW_ATTR = "_raw_"; - private static final String ISOLATION_LEVEL = "_isolationlevel_"; /** * EXPERT ONLY. @@ -751,32 +750,7 @@ public class Scan extends Query { return attr == null ? false : Bytes.toBoolean(attr); } - /* - * Set the isolation level for this scan. If the - * isolation level is set to READ_UNCOMMITTED, then - * this scan will return data from committed and - * uncommitted transactions. If the isolation level - * is set to READ_COMMITTED, then this scan will return - * data from committed transactions only. If a isolation - * level is not explicitly set on a Scan, then it - * is assumed to be READ_COMMITTED. - * @param level IsolationLevel for this scan - */ - public Scan setIsolationLevel(IsolationLevel level) { - setAttribute(ISOLATION_LEVEL, level.toBytes()); - return this; - } - /* - * @return The isolation level of this scan. - * If no isolation level was set for this scan object, - * then it returns READ_COMMITTED. - * @return The IsolationLevel for this scan - */ - public IsolationLevel getIsolationLevel() { - byte[] attr = getAttribute(ISOLATION_LEVEL); - return attr == null ? IsolationLevel.READ_COMMITTED : - IsolationLevel.fromBytes(attr); - } + /** * Set whether this scan is a small scan @@ -845,4 +819,10 @@ public class Scan extends Query { public Scan setReplicaId(int Id) { return (Scan) super.setReplicaId(Id); } + + @Override + public Scan setIsolationLevel(IsolationLevel level) { + return (Scan) super.setIsolationLevel(level); + } + }