You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by nk...@apache.org on 2013/11/20 21:30:06 UTC

svn commit: r1543936 - /hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/tool/WriteSinkCoprocessor.java

Author: nkeywal
Date: Wed Nov 20 20:30:05 2013
New Revision: 1543936

URL: http://svn.apache.org/r1543936
Log:
HBASE-10001 Add a coprocessor to help testing the performances without taking into account the disk i/o

Added:
    hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/tool/WriteSinkCoprocessor.java

Added: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/tool/WriteSinkCoprocessor.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/tool/WriteSinkCoprocessor.java?rev=1543936&view=auto
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/tool/WriteSinkCoprocessor.java (added)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/tool/WriteSinkCoprocessor.java Wed Nov 20 20:30:05 2013
@@ -0,0 +1,77 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.hbase.tool;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.client.Mutation;
+import org.apache.hadoop.hbase.coprocessor.BaseRegionObserver;
+import org.apache.hadoop.hbase.coprocessor.ObserverContext;
+import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment;
+import org.apache.hadoop.hbase.regionserver.MiniBatchOperationInProgress;
+import org.apache.hadoop.hbase.regionserver.OperationStatus;
+import org.apache.hadoop.hbase.util.Pair;
+
+import java.io.IOException;
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * This coprocessor 'shallows' all the writes. It allows to test a pure
+ * write workload, going through all the communication layers.
+ * The reads will work as well, but they as we never write, they will always always
+ * return an empty structure. The WAL is also skipped.
+ * Obviously, the region will never be split automatically. It's up to the user
+ * to split and move it.
+ * <p/>
+ * For a table created like this:
+ * create 'usertable', {NAME => 'f1', VERSIONS => 1}
+ * <p/>
+ * You can then add the coprocessor with this command:
+ * alter 'usertable', METHOD => 'table_att', 'coprocessor'=>'|org.apache.hadoop.hbase.tool.WriteSinkCoprocessor|'
+ * <p/>
+ * And then
+ * put 'usertable', 'f1', 'f1', 'f1'
+ * <p/>
+ * scan 'usertable'
+ * Will return:
+ * 0 row(s) in 0.0050 seconds
+ * <p/>
+ */
+public class WriteSinkCoprocessor extends BaseRegionObserver {
+  private static final Log LOG = LogFactory.getLog(WriteSinkCoprocessor.class);
+  private final AtomicLong ops = new AtomicLong();
+  private String regionName;
+
+  @Override
+  public void preOpen(ObserverContext<RegionCoprocessorEnvironment> e) throws IOException {
+    regionName = e.getEnvironment().getRegion().getRegionNameAsString();
+  }
+
+
+  @Override
+  public void preBatchMutate(final ObserverContext<RegionCoprocessorEnvironment> c,
+                    final MiniBatchOperationInProgress<Pair<Mutation, Integer>> miniBatchOp)
+      throws IOException {
+    if (ops.incrementAndGet() % 20000 == 0) {
+      LOG.info("Wrote " + ops.get() + " times in region " + regionName);
+    }
+
+    for (int i = 0; i < miniBatchOp.size(); i++) {
+      miniBatchOp.setOperationStatus(i,
+          new OperationStatus(HConstants.OperationStatusCode.SUCCESS));
+    }
+    c.bypass();
+  }
+}