hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r1346509 - in /hbase/branches/0.94/src: main/java/org/apache/hadoop/hbase/client/ test/java/org/apache/hadoop/hbase/client/
Date Tue, 05 Jun 2012 18:12:15 GMT
Author: stack
Date: Tue Jun  5 18:12:14 2012
New Revision: 1346509

URL: http://svn.apache.org/viewvc?rev=1346509&view=rev
Log:
HBASE-5609 Add the ability to pass additional information for slow query logging

Modified:
    hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Get.java
    hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Mutation.java
    hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/OperationWithAttributes.java
    hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Scan.java
    hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestAttributes.java

Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Get.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Get.java?rev=1346509&r1=1346508&r2=1346509&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Get.java (original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Get.java Tue Jun  5 18:12:14
2012
@@ -371,6 +371,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/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Mutation.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Mutation.java?rev=1346509&r1=1346508&r2=1346509&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Mutation.java (original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Mutation.java Tue Jun
 5 18:12:14 2012
@@ -102,6 +102,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/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/OperationWithAttributes.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/OperationWithAttributes.java?rev=1346509&r1=1346508&r2=1346509&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/OperationWithAttributes.java
(original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/OperationWithAttributes.java
Tue Jun  5 18:12:14 2012
@@ -35,6 +35,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;
@@ -104,4 +107,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/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Scan.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Scan.java?rev=1346509&r1=1346508&r2=1346509&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Scan.java (original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/Scan.java Tue Jun  5
18:12:14 2012
@@ -556,6 +556,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/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestAttributes.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestAttributes.java?rev=1346509&r1=1346508&r2=1346509&view=diff
==============================================================================
--- hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestAttributes.java (original)
+++ hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestAttributes.java Tue
Jun  5 18:12:14 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();



Mime
View raw message