Java Code Examples for org.apache.hadoop.hbase.client.TableDescriptorBuilder#setColumnFamily()

The following examples show how to use org.apache.hadoop.hbase.client.TableDescriptorBuilder#setColumnFamily() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BackupSystemTable.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Get backup system table descriptor
 * @return table's descriptor
 */
public static TableDescriptor getSystemTableDescriptor(Configuration conf) {
  TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(getTableName(conf));

  ColumnFamilyDescriptorBuilder colBuilder =
      ColumnFamilyDescriptorBuilder.newBuilder(SESSIONS_FAMILY);

  colBuilder.setMaxVersions(1);
  Configuration config = HBaseConfiguration.create();
  int ttl = config.getInt(BackupRestoreConstants.BACKUP_SYSTEM_TTL_KEY,
    BackupRestoreConstants.BACKUP_SYSTEM_TTL_DEFAULT);
  colBuilder.setTimeToLive(ttl);

  ColumnFamilyDescriptor colSessionsDesc = colBuilder.build();
  builder.setColumnFamily(colSessionsDesc);

  colBuilder = ColumnFamilyDescriptorBuilder.newBuilder(META_FAMILY);
  colBuilder.setTimeToLive(ttl);
  builder.setColumnFamily(colBuilder.build());
  return builder.build();
}
 
Example 2
Source File: MobSnapshotTestingUtils.java    From hbase with Apache License 2.0 6 votes vote down vote up
public static void createMobTable(HBaseTestingUtility util, TableName tableName,
    byte[][] splitKeys, int regionReplication, String cpClassName, byte[]... families)
    throws IOException, InterruptedException {
  TableDescriptorBuilder builder =
    TableDescriptorBuilder.newBuilder(tableName).setRegionReplication(regionReplication);
  for (byte[] family : families) {
    builder.setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(family).setMobEnabled(true)
      .setMobThreshold(0L).build());
  }
  if (!StringUtils.isBlank(cpClassName)) {
    builder.setCoprocessor(cpClassName);
  }
  util.getAdmin().createTable(builder.build(), splitKeys);
  SnapshotTestingUtils.waitForTableToBeOnline(util, tableName);
  assertEquals((splitKeys.length + 1) * regionReplication,
    util.getAdmin().getRegions(tableName).size());
}
 
Example 3
Source File: TestAccessController.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testTableModify() throws Exception {
  AccessTestAction modifyTable = new AccessTestAction() {
    @Override
    public Object run() throws Exception {
      TableDescriptorBuilder tableDescriptorBuilder =
        TableDescriptorBuilder.newBuilder(TEST_TABLE);
      ColumnFamilyDescriptor columnFamilyDescriptor =
        ColumnFamilyDescriptorBuilder.newBuilder(TEST_FAMILY).build();
      tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
      columnFamilyDescriptor = ColumnFamilyDescriptorBuilder
        .newBuilder(Bytes.toBytes("fam_" + User.getCurrent().getShortName())).build();
      tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
      ACCESS_CONTROLLER.preModifyTable(ObserverContextImpl.createAndPrepare(CP_ENV),
          TEST_TABLE,
          null,  // not needed by AccessController
          tableDescriptorBuilder.build());
      return null;
    }
  };

  verifyAllowed(modifyTable, SUPERUSER, USER_ADMIN, USER_CREATE, USER_OWNER, USER_GROUP_CREATE,
    USER_GROUP_ADMIN);
  verifyDenied(modifyTable, USER_RW, USER_RO, USER_NONE, USER_GROUP_READ, USER_GROUP_WRITE);
}
 
