Ejemplo n.º 1
1
  private static Long latestVersion(Hashtable<String, String> config, dbutil db_util)
      throws Exception {
    if (!config.get("timestamp_stop").equals(Integer.toString(Integer.MAX_VALUE))) {
      return new Long(config.get("timestamp_stop"));
    }

    String rowName = config.get("file_id") + config.get("run_id") + "_";
    if (config.get("task_id") != "") {
      try {
        rowName = rowName + String.format("%04d", new Integer(config.get("task_id")));
      } catch (NumberFormatException E) {
        rowName = rowName + config.get("task_id");
      }
    }
    Get timestampGet = new Get(rowName.getBytes());
    timestampGet.addColumn("d".getBytes(), "update".getBytes());
    Result timestampResult = db_util.doGet(config.get("db_name_updates"), timestampGet);
    KeyValue tsKv = timestampResult.getColumnLatest("d".getBytes(), "update".getBytes());
    if (tsKv == null) {
      rowName = config.get("file_id") + "_";
      timestampGet = new Get(rowName.getBytes());
      timestampGet.addColumn("d".getBytes(), "update".getBytes());
      timestampResult = db_util.doGet(config.get("db_name_updates"), timestampGet);
      tsKv = timestampResult.getColumnLatest("d".getBytes(), "update".getBytes());
    }

    if (tsKv == null) {
      return new Long(Integer.MAX_VALUE);
    }
    Long latestVersion = new Long(tsKv.getTimestamp());
    return latestVersion;
  }
Ejemplo n.º 2
0
  @Test(timeout = 300000)
  public void testDisableAndEnableTables() throws IOException {
    final byte[] row = Bytes.toBytes("row");
    final byte[] qualifier = Bytes.toBytes("qualifier");
    final byte[] value = Bytes.toBytes("value");
    final TableName table1 = TableName.valueOf("testDisableAndEnableTable1");
    final TableName table2 = TableName.valueOf("testDisableAndEnableTable2");
    Table ht1 = TEST_UTIL.createTable(table1, HConstants.CATALOG_FAMILY);
    Table ht2 = TEST_UTIL.createTable(table2, HConstants.CATALOG_FAMILY);
    Put put = new Put(row);
    put.add(HConstants.CATALOG_FAMILY, qualifier, value);
    ht1.put(put);
    ht2.put(put);
    Get get = new Get(row);
    get.addColumn(HConstants.CATALOG_FAMILY, qualifier);
    ht1.get(get);
    ht2.get(get);

    this.admin.disableTables("testDisableAndEnableTable.*");

    // Test that tables are disabled
    get = new Get(row);
    get.addColumn(HConstants.CATALOG_FAMILY, qualifier);
    boolean ok = false;
    try {
      ht1.get(get);
      ht2.get(get);
    } catch (org.apache.hadoop.hbase.DoNotRetryIOException e) {
      ok = true;
    }

    assertTrue(ok);
    this.admin.enableTables("testDisableAndEnableTable.*");

    // Test that tables are enabled
    try {
      ht1.get(get);
    } catch (IOException e) {
      ok = false;
    }
    try {
      ht2.get(get);
    } catch (IOException e) {
      ok = false;
    }
    assertTrue(ok);

    ht1.close();
    ht2.close();
  }
Ejemplo n.º 3
0
  @Test
  public void testDisableAndEnableTable() throws IOException {
    final byte[] row = Bytes.toBytes("row");
    final byte[] qualifier = Bytes.toBytes("qualifier");
    final byte[] value = Bytes.toBytes("value");
    final byte[] table = Bytes.toBytes("testDisableAndEnableTable");
    HTable ht = TEST_UTIL.createTable(table, HConstants.CATALOG_FAMILY);
    Put put = new Put(row);
    put.add(HConstants.CATALOG_FAMILY, qualifier, value);
    ht.put(put);
    Get get = new Get(row);
    get.addColumn(HConstants.CATALOG_FAMILY, qualifier);
    ht.get(get);

    this.admin.disableTable(table);

    // Test that table is disabled
    get = new Get(row);
    get.addColumn(HConstants.CATALOG_FAMILY, qualifier);
    boolean ok = false;
    try {
      ht.get(get);
    } catch (NotServingRegionException e) {
      ok = true;
    } catch (RetriesExhaustedException e) {
      ok = true;
    }
    assertTrue(ok);
    this.admin.enableTable(table);

    // Test that table is enabled
    try {
      ht.get(get);
    } catch (RetriesExhaustedException e) {
      ok = false;
    }
    assertTrue(ok);
  }
Ejemplo n.º 4
0
  @Test(timeout = 300000)
  public void testDisableAndEnableTable() throws IOException {
    final byte[] row = Bytes.toBytes("row");
    final byte[] qualifier = Bytes.toBytes("qualifier");
    final byte[] value = Bytes.toBytes("value");
    final TableName table = TableName.valueOf("testDisableAndEnableTable");
    Table ht = TEST_UTIL.createTable(table, HConstants.CATALOG_FAMILY);
    Put put = new Put(row);
    put.add(HConstants.CATALOG_FAMILY, qualifier, value);
    ht.put(put);
    Get get = new Get(row);
    get.addColumn(HConstants.CATALOG_FAMILY, qualifier);
    ht.get(get);

    this.admin.disableTable(ht.getName());
    assertTrue(
        "Table must be disabled.",
        TEST_UTIL
            .getHBaseCluster()
            .getMaster()
            .getAssignmentManager()
            .getTableStateManager()
            .isTableState(ht.getName(), ZooKeeperProtos.Table.State.DISABLED));

    // Test that table is disabled
    get = new Get(row);
    get.addColumn(HConstants.CATALOG_FAMILY, qualifier);
    boolean ok = false;
    try {
      ht.get(get);
    } catch (TableNotEnabledException e) {
      ok = true;
    }
    ok = false;
    // verify that scan encounters correct exception
    Scan scan = new Scan();
    try {
      ResultScanner scanner = ht.getScanner(scan);
      Result res = null;
      do {
        res = scanner.next();
      } while (res != null);
    } catch (TableNotEnabledException e) {
      ok = true;
    }
    assertTrue(ok);
    this.admin.enableTable(table);
    assertTrue(
        "Table must be enabled.",
        TEST_UTIL
            .getHBaseCluster()
            .getMaster()
            .getAssignmentManager()
            .getTableStateManager()
            .isTableState(ht.getName(), ZooKeeperProtos.Table.State.ENABLED));

    // Test that table is enabled
    try {
      ht.get(get);
    } catch (RetriesExhaustedException e) {
      ok = false;
    }
    assertTrue(ok);
    ht.close();
  }