Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Indexing HBase带有观察者协处理器的辅助索引。放在索引表上会导致递归_Indexing_Hbase_Observers - Fatal编程技术网

Indexing HBase带有观察者协处理器的辅助索引。放在索引表上会导致递归

Indexing HBase带有观察者协处理器的辅助索引。放在索引表上会导致递归,indexing,hbase,observers,Indexing,Hbase,Observers,在HBase数据库中,我想通过使用附加的“链接”表来创建一个辅助索引。我遵循了这个答案中给出的例子: 我对HBase的整个概念不是很熟悉,我读过一些关于创建二级索引的例子。我仅将协处理器附加到单个表,如下所示: disable 'Entry2' alter 'Entry2', METHOD => 'table_att', 'COPROCESSOR' => '/home/user/hbase/rootdir/hcoprocessors.jar|com.acme.hobservers.E

在HBase数据库中,我想通过使用附加的“链接”表来创建一个辅助索引。我遵循了这个答案中给出的例子:

我对HBase的整个概念不是很熟悉,我读过一些关于创建二级索引的例子。我仅将协处理器附加到单个表,如下所示:

disable 'Entry2'
alter 'Entry2', METHOD => 'table_att', 'COPROCESSOR' => '/home/user/hbase/rootdir/hcoprocessors.jar|com.acme.hobservers.EntryParentIndex||'
enable 'Entry2'
其源代码如下:

public class EntryParentIndex extends BaseRegionObserver{

private static final Log LOG = LogFactory.getLog(CoprocessorHost.class);

private HTablePool pool = null;

private final static String  INDEX_TABLE                       = "EntryParentIndex";
private final static String  SOURCE_TABLE                      = "Entry2";

@Override
  public void start(CoprocessorEnvironment env) throws IOException {
    pool = new HTablePool(env.getConfiguration(), 10);
 }

@Override
  public void prePut(
      final ObserverContext<RegionCoprocessorEnvironment> observerContext,
      final Put put,
      final WALEdit edit,
      final boolean writeToWAL)
    throws IOException {

    try {

         final List<KeyValue> filteredList = put.get(Bytes.toBytes ("data"),Bytes.toBytes("parentId"));
         byte [] id = put.getRow(); //Get the Entry ID

         KeyValue kv=filteredList.get( 0 ); //get Entry PARENT_ID
         byte[] parentId=kv.getValue();


        HTableInterface htbl = pool.getTable(Bytes.toBytes(INDEX_TABLE));

        //create row key for the index table
        byte[] p1=concatTwoByteArrays(parentId, ":".getBytes()); //Insert a semicolon between two UUIDs
        byte[] rowkey=concatTwoByteArrays(p1, id);

        Put indexput  = new Put(rowkey);

        //The following call is setting up a strange? recursion, resulting
        //...in thesame prePut method invoken again and again. Interestingly
        //...the recursion limits itself up to 6 times. The actual row does not
        //...get inserted into the INDEX_TABLE
        htbl.put(indexput);


        htbl.close();

    }
    catch ( IllegalArgumentException ex) {  }

  }


  @Override
  public void stop(CoprocessorEnvironment env) throws IOException {
    pool.close();
  }

  public static final byte[] concatTwoByteArrays(byte[] first, byte[] second) {
        byte[] result = Arrays.copyOf(first, first.length + second.length);
        System.arraycopy(second, 0, result, first.length, second.length);
        return result;
    }

}
公共类EntryParentIndex扩展BaseRegionObserver{
私有静态最终日志日志=LogFactory.getLog(协处理器主机.class);
私有HTablePool池=null;
私有最终静态字符串索引\u TABLE=“EntryParentIndex”;
私有最终静态字符串SOURCE_TABLE=“Entry2”;
@凌驾
public void start(协处理器环境环境)引发IOException{
pool=newhtablepool(env.getConfiguration(),10);
}
@凌驾
公共空白预打印(
最终ObserverContext ObserverContext,
最后的推杆,
最终编辑,
最终布尔值(writeToWAL)
抛出IOException{
试一试{
final List filteredList=put.get(Bytes.toBytes(“数据”)、Bytes.toBytes(“父ID”);
byte[]id=put.getRow();//获取条目id
KeyValue kv=filteredList.get(0);//获取条目父项ID
字节[]parentId=kv.getValue();
HTableInterface htbl=pool.getTable(Bytes.toBytes(INDEX_TABLE));
//为索引表创建行键
byte[]p1=concatTwoByteArrays(parentId:“:”.getBytes());//在两个UUID之间插入分号
字节[]行键=concattwobyterarrays(p1,id);
Put indexput=新Put(行键);
//下面的调用正在设置一个奇怪的递归,结果是
//…在同一个prePut方法中,反复调用en。有趣的是
//…递归将自身限制为6次。实际行不会
//…被插入到索引表中
htbl.put(indexput);
htbl.close();
}
捕获(IllegalArgumentException ex){}
}
@凌驾
公共无效停止(协处理器环境环境)引发IOException{
pool.close();
}
公共静态最终字节[]concattwobyterarrays(字节[]第一,字节[]第二){
byte[]result=Arrays.copyOf(first,first.length+second.length);
System.arraycopy(秒,0,结果,first.length,second.length);
返回结果;
}
}
这在我对源表执行put时执行。 代码中有一条注释(请查找):“下面的调用正在设置一个奇怪的”

我在日志中设置了一个调试打印,确认prePut方法只在源表上执行,而从不在索引表上执行。然而,我不明白为什么会发生这种奇怪的递归,尽管在协处理器中,我只在INDEX_表上执行一个put


我还确认源表上的put操作也是唯一的。

我已修复了我的问题。结果是,我多次添加同一个观察者,错误地认为它在Hbase重启后丢失了

对INDEX_表的.put调用不起作用的另一个原因是,我没有为它设置值,只是设置了一个行键,错误地认为这是可能的。然而HBase没有抛出任何例外,只是没有执行PUT,没有给出任何信息,这可能会让这项技术的新手感到困惑