Example 4
Source File: TestMemStoreSegmentsIterator.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws IOException {
  Configuration conf = new Configuration();
  HBaseTestingUtility hbaseUtility = new HBaseTestingUtility(conf);
  TableDescriptorBuilder tableDescriptorBuilder =
    TableDescriptorBuilder.newBuilder(TableName.valueOf(TABLE));
  ColumnFamilyDescriptor columnFamilyDescriptor =
    ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(FAMILY)).build();
  tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);

  RegionInfo info = RegionInfoBuilder.newBuilder(TableName.valueOf(TABLE)).build();
  Path rootPath = hbaseUtility.getDataTestDir(ROOT_SUB_PATH);
  this.wal = HBaseTestingUtility.createWal(conf, rootPath, info);
  this.region = HRegion.createHRegion(info, rootPath, conf,
    tableDescriptorBuilder.build(), this.wal, true);
  this.store = new HStore(this.region, columnFamilyDescriptor, conf, false);
  this.comparator = CellComparator.getInstance();
  this.compactionKVMax = HConstants.COMPACTION_KV_MAX_DEFAULT;
}
 
Example 5
Source File: TestGzipFilter.java    From hbase with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  TEST_UTIL.startMiniCluster();
  REST_TEST_UTIL.startServletContainer(TEST_UTIL.getConfiguration());
  client = new Client(new Cluster().add("localhost",
    REST_TEST_UTIL.getServletPort()));
  Admin admin = TEST_UTIL.getAdmin();
  if (admin.tableExists(TABLE)) {
    return;
  }
  TableDescriptorBuilder tableDescriptorBuilder =
    TableDescriptorBuilder.newBuilder(TABLE);
  ColumnFamilyDescriptor columnFamilyDescriptor =
    ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(CFA)).build();
  tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
  admin.createTable(tableDescriptorBuilder.build());
}
 
Example 6
Source File: TestClassLoading.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
// HBASE-6308: Test CP classloader is the CoprocessorClassLoader
public void testPrivateClassLoader() throws Exception {
  File jarFile = buildCoprocessorJar(cpName4);

  // create a table that references the jar
  TableDescriptorBuilder tdb = TableDescriptorBuilder.newBuilder(TableName.valueOf(cpName4));
  tdb.setColumnFamily(ColumnFamilyDescriptorBuilder
    .newBuilder(Bytes.toBytes("test")).build());
  tdb.setValue("COPROCESSOR$1", getLocalPath(jarFile) + "|" + cpName4 + "|" +
    Coprocessor.PRIORITY_USER);
  TableDescriptor tableDescriptor = tdb.build();
  Admin admin = TEST_UTIL.getAdmin();
  admin.createTable(tableDescriptor);
  waitForTable(tableDescriptor.getTableName());

  // verify that the coprocessor was loaded correctly
  boolean found = false;
  MiniHBaseCluster hbase = TEST_UTIL.getHBaseCluster();
  for (HRegion region: hbase.getRegionServer(0).getOnlineRegionsLocalContext()) {
    if (region.getRegionInfo().getRegionNameAsString().startsWith(cpName4)) {
      Coprocessor cp = region.getCoprocessorHost().findCoprocessor(cpName4);
      if (cp != null) {
        found = true;
        assertEquals("Class " + cpName4 + " was not loaded by CoprocessorClassLoader",
          cp.getClass().getClassLoader().getClass(), CoprocessorClassLoader.class);
      }
    }
  }
  assertTrue("Class " + cpName4 + " was missing on a region", found);
}
 
Example 7
Source File: TestHFileOutputFormat2.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void setupMockColumnFamiliesForDataBlockEncoding(Table table,
    Map<String, DataBlockEncoding> familyToDataBlockEncoding) throws IOException {
  TableDescriptorBuilder mockTableDescriptor =
    TableDescriptorBuilder.newBuilder(TABLE_NAMES[0]);
  for (Entry<String, DataBlockEncoding> entry : familyToDataBlockEncoding.entrySet()) {
    ColumnFamilyDescriptor columnFamilyDescriptor = ColumnFamilyDescriptorBuilder
      .newBuilder(Bytes.toBytes(entry.getKey()))
      .setMaxVersions(1)
      .setDataBlockEncoding(entry.getValue())
      .setBlockCacheEnabled(false)
      .setTimeToLive(0).build();
    mockTableDescriptor.setColumnFamily(columnFamilyDescriptor);
  }
  Mockito.doReturn(mockTableDescriptor).when(table).getDescriptor();
}
 
