You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2012/06/05 18:38:51 UTC
svn commit: r1346459 - in /hbase/trunk/hbase-server/src:
main/java/org/apache/hadoop/hbase/client/
test/java/org/apache/hadoop/hbase/client/
Author: stack
Date: Tue Jun 5 16:38:51 2012
New Revision: 1346459
URL: http://svn.apache.org/viewvc?rev=1346459&view=rev
Log:
HBASE-5609 Add the ability to pass additional information for slow query logging
Modified:
hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Get.java
hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Mutation.java
hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/OperationWithAttributes.java
hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Scan.java
hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAttributes.java
Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Get.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Get.java?rev=1346459&r1=1346458&r2=1346459&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Get.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Get.java Tue Jun 5 16:38:51 2012
@@ -375,6 +375,10 @@ public class Get extends OperationWithAt
if (this.filter != null) {
map.put("filter", this.filter.toString());
}
+ // add the id if set
+ if (getId() != null) {
+ map.put("id", getId());
+ }
return map;
}
Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Mutation.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Mutation.java?rev=1346459&r1=1346458&r2=1346459&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Mutation.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Mutation.java Tue Jun 5 16:38:51 2012
@@ -106,6 +106,10 @@ public abstract class Mutation extends O
}
}
map.put("totalColumns", colCount);
+ // add the id if set
+ if (getId() != null) {
+ map.put("id", getId());
+ }
return map;
}
Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/OperationWithAttributes.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/OperationWithAttributes.java?rev=1346459&r1=1346458&r2=1346459&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/OperationWithAttributes.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/OperationWithAttributes.java Tue Jun 5 16:38:51 2012
@@ -39,6 +39,9 @@ public abstract class OperationWithAttri
// a opaque blob of attributes
private Map<String, byte[]> attributes;
+ // used for uniquely identifying an operation
+ static public String ID_ATRIBUTE = "_operation.attributes.id";
+
public void setAttribute(String name, byte[] value) {
if (attributes == null && value == null) {
return;
@@ -108,4 +111,27 @@ public abstract class OperationWithAttri
}
}
}
+
+ /**
+ * This method allows you to set an identifier on an operation. The original
+ * motivation for this was to allow the identifier to be used in slow query
+ * logging, but this could obviously be useful in other places. One use of
+ * this could be to put a class.method identifier in here to see where the
+ * slow query is coming from.
+ * @param id
+ * id to set for the scan
+ */
+ public void setId(String id) {
+ setAttribute(ID_ATRIBUTE, Bytes.toBytes(id));
+ }
+
+ /**
+ * This method allows you to retrieve the identifier for the operation if one
+ * was set.
+ * @return the id or null if not set
+ */
+ public String getId() {
+ byte[] attr = getAttribute(ID_ATRIBUTE);
+ return attr == null? null: Bytes.toString(attr);
+ }
}
Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Scan.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Scan.java?rev=1346459&r1=1346458&r2=1346459&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Scan.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/client/Scan.java Tue Jun 5 16:38:51 2012
@@ -560,6 +560,10 @@ public class Scan extends OperationWithA
if (this.filter != null) {
map.put("filter", this.filter.toString());
}
+ // add the id if set
+ if (getId() != null) {
+ map.put("id", getId());
+ }
return map;
}
Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAttributes.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAttributes.java?rev=1346459&r1=1346458&r2=1346459&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAttributes.java (original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAttributes.java Tue Jun 5 16:38:51 2012
@@ -154,6 +154,46 @@ public class TestAttributes {
Assert.assertNull(del.getAttributesMap().get("attribute1"));
}
+ @Test
+ public void testGetId() {
+ Get get = new Get();
+ Assert.assertNull("Make sure id is null if unset", get.toMap().get("id"));
+ get.setId("myId");
+ Assert.assertEquals("myId", get.toMap().get("id"));
+ }
+
+ @Test
+ public void testAppendId() {
+ Append append = new Append();
+ Assert.assertNull("Make sure id is null if unset", append.toMap().get("id"));
+ append.setId("myId");
+ Assert.assertEquals("myId", append.toMap().get("id"));
+ }
+
+ @Test
+ public void testDeleteId() {
+ Delete delete = new Delete();
+ Assert.assertNull("Make sure id is null if unset", delete.toMap().get("id"));
+ delete.setId("myId");
+ Assert.assertEquals("myId", delete.toMap().get("id"));
+ }
+
+ @Test
+ public void testPutId() {
+ Put put = new Put();
+ Assert.assertNull("Make sure id is null if unset", put.toMap().get("id"));
+ put.setId("myId");
+ Assert.assertEquals("myId", put.toMap().get("id"));
+ }
+
+ @Test
+ public void testScanId() {
+ Scan scan = new Scan();
+ Assert.assertNull("Make sure id is null if unset", scan.toMap().get("id"));
+ scan.setId("myId");
+ Assert.assertEquals("myId", scan.toMap().get("id"));
+ }
+
@org.junit.Rule
public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();