Java Examples for org.apache.hadoop.hbase.TableNotDisabledException

The following java examples will help you to understand the usage of org.apache.hadoop.hbase.TableNotDisabledException. These source code samples are taken from different open source projects.

Example 1
Project: incubator-atlas-master  File: HBaseAdmin1_0.java View source code
@Override
public void clearTable(String tableString, long timestamp) throws IOException {
    TableName tableName = TableName.valueOf(tableString);
    if (!adm.tableExists(tableName)) {
        log.debug("Attempted to clear table {} before it exists (noop)", tableString);
        return;
    }
    if (!adm.isTableDisabled(tableName))
        adm.disableTable(tableName);
    if (!adm.isTableDisabled(tableName))
        throw new RuntimeException("Unable to disable table " + tableName);
    // This API call appears to both truncate and reenable the table.
    log.info("Truncating table {}", tableName);
    adm.truncateTable(tableName, true);
    try {
        adm.enableTable(tableName);
    } catch (TableNotDisabledException e) {
        log.debug("Table automatically reenabled by truncation: {}", tableName, e);
    }
}
Example 2
Project: learning-hadoop-master  File: TestCreateTable.java View source code
public static void tableExistFamily(HBaseAdmin hba, String tableName) throws IOException {
    String testColumn1 = "test1";
    String testColumn2 = "test2";
    boolean before = false;
    boolean after = false;
    before = existsFamilyName(hba, tableName, testColumn1);
    boolean getException = false;
    try {
        hba.addColumn(tableName, new HColumnDescriptor(testColumn1));
    } catch (TableNotDisabledException e) {
        getException = true;
    } finally {
    }
    after = existsFamilyName(hba, tableName, testColumn1);
    getException = false;
    try {
        hba.deleteColumn(tableName, testColumn1);
    } catch (TableNotDisabledException e) {
        getException = true;
    } finally {
    }
    after = existsFamilyName(hba, tableName, testColumn1);
    hba.disableTable(tableName);
    before = existsFamilyName(hba, tableName, testColumn2);
    hba.addColumn(tableName, new HColumnDescriptor(testColumn2));
    after = existsFamilyName(hba, tableName, testColumn2);
    System.out.println(before + " : " + after);
    before = after;
    hba.deleteColumn(tableName, testColumn2);
    after = existsFamilyName(hba, tableName, testColumn2);
    System.out.println(before + " : " + after);
    hba.enableTable(tableName);
}
Example 3
Project: sleuthkit-hadoop-master  File: HBaseTables.java View source code
public static HTable summon(Configuration conf, byte[] tname, byte[] cfam) throws IOException {
    final HBaseAdmin admin = new HBaseAdmin(conf);
    final HTableDescriptor tableDesc = new HTableDescriptor(tname);
    if (!tableDesc.hasFamily(cfam)) {
        final HColumnDescriptor colFamDesc = new HColumnDescriptor(cfam);
        colFamDesc.setCompressionType(Compression.Algorithm.SNAPPY);
        tableDesc.addFamily(colFamDesc);
    }
    try {
        admin.createTable(tableDesc);
    } catch (TableExistsException e) {
    }
    try {
        admin.enableTable(tname);
    } catch (TableNotDisabledException e) {
    }
    // FIXME: check what happens if we do this when the table doesn't exist
    return new HTable(conf, tname);
}
Example 4
Project: hbase-master  File: HMaster.java View source code
@Override
public void checkTableModifiable(final TableName tableName) throws IOException, TableNotFoundException, TableNotDisabledException {
    if (isCatalogTable(tableName)) {
        throw new IOException("Can't modify catalog tables");
    }
    if (!MetaTableAccessor.tableExists(getConnection(), tableName)) {
        throw new TableNotFoundException(tableName);
    }
    if (!getTableStateManager().isTableState(tableName, TableState.State.DISABLED)) {
        throw new TableNotDisabledException(tableName);
    }
}
Example 5
Project: hbase-book-master  File: SnapshotExample.java View source code
public static void main(String[] args) throws IOException, InterruptedException {
    Configuration conf = HBaseConfiguration.create();
    conf.setInt("hbase.client.retries.number", 1);
    HBaseHelper helper = HBaseHelper.getHelper(conf);
    helper.dropTable("testtable");
    helper.dropTable("testtable2");
    helper.dropTable("testtable3");
    helper.createTable("testtable", 3, "colfam1", "colfam2");
    helper.put("testtable", new String[] { "row1" }, new String[] { "colfam1", "colfam2" }, new String[] { "qual1", "qual1", "qual2", "qual2", "qual3", "qual3" }, new long[] { 1, 2, 3, 4, 5, 6 }, new String[] { "val1", "val1", "val2", "val2", "val3", "val3" });
    System.out.println("Before snapshot calls...");
    helper.dump("testtable", new String[] { "row1" }, null, null);
    Connection connection = ConnectionFactory.createConnection(conf);
    TableName tableName = TableName.valueOf("testtable");
    Table table = connection.getTable(tableName);
    Admin admin = connection.getAdmin();
    /*
    When you try to snapshot with an existing name:
    Exception in thread "main" org.apache.hadoop.hbase.client.RetriesExhaustedException:
      Failed after attempts=1, exceptions:
    Mon Apr 13 11:21:58 CEST 2015, RpcRetryingCaller{globalStartTime=1428916918532, pause=100, retries=1}, org.apache.hadoop.hbase.ipc.RemoteWithExtrasException(org.apache.hadoop.hbase.snapshot.SnapshotExistsException): org.apache.hadoop.hbase.snapshot.SnapshotExistsException: Snapshot 'snapshot2' already stored on the filesystem.
    	at org.apache.hadoop.hbase.master.snapshot.SnapshotManager.takeSnapshot(SnapshotManager.java:518)
      ...
     */
    admin.deleteSnapshots("snapshot.*");
    // vv SnapshotExample
    // co SnapshotExample-1-Snap1 Create a snapshot of the initial table, then list all available snapshots next.
    admin.snapshot("snapshot1", tableName);
    List<HBaseProtos.SnapshotDescription> snaps = admin.listSnapshots();
    System.out.println("Snapshots after snapshot 1: " + snaps);
    Delete delete = new Delete(Bytes.toBytes("row1"));
    // co SnapshotExample-2-Delete Remove one column and do two more snapshots, one without first flushing, then another with a preceding flush.
    delete.addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("qual1"));
    table.delete(delete);
    admin.snapshot("snapshot2", tableName, HBaseProtos.SnapshotDescription.Type.SKIPFLUSH);
    admin.snapshot("snapshot3", tableName, HBaseProtos.SnapshotDescription.Type.FLUSH);
    snaps = admin.listSnapshots();
    System.out.println("Snapshots after snapshot 2 & 3: " + snaps);
    Put put = new Put(Bytes.toBytes("row2")).addColumn(Bytes.toBytes("colfam1"), Bytes.toBytes("qual10"), // co SnapshotExample-3-Put Add a new row to the table and take yet another snapshot.
    Bytes.toBytes("val10"));
    table.put(put);
    HBaseProtos.SnapshotDescription snapshotDescription = HBaseProtos.SnapshotDescription.newBuilder().setName("snapshot4").setTable(tableName.getNameAsString()).build();
    admin.takeSnapshotAsync(snapshotDescription);
    snaps = admin.listSnapshots();
    System.out.println("Snapshots before waiting: " + snaps);
    System.out.println("Waiting...");
    while (!admin.isSnapshotFinished(snapshotDescription)) {
        // co SnapshotExample-4-Wait Wait for the asynchronous snapshot to complete. List the snapshots before and after the waiting.
        Thread.sleep(1 * 1000);
        System.out.print(".");
    }
    System.out.println();
    System.out.println("Snapshot completed.");
    snaps = admin.listSnapshots();
    System.out.println("Snapshots after waiting: " + snaps);
    System.out.println("Table before restoring snapshot 1");
    helper.dump("testtable", new String[] { "row1", "row2" }, null, null);
    // ^^ SnapshotExample
    /*
    If the table is not disabled you will receive this error:
    Exception in thread "main" org.apache.hadoop.hbase.TableNotDisabledException: testtable
    	at org.apache.hadoop.hbase.client.HBaseAdmin.restoreSnapshot(HBaseAdmin.java:3153)
    	at org.apache.hadoop.hbase.client.HBaseAdmin.restoreSnapshot(HBaseAdmin.java:3088)
    	at admin.SnapshotExample.main(SnapshotExample.java:88)
      ...
    	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
     */
    // vv SnapshotExample
    admin.disableTable(tableName);
    // co SnapshotExample-5-Restore Restore the first snapshot, recreating the initial table. This needs to be done on a disabled table.
    admin.restoreSnapshot("snapshot1");
    admin.enableTable(tableName);
    System.out.println("Table after restoring snapshot 1");
    helper.dump("testtable", new String[] { "row1", "row2" }, null, null);
    // co SnapshotExample-6-DelSnap1 Remove the first snapshot, and list the available ones again.
    admin.deleteSnapshot("snapshot1");
    snaps = admin.listSnapshots();
    System.out.println("Snapshots after deletion: " + snaps);
    admin.cloneSnapshot("snapshot2", TableName.valueOf("testtable2"));
    System.out.println("New table after cloning snapshot 2");
    helper.dump("testtable2", new String[] { "row1", "row2" }, null, null);
    // co SnapshotExample-7-Clone Clone the second and third snapshot into a new table, dump the content to show the difference between the "skipflush" and "flush" types.
    admin.cloneSnapshot("snapshot3", TableName.valueOf("testtable3"));
    System.out.println("New table after cloning snapshot 3");
    helper.dump("testtable3", new String[] { "row1", "row2" }, null, null);
    // ^^ SnapshotExample
    table.close();
    connection.close();
    helper.close();
}
Example 6
Project: pbase-master  File: HMaster.java View source code
@Override
public void checkTableModifiable(final TableName tableName) throws IOException, TableNotFoundException, TableNotDisabledException {
    if (isCatalogTable(tableName)) {
        throw new IOException("Can't modify catalog tables");
    }
    if (!MetaTableAccessor.tableExists(getConnection(), tableName)) {
        throw new TableNotFoundException(tableName);
    }
    if (!getAssignmentManager().getTableStateManager().isTableState(tableName, ZooKeeperProtos.Table.State.DISABLED)) {
        throw new TableNotDisabledException(tableName);
    }
}
Example 7
Project: hadoop-hbase-master  File: HMaster.java View source code
@Override
public void checkTableModifiable(final byte[] tableName) throws IOException {
    String tableNameStr = Bytes.toString(tableName);
    if (isCatalogTable(tableName)) {
        throw new IOException("Can't modify catalog tables");
    }
    if (!MetaReader.tableExists(getCatalogTracker(), tableNameStr)) {
        throw new TableNotFoundException(tableNameStr);
    }
    if (!getAssignmentManager().getZKTable().isDisabledTable(Bytes.toString(tableName))) {
        throw new TableNotDisabledException(tableName);
    }
}
Example 8
Project: falcon-master  File: HBaseAdmin1_0.java View source code
@Override
public void clearTable(String tableString, long timestamp) throws IOException {
    TableName tableName = TableName.valueOf(tableString);
    if (!adm.tableExists(tableName)) {
        log.debug("Attempted to clear table {} before it exists (noop)", tableString);
        return;
    }
    if (!adm.isTableDisabled(tableName))
        adm.disableTable(tableName);
    if (!adm.isTableDisabled(tableName))
        throw new RuntimeException("Unable to disable table " + tableName);
    // This API call appears to both truncate and reenable the table.
    log.info("Truncating table {}", tableName);
    adm.truncateTable(tableName, true);
    try {
        adm.enableTable(tableName);
    } catch (TableNotDisabledException e) {
        log.debug("Table automatically reenabled by truncation: {}", tableName, e);
    }
}
Example 9
Project: janusgraph-master  File: HBaseAdmin1_0.java View source code
@Override
public void clearTable(String tableString, long timestamp) throws IOException {
    TableName tableName = TableName.valueOf(tableString);
    if (!adm.tableExists(tableName)) {
        log.debug("Attempted to clear table {} before it exists (noop)", tableString);
        return;
    }
    if (!adm.isTableDisabled(tableName))
        adm.disableTable(tableName);
    if (!adm.isTableDisabled(tableName))
        throw new RuntimeException("Unable to disable table " + tableName);
    // This API call appears to both truncate and reenable the table.
    log.info("Truncating table {}", tableName);
    adm.truncateTable(tableName, true);
    try {
        adm.enableTable(tableName);
    } catch (TableNotDisabledException e) {
        log.debug("Table automatically reenabled by truncation: {}", tableName, e);
    }
}
Example 10
Project: janus-master  File: HBaseAdmin1_0.java View source code
@Override
public void clearTable(String tableString, long timestamp) throws IOException {
    TableName tableName = TableName.valueOf(tableString);
    if (!adm.tableExists(tableName)) {
        log.debug("Attempted to clear table {} before it exists (noop)", tableString);
        return;
    }
    if (!adm.isTableDisabled(tableName))
        adm.disableTable(tableName);
    if (!adm.isTableDisabled(tableName))
        throw new RuntimeException("Unable to disable table " + tableName);
    // This API call appears to both truncate and reenable the table.
    log.info("Truncating table {}", tableName);
    adm.truncateTable(tableName, true);
    try {
        adm.enableTable(tableName);
    } catch (TableNotDisabledException e) {
        log.debug("Table automatically reenabled by truncation: {}", tableName, e);
    }
}
Example 11
Project: SecureBase-master  File: HMaster.java View source code
@Override
public void checkTableModifiable(final byte[] tableName) throws IOException {
    String tableNameStr = Bytes.toString(tableName);
    if (isCatalogTable(tableName)) {
        throw new IOException("Can't modify catalog tables");
    }
    if (!MetaReader.tableExists(getCatalogTracker(), tableNameStr)) {
        throw new TableNotFoundException(tableNameStr);
    }
    if (!getAssignmentManager().getZKTable().isDisabledTable(Bytes.toString(tableName))) {
        throw new TableNotDisabledException(tableName);
    }
}
Example 12
Project: hbase-cache-master  File: HMaster.java View source code
@Override
public void checkTableModifiable(final byte[] tableName) throws IOException, TableNotFoundException, TableNotDisabledException {
    String tableNameStr = Bytes.toString(tableName);
    if (isCatalogTable(tableName)) {
        throw new IOException("Can't modify catalog tables");
    }
    if (!MetaReader.tableExists(getCatalogTracker(), tableNameStr)) {
        throw new TableNotFoundException(tableNameStr);
    }
    if (!getAssignmentManager().getZKTable().isDisabledTable(Bytes.toString(tableName))) {
        throw new TableNotDisabledException(tableName);
    }
}
Example 13
Project: hindex-master  File: HMaster.java View source code
@Override
public void checkTableModifiable(final byte[] tableName) throws IOException {
    String tableNameStr = Bytes.toString(tableName);
    if (isCatalogTable(tableName)) {
        throw new IOException("Can't modify catalog tables");
    }
    if (!MetaReader.tableExists(getCatalogTracker(), tableNameStr)) {
        throw new TableNotFoundException(tableNameStr);
    }
    if (!getAssignmentManager().getZKTable().isDisabledTable(Bytes.toString(tableName))) {
        throw new TableNotDisabledException(tableName);
    }
}
Example 14
Project: HBase-Research-master  File: HMaster.java View source code
@Override
public void checkTableModifiable(final byte[] tableName) throws IOException {
    String tableNameStr = Bytes.toString(tableName);
    if (isCatalogTable(tableName)) {
        throw new IOException("Can't modify catalog tables");
    }
    if (!MetaReader.tableExists(getCatalogTracker(), tableNameStr)) {
        throw new TableNotFoundException(tableNameStr);
    }
    if (!getAssignmentManager().getZKTable().isDisabledTable(Bytes.toString(tableName))) {
        throw new TableNotDisabledException(tableName);
    }
}
Example 15
Project: CCIndex_HBase_0.90.0-master  File: HMaster.java View source code
@Override
public void checkTableModifiable(final byte[] tableName) throws IOException {
    String tableNameStr = Bytes.toString(tableName);
    if (isCatalogTable(tableName)) {
        throw new IOException("Can't modify catalog tables");
    }
    if (!MetaReader.tableExists(getCatalogTracker(), tableNameStr)) {
        throw new TableNotFoundException(tableNameStr);
    }
    if (!getAssignmentManager().getZKTable().isDisabledTable(Bytes.toString(tableName))) {
        throw new TableNotDisabledException(tableName);
    }
}
Example 16
Project: hbase-trunk-mttr-master  File: HMaster.java View source code
@Override
public void checkTableModifiable(final byte[] tableName) throws IOException {
    String tableNameStr = Bytes.toString(tableName);
    if (isCatalogTable(tableName)) {
        throw new IOException("Can't modify catalog tables");
    }
    if (!MetaReader.tableExists(getCatalogTracker(), tableNameStr)) {
        throw new TableNotFoundException(tableNameStr);
    }
    if (!getAssignmentManager().getZKTable().isDisabledTable(Bytes.toString(tableName))) {
        throw new TableNotDisabledException(tableName);
    }
}
Example 17
Project: CSBT-master  File: ClusterVerifierUtil.java View source code
public static void enableTable(HBaseAdmin admin, String tableName) throws IOException {
    try {
        admin.enableTable(tableName);
    } catch (TableNotDisabledException e) {
    }
}