Example 8
Source File: HBaseFsck.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * To fabricate a .tableinfo file with following contents<br>
 * 1. the correct tablename <br>
 * 2. the correct colfamily list<br>
 * 3. the default properties for both {@link TableDescriptor} and {@link ColumnFamilyDescriptor}<br>
 * @throws IOException
 */
private boolean fabricateTableInfo(FSTableDescriptors fstd, TableName tableName,
    Set<String> columns) throws IOException {
  if (columns ==null || columns.isEmpty()) return false;
  TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
  for (String columnfamimly : columns) {
    builder.setColumnFamily(ColumnFamilyDescriptorBuilder.of(columnfamimly));
  }
  fstd.createTableDescriptor(builder.build(), true);
  return true;
}
 
Example 9
Source File: RegionSplitter.java    From hbase with Apache License 2.0 5 votes vote down vote up
static void createPresplitTable(TableName tableName, SplitAlgorithm splitAlgo,
        String[] columnFamilies, Configuration conf)
throws IOException, InterruptedException {
  final int splitCount = conf.getInt("split.count", 0);
  Preconditions.checkArgument(splitCount > 1, "Split count must be > 1");

  Preconditions.checkArgument(columnFamilies.length > 0,
      "Must specify at least one column family. ");
  LOG.debug("Creating table " + tableName + " with " + columnFamilies.length
      + " column families.  Presplitting to " + splitCount + " regions");

  TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
  for (String cf : columnFamilies) {
    builder.setColumnFamily(ColumnFamilyDescriptorBuilder.of(cf));
  }
  try (Connection connection = ConnectionFactory.createConnection(conf)) {
    Admin admin = connection.getAdmin();
    try {
      Preconditions.checkArgument(!admin.tableExists(tableName),
        "Table already exists: " + tableName);
      admin.createTable(builder.build(), splitAlgo.split(splitCount));
    } finally {
      admin.close();
    }
    LOG.debug("Table created!  Waiting for regions to show online in META...");
    if (!conf.getBoolean("split.verify", true)) {
      // NOTE: createTable is synchronous on the table, but not on the regions
      int onlineRegions = 0;
      while (onlineRegions < splitCount) {
        onlineRegions = MetaTableAccessor.getRegionCount(connection, tableName);
        LOG.debug(onlineRegions + " of " + splitCount + " regions online...");
        if (onlineRegions < splitCount) {
          Thread.sleep(10 * 1000); // sleep
        }
      }
    }
    LOG.debug("Finished creating table with " + splitCount + " regions");
  }
}
 
Example 10
Source File: TestMasterQuotasObserver.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void createTable(Admin admin, TableName tn) throws Exception {
  // Create a table
  TableDescriptorBuilder tableDescriptorBuilder =
    TableDescriptorBuilder.newBuilder(tn);
  ColumnFamilyDescriptor columnFamilyDescriptor =
    ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("F1")).build();
  tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
  admin.createTable(tableDescriptorBuilder.build());
}
 
Example 11
Source File: TestMultiRowResource.java    From hbase with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  conf = TEST_UTIL.getConfiguration();
  conf.setBoolean(RESTServer.REST_CSRF_ENABLED_KEY, csrfEnabled);
  if (csrfEnabled) {
    conf.set(RESTServer.REST_CSRF_BROWSER_USERAGENTS_REGEX_KEY, ".*");
  }
  extraHdr = new BasicHeader(RESTServer.REST_CSRF_CUSTOM_HEADER_DEFAULT, "");
  TEST_UTIL.startMiniCluster();
  REST_TEST_UTIL.startServletContainer(conf);
  context = JAXBContext.newInstance(
          CellModel.class,
          CellSetModel.class,
          RowModel.class);
  marshaller = context.createMarshaller();
  unmarshaller = context.createUnmarshaller();
  client = new Client(new Cluster().add("localhost", REST_TEST_UTIL.getServletPort()));
  Admin admin = TEST_UTIL.getAdmin();
  if (admin.tableExists(TABLE)) {
    return;
  }
  TableDescriptorBuilder tableDescriptorBuilder =
    TableDescriptorBuilder.newBuilder(TABLE);
  ColumnFamilyDescriptor columnFamilyDescriptor =
    ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(CFA)).build();
  tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
  columnFamilyDescriptor =
    ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(CFB)).build();
  tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
  admin.createTable(tableDescriptorBuilder.build());
}
 
