Java 类org.apache.hadoop.hbase.index.manager.IndexManager 实例源码

项目:HIndex    文件:TestIndexRegionObserver.java   
@Test(timeout = 180000)
public void testPostOpenCoprocessor() throws IOException, KeeperException, InterruptedException {
  String userTableName = "testPostOpenCoprocessor";

  HTableDescriptor ihtd =
    TestUtils.createIndexedHTableDescriptor(userTableName, "col", "Index1", "col", "ql");
  admin.createTable(ihtd);

  // Check the number of indices
  List<IndexSpecification> list = IndexManager.getInstance().getIndicesForTable(userTableName);
  Assert.assertEquals(1, list.size());

  // Check the index name
  boolean bool = false;
  for (IndexSpecification e : list) {
    if (e.getName().equals("Index1")) bool = true;
  }
  Assert.assertTrue(bool);
}
项目:hindex    文件:TestIndexRegionObserver.java   
@Test(timeout = 180000)
public void testPostOpenCoprocessor() throws IOException, KeeperException, InterruptedException {
  HBaseAdmin admin = UTIL.getHBaseAdmin();
  ZooKeeperWatcher zkw = HBaseTestingUtility.getZooKeeperWatcher(UTIL);
  String userTableName = "testPostOpenCoprocessor";
  IndexedHTableDescriptor ihtd = new IndexedHTableDescriptor(userTableName);
  HColumnDescriptor hcd = new HColumnDescriptor("col");
  IndexSpecification iSpec = new IndexSpecification("Index1");
  iSpec.addIndexColumn(hcd, "ql", ValueType.String, 10);
  ihtd.addFamily(hcd);
  ihtd.addIndex(iSpec);
  admin.createTable(ihtd);
  ZKAssign.blockUntilNoRIT(zkw);

  // Check the number of indices
  List<IndexSpecification> list = IndexManager.getInstance().getIndicesForTable(userTableName);
  Assert.assertEquals(1, list.size());

  // Check the index name
  boolean bool = false;
  for (IndexSpecification e : list) {
    if (e.getName().equals("Index1")) bool = true;
  }
  Assert.assertTrue(bool);
}
项目:HIndex    文件:ScanFilterEvaluator.java   
private void createRegionScanner(HRegion indexRegion, String userTableName,
    List<IndexRegionScanner> scanners, ByteArrayBuilder indexNameBuilder, Scan scan,
    boolean isRange, int scannerIndex) throws IOException {
  RegionScanner scannerForIndexRegion = indexRegion.getScanner(scan);
  LeafIndexRegionScanner leafIndexRegionScanner =
      new LeafIndexRegionScanner(IndexManager.getInstance().getIndex(userTableName,
        indexNameBuilder.array()), scannerForIndexRegion, new TTLExpiryChecker());
  leafIndexRegionScanner.setScannerIndex(scannerIndex);
  leafIndexRegionScanner.setRangeFlag(isRange);
  scanners.add(leafIndexRegionScanner);
}
项目:HIndex    文件:TestIndexRegionObserver.java   
@Test(timeout = 180000)
public void testIndexManagerCleanUp() throws Exception {
  Configuration conf = UTIL.getConfiguration();
  conf.setBoolean("hbase.use.secondary.index", true);
  String userTableName = "testIndexManagerCleanUp";
  HTableDescriptor ihtd = new HTableDescriptor(TableName.valueOf(userTableName));
  HColumnDescriptor hcd = new HColumnDescriptor("col1");
  ihtd.addFamily(hcd);
  IndexSpecification iSpec = new IndexSpecification("Index1");
  iSpec.addIndexColumn(hcd, "ql", ValueType.String, 10);
  TableIndices indices = new TableIndices();
  indices.addIndex(iSpec);
  ihtd.setValue(Constants.INDEX_SPEC_KEY, indices.toByteArray());

  byte[][] splits = new byte[10][];
  char c = 'A';
  for (int i = 0; i < 10; i++) {
    byte[] b = { (byte) c };
    splits[i] = b;
    c++;
  }
  admin.createTable(ihtd, splits);
  IndexManager instance = IndexManager.getInstance();
  int regionCount = instance.getTableRegionCount(userTableName);
  Assert.assertEquals(11, regionCount);

  admin.disableTable(Bytes.toBytes(userTableName));
  regionCount = instance.getTableRegionCount(userTableName);
  Assert.assertEquals(0, regionCount);

  admin.enableTable(userTableName);
  regionCount = instance.getTableRegionCount(userTableName);
  Assert.assertEquals(11, regionCount);
}
项目:HIndex    文件:TestIndexRegionObserver.java   
@Test(timeout = 180000)
public void testIndexManagerWithSplitTransactions() throws Exception {
  Configuration conf = UTIL.getConfiguration();
  ZooKeeperWatcher zkw = UTIL.getZooKeeperWatcher(UTIL);
  conf.setBoolean("hbase.use.secondary.index", true);
  String userTableName = "testIndexManagerWithSplitTransactions";
  HTableDescriptor ihtd = new HTableDescriptor(TableName.valueOf(userTableName));
  HColumnDescriptor hcd = new HColumnDescriptor("col1");
  ihtd.addFamily(hcd);
  IndexSpecification iSpec = new IndexSpecification("Index1");
  iSpec.addIndexColumn(hcd, "ql", ValueType.String, 10);
  TableIndices indices = new TableIndices();
  indices.addIndex(iSpec);
  ihtd.setValue(Constants.INDEX_SPEC_KEY, indices.toByteArray());
  admin.createTable(ihtd);

  IndexManager manager = IndexManager.getInstance();
  int count = manager.getTableRegionCount(userTableName);
  Assert.assertEquals(1, count);

  HTable table = new HTable(conf, userTableName);
  Put p = null;
  for (int i = 0; i < 10; i++) {
    p = new Put(Bytes.toBytes("row" + i));
    p.add(Bytes.toBytes("col1"), Bytes.toBytes("ql"), Bytes.toBytes("test_val"));
    table.put(p);
  }

  admin.split(userTableName, "row5");
  Threads.sleep(10000);
  ZKAssign.blockUntilNoRIT(zkw);
  UTIL.waitUntilAllRegionsAssigned(TableName.valueOf(userTableName));
  count = manager.getTableRegionCount(userTableName);
  Assert.assertEquals(2, count);
}
项目:HIndex    文件:TestIndexRegionObserver.java   
@Test(timeout = 180000)
public void testIndexManagerWithFailedSplitOfIndexRegion() throws Exception {
  Configuration conf = UTIL.getConfiguration();
  conf.setBoolean("hbase.use.secondary.index", true);
  String userTableName = "testIndexManagerWithFailedSplitOfIndexRegion";
  HTableDescriptor ihtd = new HTableDescriptor(TableName.valueOf(userTableName));
  HColumnDescriptor hcd = new HColumnDescriptor("col1");
  ihtd.addFamily(hcd);
  IndexSpecification iSpec = new IndexSpecification("Index1");
  iSpec.addIndexColumn(hcd, "ql", ValueType.String, 10);
  TableIndices indices = new TableIndices();
  indices.addIndex(iSpec);
  ihtd.setValue(Constants.INDEX_SPEC_KEY, indices.toByteArray());
  admin.createTable(ihtd);

  IndexManager manager = IndexManager.getInstance();
  int count = manager.getTableRegionCount(userTableName);
  Assert.assertEquals(1, count);

  HTable table = new HTable(conf, userTableName);
  Put p = null;
  for (int i = 0; i < 10; i++) {
    p = new Put(Bytes.toBytes("row" + i));
    p.add(Bytes.toBytes("col1"), Bytes.toBytes("ql"), Bytes.toBytes("test_val"));
    table.put(p);
  }

  admin.split(userTableName);

  count = manager.getTableRegionCount(userTableName);
  Assert.assertEquals(1, count);
}
项目:HIndex    文件:TestScanFilterEvaluator.java   
public void testWhenORWithSameColumnAppearsinDiffChild() throws Exception {
  Configuration conf = HBaseConfiguration.create();
  region = initHRegion(tableName, "tesWhenORWithSameColumnAppearsinDiffChild", conf, family);
  ScanFilterEvaluator mapper = new ScanFilterEvaluator();
  List<IndexSpecification> indices = new ArrayList<IndexSpecification>();
  // create the indices.
  indices.add(createIndexSpecification("cf1", ValueType.String, 10, new String[] { "c2", "c3" },
    "idx1"));

  indices
      .add(createIndexSpecification("cf1", ValueType.String, 10, new String[] { "c1" }, "idx2"));

  FilterList masterFilter = new FilterList(Operator.MUST_PASS_ONE);
  // create the filter
  FilterList filter = new FilterList(Operator.MUST_PASS_ALL);
  SingleColumnValueFilter iscvf1 =
      new SingleColumnValueFilter("cf1".getBytes(), "c1".getBytes(), CompareOp.GREATER,
          "a".getBytes());
  SingleColumnValueFilter iscvf2 =
      new SingleColumnValueFilter("cf1".getBytes(), "c2".getBytes(), CompareOp.EQUAL,
          "K".getBytes());
  filter.addFilter(iscvf1);
  filter.addFilter(iscvf2);

  SingleColumnValueFilter iscvf3 =
      new SingleColumnValueFilter("cf1".getBytes(), "c1".getBytes(), CompareOp.GREATER,
          "d".getBytes());
  // filter2.addFilter(iscvf3);

  masterFilter.addFilter(filter);
  masterFilter.addFilter(iscvf3);
  Scan scan = new Scan();
  scan.setFilter(masterFilter);

  IndexManager.getInstance().addIndexForTable(this.region.getTableDesc().getNameAsString(),
    indices);
  mapper.evaluate(scan, indices, new byte[0], this.region, this.region.getTableDesc()
      .getNameAsString());
}
项目:hindex    文件:IndexRegionObserver.java   
@Override
public void preSplitAfterPONR(ObserverContext<RegionCoprocessorEnvironment> ctx)
    throws IOException {
  RegionCoprocessorEnvironment environment = ctx.getEnvironment();
  HRegionServer rs = (HRegionServer) environment.getRegionServerServices();
  HRegion region = environment.getRegion();
  String userTableName = region.getTableDesc().getNameAsString();
  String indexTableName = IndexUtils.getIndexTableName(userTableName);
  if (IndexUtils.isIndexTable(userTableName)) {
    return;
  }
  LOG.trace("Entering postSplit for the table " + userTableName + " for the region "
      + region.getRegionInfo());
  IndexManager indexManager = IndexManager.getInstance();
  SplitTransaction splitTransaction = null;
  if (indexManager.getIndicesForTable(userTableName) != null) {
    try {
      SplitInfo splitInfo = splitThreadLocal.get();
      splitTransaction = splitInfo.getSplitTransaction();
      PairOfSameType<HRegion> daughters = splitInfo.getDaughters();
      if (splitTransaction != null && daughters != null) {
        splitTransaction.stepsAfterPONR(rs, rs, daughters);
        LOG.info("Daughter regions are opened and split transaction finished"
            + " for zknodes for index table " + indexTableName + " for the region "
            + region.getRegionInfo());
      }
    } catch (Exception ex) {
      String msg =
          "Splitting of index region has failed in stepsAfterPONR stage so aborting the server";
      LOG.error(msg, ex);
      rs.abort(msg);
    }
  }
}
项目:hindex    文件:ScanFilterEvaluator.java   
private void createRegionScanner(HRegion indexRegion, String userTableName,
    List<IndexRegionScanner> scanners, ByteArrayBuilder indexNameBuilder, Scan scan,
    boolean isRange, int scannerIndex) throws IOException {
  RegionScanner scannerForIndexRegion = indexRegion.getScanner(scan);
  LeafIndexRegionScanner leafIndexRegionScanner =
      new LeafIndexRegionScanner(IndexManager.getInstance().getIndex(userTableName,
        indexNameBuilder.array()), scannerForIndexRegion, new TTLExpiryChecker());
  leafIndexRegionScanner.setScannerIndex(scannerIndex);
  leafIndexRegionScanner.setRangeFlag(isRange);
  scanners.add(leafIndexRegionScanner);
}
项目:hindex    文件:TestIndexRegionObserver.java   
@Test(timeout = 180000)
public void testIndexManagerCleanUp() throws Exception {
  HBaseAdmin admin = new HBaseAdmin(UTIL.getConfiguration());
  Configuration conf = admin.getConfiguration();
  conf.setBoolean("hbase.use.secondary.index", true);
  ZooKeeperWatcher zkw = HBaseTestingUtility.getZooKeeperWatcher(UTIL);
  String userTableName = "testIndexManagerCleanUp";
  IndexedHTableDescriptor ihtd = new IndexedHTableDescriptor(userTableName);
  HColumnDescriptor hcd = new HColumnDescriptor("col1");
  ihtd.addFamily(hcd);
  IndexSpecification iSpec = new IndexSpecification("Index1");
  iSpec.addIndexColumn(hcd, "ql", ValueType.String, 10);
  ihtd.addIndex(iSpec);

  byte[][] splits = new byte[10][];
  char c = 'A';
  for (int i = 0; i < 10; i++) {
    byte[] b = { (byte) c };
    splits[i] = b;
    c++;
  }
  admin.createTable(ihtd, splits);
  ZKAssign.blockUntilNoRIT(zkw);
  IndexManager instance = IndexManager.getInstance();
  int regionCount = instance.getTableRegionCount(userTableName);
  Assert.assertEquals(11, regionCount);

  admin.disableTable(Bytes.toBytes(userTableName));
  ZKAssign.blockUntilNoRIT(zkw);
  regionCount = instance.getTableRegionCount(userTableName);
  Assert.assertEquals(0, regionCount);

  admin.enableTable(userTableName);
  ZKAssign.blockUntilNoRIT(zkw);
  regionCount = instance.getTableRegionCount(userTableName);
  Assert.assertEquals(11, regionCount);
}
项目:hindex    文件:TestIndexRegionObserver.java   
@Test(timeout = 180000)
public void testIndexManagerWithSplitTransactions() throws Exception {
  HBaseAdmin admin = new HBaseAdmin(UTIL.getConfiguration());
  Configuration conf = admin.getConfiguration();
  conf.setBoolean("hbase.use.secondary.index", true);
  ZooKeeperWatcher zkw = HBaseTestingUtility.getZooKeeperWatcher(UTIL);
  String userTableName = "testIndexManagerWithSplitTransactions";
  IndexedHTableDescriptor ihtd = new IndexedHTableDescriptor(userTableName);
  HColumnDescriptor hcd = new HColumnDescriptor("col1");
  ihtd.addFamily(hcd);
  IndexSpecification iSpec = new IndexSpecification("Index1");
  iSpec.addIndexColumn(hcd, "ql", ValueType.String, 10);
  ihtd.addIndex(iSpec);
  admin.createTable(ihtd);
  ZKAssign.blockUntilNoRIT(zkw);

  IndexManager manager = IndexManager.getInstance();
  int count = manager.getTableRegionCount(userTableName);
  Assert.assertEquals(1, count);

  HTable table = new HTable(conf, userTableName);
  Put p = null;
  for (int i = 0; i < 10; i++) {
    p = new Put(Bytes.toBytes("row" + i));
    p.add(Bytes.toBytes("col1"), Bytes.toBytes("ql"), Bytes.toBytes("test_val"));
    table.put(p);
  }

  admin.split(userTableName, "row5");
  ZKAssign.blockUntilNoRIT(zkw);

  count = manager.getTableRegionCount(userTableName);
  Assert.assertEquals(2, count);
}
项目:hindex    文件:TestIndexRegionObserver.java   
@Test(timeout = 180000)
public void testIndexManagerWithFailedSplitOfIndexRegion() throws Exception {
  HBaseAdmin admin = new HBaseAdmin(UTIL.getConfiguration());
  Configuration conf = admin.getConfiguration();
  conf.setBoolean("hbase.use.secondary.index", true);
  ZooKeeperWatcher zkw = HBaseTestingUtility.getZooKeeperWatcher(UTIL);
  String userTableName = "testIndexManagerWithFailedSplitOfIndexRegion";
  IndexedHTableDescriptor ihtd = new IndexedHTableDescriptor(userTableName);
  HColumnDescriptor hcd = new HColumnDescriptor("col1");
  ihtd.addFamily(hcd);
  IndexSpecification iSpec = new IndexSpecification("Index1");
  iSpec.addIndexColumn(hcd, "ql", ValueType.String, 10);
  ihtd.addIndex(iSpec);
  admin.createTable(ihtd);
  ZKAssign.blockUntilNoRIT(zkw);

  IndexManager manager = IndexManager.getInstance();
  int count = manager.getTableRegionCount(userTableName);
  Assert.assertEquals(1, count);

  HTable table = new HTable(conf, userTableName);
  Put p = null;
  for (int i = 0; i < 10; i++) {
    p = new Put(Bytes.toBytes("row" + i));
    p.add(Bytes.toBytes("col1"), Bytes.toBytes("ql"), Bytes.toBytes("test_val"));
    table.put(p);
  }

  admin.split(userTableName);
  ZKAssign.blockUntilNoRIT(zkw);

  count = manager.getTableRegionCount(userTableName);
  Assert.assertEquals(1, count);
}
项目:hindex    文件:TestScanFilterEvaluator.java   
public void testWhenORWithSameColumnAppearsinDiffChild() throws Exception {
  Configuration conf = HBaseConfiguration.create();
  region = initHRegion(tableName, "tesWhenORWithSameColumnAppearsinDiffChild", conf, family);
  ScanFilterEvaluator mapper = new ScanFilterEvaluator();
  List<IndexSpecification> indices = new ArrayList<IndexSpecification>();
  // create the indices.
  indices.add(createIndexSpecification("cf1", ValueType.String, 10, new String[] { "c2", "c3" },
    "idx1"));

  indices
      .add(createIndexSpecification("cf1", ValueType.String, 10, new String[] { "c1" }, "idx2"));

  FilterList masterFilter = new FilterList(Operator.MUST_PASS_ONE);
  // create the filter
  FilterList filter = new FilterList(Operator.MUST_PASS_ALL);
  SingleColumnValueFilter iscvf1 =
      new SingleColumnValueFilter("cf1".getBytes(), "c1".getBytes(), CompareOp.GREATER,
          "a".getBytes());
  SingleColumnValueFilter iscvf2 =
      new SingleColumnValueFilter("cf1".getBytes(), "c2".getBytes(), CompareOp.EQUAL,
          "K".getBytes());
  filter.addFilter(iscvf1);
  filter.addFilter(iscvf2);

  SingleColumnValueFilter iscvf3 =
      new SingleColumnValueFilter("cf1".getBytes(), "c1".getBytes(), CompareOp.GREATER,
          "d".getBytes());
  // filter2.addFilter(iscvf3);

  masterFilter.addFilter(filter);
  masterFilter.addFilter(iscvf3);
  Scan scan = new Scan();
  scan.setFilter(masterFilter);

  IndexManager.getInstance().addIndexForTable(this.region.getTableDesc().getNameAsString(),
    indices);
  mapper.evaluate(scan, indices, new byte[0], this.region, this.region.getTableDesc()
      .getNameAsString());
}
项目:HIndex    文件:IndexMasterObserver.java   
@Override
public void postModifyTableHandler(ObserverContext<MasterCoprocessorEnvironment> ctx,
    TableName tableName, HTableDescriptor htd) throws IOException {
  String table = tableName.getNameAsString();
  MasterServices master = ctx.getEnvironment().getMasterServices();
  List<Pair<HRegionInfo, ServerName>> tableRegionsAndLocations = null;
  LOG.info("Entering postModifyTable for the table " + table);
  byte[] indexBytes = htd.getValue(Constants.INDEX_SPEC_KEY);
  if (indexBytes != null) {
    TableDescriptors tableDescriptors = master.getTableDescriptors();
    Map<String, HTableDescriptor> allTableDesc = tableDescriptors.getAll();
    String indexTableName = IndexUtils.getIndexTableName(table);
    if (allTableDesc.containsKey(indexTableName)) {
      // Do table modification
      TableIndices tableIndices = new TableIndices();
      tableIndices.readFields(indexBytes);
      List<IndexSpecification> indices = tableIndices.getIndices();
      if (indices.isEmpty()) {
        LOG.error("Empty indices are passed to modify the table " + table);
        return;
      }
      IndexManager idxManager = IndexManager.getInstance();
      idxManager.removeIndices(table);
      idxManager.addIndexForTable(table, indices);
      LOG.info("Successfully updated the indexes for the table  " + table + " to " + indices);
    } else {
      try {
        tableRegionsAndLocations =
            MetaReader.getTableRegionsAndLocations(master.getCatalogTracker(), tableName, true);
      } catch (InterruptedException e) {
        LOG.error("Exception while trying to create index table for the existing table " + table);
        return;
      }
      if (tableRegionsAndLocations != null) {
        HRegionInfo[] regionInfo = new HRegionInfo[tableRegionsAndLocations.size()];
        for (int i = 0; i < tableRegionsAndLocations.size(); i++) {
          regionInfo[i] = tableRegionsAndLocations.get(i).getFirst();
        }

        byte[][] splitKeys = getSplitKeys(regionInfo);
        createSecondaryIndexTable(htd, splitKeys, master, true);
      }
    }
  }
  LOG.info("Exiting postModifyTable for the table " + table);
}
项目:HIndex    文件:IndexRegionObserver.java   
public RegionScanner postScannerOpen(ObserverContext<RegionCoprocessorEnvironment> e, Scan scan,
    RegionScanner s) {
  HRegion region = e.getEnvironment().getRegion();
  HTableDescriptor tableDesc = region.getTableDesc();
  String tableName = tableDesc.getNameAsString();
  HRegionServer rs = (HRegionServer) e.getEnvironment().getRegionServerServices();
  if (isNotIndexedTableDescriptor(tableDesc)) {
    return s;
  }
  // If the passed region is a region from an indexed table
  SeekAndReadRegionScanner bsrs = null;

  try {
    List<IndexSpecification> indexlist = IndexManager.getInstance().getIndicesForTable(tableName);
    if (indexlist == null || indexlist.isEmpty()) {
      // Not an indexed table. Just return.
      return s;
    }
    if (indexlist != null) {
      LOG.info("Entering postScannerOpen for the table " + tableName);
      Collection<HRegion> onlineRegions = ((HRegionServer) rs).getOnlineRegionsLocalContext();
      for (HRegion onlineIdxRegion : onlineRegions) {
        if (IndexUtils.isCatalogOrSystemTable(onlineIdxRegion.getTableDesc().getTableName())) {
          continue;
        }
        if (onlineIdxRegion.equals(region)) {
          continue;
        }
        if (Bytes.equals(onlineIdxRegion.getStartKey(), region.getStartKey())
            && Bytes.equals(Bytes.toBytes(IndexUtils.getIndexTableName(region.getTableDesc()
                .getNameAsString())), onlineIdxRegion.getTableDesc().getName())) {
          ScanFilterEvaluator mapper = new ScanFilterEvaluator();
          IndexRegionScanner indexScanner =
              mapper.evaluate(scan, indexlist, onlineIdxRegion.getStartKey(), onlineIdxRegion,
                tableName);
          if (indexScanner == null) return s;
          SeekPointFetcher spf = new SeekPointFetcher(indexScanner);
          ReInitializableRegionScanner reinitializeScanner =
              new ReInitializableRegionScannerImpl(s, scan, spf);
          bsrs = new BackwardSeekableRegionScanner(reinitializeScanner, scan, region, null);
          scannerMap.put(bsrs, spf);
          LOG.trace("Scanner Map has " + scannerMap);
          break;
        }
      }
      LOG.trace("Exiting postScannerOpen for the table " + tableName);
    }
  } catch (Exception ex) {
    LOG.error("Exception occured in postScannerOpen for the table " + tableName, ex);
  }
  if (bsrs != null) {
    return bsrs;
  } else {
    return s;
  }
}
项目:HIndex    文件:TestIndexRegionObserver.java   
@Test(timeout = 180000)
public void testIndexManagerWithFailedSplitTransaction() throws Exception {
  Configuration conf = UTIL.getConfiguration();
  conf.setBoolean("hbase.use.secondary.index", true);
  String userTableName = "testIndexManagerWithFailedSplitTransaction";
  HTableDescriptor ihtd = new HTableDescriptor(TableName.valueOf(userTableName));
  HColumnDescriptor hcd = new HColumnDescriptor("col1");
  ihtd.addFamily(hcd);
  IndexSpecification iSpec = new IndexSpecification("Index1");
  iSpec.addIndexColumn(hcd, "ql", ValueType.String, 10);
  TableIndices indices = new TableIndices();
  indices.addIndex(iSpec);
  ihtd.setValue(Constants.INDEX_SPEC_KEY, indices.toByteArray());
  admin.createTable(ihtd);

  IndexManager manager = IndexManager.getInstance();
  int count = manager.getTableRegionCount(userTableName);
  Assert.assertEquals(1, count);

  HTable table = new HTable(conf, userTableName);
  Put p = null;
  for (int i = 0; i < 10; i++) {
    p = new Put(Bytes.toBytes("row" + i));
    p.add(Bytes.toBytes("col1"), Bytes.toBytes("ql"), Bytes.toBytes("test_val"));
    table.put(p);
  }
  List<HRegion> regions = UTIL.getMiniHBaseCluster().getRegions(Bytes.toBytes(userTableName));
  HRegionServer rs = UTIL.getMiniHBaseCluster().getRegionServer(0);
  SplitTransaction st = null;

  st = new MockedSplitTransaction(regions.get(0), "row5".getBytes());
  try {
    st.prepare();
    st.execute(rs, rs);
  } catch (IOException e) {
    st.rollback(rs, rs);
  }

  count = manager.getTableRegionCount(userTableName);
  Assert.assertEquals(1, count);
}
项目:hindex    文件:IndexMasterObserver.java   
@Override
public void postModifyTableHandler(ObserverContext<MasterCoprocessorEnvironment> ctx,
    byte[] tableName, HTableDescriptor htd) throws IOException {
  String table = Bytes.toString(tableName);
  MasterServices master = ctx.getEnvironment().getMasterServices();
  List<Pair<HRegionInfo, ServerName>> tableRegionsAndLocations = null;
  LOG.info("Entering postModifyTable for the table " + table);
  if (htd instanceof IndexedHTableDescriptor) {
    TableDescriptors tableDescriptors = master.getTableDescriptors();
    Map<String, HTableDescriptor> allTableDesc = tableDescriptors.getAll();
    String indexTableName = IndexUtils.getIndexTableName(tableName);
    if (allTableDesc.containsKey(indexTableName)) {
      // Do table modification
      List<IndexSpecification> indices = ((IndexedHTableDescriptor) htd).getIndices();
      if (indices.isEmpty()) {
        LOG.error("Empty indices are passed to modify the table " + Bytes.toString(tableName));
        return;
      }
      IndexManager idxManager = IndexManager.getInstance();
      idxManager.removeIndices(table);
      idxManager.addIndexForTable(table, indices);
      LOG.info("Successfully updated the indexes for the table  " + table + " to " + indices);
    } else {
      try {
        tableRegionsAndLocations =
            MetaReader.getTableRegionsAndLocations(master.getCatalogTracker(), tableName, true);
      } catch (InterruptedException e) {
        LOG.error("Exception while trying to create index table for the existing table " + table);
        return;
      }
      if (tableRegionsAndLocations != null) {
        HRegionInfo[] regionInfo = new HRegionInfo[tableRegionsAndLocations.size()];
        for (int i = 0; i < tableRegionsAndLocations.size(); i++) {
          regionInfo[i] = tableRegionsAndLocations.get(i).getFirst();
        }

        byte[][] splitKeys = IndexUtils.getSplitKeys(regionInfo);
        IndexedHTableDescriptor iDesc = (IndexedHTableDescriptor) htd;
        createSecondaryIndexTable(iDesc, splitKeys, master, true);
      }
    }
  }
  LOG.info("Exiting postModifyTable for the table " + table);
}
项目:hindex    文件:IndexRegionObserver.java   
public RegionScanner postScannerOpen(ObserverContext<RegionCoprocessorEnvironment> e, Scan scan,
    RegionScanner s) {
  HRegion region = e.getEnvironment().getRegion();
  String tableName = region.getTableDesc().getNameAsString();
  HRegionServer rs = (HRegionServer) e.getEnvironment().getRegionServerServices();
  // If the passed region is a region from an indexed table
  SeekAndReadRegionScanner bsrs = null;

  try {
    List<IndexSpecification> indexlist = IndexManager.getInstance().getIndicesForTable(tableName);
    if (indexlist != null) {
      if (indexlist == null || indexlist.isEmpty()) {
        // Not an indexed table. Just return.
        return s;
      }
      LOG.trace("Entering postScannerOpen for the table " + tableName);
      Collection<HRegion> onlineRegions = rs.getOnlineRegionsLocalContext();
      for (HRegion onlineIdxRegion : onlineRegions) {
        if (IndexUtils.isCatalogTable(Bytes.toBytes(onlineIdxRegion.getTableDesc()
            .getNameAsString()))) {
          continue;
        }
        if (onlineIdxRegion.equals(region)) {
          continue;
        }
        if (Bytes.equals(onlineIdxRegion.getStartKey(), region.getStartKey())
            && Bytes.equals(Bytes.toBytes(IndexUtils.getIndexTableName(region.getTableDesc()
                .getNameAsString())), onlineIdxRegion.getTableDesc().getName())) {
          ScanFilterEvaluator mapper = new ScanFilterEvaluator();
          IndexRegionScanner indexScanner =
              mapper.evaluate(scan, indexlist, onlineIdxRegion.getStartKey(), onlineIdxRegion,
                tableName);
          if (indexScanner == null) return s;
          SeekPointFetcher spf = new SeekPointFetcher(indexScanner);
          ReInitializableRegionScanner reinitializeScanner =
              new ReInitializableRegionScannerImpl(s, scan, spf);
          bsrs = new BackwardSeekableRegionScanner(reinitializeScanner, scan, region, null);
          scannerMap.put(bsrs, spf);
          LOG.trace("Scanner Map has " + scannerMap);
          break;
        }
      }
      LOG.trace("Exiting postScannerOpen for the table " + tableName);
    }
  } catch (Exception ex) {
    LOG.error("Exception occured in postScannerOpen for the table " + tableName, ex);
  }
  if (bsrs != null) {
    return bsrs;
  } else {
    return s;
  }
}
项目:hindex    文件:TestIndexRegionObserver.java   
@Test(timeout = 180000)
public void testIndexManagerWithFailedSplitTransaction() throws Exception {
  HBaseAdmin admin = new HBaseAdmin(UTIL.getConfiguration());
  Configuration conf = admin.getConfiguration();
  conf.setBoolean("hbase.use.secondary.index", true);
  ZooKeeperWatcher zkw = HBaseTestingUtility.getZooKeeperWatcher(UTIL);
  String userTableName = "testIndexManagerWithFailedSplitTransaction";
  IndexedHTableDescriptor ihtd = new IndexedHTableDescriptor(userTableName);
  HColumnDescriptor hcd = new HColumnDescriptor("col1");
  ihtd.addFamily(hcd);
  IndexSpecification iSpec = new IndexSpecification("Index1");
  iSpec.addIndexColumn(hcd, "ql", ValueType.String, 10);
  ihtd.addIndex(iSpec);
  admin.createTable(ihtd);
  ZKAssign.blockUntilNoRIT(zkw);

  IndexManager manager = IndexManager.getInstance();
  int count = manager.getTableRegionCount(userTableName);
  Assert.assertEquals(1, count);

  HTable table = new HTable(conf, userTableName);
  Put p = null;
  for (int i = 0; i < 10; i++) {
    p = new Put(Bytes.toBytes("row" + i));
    p.add(Bytes.toBytes("col1"), Bytes.toBytes("ql"), Bytes.toBytes("test_val"));
    table.put(p);
  }
  List<HRegion> regions = UTIL.getMiniHBaseCluster().getRegions(Bytes.toBytes(userTableName));
  HRegionServer rs = UTIL.getMiniHBaseCluster().getRegionServer(0);
  SplitTransaction st = null;

  st = new MockedSplitTransaction(regions.get(0), null) {
    @Override
    protected void splitStoreFiles(final Path splitdir, final List<StoreFile> hstoreFilesToSplit)
        throws IOException {
      throw new IOException();
    }
  };

  try {
    st.execute(rs, rs);
  } catch (IOException e) {
    st.rollback(rs, rs);
  }

  count = manager.getTableRegionCount(userTableName);
  Assert.assertEquals(1, count);
}
项目:hindex    文件:TestScanFilterEvaluator.java   
public void testDiffCombinations() throws Exception {
  Configuration conf = HBaseConfiguration.create();
  region = initHRegion(tableName, "testDiffCombinations", conf, family);
  ScanFilterEvaluator mapper = new ScanFilterEvaluator();
  List<IndexSpecification> indices = new ArrayList<IndexSpecification>();

  // create the indices.
  indices.add(createIndexSpecification("cf1", ValueType.String, 10, new String[] { "c2", "c3",
      "c4", "c5", "c6" }, "idx1"));

  indices.add(createIndexSpecification("cf1", ValueType.String, 10, new String[] { "c2", "c1",
      "c3", "c4" }, "idx4"));

  FilterList masterFilter = new FilterList(Operator.MUST_PASS_ALL);
  // create the filter
  FilterList filter = new FilterList(Operator.MUST_PASS_ALL);
  SingleColumnValueFilter iscvf1 =
      new SingleColumnValueFilter("cf1".getBytes(), "c1".getBytes(), CompareOp.EQUAL,
          "a".getBytes());
  SingleColumnValueFilter iscvf2 =
      new SingleColumnValueFilter("cf1".getBytes(), "c2".getBytes(), CompareOp.EQUAL,
          "K".getBytes());
  filter.addFilter(iscvf1);
  filter.addFilter(iscvf2);

  FilterList filter1 = new FilterList(Operator.MUST_PASS_ALL);
  iscvf1 =
      new SingleColumnValueFilter("cf1".getBytes(), "c3".getBytes(), CompareOp.EQUAL,
          "a".getBytes());
  iscvf2 =
      new SingleColumnValueFilter("cf1".getBytes(), "c4".getBytes(), CompareOp.EQUAL,
          "K".getBytes());
  filter1.addFilter(iscvf1);
  filter1.addFilter(iscvf2);

  FilterList filter2 = new FilterList(Operator.MUST_PASS_ALL);
  iscvf1 =
      new SingleColumnValueFilter("cf1".getBytes(), "c5".getBytes(), CompareOp.EQUAL,
          "a".getBytes());
  filter2.addFilter(iscvf1);

  // filter2.addFilter(iscvf3);

  masterFilter.addFilter(filter);
  masterFilter.addFilter(filter1);
  masterFilter.addFilter(filter2);
  Scan scan = new Scan();
  scan.setFilter(masterFilter);

  IndexManager.getInstance().addIndexForTable(this.region.getTableDesc().getNameAsString(),
    indices);
  mapper.evaluate(scan, indices, new byte[0], this.region, this.region.getTableDesc()
      .getNameAsString());
}
项目:hindex    文件:TestScanFilterEvaluator.java   
public void testDiffCombinations1() throws Exception {
  Configuration conf = HBaseConfiguration.create();
  region = initHRegion(tableName, "testDiffCombinations1", conf, family);
  ScanFilterEvaluator mapper = new ScanFilterEvaluator();
  List<IndexSpecification> indices = new ArrayList<IndexSpecification>();
  // create the indices.
  indices.add(createIndexSpecification("cf1", ValueType.String, 10, new String[] { "c2", "c3",
      "c4", }, "idx1"));

  indices.add(createIndexSpecification("cf1", ValueType.String, 10, new String[] { "c2", "c1" },
    "idx2"));

  indices
      .add(createIndexSpecification("cf1", ValueType.String, 10, new String[] { "c5" }, "idx3"));

  FilterList masterFilter = new FilterList(Operator.MUST_PASS_ALL);
  // create the filter
  FilterList filter = new FilterList(Operator.MUST_PASS_ALL);
  SingleColumnValueFilter iscvf1 =
      new SingleColumnValueFilter("cf1".getBytes(), "c1".getBytes(), CompareOp.EQUAL,
          "a".getBytes());
  SingleColumnValueFilter iscvf2 =
      new SingleColumnValueFilter("cf1".getBytes(), "c2".getBytes(), CompareOp.EQUAL,
          "K".getBytes());
  filter.addFilter(iscvf1);
  filter.addFilter(iscvf2);

  FilterList filter1 = new FilterList(Operator.MUST_PASS_ALL);
  iscvf1 =
      new SingleColumnValueFilter("cf1".getBytes(), "c3".getBytes(), CompareOp.EQUAL,
          "a".getBytes());
  iscvf2 =
      new SingleColumnValueFilter("cf1".getBytes(), "c4".getBytes(), CompareOp.EQUAL,
          "K".getBytes());
  filter1.addFilter(iscvf1);
  filter1.addFilter(iscvf2);

  FilterList filter2 = new FilterList(Operator.MUST_PASS_ALL);
  iscvf1 =
      new SingleColumnValueFilter("cf1".getBytes(), "c5".getBytes(), CompareOp.EQUAL,
          "a".getBytes());
  filter2.addFilter(iscvf1);

  // filter2.addFilter(iscvf3);

  masterFilter.addFilter(filter);
  masterFilter.addFilter(filter1);
  masterFilter.addFilter(filter2);
  Scan scan = new Scan();
  scan.setFilter(masterFilter);
  IndexManager.getInstance().addIndexForTable(this.region.getTableDesc().getNameAsString(),
    indices);
  mapper.evaluate(scan, indices, new byte[0], this.region, this.region.getTableDesc()
      .getNameAsString());
}
项目:hindex    文件:TestScanFilterEvaluator.java   
public void testDiffCombinations2() throws Exception {
  Configuration conf = HBaseConfiguration.create();
  region = initHRegion(tableName, "testDiffCombinations2", conf, family);
  ScanFilterEvaluator mapper = new ScanFilterEvaluator();
  List<IndexSpecification> indices = new ArrayList<IndexSpecification>();
  // create the indices.
  indices.add(createIndexSpecification("cf1", ValueType.String, 10, new String[] { "c2", "c3" },
    "idx1"));

  indices.add(createIndexSpecification("cf1", ValueType.String, 10, new String[] { "c2", "c1" },
    "idx2"));

  indices
      .add(createIndexSpecification("cf1", ValueType.String, 10, new String[] { "c5" }, "idx3"));

  FilterList masterFilter = new FilterList(Operator.MUST_PASS_ALL);
  // create the filter
  FilterList filter = new FilterList(Operator.MUST_PASS_ALL);
  SingleColumnValueFilter iscvf1 =
      new SingleColumnValueFilter("cf1".getBytes(), "c1".getBytes(), CompareOp.EQUAL,
          "a".getBytes());
  SingleColumnValueFilter iscvf2 =
      new SingleColumnValueFilter("cf1".getBytes(), "c2".getBytes(), CompareOp.EQUAL,
          "K".getBytes());
  filter.addFilter(iscvf1);
  filter.addFilter(iscvf2);

  FilterList filter1 = new FilterList(Operator.MUST_PASS_ALL);
  iscvf1 =
      new SingleColumnValueFilter("cf1".getBytes(), "c3".getBytes(), CompareOp.EQUAL,
          "a".getBytes());
  iscvf2 =
      new SingleColumnValueFilter("cf1".getBytes(), "c4".getBytes(), CompareOp.EQUAL,
          "K".getBytes());
  filter1.addFilter(iscvf1);
  filter1.addFilter(iscvf2);

  FilterList filter2 = new FilterList(Operator.MUST_PASS_ALL);
  iscvf1 =
      new SingleColumnValueFilter("cf1".getBytes(), "c5".getBytes(), CompareOp.EQUAL,
          "a".getBytes());
  filter2.addFilter(iscvf1);

  // filter2.addFilter(iscvf3);

  masterFilter.addFilter(filter);
  masterFilter.addFilter(filter1);
  masterFilter.addFilter(filter2);
  Scan scan = new Scan();
  scan.setFilter(masterFilter);

  IndexManager.getInstance().addIndexForTable(this.region.getTableDesc().getNameAsString(),
    indices);
  mapper.evaluate(scan, indices, new byte[0], this.region, this.region.getTableDesc()
      .getNameAsString());
}
项目:hindex    文件:TestScanFilterEvaluator.java   
public void testDiffCombinations3() throws Exception {
  Configuration conf = HBaseConfiguration.create();
  region = initHRegion(tableName, "testDiffCombinations3", conf, family);
  ScanFilterEvaluator mapper = new ScanFilterEvaluator();
  List<IndexSpecification> indices = new ArrayList<IndexSpecification>();
  // create the indices.
  indices.add(createIndexSpecification("cf1", ValueType.String, 10, new String[] { "c2", "c3" },
    "idx1"));

  indices
      .add(createIndexSpecification("cf1", ValueType.String, 10, new String[] { "c1" }, "idx2"));

  indices
      .add(createIndexSpecification("cf1", ValueType.String, 10, new String[] { "c5" }, "idx3"));

  indices
      .add(createIndexSpecification("cf1", ValueType.String, 10, new String[] { "c4" }, "idx4"));

  indices
      .add(createIndexSpecification("cf1", ValueType.String, 10, new String[] { "c6" }, "idx5"));

  FilterList masterFilter = new FilterList(Operator.MUST_PASS_ALL);
  // create the filter
  FilterList filter = new FilterList(Operator.MUST_PASS_ALL);
  SingleColumnValueFilter iscvf1 =
      new SingleColumnValueFilter("cf1".getBytes(), "c1".getBytes(), CompareOp.EQUAL,
          "a".getBytes());
  SingleColumnValueFilter iscvf2 =
      new SingleColumnValueFilter("cf1".getBytes(), "c2".getBytes(), CompareOp.EQUAL,
          "K".getBytes());
  filter.addFilter(iscvf1);
  filter.addFilter(iscvf2);

  FilterList filter1 = new FilterList(Operator.MUST_PASS_ALL);
  iscvf1 =
      new SingleColumnValueFilter("cf1".getBytes(), "c3".getBytes(), CompareOp.EQUAL,
          "a".getBytes());
  iscvf2 =
      new SingleColumnValueFilter("cf1".getBytes(), "c4".getBytes(), CompareOp.EQUAL,
          "K".getBytes());
  filter1.addFilter(iscvf1);
  filter1.addFilter(iscvf2);

  FilterList filter2 = new FilterList(Operator.MUST_PASS_ALL);
  iscvf1 =
      new SingleColumnValueFilter("cf1".getBytes(), "c5".getBytes(), CompareOp.EQUAL,
          "a".getBytes());
  filter2.addFilter(iscvf1);

  // filter2.addFilter(iscvf3);

  masterFilter.addFilter(filter);
  masterFilter.addFilter(filter1);
  masterFilter.addFilter(filter2);
  Scan scan = new Scan();
  scan.setFilter(masterFilter);

  IndexManager.getInstance().addIndexForTable(this.region.getTableDesc().getNameAsString(),
    indices);
  mapper.evaluate(scan, indices, new byte[0], this.region, this.region.getTableDesc()
      .getNameAsString());
}