Java 类org.apache.hadoop.hbase.index.util.IndexUtils 实例源码

项目:HIndex    文件:IndexMasterObserver.java   
private boolean checkRegionInTransition(ObserverContext<MasterCoprocessorEnvironment> ctx,
    HRegionInfo hri) {
  MasterServices master = ctx.getEnvironment().getMasterServices();
  RegionStates regionStates = master.getAssignmentManager().getRegionStates();
  String tableName = hri.getTable().getNameAsString();
  if (!IndexUtils.isIndexTable(tableName)) {
    if (regionStates.isRegionInTransition(hri)) {
      return true;
    } else {
      String indexTableName = IndexUtils.getIndexTableName(tableName);
      for (Entry<String, RegionState> region : regionStates.getRegionsInTransition().entrySet()) {
        HRegionInfo regionInfo = region.getValue().getRegion();
        if (indexTableName.equals(regionInfo.getTable().getNameAsString())) {
          if (Bytes.compareTo(hri.getStartKey(), regionInfo.getStartKey()) == 0) {
            return true;
          }
        }
      }
    }
  }
  return false;
}
项目:HIndex    文件:IndexMasterObserver.java   
@Override
public void postDeleteTableHandler(ObserverContext<MasterCoprocessorEnvironment> ctx,
    TableName tableName) throws IOException {
  LOG.info("Entered into postDeleteTableHandler of table " + tableName + '.');
  MasterServices master = ctx.getEnvironment().getMasterServices();
  TableName indexTableName = TableName.valueOf(IndexUtils.getIndexTableName(tableName));
  boolean indexTablePresent =
      master.getAssignmentManager().getZKTable().isTablePresent(indexTableName);
  // Not checking for disabled state because before deleting user table both user and index table
  // should be disabled.
  if ((!IndexUtils.isIndexTable(tableName)) && indexTablePresent) {
    LoadBalancer balancer = master.getAssignmentManager().getBalancer();
    if (balancer instanceof SecIndexLoadBalancer) {
      ((SecIndexLoadBalancer) balancer).removeIndexedTable(tableName);
    }
    DeleteTableHandler dth = new DeleteTableHandler(indexTableName, master, master);
    dth.prepare();
    dth.process();
  }
  LOG.info("Exiting from postDeleteTableHandler of table " + tableName + '.');
}
项目:HIndex    文件:IndexRegionObserver.java   
private HRegion getIndexTableRegion(String tableName, HRegion userRegion, HRegionServer rs)
    throws IOException {
  TableName indexTableName = TableName.valueOf(IndexUtils.getIndexTableName(tableName));
  Collection<HRegion> idxTabRegions = rs.getOnlineRegions(indexTableName);
  for (HRegion idxTabRegion : idxTabRegions) {
    // TODO start key check is enough? May be we can check for the
    // possibility for N-1 Mapping?
    if (Bytes.equals(idxTabRegion.getStartKey(), userRegion.getStartKey())) {
      return idxTabRegion;
    }
  }
  // No corresponding index region found in the RS online regions list!
  String message =
      "Index Region not found on the region server . " + "So skipping the put. Need Balancing";
  LOG.warn(message);
  // TODO give a proper Exception msg
  throw new DoNotRetryIOException(message);
}
项目:HIndex    文件:IndexRegionObserver.java   
private void prepareIndexMutations(List<IndexSpecification> indices, HRegion userRegion,
    Mutation mutation, String tableName, HRegion indexRegion) throws IOException {
  IndexEdits indexEdits = threadLocal.get();
  if (mutation instanceof Put) {
    for (IndexSpecification index : indices) {
      // Handle each of the index
      Mutation indexPut = IndexUtils.prepareIndexPut((Put) mutation, index, indexRegion);
      if (null != indexPut) {
        // This mutation can be null when the user table mutation is not
        // containing all of the indexed col value.
        indexEdits.add(indexPut);
      }
    }
  } else if (mutation instanceof Delete) {
    Collection<? extends Mutation> indexDeletes =
        prepareIndexDeletes((Delete) mutation, userRegion, indices, indexRegion);
    indexEdits.addAll(indexDeletes);
  } else {
    // TODO : Log or throw exception
  }
}
项目:HIndex    文件:IndexRegionObserver.java   
@Override
public InternalScanner preCompactScannerOpen(ObserverContext<RegionCoprocessorEnvironment> c,
    Store store, List<? extends KeyValueScanner> scanners, ScanType scanType, long earliestPutTs,
    InternalScanner s, CompactionRequest request) throws IOException {
  HRegionServer rs = (HRegionServer) c.getEnvironment().getRegionServerServices();
  if (!IndexUtils.isIndexTable(store.getTableName())) {
    // Not an index table
    return null;
  }
  long smallestReadPoint = c.getEnvironment().getRegion().getSmallestReadPoint();
  String actualTableName = IndexUtils.getActualTableName(store.getTableName().getNameAsString());
  TTLStoreScanner ttlStoreScanner =
      new TTLStoreScanner(store, smallestReadPoint, earliestPutTs, scanType, scanners,
          new TTLExpiryChecker(), actualTableName, rs);
  return ttlStoreScanner;
}
项目:HIndex    文件:TestSecIndexColocator.java   
@Test(timeout = 180000)
public void testWhenUserTableIsDisabledButIndexTableIsInEnabledState() throws Exception {
  String table = "testWhenUserTableIsDisabledButIndexTableIsInEnabledState";
  HTableDescriptor htd =
      TestUtils.createIndexedHTableDescriptor(table, "cf", "index_name", "cf", "cq");
  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(htd, splits);
  admin.disableTable(table);
  admin.enableTable(IndexUtils.getIndexTableName(table));
  SecondaryIndexColocator colocator = new SecondaryIndexColocator(UTIL.getConfiguration());
  colocator.setUp();
  colocator.checkForCoLocationInconsistency();
  assertTrue(
    "The enabled table should be now disabled",
    ZKTableReadOnly.isDisabledTable(HBaseTestingUtility.getZooKeeperWatcher(UTIL),
      TableName.valueOf(IndexUtils.getIndexTableName(table))));
}
项目:HIndex    文件:TestSecIndexLoadBalancer.java   
@Test(timeout = 180000)
public void testRoundRobinAssignmentDuringIndexTableCreation() throws Exception {
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();
  HMaster master = cluster.getMaster();
  String tableName = "testRoundRobinAssignmentDuringIndexTableCreation";
  String indexTableName = IndexUtils.getIndexTableName(tableName);
  HTableDescriptor iHtd =
      TestUtils.createIndexedHTableDescriptor(tableName, "cf", "index_name", "cf", "cq");
  char c = 'A';
  byte[][] split = new byte[20][];
  for (int i = 0; i < 20; i++) {
    byte[] b = { (byte) c };
    split[i] = b;
    c++;
  }
  admin.createTable(iHtd, split);
  boolean isRegionColocated = TestUtils.checkForColocation(master, tableName, indexTableName);
  assertTrue("User regions and index regions should colocate.", isRegionColocated);
}
项目:HIndex    文件:TestIndexMasterObserver.java   
@Test(timeout = 180000)
public void testIndexTableCreationAlongWithNormalTablesAfterMasterRestart() throws Exception {
  TableName tableName =
      TableName.valueOf("testIndexTableCreationAlongWithNormalTablesAfterMasterRestart");
  HTableDescriptor htd = new HTableDescriptor(tableName);
  admin.createTable(htd);
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();
  cluster.abortMaster(0);
  cluster.waitOnMaster(0);
  HMaster master = cluster.startMaster().getMaster();
  cluster.waitForActiveAndReadyMaster();

  boolean tableExist =
      MetaReader.tableExists(master.getCatalogTracker(),
        TableName.valueOf(IndexUtils.getIndexTableName(tableName)));
  assertFalse("Index table should be not created after master start up.", tableExist);
}
项目:HIndex    文件:TestIndexMasterObserver.java   
@Test(timeout = 180000)
public void testDisabledIndexTableShouldBeEnabledIfUserTableEnabledAndMasterRestarted()
    throws Exception {
  String tableName = "testDisabledIndexTableEnabledIfUserTableEnabledAndMasterRestarted";
  String indexTableName = IndexUtils.getIndexTableName(tableName);
  ZooKeeperWatcher zkw = HBaseTestingUtility.getZooKeeperWatcher(UTIL);
  HTableDescriptor iHtd =
      TestUtils.createIndexedHTableDescriptor(tableName, "cf", "index_name", "cf", "cq");
  admin.createTable(iHtd);
  admin.disableTable(indexTableName);
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();
  cluster.abortMaster(0);
  cluster.startMaster();
  cluster.waitOnMaster(0);
  cluster.waitForActiveAndReadyMaster();
  Thread.sleep(1000);
  assertTrue("User table should be enabled.", admin.isTableEnabled(tableName));
  assertTrue("Index table should be enabled.", admin.isTableEnabled(indexTableName));
}
项目:HIndex    文件:TestIndexMasterObserver.java   
@Test(timeout = 180000)
public void testEnabledIndexTableShouldBeDisabledIfUserTableDisabledAndMasterRestarted()
    throws Exception {
  String tableName = "testEnabledIndexTableDisabledIfUserTableDisabledAndMasterRestarted";
  String indexTableName = IndexUtils.getIndexTableName(tableName);
  HTableDescriptor iHtd =
      TestUtils.createIndexedHTableDescriptor(tableName, "cf", "index_name", "cf", "cq");
  admin.createTable(iHtd);
  admin.disableTable(tableName);
  admin.enableTable(indexTableName);
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();
  cluster.abortMaster(0);
  cluster.startMaster();
  cluster.waitOnMaster(0);
  cluster.waitForActiveAndReadyMaster();
  Thread.sleep(1000);
  assertTrue("User table should be disabled.", admin.isTableDisabled(tableName));
  assertTrue("Index table should be disabled.", admin.isTableDisabled(indexTableName));
}
项目:HIndex    文件:TestIndexMasterObserver.java   
@Test(timeout = 180000)
public void testDisabledIndexTableShouldBeEnabledIfUserTableInEnablingAndMasterRestarted()
    throws Exception {
  String tableName = "testDisabledIndexTableEnabledIfUserTableInEnablingAndMasterRestarted";
  String indexTableName = IndexUtils.getIndexTableName(tableName);
  HTableDescriptor iHtd =
      TestUtils.createIndexedHTableDescriptor(tableName, "cf", "index_name", "cf", "cq");
  admin.createTable(iHtd);
  admin.disableTable(indexTableName);
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();
  HMaster master = cluster.getMaster();
  master.getAssignmentManager().getZKTable().setEnablingTable(TableName.valueOf(tableName));
  cluster.abortMaster(0);
  cluster.startMaster();
  cluster.waitOnMaster(0);
  cluster.waitForActiveAndReadyMaster();
  Thread.sleep(1000);
  assertTrue("User table should be enabled.", admin.isTableEnabled(tableName));
  assertTrue("Index table should be enabled.", admin.isTableEnabled(indexTableName));
}
项目:HIndex    文件:TestIndexMasterObserver.java   
@Test(timeout = 180000)
public void testEnabledIndexTableShouldBeDisabledIfUserTableInDisablingAndMasterRestarted()
    throws Exception {
  String tableName = "testEnabledIndexTableDisabledIfUserTableInDisablingAndMasterRestarted";
  String indexTableName = IndexUtils.getIndexTableName(tableName);
  HTableDescriptor iHtd =
      TestUtils.createIndexedHTableDescriptor(tableName, "cf", "index_name", "cf", "cq");
  admin.createTable(iHtd);
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();
  HMaster master = cluster.getMaster();
  master.getAssignmentManager().getZKTable().setDisablingTable(TableName.valueOf(tableName));
  cluster.abortMaster(0);
  cluster.startMaster();
  cluster.waitOnMaster(0);
  cluster.waitForActiveAndReadyMaster();
  Thread.sleep(1000);
  assertTrue("User table should be disabled.", admin.isTableDisabled(tableName));
  assertTrue("Index table should be disabled.", admin.isTableDisabled(indexTableName));
}
项目:HIndex    文件:TestIndexMasterObserver.java   
@Test(timeout = 180000)
public void testShouldModifyTableWithIndexDetails() throws Exception {
  String tableName = "testShouldModifyTableWithIndexDetails";
  HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName));
  htd.addFamily(new HColumnDescriptor(Bytes.toBytes("f1")));
  htd.addFamily(new HColumnDescriptor(Bytes.toBytes("f2")));
  admin.createTable(htd);
  TableName indexTableName = TableName.valueOf(IndexUtils.getIndexTableName(tableName));
  admin.disableTable(tableName);
  HTableDescriptor ihtd =
      TestUtils.createIndexedHTableDescriptor(tableName, "f1", "idx1", "f1", "q1");
  admin.modifyTable(Bytes.toBytes(tableName), ihtd);
  List<HRegionInfo> regionsOfTable =
      UTIL.getHBaseCluster().getMaster().getAssignmentManager().getRegionStates()
          .getRegionsOfTable(indexTableName);
  while (regionsOfTable.size() != 1) {
    regionsOfTable =
        UTIL.getHBaseCluster().getMaster().getAssignmentManager()
            .getRegionStates().getRegionsOfTable(indexTableName);
  }
  admin.enableTable(tableName);
  assertTrue(admin.isTableEnabled(Bytes.toBytes(IndexUtils.getIndexTableName(tableName))));
}
项目:HIndex    文件:TestExtendedPutOps.java   
@Test(timeout = 180000)
public void testPutWithOneUnitLengthSeparatorWithoutValue() throws IOException {
  Path basedir = new Path(DIR + "TestIndexPut");
  Configuration conf = TEST_UTIL.getConfiguration();
  HTableDescriptor htd =
      new HTableDescriptor(TableName.valueOf("testPutWithOneUnitLengthSeparatorWithoutValue"));
  HRegionInfo info = new HRegionInfo(htd.getTableName(), "ABC".getBytes(), "BBB".getBytes(), false);
  HRegion region = HRegion.createHRegion(info, basedir, conf, htd);
  IndexSpecification spec = new IndexSpecification("index");
  spec.addIndexColumn(new HColumnDescriptor("col"), "ql1", new SeparatorPartition("_", 4),
    ValueType.String, 10);
  byte[] value1 = "2ndFloor_solitaire_huawei__karnataka".getBytes();
  Put p = new Put("row".getBytes());
  p.add("col".getBytes(), "ql1".getBytes(), value1);
  Put indexPut = IndexUtils.prepareIndexPut(p, spec, region);
  byte[] indexRowKey = indexPut.getRow();
  byte[] actualResult = new byte[10];
  System.arraycopy(indexRowKey, 22, actualResult, 0, actualResult.length);
  byte[] expectedResult = new byte[10];
  Assert.assertTrue(Bytes.equals(actualResult, expectedResult));
}
项目:HIndex    文件:TestExtendedPutOps.java   
@Test(timeout = 180000)
public void testIndexPutWithOffsetAndLength() throws IOException {
  Path basedir = new Path(DIR + "TestIndexPut");
  Configuration conf = TEST_UTIL.getConfiguration();
  HTableDescriptor htd =
      new HTableDescriptor(TableName.valueOf("testIndexPutWithOffsetAndLength"));
  HRegionInfo info = new HRegionInfo(htd.getTableName(), "ABC".getBytes(), "BBB".getBytes(), false);
  HRegion region = HRegion.createHRegion(info, basedir, conf, htd);
  IndexSpecification spec = new IndexSpecification("index");
  spec.addIndexColumn(new HColumnDescriptor("col"), "ql1", new SpatialPartition(20, 2),
    ValueType.String, 18);

  byte[] value1 = "AB---CD---EF---GH---IJ---KL---MN---OP---".getBytes();
  Put p = new Put("row".getBytes());
  p.add("col".getBytes(), "ql1".getBytes(), value1);
  Put indexPut = IndexUtils.prepareIndexPut(p, spec, region);
  byte[] indexRowKey = indexPut.getRow();
  byte[] actualResult = new byte[2];
  System.arraycopy(indexRowKey, 22, actualResult, 0, actualResult.length);
  byte[] expectedResult = new byte[2];
  System.arraycopy("IJ".getBytes(), 0, expectedResult, 0, "IJ".getBytes().length);
  Assert.assertTrue(Bytes.equals(actualResult, expectedResult));
}
项目:HIndex    文件:TestExtendedPutOps.java   
@Test(timeout = 180000)
public void testIndexPutwithPositiveIntDataTypes() throws IOException {
  Path basedir = new Path(DIR + "TestIndexPut");
  Configuration conf = TEST_UTIL.getConfiguration();
  HTableDescriptor htd =
      new HTableDescriptor(TableName.valueOf("testIndexPutwithPositiveIntDataTypes"));
  HRegionInfo info = new HRegionInfo(htd.getTableName(), "ABC".getBytes(), "BBB".getBytes(), false);
  // HLog hlog = UTIL.getMiniHBaseCluster().getRegionServer(0).getWAL();
  HRegion region = HRegion.createHRegion(info, basedir, conf, htd);
  IndexSpecification spec = new IndexSpecification("index");
  spec.addIndexColumn(new HColumnDescriptor("col"), "ql1", ValueType.Int, 4);
  spec.addIndexColumn(new HColumnDescriptor("col"), "ql2", ValueType.Float, 4);

  byte[] value1 = Bytes.toBytes(1000);
  Put p = new Put("row".getBytes());
  p.add("col".getBytes(), "ql1".getBytes(), value1);
  Put indexPut1 = IndexUtils.prepareIndexPut(p, spec, region);
  int a = 1000;
  byte[] expectedResult = Bytes.toBytes(a ^ (1 << 31));
  byte[] actualResult = new byte[4];
  byte[] indexRowKey = indexPut1.getRow();
  System.arraycopy(indexRowKey, 22, actualResult, 0, actualResult.length);
  Assert.assertTrue(Bytes.equals(expectedResult, actualResult));
}
项目:HIndex    文件:TestExtendedPutOps.java   
@Test(timeout = 180000)
public void testIndexPutWithNegativeIntDataTypes() throws IOException {
  Path basedir = new Path(DIR + "TestIndexPut");
  Configuration conf = TEST_UTIL.getConfiguration();
  HTableDescriptor htd =
      new HTableDescriptor(TableName.valueOf("testIndexPutWithNegativeIntDataTypes"));
  HRegionInfo info = new HRegionInfo(htd.getTableName(), "ABC".getBytes(), "BBB".getBytes(), false);
  // HLog hlog = UTIL.getMiniHBaseCluster().getRegionServer(0).getWAL();
  HRegion region = HRegion.createHRegion(info, basedir, conf, htd);
  IndexSpecification spec = new IndexSpecification("index");
  spec.addIndexColumn(new HColumnDescriptor("col"), "ql1", ValueType.Int, 4);
  spec.addIndexColumn(new HColumnDescriptor("col"), "ql2", ValueType.Float, 4);

  byte[] value1 = Bytes.toBytes(-2562351);
  Put p = new Put("row".getBytes());
  p.add("col".getBytes(), "ql1".getBytes(), value1);
  Put indexPut = IndexUtils.prepareIndexPut(p, spec, region);
  int a = -2562351;
  byte[] expectedResult = Bytes.toBytes(a ^ (1 << 31));
  byte[] actualResult = new byte[4];
  byte[] indexRowKey = indexPut.getRow();
  System.arraycopy(indexRowKey, 22, actualResult, 0, actualResult.length);
  Assert.assertTrue(Bytes.equals(expectedResult, actualResult));
}
项目:HIndex    文件:TestExtendedPutOps.java   
@Test(timeout = 180000)
public void testIndexPutWithLongDataTypes() throws IOException {
  Path basedir = new Path(DIR + "TestIndexPut");
  Configuration conf = TEST_UTIL.getConfiguration();
  HTableDescriptor htd = new HTableDescriptor("testIndexPutWithNegativeIntDataTypes");
  HRegionInfo info = new HRegionInfo(htd.getTableName(), "ABC".getBytes(), "BBB".getBytes(), false);
  // HLog hlog = UTIL.getMiniHBaseCluster().getRegionServer(0).getWAL();
  HRegion region = HRegion.createHRegion(info, basedir, conf, htd);
  IndexSpecification spec = new IndexSpecification("index");
  spec.addIndexColumn(new HColumnDescriptor("col"), "ql1", ValueType.Long, 4);

  byte[] value1 = Bytes.toBytes(-2562351L);
  Put p = new Put("row".getBytes());
  p.add("col".getBytes(), "ql1".getBytes(), value1);
  Put indexPut = IndexUtils.prepareIndexPut(p, spec, region);
  long a = -2562351L;
  byte[] expectedResult = Bytes.toBytes(a ^ (1L << 63));
  byte[] actualResult = new byte[8];
  byte[] indexRowKey = indexPut.getRow();
  System.arraycopy(indexRowKey, 22, actualResult, 0, actualResult.length);
  Assert.assertTrue(Bytes.equals(expectedResult, actualResult));
}
项目:HIndex    文件:TestExtendedPutOps.java   
@Test(timeout = 180000)
public void testIndexPutWithShortDataTypes() throws IOException {
  Path basedir = new Path(DIR + "TestIndexPut");
  Configuration conf = TEST_UTIL.getConfiguration();
  HTableDescriptor htd = new HTableDescriptor("testIndexPutWithNegativeIntDataTypes");
  HRegionInfo info = new HRegionInfo(htd.getTableName(), "ABC".getBytes(), "BBB".getBytes(), false);
  // HLog hlog = UTIL.getMiniHBaseCluster().getRegionServer(0).getWAL();
  HRegion region = HRegion.createHRegion(info, basedir, conf, htd);
  IndexSpecification spec = new IndexSpecification("index");
  spec.addIndexColumn(new HColumnDescriptor("col"), "ql1", ValueType.Short, 4);

  short s = 1000;
  byte[] value1 = Bytes.toBytes(s);
  Put p = new Put("row".getBytes());
  p.add("col".getBytes(), "ql1".getBytes(), value1);
  Put indexPut = IndexUtils.prepareIndexPut(p, spec, region);
  byte[] expectedResult = Bytes.toBytes(s);
  expectedResult[0] ^= 1 << 7;
  byte[] actualResult = new byte[2];
  byte[] indexRowKey = indexPut.getRow();
  System.arraycopy(indexRowKey, 22, actualResult, 0, actualResult.length);
  Assert.assertTrue(Bytes.equals(expectedResult, actualResult));
}
项目:HIndex    文件:TestExtendedPutOps.java   
@Test(timeout = 180000)
public void testIndexPutWithByteDataTypes() throws IOException {
  Path basedir = new Path(DIR + "TestIndexPut");
  Configuration conf = TEST_UTIL.getConfiguration();
  HTableDescriptor htd = new HTableDescriptor("testIndexPutWithNegativeIntDataTypes");
  HRegionInfo info = new HRegionInfo(htd.getTableName(), "ABC".getBytes(), "BBB".getBytes(), false);
  // HLog hlog = UTIL.getMiniHBaseCluster().getRegionServer(0).getWAL();
  HRegion region = HRegion.createHRegion(info, basedir, conf, htd);
  IndexSpecification spec = new IndexSpecification("index");
  spec.addIndexColumn(new HColumnDescriptor("col"), "ql1", ValueType.Short, 4);

  byte b = 100;
  byte[] value1 = Bytes.toBytes(b);
  Put p = new Put("row".getBytes());
  p.add("col".getBytes(), "ql1".getBytes(), value1);
  Put indexPut = IndexUtils.prepareIndexPut(p, spec, region);
  byte[] expectedResult = Bytes.toBytes(b);
  expectedResult[0] ^= 1 << 7;
  byte[] actualResult = new byte[2];
  byte[] indexRowKey = indexPut.getRow();
  System.arraycopy(indexRowKey, 22, actualResult, 0, actualResult.length);
  Assert.assertTrue(Bytes.equals(expectedResult, actualResult));
}
项目:HIndex    文件:TestExtendedPutOps.java   
@Test(timeout = 180000)
public void testIndexPutWithCharDataTypes() throws IOException {
  Path basedir = new Path(DIR + "TestIndexPut");
  Configuration conf = TEST_UTIL.getConfiguration();
  HTableDescriptor htd = new HTableDescriptor("testIndexPutWithNegativeIntDataTypes");
  HRegionInfo info = new HRegionInfo(htd.getTableName(), "ABC".getBytes(), "BBB".getBytes(), false);
  // HLog hlog = UTIL.getMiniHBaseCluster().getRegionServer(0).getWAL();
  HRegion region = HRegion.createHRegion(info, basedir, conf, htd);
  IndexSpecification spec = new IndexSpecification("index");
  spec.addIndexColumn(new HColumnDescriptor("col"), "ql1", ValueType.Char, 4);

  char c = 'A';
  byte[] value1 = new byte[2];
  value1[1] = (byte) c;
  c >>= 8;
  value1[0] = (byte) c;
  Put p = new Put("row".getBytes());
  p.add("col".getBytes(), "ql1".getBytes(), value1);
  Put indexPut = IndexUtils.prepareIndexPut(p, spec, region);
  byte[] actualResult = new byte[2];
  byte[] indexRowKey = indexPut.getRow();
  System.arraycopy(indexRowKey, 22, actualResult, 0, actualResult.length);
  Assert.assertTrue(Bytes.equals(value1, actualResult));
}
项目:hindex    文件:SecIndexLoadBalancer.java   
private ServerName getRandomServer(HRegionInfo regionInfo, List<ServerName> servers) {
  ServerName sn = null;
  String tableName = regionInfo.getTableNameAsString();
  if (true == IndexUtils.isIndexTable(tableName)) {
    String actualTableName = extractActualTableName(tableName);
    sn =
        this.delegator.randomAssignment(new HRegionInfo(Bytes.toBytes(actualTableName),
            regionInfo.getStartKey(), regionInfo.getEndKey()), servers);
  } else {
    sn = this.delegator.randomAssignment(regionInfo, servers);
  }
  if (sn == null) {
    return null;
  }
  synchronized (this.regionLocation) {
    putRegionPlan(regionInfo, sn);
  }
  return sn;
}
项目:hindex    文件:IndexMapReduceUtil.java   
public static List<Put> getIndexPut(Put userPut, Configuration conf) throws IOException {
  String tableName = conf.get(TableInputFormat.INPUT_TABLE);
  IndexedHTableDescriptor tableDescriptor = getTableDescriptor(tableName, conf);
  List<Put> indexPuts = new ArrayList<Put>();
  if (tableDescriptor != null) {
    List<IndexSpecification> indices = tableDescriptor.getIndices();
    for (IndexSpecification index : indices) {
      byte[] startkey = getStartKey(conf, tableName, userPut.getRow());
      Put indexPut = IndexUtils.prepareIndexPut(userPut, index, startkey);
      if (indexPut != null) {
        indexPuts.add(indexPut);
      }
    }
  }
  return indexPuts;
}
项目:hindex    文件:IndexMapReduceUtil.java   
public static List<Delete> getIndexDelete(Delete userDelete, Configuration conf)
    throws IOException {
  String tableName = conf.get(TableInputFormat.INPUT_TABLE);
  IndexedHTableDescriptor tableDescriptor = getTableDescriptor(tableName, conf);
  List<Delete> indexDeletes = new ArrayList<Delete>();
  if (tableDescriptor != null) {
    List<IndexSpecification> indices = tableDescriptor.getIndices();
    for (IndexSpecification index : indices) {
      byte[] startkey = getStartKey(conf, tableName, userDelete.getRow());
      Delete indexDelete = IndexUtils.prepareIndexDelete(userDelete, index, startkey);
      if (indexDelete != null) {
        indexDeletes.add(indexDelete);
      }
    }
  }
  return indexDeletes;
}
项目:hindex    文件:IndexMasterObserver.java   
@Override
public void postCreateTableHandler(ObserverContext<MasterCoprocessorEnvironment> ctx,
    HTableDescriptor desc, HRegionInfo[] regions) throws IOException {
  LOG.info("Entered into postCreateTableHandler of table " + desc.getNameAsString() + '.');
  if (desc instanceof IndexedHTableDescriptor) {
    MasterServices master = ctx.getEnvironment().getMasterServices();
    byte[][] splitKeys = IndexUtils.getSplitKeys(regions);
    // In case of post call for the index table creation, it wont be
    // IndexedHTableDescriptor
    IndexedHTableDescriptor iDesc = (IndexedHTableDescriptor) desc;
    createSecondaryIndexTable(iDesc, splitKeys, master, false);
    // if there is any user scenarios
    // we can add index datails to index manager
  }
  LOG.info("Exiting from postCreateTableHandler of table " + desc.getNameAsString() + '.');
}
项目:hindex    文件:IndexMasterObserver.java   
private boolean checkRegionInTransition(ObserverContext<MasterCoprocessorEnvironment> ctx,
    HRegionInfo hri) {
  MasterServices master = ctx.getEnvironment().getMasterServices();
  AssignmentManager am = master.getAssignmentManager();
  boolean isRegionInTransition = false;
  String tableName = hri.getTableNameAsString();
  if (false == IndexUtils.isIndexTable(tableName)) {
    NavigableMap<String, RegionState> regionsInTransition = am.getRegionsInTransition();
    RegionState regionState = regionsInTransition.get(hri.getEncodedName());
    if (regionState != null) {
      isRegionInTransition = true;
    } else {
      String indexTableName = IndexUtils.getIndexTableName(tableName);
      for (Entry<String, RegionState> region : regionsInTransition.entrySet()) {
        HRegionInfo regionInfo = region.getValue().getRegion();
        if (indexTableName.equals(regionInfo.getTableNameAsString())) {
          if (Bytes.compareTo(hri.getStartKey(), regionInfo.getStartKey()) == 0) {
            isRegionInTransition = true;
            break;
          }
        }
      }
    }
  }
  return isRegionInTransition;
}
项目:hindex    文件:IndexRegionObserver.java   
private HRegion getIndexTableRegion(String tableName, HRegion userRegion, HRegionServer rs)
    throws IOException {
  String indexTableName = IndexUtils.getIndexTableName(tableName);
  Collection<HRegion> idxTabRegions = rs.getOnlineRegions(Bytes.toBytes(indexTableName));
  for (HRegion idxTabRegion : idxTabRegions) {
    // TODO start key check is enough? May be we can check for the
    // possibility for N-1 Mapping?
    if (Bytes.equals(idxTabRegion.getStartKey(), userRegion.getStartKey())) {
      return idxTabRegion;
    }
  }
  // No corresponding index region found in the RS online regions list!
  LOG.warn("Index Region not found on the region server . "
      + "So skipping the put. Need Balancing");
  // TODO give a proper Exception msg
  throw new IOException();
}
项目:hindex    文件:IndexRegionObserver.java   
private void prepareIndexMutations(List<IndexSpecification> indices, HRegion userRegion,
    Mutation mutation, String tableName, HRegion indexRegion) throws IOException {
  IndexEdits indexEdits = threadLocal.get();
  if (mutation instanceof Put) {
    for (IndexSpecification index : indices) {
      // Handle each of the index
      Mutation indexPut = IndexUtils.prepareIndexPut((Put) mutation, index, indexRegion);
      if (null != indexPut) {
        // This mutation can be null when the user table mutation is not
        // containing all of the indexed col value.
        indexEdits.add(indexPut);
      }
    }
  } else if (mutation instanceof Delete) {
    Collection<? extends Mutation> indexDeletes =
        prepareIndexDeletes((Delete) mutation, userRegion, indices, indexRegion);
    indexEdits.addAll(indexDeletes);
  } else {
    // TODO : Log or throw exception
  }
}
项目:hindex    文件:IndexRegionObserver.java   
@Override
public void preRollBack(ObserverContext<RegionCoprocessorEnvironment> ctx) throws IOException {
  RegionCoprocessorEnvironment environment = ctx.getEnvironment();
  HRegionServer rs = (HRegionServer) environment.getRegionServerServices();
  HRegion region = environment.getRegion();
  String userTableName = region.getTableDesc().getNameAsString();
  if (IndexUtils.isIndexTable(userTableName)) {
    return;
  }
  LOG.trace("Entering preRollBack for the table " + userTableName + " for the region "
      + region.getRegionInfo());
  SplitInfo splitInfo = splitThreadLocal.get();
  SplitTransaction splitTransaction = splitInfo.getSplitTransaction();
  try {
    if (splitTransaction != null) {
      splitTransaction.rollback(rs, rs);
      LOG.info("preRollBack successfully done for the table " + userTableName
          + " for the region " + region.getRegionInfo());
    }
  } catch (Exception e) {
    LOG.error(
      "Error while rolling back the split failure for index region "
          + splitTransaction.getParent(), e);
    rs.abort("Abort; we got an error during rollback of index");
  }
}
项目:hindex    文件:IndexRegionObserver.java   
@Override
public InternalScanner preCompactScannerOpen(ObserverContext<RegionCoprocessorEnvironment> c,
    Store store, List<? extends KeyValueScanner> scanners, ScanType scanType, long earliestPutTs,
    InternalScanner s) throws IOException {
  HRegionServer rs = (HRegionServer) c.getEnvironment().getRegionServerServices();
  if (!store.getTableName().contains(Constants.INDEX_TABLE_SUFFIX)) {
    // Not an index table
    return null;
  }
  long smallestReadPoint = c.getEnvironment().getRegion().getSmallestReadPoint();
  String actualTableName = IndexUtils.getActualTableNameFromIndexTableName(store.getTableName());
  TTLStoreScanner ttlStoreScanner =
      new TTLStoreScanner(store, smallestReadPoint, earliestPutTs, scanType, scanners,
          new TTLExpiryChecker(), actualTableName, rs);
  return ttlStoreScanner;
}
项目:hindex    文件:TestIndexMasterObserver.java   
@Test(timeout = 180000)
public void testDisabledIndexTableShouldBeEnabledIfUserTableEnabledAndMasterRestarted()
    throws Exception {
  String tableName = "testDisabledIndexTableEnabledIfUserTableEnabledAndMasterRestarted";
  String indexTableName = IndexUtils.getIndexTableName(tableName);
  HBaseAdmin admin = new HBaseAdmin(UTIL.getConfiguration());
  ZooKeeperWatcher zkw = HBaseTestingUtility.getZooKeeperWatcher(UTIL);
  IndexedHTableDescriptor iHtd =
      createIndexedHTableDescriptor(tableName, "cf", "index_name", "cf", "cq");
  admin.createTable(iHtd);
  admin.disableTable(indexTableName);
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();
  cluster.abortMaster(0);
  cluster.startMaster();
  cluster.waitOnMaster(0);
  cluster.waitForActiveAndReadyMaster();
  Thread.sleep(1000);
  assertTrue("User table should be enabled.", admin.isTableEnabled(tableName));
  assertTrue("Index table should be enabled.", admin.isTableEnabled(indexTableName));
}
项目:hindex    文件:TestIndexMasterObserver.java   
@Test(timeout = 180000)
public void testEnabledIndexTableShouldBeDisabledIfUserTableDisabledAndMasterRestarted()
    throws Exception {
  String tableName = "testEnabledIndexTableDisabledIfUserTableDisabledAndMasterRestarted";
  String indexTableName = IndexUtils.getIndexTableName(tableName);
  HBaseAdmin admin = new HBaseAdmin(UTIL.getConfiguration());
  ZooKeeperWatcher zkw = HBaseTestingUtility.getZooKeeperWatcher(UTIL);
  IndexedHTableDescriptor iHtd =
      createIndexedHTableDescriptor(tableName, "cf", "index_name", "cf", "cq");
  admin.createTable(iHtd);
  admin.disableTable(tableName);
  admin.enableTable(indexTableName);
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();
  cluster.abortMaster(0);
  cluster.startMaster();
  cluster.waitOnMaster(0);
  cluster.waitForActiveAndReadyMaster();
  Thread.sleep(1000);
  assertTrue("User table should be disabled.", admin.isTableDisabled(tableName));
  assertTrue("Index table should be disabled.", admin.isTableDisabled(indexTableName));
}
项目:hindex    文件:TestIndexMasterObserver.java   
@Test(timeout = 180000)
public void testDisabledIndexTableShouldBeEnabledIfUserTableInEnablingAndMasterRestarted()
    throws Exception {
  String tableName = "testDisabledIndexTableEnabledIfUserTableInEnablingAndMasterRestarted";
  String indexTableName = IndexUtils.getIndexTableName(tableName);
  HBaseAdmin admin = new HBaseAdmin(UTIL.getConfiguration());
  ZooKeeperWatcher zkw = HBaseTestingUtility.getZooKeeperWatcher(UTIL);
  IndexedHTableDescriptor iHtd =
      createIndexedHTableDescriptor(tableName, "cf", "index_name", "cf", "cq");
  admin.createTable(iHtd);
  admin.disableTable(indexTableName);
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();
  HMaster master = cluster.getMaster();
  master.getAssignmentManager().getZKTable().setEnablingTable(tableName);
  cluster.abortMaster(0);
  cluster.startMaster();
  cluster.waitOnMaster(0);
  cluster.waitForActiveAndReadyMaster();
  Thread.sleep(1000);
  assertTrue("User table should be enabled.", admin.isTableEnabled(tableName));
  assertTrue("Index table should be enabled.", admin.isTableEnabled(indexTableName));
}
项目:hindex    文件:TestIndexMasterObserver.java   
@Test(timeout = 180000)
public void testEnabledIndexTableShouldBeDisabledIfUserTableInDisablingAndMasterRestarted()
    throws Exception {
  String tableName = "testEnabledIndexTableDisabledIfUserTableInDisablingAndMasterRestarted";
  String indexTableName = IndexUtils.getIndexTableName(tableName);
  HBaseAdmin admin = new HBaseAdmin(UTIL.getConfiguration());
  ZooKeeperWatcher zkw = HBaseTestingUtility.getZooKeeperWatcher(UTIL);
  IndexedHTableDescriptor iHtd =
      createIndexedHTableDescriptor(tableName, "cf", "index_name", "cf", "cq");
  admin.createTable(iHtd);
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();
  HMaster master = cluster.getMaster();
  master.getAssignmentManager().getZKTable().setDisablingTable(tableName);
  cluster.abortMaster(0);
  cluster.startMaster();
  cluster.waitOnMaster(0);
  cluster.waitForActiveAndReadyMaster();
  Thread.sleep(1000);
  assertTrue("User table should be disabled.", admin.isTableDisabled(tableName));
  assertTrue("Index table should be disabled.", admin.isTableDisabled(indexTableName));
}
项目:hindex    文件:TestIndexMasterObserver.java   
@Test(timeout = 180000)
public void testIndexTableShouldBeDeletedIfUserTableDeleted() throws Exception {
  String tableName = "testIndexTableDeletedIfUserTableDeleted";
  String indexTableName = IndexUtils.getIndexTableName(tableName);
  HBaseAdmin admin = new HBaseAdmin(UTIL.getConfiguration());
  ZooKeeperWatcher zkw = HBaseTestingUtility.getZooKeeperWatcher(UTIL);
  IndexedHTableDescriptor iHtd =
      createIndexedHTableDescriptor(tableName, "cf", "index_name", "cf", "cq");
  admin.createTable(iHtd);
  admin.disableTable(tableName);
  admin.deleteTable(tableName);
  assertFalse("User table should not be available after deletion.",
    admin.isTableAvailable(tableName));
  assertFalse("Index table should not be available after deletion.",
    admin.isTableAvailable(indexTableName));
}
项目:hindex    文件:TestExtendedPutOps.java   
@Test(timeout = 180000)
public void testPutWithOneUnitLengthSeparatorWithoutValue() throws IOException {
  Path basedir = new Path(DIR + "TestIndexPut");
  Configuration conf = TEST_UTIL.getConfiguration();
  HTableDescriptor htd = new HTableDescriptor("testPutWithOneUnitLengthSeparatorWithoutValue");
  HRegionInfo info = new HRegionInfo(htd.getName(), "ABC".getBytes(), "BBB".getBytes(), false);
  HRegion region = HRegion.createHRegion(info, basedir, conf, htd);
  IndexSpecification spec = new IndexSpecification("index");
  spec.addIndexColumn(new HColumnDescriptor("col"), "ql1", new SeparatorPartition("_", 4),
    ValueType.String, 10);
  byte[] value1 = "2ndFloor_solitaire_huawei__karnataka".getBytes();
  Put p = new Put("row".getBytes());
  p.add("col".getBytes(), "ql1".getBytes(), value1);
  Put indexPut = IndexUtils.prepareIndexPut(p, spec, region);
  byte[] indexRowKey = indexPut.getRow();
  byte[] actualResult = new byte[10];
  System.arraycopy(indexRowKey, 22, actualResult, 0, actualResult.length);
  byte[] expectedResult = new byte[10];
  Assert.assertTrue(Bytes.equals(actualResult, expectedResult));
}
项目:hindex    文件:TestExtendedPutOps.java   
@Test(timeout = 180000)
public void testIndexPutWithOffsetAndLength() throws IOException {
  Path basedir = new Path(DIR + "TestIndexPut");
  Configuration conf = TEST_UTIL.getConfiguration();
  HTableDescriptor htd = new HTableDescriptor("testIndexPutWithOffsetAndLength");
  HRegionInfo info = new HRegionInfo(htd.getName(), "ABC".getBytes(), "BBB".getBytes(), false);
  HRegion region = HRegion.createHRegion(info, basedir, conf, htd);
  IndexSpecification spec = new IndexSpecification("index");
  spec.addIndexColumn(new HColumnDescriptor("col"), "ql1", new SpatialPartition(20, 2),
    ValueType.String, 18);

  byte[] value1 = "AB---CD---EF---GH---IJ---KL---MN---OP---".getBytes();
  Put p = new Put("row".getBytes());
  p.add("col".getBytes(), "ql1".getBytes(), value1);
  Put indexPut = IndexUtils.prepareIndexPut(p, spec, region);
  byte[] indexRowKey = indexPut.getRow();
  byte[] actualResult = new byte[2];
  System.arraycopy(indexRowKey, 22, actualResult, 0, actualResult.length);
  byte[] expectedResult = new byte[2];
  System.arraycopy("IJ".getBytes(), 0, expectedResult, 0, "IJ".getBytes().length);
  Assert.assertTrue(Bytes.equals(actualResult, expectedResult));
}
项目:hindex    文件:TestExtendedPutOps.java   
@Test(timeout = 180000)
public void testIndexPutwithPositiveIntDataTypes() throws IOException {
  Path basedir = new Path(DIR + "TestIndexPut");
  Configuration conf = TEST_UTIL.getConfiguration();
  HTableDescriptor htd = new HTableDescriptor("testIndexPutwithPositiveIntDataTypes");
  HRegionInfo info = new HRegionInfo(htd.getName(), "ABC".getBytes(), "BBB".getBytes(), false);
  // HLog hlog = UTIL.getMiniHBaseCluster().getRegionServer(0).getWAL();
  HRegion region = HRegion.createHRegion(info, basedir, conf, htd);
  IndexSpecification spec = new IndexSpecification("index");
  spec.addIndexColumn(new HColumnDescriptor("col"), "ql1", ValueType.Int, 4);
  spec.addIndexColumn(new HColumnDescriptor("col"), "ql2", ValueType.Float, 4);

  byte[] value1 = Bytes.toBytes(1000);
  Put p = new Put("row".getBytes());
  p.add("col".getBytes(), "ql1".getBytes(), value1);
  Put indexPut1 = IndexUtils.prepareIndexPut(p, spec, region);
  int a = 1000;
  byte[] expectedResult = Bytes.toBytes(a ^ (1 << 31));
  byte[] actualResult = new byte[4];
  byte[] indexRowKey = indexPut1.getRow();
  System.arraycopy(indexRowKey, 22, actualResult, 0, actualResult.length);
  Assert.assertTrue(Bytes.equals(expectedResult, actualResult));
}
项目:hindex    文件:TestExtendedPutOps.java   
@Test(timeout = 180000)
public void testIndexPutWithNegativeIntDataTypes() throws IOException {
  Path basedir = new Path(DIR + "TestIndexPut");
  Configuration conf = TEST_UTIL.getConfiguration();
  HTableDescriptor htd = new HTableDescriptor("testIndexPutWithNegativeIntDataTypes");
  HRegionInfo info = new HRegionInfo(htd.getName(), "ABC".getBytes(), "BBB".getBytes(), false);
  // HLog hlog = UTIL.getMiniHBaseCluster().getRegionServer(0).getWAL();
  HRegion region = HRegion.createHRegion(info, basedir, conf, htd);
  IndexSpecification spec = new IndexSpecification("index");
  spec.addIndexColumn(new HColumnDescriptor("col"), "ql1", ValueType.Int, 4);
  spec.addIndexColumn(new HColumnDescriptor("col"), "ql2", ValueType.Float, 4);

  byte[] value1 = Bytes.toBytes(-2562351);
  Put p = new Put("row".getBytes());
  p.add("col".getBytes(), "ql1".getBytes(), value1);
  Put indexPut = IndexUtils.prepareIndexPut(p, spec, region);
  int a = -2562351;
  byte[] expectedResult = Bytes.toBytes(a ^ (1 << 31));
  byte[] actualResult = new byte[4];
  byte[] indexRowKey = indexPut.getRow();
  System.arraycopy(indexRowKey, 22, actualResult, 0, actualResult.length);
  Assert.assertTrue(Bytes.equals(expectedResult, actualResult));
}
项目:hindex    文件:TestExtendedPutOps.java   
@Test(timeout = 180000)
public void testIndexPutWithLongDataTypes() throws IOException {
  Path basedir = new Path(DIR + "TestIndexPut");
  Configuration conf = TEST_UTIL.getConfiguration();
  HTableDescriptor htd = new HTableDescriptor("testIndexPutWithNegativeIntDataTypes");
  HRegionInfo info = new HRegionInfo(htd.getName(), "ABC".getBytes(), "BBB".getBytes(), false);
  // HLog hlog = UTIL.getMiniHBaseCluster().getRegionServer(0).getWAL();
  HRegion region = HRegion.createHRegion(info, basedir, conf, htd);
  IndexSpecification spec = new IndexSpecification("index");
  spec.addIndexColumn(new HColumnDescriptor("col"), "ql1", ValueType.Long, 4);

  byte[] value1 = Bytes.toBytes(-2562351L);
  Put p = new Put("row".getBytes());
  p.add("col".getBytes(), "ql1".getBytes(), value1);
  Put indexPut = IndexUtils.prepareIndexPut(p, spec, region);
  long a = -2562351L;
  byte[] expectedResult = Bytes.toBytes(a ^ (1L << 63));
  byte[] actualResult = new byte[8];
  byte[] indexRowKey = indexPut.getRow();
  System.arraycopy(indexRowKey, 22, actualResult, 0, actualResult.length);
  Assert.assertTrue(Bytes.equals(expectedResult, actualResult));
}