Example 12
Source File: MasterProcedureTestingUtility.java    From hbase with Apache License 2.0 5 votes vote down vote up
public static TableDescriptor createHTD(final TableName tableName, final String... family) {
  TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
  for (int i = 0; i < family.length; ++i) {
    builder.setColumnFamily(ColumnFamilyDescriptorBuilder.of(family[i]));
  }
  return builder.build();
}
 
Example 13
Source File: HbaseSessions.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
public void createTable(String table, List<byte[]> cfs) throws IOException {
    TableDescriptorBuilder tdb = TableDescriptorBuilder.newBuilder(
                                 TableName.valueOf(this.namespace, table));
    for (byte[] cf : cfs) {
        tdb.setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(cf)
                                                         .build());
    }
    tdb.setCoprocessor(COPROCESSOR_AGGR);
    try(Admin admin = this.hbase.getAdmin()) {
        admin.createTable(tdb.build());
    }
}
 
Example 14
Source File: TestNamespaceAuditor.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testRestoreSnapshot() throws Exception {
  String nsp = prefix + "_testRestoreSnapshot";
  NamespaceDescriptor nspDesc =
      NamespaceDescriptor.create(nsp)
          .addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "10").build();
  ADMIN.createNamespace(nspDesc);
  assertNotNull("Namespace descriptor found null.", ADMIN.getNamespaceDescriptor(nsp));
  TableName tableName1 = TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table1");
  ColumnFamilyDescriptor columnFamilyDescriptor =
    ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("fam1")).build();
  TableDescriptorBuilder tableDescOne = TableDescriptorBuilder
    .newBuilder(tableName1);
  tableDescOne.setColumnFamily(columnFamilyDescriptor);
  ADMIN.createTable(tableDescOne.build(), Bytes.toBytes("AAA"), Bytes.toBytes("ZZZ"), 4);

  NamespaceTableAndRegionInfo nstate = getNamespaceState(nsp);
  assertEquals("Intial region count should be 4.", 4, nstate.getRegionCount());

  String snapshot = "snapshot_testRestoreSnapshot";
  ADMIN.snapshot(snapshot, tableName1);

  List<RegionInfo> regions = ADMIN.getRegions(tableName1);
  Collections.sort(regions, RegionInfo.COMPARATOR);

  ADMIN.split(tableName1, Bytes.toBytes("JJJ"));
  Thread.sleep(2000);
  assertEquals("Total regions count should be 5.", 5, nstate.getRegionCount());

  ADMIN.disableTable(tableName1);
  ADMIN.restoreSnapshot(snapshot);

  assertEquals("Total regions count should be 4 after restore.", 4, nstate.getRegionCount());

  ADMIN.enableTable(tableName1);
  ADMIN.deleteSnapshot(snapshot);
}
 
Example 15
Source File: TestNamespace.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void createTableInDefaultNamespace() throws Exception {
  TableDescriptorBuilder tableDescriptorBuilder =
    TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName()));
  ColumnFamilyDescriptor columnFamilyDescriptor =
    ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("cf1")).build();
  tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
  TableDescriptor tableDescriptor = tableDescriptorBuilder.build();
  admin.createTable(tableDescriptor);
  assertTrue(admin.listTableDescriptors().size() == 1);
  admin.disableTable(tableDescriptor.getTableName());
  admin.deleteTable(tableDescriptor.getTableName());
}
 
Example 16
Source File: TestSerialization.java    From hbase with Apache License 2.0 5 votes vote down vote up
private RegionInfo createRandomRegion(final String name) {
  TableDescriptorBuilder tableDescriptorBuilder =
    TableDescriptorBuilder.newBuilder(TableName.valueOf(name));
  String[] families = new String[] { "info", "anchor" };
  for (int i = 0; i < families.length; i++) {
    ColumnFamilyDescriptor columnFamilyDescriptor =
      ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(families[i])).build();
    tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
  }
  TableDescriptor tableDescriptor = tableDescriptorBuilder.build();
  return RegionInfoBuilder.newBuilder(tableDescriptor.getTableName()).build();
}
 
