private boolean prepareCreate(final MasterProcedureEnv env) throws IOException { final TableName tableName = getTableName(); if (MetaTableAccessor.tableExists(env.getMasterServices().getConnection(), tableName)) { setFailure("master-create-table", new TableExistsException(getTableName())); return false; } // During master initialization, the ZK state could be inconsistent from failed DDL // in the past. If we fail here, it would prevent master to start. We should force // setting the system table state regardless the table state. boolean skipTableStateCheck = !(env.getMasterServices().isInitialized()) && tableName.isSystemTable(); if (!skipTableStateCheck) { TableStateManager tsm = env.getMasterServices().getAssignmentManager().getTableStateManager(); if (tsm.isTableState(tableName, true, ZooKeeperProtos.Table.State.ENABLING, ZooKeeperProtos.Table.State.ENABLED)) { LOG.warn("The table " + tableName + " does not exist in meta but has a znode. " + "run hbck to fix inconsistencies."); setFailure("master-create-table", new TableExistsException(getTableName())); return false; } } return true; }
@Test(timeout=60000, expected=TableExistsException.class) public void testCreateExisting() throws Exception { final TableName tableName = TableName.valueOf("testCreateExisting"); final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); final HTableDescriptor htd = MasterProcedureTestingUtility.createHTD(tableName, "f"); final HRegionInfo[] regions = ModifyRegionUtils.createHRegionInfos(htd, null); // create the table long procId1 = procExec.submitProcedure( new CreateTableProcedure(procExec.getEnvironment(), htd, regions), nonceGroup, nonce); // create another with the same name ProcedurePrepareLatch latch2 = new ProcedurePrepareLatch.CompatibilityLatch(); long procId2 = procExec.submitProcedure( new CreateTableProcedure(procExec.getEnvironment(), htd, regions, latch2), nonceGroup + 1, nonce + 1); ProcedureTestingUtility.waitProcedure(procExec, procId1); ProcedureTestingUtility.assertProcNotFailed(procExec.getResult(procId1)); ProcedureTestingUtility.waitProcedure(procExec, procId2); latch2.await(); }
/** * Creates a table with given table name and specified number of column * families if the table does not already exist. */ private void setupTable(final Connection connection, TableName table, int cfs) throws IOException { try { LOG.info("Creating table " + table); HTableDescriptor htd = new HTableDescriptor(table); for (int i = 0; i < cfs; i++) { htd.addFamily(new HColumnDescriptor(family(i))); } try (Admin admin = connection.getAdmin()) { admin.createTable(htd); } } catch (TableExistsException tee) { LOG.info("Table " + table + " already exists"); } }
public static void create() throws Exception { HBaseAdmin admin = new HBaseAdmin(cfg); if (admin.tableExists(tableName)) { System.out.println("[info]table has created!"); } else { try { TableName table = TableName.valueOf(tableName); HTableDescriptor tableDescriptor = new HTableDescriptor(table); tableDescriptor.addFamily(new HColumnDescriptor(familyName)); admin.createTable(tableDescriptor); } catch (TableExistsException e) { System.out.println("[warning] table exists!"); } } System.out.println("[info]create table success!"); }
public static void create() throws Exception { HBaseAdmin admin = new HBaseAdmin(cfg); if (admin.tableExists(tableName)) { System.out.println("[info]table has created!"); } else { TableName table = TableName.valueOf(tableName); HTableDescriptor tableDescriptor = new HTableDescriptor(table); tableDescriptor.addFamily(new HColumnDescriptor(familyName)); try{ admin.createTable(tableDescriptor); }catch(TableExistsException e) { System.out.println("[warning] table exists!"); } } System.out.println("[info]create table success!"); }
/** * Create the prune state table given the {@link TableName} if the table doesn't exist already. * * @param stateTable prune state table name */ protected void createPruneTable(TableName stateTable) throws IOException { try (Admin admin = this.connection.getAdmin()) { if (admin.tableExists(stateTable)) { LOG.debug("Not creating pruneStateTable {} since it already exists.", stateTable.getNameWithNamespaceInclAsString()); return; } HTableDescriptor htd = new HTableDescriptor(stateTable); htd.addFamily(new HColumnDescriptor(DataJanitorState.FAMILY).setMaxVersions(1)); admin.createTable(htd); LOG.info("Created pruneTable {}", stateTable.getNameWithNamespaceInclAsString()); } catch (TableExistsException ex) { // Expected if the prune state table is being created at the same time by another client LOG.debug("Not creating pruneStateTable {} since it already exists.", stateTable.getNameWithNamespaceInclAsString(), ex); } }
/** * Create the prune state table given the {@link TableName} if the table doesn't exist already. * * @param stateTable prune state table name */ protected void createPruneTable(TableName stateTable) throws IOException { try { if (hBaseAdmin.tableExists(stateTable)) { LOG.debug("Not creating pruneStateTable {}:{} since it already exists.", stateTable.getNamespaceAsString(), stateTable.getNameAsString()); return; } HTableDescriptor htd = new HTableDescriptor(stateTable); htd.addFamily(new HColumnDescriptor(DataJanitorState.FAMILY).setMaxVersions(1)); hBaseAdmin.createTable(htd); LOG.info("Created pruneTable {}:{}", stateTable.getNamespaceAsString(), stateTable.getNameAsString()); } catch (TableExistsException ex) { // Expected if the prune state table is being created at the same time by another client LOG.debug("Not creating pruneStateTable {}:{} since it already exists.", stateTable.getNamespaceAsString(), stateTable.getNameAsString(), ex); } }
/** * Create the prune state table given the {@link TableName} if the table doesn't exist already. * * @param stateTable prune state table name */ protected void createPruneTable(TableName stateTable) throws IOException { try (Admin admin = this.connection.getAdmin()) { if (admin.tableExists(stateTable)) { LOG.debug("Not creating pruneStateTable {}:{} since it already exists.", stateTable.getNamespaceAsString(), stateTable.getNameAsString()); return; } HTableDescriptor htd = new HTableDescriptor(stateTable); htd.addFamily(new HColumnDescriptor(DataJanitorState.FAMILY).setMaxVersions(1)); admin.createTable(htd); LOG.info("Created pruneTable {}:{}", stateTable.getNamespaceAsString(), stateTable.getNameAsString()); } catch (TableExistsException ex) { // Expected if the prune state table is being created at the same time by another client LOG.debug("Not creating pruneStateTable {}:{} since it already exists.", stateTable.getNamespaceAsString(), stateTable.getNameAsString(), ex); } }
public CloneSnapshotHandler(final MasterServices masterServices, final SnapshotDescription snapshot, final HTableDescriptor hTableDescriptor, final MasterMetrics metricsMaster) throws NotAllMetaRegionsOnlineException, TableExistsException, IOException { super(masterServices, masterServices.getMasterFileSystem(), masterServices.getServerManager(), hTableDescriptor, masterServices.getConfiguration(), null, masterServices.getCatalogTracker(), masterServices.getAssignmentManager()); this.metricsMaster = metricsMaster; // Snapshot information this.snapshot = snapshot; // Monitor this.monitor = new ForeignExceptionDispatcher(); this.status = TaskMonitor.get().createStatus("Cloning snapshot '" + snapshot.getName() + "' to table " + hTableDescriptor.getNameAsString()); }
static void checkAndSetEnablingTable(final AssignmentManager assignmentManager, final TableName tableName) throws IOException { // If we have multiple client threads trying to create the table at the // same time, given the async nature of the operation, the table // could be in a state where hbase:meta table hasn't been updated yet in // the process() function. // Use enabling state to tell if there is already a request for the same // table in progress. This will introduce a new zookeeper call. Given // createTable isn't a frequent operation, that should be ok. // TODO: now that we have table locks, re-evaluate above -- table locks are not enough. // We could have cleared the hbase.rootdir and not zk. How can we detect this case? // Having to clean zk AND hdfs is awkward. try { if (!assignmentManager.getTableStateManager().setTableStateIfNotInStates(tableName, ZooKeeperProtos.Table.State.ENABLING, ZooKeeperProtos.Table.State.ENABLING, ZooKeeperProtos.Table.State.ENABLED)) { throw new TableExistsException(tableName); } } catch (CoordinatedStateException e) { throw new IOException("Unable to ensure that the table will be" + " enabling because of a ZooKeeper issue", e); } }
private void createTableIfMissing() throws IOException { try { HTableDescriptor ihtd = new HTableDescriptor(TableName.valueOf(TABLE_NAME)); for (byte[] family : FAMILIES) { ihtd.addFamily(new HColumnDescriptor(family)); } IndexSpecification iSpec = new IndexSpecification("ScanIndex"); iSpec.addIndexColumn(new HColumnDescriptor(Bytes.toString(FAMILY_A)), Bytes.toString(QUALIFIER_NAME) + "1", ValueType.String, 10); TableIndices indices = new TableIndices(); indices.addIndex(iSpec); HBaseAdmin admin = new IndexAdmin(util.getConfiguration()); admin.createTable(ihtd); admin.close(); } catch (TableExistsException tee) { } }
private boolean prepareCreate(final MasterProcedureEnv env) throws IOException { final TableName tableName = getTableName(); if (MetaTableAccessor.tableExists(env.getMasterServices().getConnection(), tableName)) { setFailure("master-create-table", new TableExistsException(getTableName())); return false; } // check that we have at least 1 CF if (tableDescriptor.getColumnFamilyCount() == 0) { setFailure("master-create-table", new DoNotRetryIOException("Table " + getTableName().toString() + " should have at least one column family.")); return false; } return true; }
@Test(expected=TableExistsException.class) public void testCreateExisting() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); final TableDescriptor htd = MasterProcedureTestingUtility.createHTD(tableName, "f"); final RegionInfo[] regions = ModifyRegionUtils.createRegionInfos(htd, null); // create the table long procId1 = procExec.submitProcedure( new CreateTableProcedure(procExec.getEnvironment(), htd, regions)); // create another with the same name ProcedurePrepareLatch latch2 = new ProcedurePrepareLatch.CompatibilityLatch(); long procId2 = procExec.submitProcedure( new CreateTableProcedure(procExec.getEnvironment(), htd, regions, latch2)); ProcedureTestingUtility.waitProcedure(procExec, procId1); ProcedureTestingUtility.assertProcNotFailed(procExec.getResult(procId1)); ProcedureTestingUtility.waitProcedure(procExec, procId2); latch2.await(); }
@Test(timeout=60000) public void testCloneSnapshotToSameTable() throws Exception { // take the snapshot SnapshotProtos.SnapshotDescription snapshotDesc = getSnapshot(); final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); final TableName clonedTableName = TableName.valueOf(snapshotDesc.getTable()); final HTableDescriptor htd = createHTableDescriptor(clonedTableName, CF); long procId = ProcedureTestingUtility.submitAndWait( procExec, new CloneSnapshotProcedure(procExec.getEnvironment(), htd, snapshotDesc)); Procedure<?> result = procExec.getResult(procId); assertTrue(result.isFailed()); LOG.debug("Clone snapshot failed with exception: " + result.getException()); assertTrue( ProcedureTestingUtility.getExceptionCause(result) instanceof TableExistsException); }
/** * Creates a table with given table name and specified number of column * families if the table does not already exist. */ public void setupTable(TableName table, int cfs) throws IOException { try { LOG.info("Creating table " + table); HTableDescriptor htd = new HTableDescriptor(table); htd.addCoprocessor(MyObserver.class.getName()); MyObserver.sleepDuration = this.sleepDuration; for (int i = 0; i < 10; i++) { htd.addFamily(new HColumnDescriptor(family(i))); } UTIL.getAdmin().createTable(htd); } catch (TableExistsException tee) { LOG.info("Table " + table + " already exists"); } }
@Test(timeout = 180000) public void testCreateIndexTableWhenBothIndexAndUserTableExist() throws Exception { HBaseAdmin admin = UTIL.getHBaseAdmin(); IndexedHTableDescriptor iHtd = createIndexedHTableDescriptor("testCreateIndexTableWhenBothIndexAndUserTableExist", "cf", "index_name", "cf", "cq"); admin.createTable(iHtd); try { admin.createTable(iHtd); fail("Should throw TableExistsException " + "if both user table and index table exist."); } catch (TableExistsException t) { } }
private void createTable(HColumnDescriptor family, TableName table) throws IOException { HTableDescriptor hbTable = new HTableDescriptor(table); hbTable.addFamily(family); try { admin.createTable(hbTable); } catch (TableExistsException e) { if (!admin.tableExists(table)) { //Schroedinger's cat: TableExistsException but does not exist at the same time throw new IllegalStateException("Table should exist but does not", e); } //table was created in the meantime return; } log.info("Created HBase table '{}'", table.getNameAsString()); }
static void checkAndSetEnablingTable(final AssignmentManager assignmentManager, final TableName tableName, boolean skipTableStateCheck) throws IOException { // If we have multiple client threads trying to create the table at the // same time, given the async nature of the operation, the table // could be in a state where hbase:meta table hasn't been updated yet in // the process() function. // Use enabling state to tell if there is already a request for the same // table in progress. This will introduce a new zookeeper call. Given // createTable isn't a frequent operation, that should be ok. // TODO: now that we have table locks, re-evaluate above -- table locks are not enough. // We could have cleared the hbase.rootdir and not zk. How can we detect this case? // Having to clean zk AND hdfs is awkward. try { if (skipTableStateCheck) { assignmentManager.getTableStateManager().setTableState( tableName, ZooKeeperProtos.Table.State.ENABLING); } else if (!assignmentManager.getTableStateManager().setTableStateIfNotInStates( tableName, ZooKeeperProtos.Table.State.ENABLING, ZooKeeperProtos.Table.State.ENABLING, ZooKeeperProtos.Table.State.ENABLED)) { throw new TableExistsException(tableName); } } catch (CoordinatedStateException e) { throw new IOException("Unable to ensure that the table will be" + " enabling because of a ZooKeeper issue", e); } }
@Override public void completionCleanup(Procedure proc) { if (proc instanceof TableProcedureInterface) { TableProcedureInterface iProcTable = (TableProcedureInterface)proc; boolean tableDeleted; if (proc.hasException()) { IOException procEx = proc.getException().unwrapRemoteException(); if (iProcTable.getTableOperationType() == TableOperationType.CREATE) { // create failed because the table already exist tableDeleted = !(procEx instanceof TableExistsException); } else { // the operation failed because the table does not exist tableDeleted = (procEx instanceof TableNotFoundException); } } else { // the table was deleted tableDeleted = (iProcTable.getTableOperationType() == TableOperationType.DELETE); } if (tableDeleted) { markTableAsDeleted(iProcTable.getTableName()); return; } } else { // No cleanup for ServerProcedureInterface types, yet. return; } }
/** * Check quota to create table. We add the table information to namespace state cache, assuming * the operation will pass. If the operation fails, then the next time namespace state chore runs * namespace state cache will be corrected. * @param tName - The table name to check quota. * @param regions - Number of regions that will be added. * @throws IOException Signals that an I/O exception has occurred. */ public void checkQuotaToCreateTable(TableName tName, int regions) throws IOException { if (stateManager.isInitialized()) { // We do this check to fail fast. if (MetaTableAccessor.tableExists(this.masterServices.getConnection(), tName)) { throw new TableExistsException(tName); } stateManager.checkAndUpdateNamespaceTableCount(tName, regions); } else { checkTableTypeAndThrowException(tName); } }
/** * For HADOOP-2579 * @throws IOException */ @Test (expected=TableExistsException.class, timeout=300000) public void testTableExistsExceptionWithATable() throws IOException { final TableName name = TableName.valueOf("testTableExistsExceptionWithATable"); TEST_UTIL.createTable(name, HConstants.CATALOG_FAMILY).close(); TEST_UTIL.createTable(name, HConstants.CATALOG_FAMILY); }
/** * Creates a table with given table name,specified number of column families<br> * and splitkeys if the table does not already exist. * @param table * @param cfs * @param SPLIT_KEYS */ private void setupTableWithSplitkeys(TableName table, int cfs, byte[][] SPLIT_KEYS) throws IOException { try { LOG.info("Creating table " + table); HTableDescriptor htd = new HTableDescriptor(table); for (int i = 0; i < cfs; i++) { htd.addFamily(new HColumnDescriptor(family(i))); } util.createTable(htd, SPLIT_KEYS); } catch (TableExistsException tee) { LOG.info("Table " + table + " already exists"); } }
@Override public HTableDescriptor get(TableName tablename) throws TableExistsException, FileNotFoundException, IOException { LOG.info((super.isUsecache() ? "Cached" : "Non-Cached") + " HTableDescriptor.get() on " + tablename + ", cachehits=" + this.cachehits); return super.get(tablename); }
/** * Creates a table with given table name and specified number of column * families if the table does not already exist. */ private void setupTable(TableName table, int cfs) throws IOException { try { LOG.info("Creating table " + table); HTableDescriptor htd = new HTableDescriptor(table); for (int i = 0; i < 10; i++) { htd.addFamily(new HColumnDescriptor(family(i))); } UTIL.getHBaseAdmin().createTable(htd); } catch (TableExistsException tee) { LOG.info("Table " + table + " already exists"); } }
private static void create(Admin admin, TableName tableName, byte[]... families) throws IOException { HTableDescriptor desc = new HTableDescriptor(tableName); for (byte[] family : families) { HColumnDescriptor colDesc = new HColumnDescriptor(family); colDesc.setMaxVersions(1); colDesc.setCompressionType(Algorithm.GZ); desc.addFamily(colDesc); } try { admin.createTable(desc); } catch (TableExistsException tee) { /* Ignore */ } }
@Override public void cloneSnapshot(byte[] name, TableName tn) throws IOException, TableExistsException, RestoreSnapshotException, UnsupportedOperationException { if (repository.isActivated()) { throw new UnsupportedOperationException(UNSUPPORTED_WHEN_COLMANAGER_ACTIVATED_MSG); } wrappedHbaseAdmin.cloneSnapshot(name, tn); }
@Override public void cloneSnapshot(String string, TableName tn) throws IOException, TableExistsException, RestoreSnapshotException, UnsupportedOperationException { if (repository.isActivated()) { throw new UnsupportedOperationException(UNSUPPORTED_WHEN_COLMANAGER_ACTIVATED_MSG); } wrappedHbaseAdmin.cloneSnapshot(string, tn); }
@Before public void setUp() throws Exception { if (systemReady) { try { hbaseUtil.createTable(HBaseHelper.getHBaseFieldAsBytes(PERSON_TABLE), families); } catch (TableExistsException ex) { //Ignore if table exists } super.setUp(); } }
@Before public void setUp() throws Exception { if (systemReady) { try { hbaseUtil.createTable(HBaseHelper.getHBaseFieldAsBytes(PERSON_TABLE), HBaseHelper.getHBaseFieldAsBytes(INFO_FAMILY)); } catch (TableExistsException ex) { //Ignore if table exists } this.repository = new HBaseIdempotentRepository(hbaseUtil.getConfiguration(), PERSON_TABLE, INFO_FAMILY, "mycolumn"); super.setUp(); } }