Return-Path: X-Original-To: apmail-hbase-commits-archive@www.apache.org Delivered-To: apmail-hbase-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7FB65105E0 for ; Wed, 5 Jun 2013 22:15:05 +0000 (UTC) Received: (qmail 10144 invoked by uid 500); 5 Jun 2013 22:15:05 -0000 Delivered-To: apmail-hbase-commits-archive@hbase.apache.org Received: (qmail 10064 invoked by uid 500); 5 Jun 2013 22:15:05 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 10057 invoked by uid 99); 5 Jun 2013 22:15:05 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Jun 2013 22:15:05 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 05 Jun 2013 22:15:03 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 75FAF2388847; Wed, 5 Jun 2013 22:14:44 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1490047 - in /hbase/branches/0.95/hbase-server/src: main/java/org/apache/hadoop/hbase/regionserver/RegionCoprocessorHost.java test/java/org/apache/hadoop/hbase/TestOpenTableInCoprocessor.java Date: Wed, 05 Jun 2013 22:14:44 -0000 To: commits@hbase.apache.org From: jyates@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130605221444.75FAF2388847@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jyates Date: Wed Jun 5 22:14:44 2013 New Revision: 1490047 URL: http://svn.apache.org/r1490047 Log: HBASE-8684: Table Coprocessor can't access external HTable by default Added: hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/TestOpenTableInCoprocessor.java Modified: hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionCoprocessorHost.java Modified: hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionCoprocessorHost.java URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionCoprocessorHost.java?rev=1490047&r1=1490046&r2=1490047&view=diff ============================================================================== --- hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionCoprocessorHost.java (original) +++ hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/RegionCoprocessorHost.java Wed Jun 5 22:14:44 2013 @@ -36,6 +36,7 @@ import org.apache.hadoop.conf.Configurat import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.Coprocessor; import org.apache.hadoop.hbase.CoprocessorEnvironment; +import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HTableDescriptor; @@ -182,7 +183,9 @@ public class RegionCoprocessorHost } if (cfgSpec != null) { cfgSpec = cfgSpec.substring(cfgSpec.indexOf('|') + 1); - Configuration newConf = new Configuration(conf); + // do an explicit deep copy of the passed configuration + Configuration newConf = new Configuration(false); + HBaseConfiguration.merge(newConf, conf); Matcher m = HConstants.CP_HTD_ATTR_VALUE_PARAM_PATTERN.matcher(cfgSpec); while (m.find()) { newConf.set(m.group(1), m.group(2)); Added: hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/TestOpenTableInCoprocessor.java URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/TestOpenTableInCoprocessor.java?rev=1490047&view=auto ============================================================================== --- hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/TestOpenTableInCoprocessor.java (added) +++ hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/TestOpenTableInCoprocessor.java Wed Jun 5 22:14:44 2013 @@ -0,0 +1,131 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; + +import org.apache.hadoop.hbase.client.Durability; +import org.apache.hadoop.hbase.client.HBaseAdmin; +import org.apache.hadoop.hbase.client.HTable; +import org.apache.hadoop.hbase.client.HTableInterface; +import org.apache.hadoop.hbase.client.Put; +import org.apache.hadoop.hbase.client.Result; +import org.apache.hadoop.hbase.client.ResultScanner; +import org.apache.hadoop.hbase.client.Scan; +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.wal.WALEdit; +import org.apache.hadoop.hbase.util.Bytes; +import org.junit.AfterClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +/** + * Test that a coprocessor can open a connection and write to another table, inside a hook. + */ +@Category(MediumTests.class) +public class TestOpenTableInCoprocessor { + + private static final byte[] otherTable = Bytes.toBytes("otherTable"); + private static final byte[] family = new byte[] { 'f' }; + + private static boolean completed = false; + + /** + * Custom coprocessor that just copies the write to another table. + */ + public static class SendToOtherTableCoprocessor extends BaseRegionObserver { + + @Override + public void prePut(ObserverContext e, Put put, WALEdit edit, + final Durability durability) throws IOException { + HTableInterface table = e.getEnvironment().getTable(otherTable); + Put p = new Put(new byte[] { 'a' }); + p.add(family, null, new byte[] { 'a' }); + table.put(put); + table.flushCommits(); + completed = true; + table.close(); + } + + } + + private static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); + + @AfterClass + public static void cleanup() throws Exception { + UTIL.getHBaseAdmin().close(); + } + + @Test + public void testCoprocessorCanCreateConnectionToRemoteTable() throws Throwable { + HTableDescriptor primary = new HTableDescriptor("primary"); + primary.addFamily(new HColumnDescriptor(family)); + // add our coprocessor + primary.addCoprocessor(SendToOtherTableCoprocessor.class.getName()); + + HTableDescriptor other = new HTableDescriptor(otherTable); + other.addFamily(new HColumnDescriptor(family)); + UTIL.startMiniCluster(); + + HBaseAdmin admin = UTIL.getHBaseAdmin(); + admin.createTable(primary); + admin.createTable(other); + admin.close(); + + HTable table = new HTable(UTIL.getConfiguration(), "primary"); + Put p = new Put(new byte[] { 'a' }); + p.add(family, null, new byte[] { 'a' }); + table.put(p); + table.flushCommits(); + table.close(); + + HTable target = new HTable(UTIL.getConfiguration(), otherTable); + assertTrue("Didn't complete update to target table!", completed); + assertEquals("Didn't find inserted row", 1, getKeyValueCount(target)); + target.close(); + + UTIL.shutdownMiniCluster(); + } + + /** + * Count the number of keyvalue in the table. Scans all possible versions + * @param table table to scan + * @return number of keyvalues over all rows in the table + * @throws IOException + */ + private int getKeyValueCount(HTable table) throws IOException { + Scan scan = new Scan(); + scan.setMaxVersions(Integer.MAX_VALUE - 1); + + ResultScanner results = table.getScanner(scan); + int count = 0; + for (Result res : results) { + count += res.list().size(); + System.out.println(count + ") " + res); + } + results.close(); + + return count; + } +} \ No newline at end of file