Example 17
Source File: SnapshotTestingUtils.java    From hbase with Apache License 2.0 5 votes vote down vote up
public static void createTable(final HBaseTestingUtility util, final TableName tableName,
    int regionReplication, int nRegions, final byte[]... families)
    throws IOException, InterruptedException {
  TableDescriptorBuilder builder
    = TableDescriptorBuilder
        .newBuilder(tableName)
        .setRegionReplication(regionReplication);
  for (byte[] family : families) {
    builder.setColumnFamily(ColumnFamilyDescriptorBuilder.of(family));
  }
  byte[][] splitKeys = getSplitKeys(nRegions);
  util.createTable(builder.build(), splitKeys);
  assertEquals((splitKeys.length + 1) * regionReplication,
      util.getAdmin().getRegions(tableName).size());
}
 
Example 18
Source File: TestNamespaceAuditor.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testStatePreserve() throws Exception {
  final String nsp1 = prefix + "_testStatePreserve";
  NamespaceDescriptor nspDesc = NamespaceDescriptor.create(nsp1)
      .addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "20")
      .addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "10").build();
  ADMIN.createNamespace(nspDesc);
  TableName tableOne = TableName.valueOf(nsp1 + TableName.NAMESPACE_DELIM + "table1");
  TableName tableTwo = TableName.valueOf(nsp1 + TableName.NAMESPACE_DELIM + "table2");
  TableName tableThree = TableName.valueOf(nsp1 + TableName.NAMESPACE_DELIM + "table3");
  ColumnFamilyDescriptor columnFamilyDescriptor =
    ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("fam1")).build();
  TableDescriptorBuilder tableDescOne = TableDescriptorBuilder
    .newBuilder(tableOne);
  tableDescOne.setColumnFamily(columnFamilyDescriptor);
  TableDescriptorBuilder tableDescTwo = TableDescriptorBuilder
    .newBuilder(tableTwo);
  tableDescTwo.setColumnFamily(columnFamilyDescriptor);
  TableDescriptorBuilder tableDescThree = TableDescriptorBuilder
    .newBuilder(tableThree);
  tableDescThree.setColumnFamily(columnFamilyDescriptor);

  ADMIN.createTable(tableDescOne.build(), Bytes.toBytes("1"), Bytes.toBytes("1000"), 3);
  ADMIN.createTable(tableDescTwo.build(), Bytes.toBytes("1"), Bytes.toBytes("1000"), 3);
  ADMIN.createTable(tableDescThree.build(), Bytes.toBytes("1"), Bytes.toBytes("1000"), 4);
  ADMIN.disableTable(tableThree);
  deleteTable(tableThree);
  // wait for chore to complete
  UTIL.waitFor(1000, new Waiter.Predicate<Exception>() {
    @Override
    public boolean evaluate() throws Exception {
      return (getNamespaceState(nsp1).getTables().size() == 2);
    }
  });
  NamespaceTableAndRegionInfo before = getNamespaceState(nsp1);
  killActiveMaster();
  NamespaceTableAndRegionInfo after = getNamespaceState(nsp1);
  assertEquals("Expected: " + before.getTables() + " Found: " + after.getTables(), before
      .getTables().size(), after.getTables().size());
}
 
Example 19
Source File: TestMultipleColumnPrefixFilter.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testMultipleColumnPrefixFilterWithManyFamilies() throws IOException {
  String family1 = "Family1";
  String family2 = "Family2";
  TableDescriptorBuilder tableDescriptorBuilder =
    TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName()));
  ColumnFamilyDescriptor columnFamilyDescriptor =
    ColumnFamilyDescriptorBuilder
      .newBuilder(Bytes.toBytes(family1))
      .setMaxVersions(3)
      .build();
  tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
  columnFamilyDescriptor = ColumnFamilyDescriptorBuilder
    .newBuilder(Bytes.toBytes(family2))
    .setMaxVersions(3)
    .build();
  tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
  TableDescriptor tableDescriptor = tableDescriptorBuilder.build();
  RegionInfo info = RegionInfoBuilder.newBuilder(tableDescriptor.getTableName()).build();
  HRegion region = HBaseTestingUtility.createRegionAndWAL(info, TEST_UTIL.
    getDataTestDir(), TEST_UTIL.getConfiguration(), tableDescriptor);

  List<String> rows = generateRandomWords(100, "row");
  List<String> columns = generateRandomWords(10000, "column");
  long maxTimestamp = 3;

  List<Cell> kvList = new ArrayList<>();

  Map<String, List<Cell>> prefixMap = new HashMap<>();

  prefixMap.put("p", new ArrayList<>());
  prefixMap.put("q", new ArrayList<>());
  prefixMap.put("s", new ArrayList<>());

  String valueString = "ValueString";

  for (String row: rows) {
    Put p = new Put(Bytes.toBytes(row));
    p.setDurability(Durability.SKIP_WAL);
    for (String column: columns) {
      for (long timestamp = 1; timestamp <= maxTimestamp; timestamp++) {
        double rand = Math.random();
        Cell kv;
        if (rand < 0.5) {
          kv = KeyValueTestUtil.create(row, family1, column, timestamp, valueString);
        } else {
          kv = KeyValueTestUtil.create(row, family2, column, timestamp, valueString);
        }
        p.add(kv);
        kvList.add(kv);
        for (String s: prefixMap.keySet()) {
          if (column.startsWith(s)) {
            prefixMap.get(s).add(kv);
          }
        }
      }
    }
    region.put(p);
  }

  MultipleColumnPrefixFilter filter;
  Scan scan = new Scan();
  scan.readAllVersions();
  byte [][] filter_prefix = new byte [2][];
  filter_prefix[0] = new byte [] {'p'};
  filter_prefix[1] = new byte [] {'q'};

  filter = new MultipleColumnPrefixFilter(filter_prefix);
  scan.setFilter(filter);
  List<Cell> results = new ArrayList<>();
  InternalScanner scanner = region.getScanner(scan);
  while (scanner.next(results))
    ;
  assertEquals(prefixMap.get("p").size() + prefixMap.get("q").size(), results.size());

  HBaseTestingUtility.closeRegionAndWAL(region);
}
 
Example 20
Source File: TestFSTableDescriptors.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test public void testTableDescriptors()
throws IOException, InterruptedException {
  final String name = this.name.getMethodName();
  FileSystem fs = FileSystem.get(UTIL.getConfiguration());
  // Cleanup old tests if any debris laying around.
  Path rootdir = new Path(UTIL.getDataTestDir(), name);
  FSTableDescriptors htds = new FSTableDescriptors(fs, rootdir) {
    @Override
    public TableDescriptor get(TableName tablename)
        throws TableExistsException, FileNotFoundException, IOException {
      LOG.info(tablename + ", cachehits=" + this.cachehits);
      return super.get(tablename);
    }
  };
  final int count = 10;
  // Write out table infos.
  for (int i = 0; i < count; i++) {
    htds.createTableDescriptor(TableDescriptorBuilder.newBuilder(TableName.valueOf(name + i)).build());
  }

  for (int i = 0; i < count; i++) {
    assertTrue(htds.get(TableName.valueOf(name + i)) !=  null);
  }
  for (int i = 0; i < count; i++) {
    assertTrue(htds.get(TableName.valueOf(name + i)) !=  null);
  }
  // Update the table infos
  for (int i = 0; i < count; i++) {
    TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(TableName.valueOf(name + i));
    builder.setColumnFamily(ColumnFamilyDescriptorBuilder.of("" + i));
    htds.updateTableDescriptor(builder.build());
  }
  // Wait a while so mod time we write is for sure different.
  Thread.sleep(100);
  for (int i = 0; i < count; i++) {
    assertTrue(htds.get(TableName.valueOf(name + i)) !=  null);
  }
  for (int i = 0; i < count; i++) {
    assertTrue(htds.get(TableName.valueOf(name + i)) !=  null);
  }
  assertEquals(count * 4, htds.invocations);
  assertTrue("expected=" + (count * 2) + ", actual=" + htds.cachehits,
    htds.cachehits >= (count * 2));
}