Java Code Examples for org.apache.hadoop.hbase.MetaTableAccessor#tableExists()
The following examples show how to use
org.apache.hadoop.hbase.MetaTableAccessor#tableExists() .
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: VisibilityController.java From hbase with Apache License 2.0 | 6 votes |
/********************************* Master related hooks **********************************/ @Override public void postStartMaster(ObserverContext<MasterCoprocessorEnvironment> ctx) throws IOException { // Need to create the new system table for labels here if (!MetaTableAccessor.tableExists(ctx.getEnvironment().getConnection(), LABELS_TABLE_NAME)) { TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor = new TableDescriptorBuilder.ModifyableTableDescriptor(LABELS_TABLE_NAME); ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor familyDescriptor = new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(LABELS_TABLE_FAMILY); familyDescriptor.setBloomFilterType(BloomType.NONE); // We will cache all the labels. No need of normal // table block cache. familyDescriptor.setBlockCacheEnabled(false); tableDescriptor.setColumnFamily(familyDescriptor); // Let the "labels" table having only one region always. We are not expecting too many labels in // the system. tableDescriptor.setValue(HTableDescriptor.SPLIT_POLICY, DisabledRegionSplitPolicy.class.getName()); try (Admin admin = ctx.getEnvironment().getConnection().getAdmin()) { admin.createTable(tableDescriptor); } } }
Example 2
Source File: CreateTableProcedure.java From hbase with Apache License 2.0 | 5 votes |
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; } if (!tableName.isSystemTable()) { // do not check rs group for system tables as we may block the bootstrap. Supplier<String> forWhom = () -> "table " + tableName; RSGroupInfo rsGroupInfo = MasterProcedureUtil.checkGroupExists( env.getMasterServices().getRSGroupInfoManager()::getRSGroup, tableDescriptor.getRegionServerGroup(), forWhom); if (rsGroupInfo == null) { // we do not set rs group info on table, check if we have one on namespace String namespace = tableName.getNamespaceAsString(); NamespaceDescriptor nd = env.getMasterServices().getClusterSchema().getNamespace(namespace); forWhom = () -> "table " + tableName + "(inherit from namespace)"; rsGroupInfo = MasterProcedureUtil.checkGroupExists( env.getMasterServices().getRSGroupInfoManager()::getRSGroup, MasterProcedureUtil.getNamespaceGroup(nd), forWhom); } MasterProcedureUtil.checkGroupNotEmpty(rsGroupInfo, forWhom); } return true; }
Example 3
Source File: NamespaceAuditor.java From hbase with Apache License 2.0 | 5 votes |
/** * 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); } }
Example 4
Source File: SlowLogMasterService.java From hbase with Apache License 2.0 | 5 votes |
public void init() throws IOException { if (!slowlogTableEnabled) { LOG.info("Slow/Large requests logging to system table hbase:slowlog is disabled. Quitting."); return; } if (!MetaTableAccessor.tableExists(masterServices.getConnection(), SlowLogTableAccessor.SLOW_LOG_TABLE_NAME)) { LOG.info("slowlog table not found. Creating."); this.masterServices.createSystemTable(TABLE_DESCRIPTOR_BUILDER.build()); } }
Example 5
Source File: EnableTableProcedure.java From hbase with Apache License 2.0 | 5 votes |
/** * Action before any real action of enabling table. Set the exception in the procedure instead * of throwing it. This approach is to deal with backward compatible with 1.0. * @param env MasterProcedureEnv * @return whether the table passes the necessary checks * @throws IOException */ private boolean prepareEnable(final MasterProcedureEnv env) throws IOException { boolean canTableBeEnabled = true; // Check whether table exists if (!MetaTableAccessor.tableExists(env.getMasterServices().getConnection(), tableName)) { setFailure("master-enable-table", new TableNotFoundException(tableName)); canTableBeEnabled = false; } else { // There could be multiple client requests trying to disable or enable // the table at the same time. Ensure only the first request is honored // After that, no other requests can be accepted until the table reaches // DISABLED or ENABLED. // // Note: in 1.0 release, we called TableStateManager.setTableStateIfInStates() to set // the state to ENABLING from DISABLED. The implementation was done before table lock // was implemented. With table lock, there is no need to set the state here (it will // set the state later on). A quick state check should be enough for us to move forward. TableStateManager tsm = env.getMasterServices().getTableStateManager(); TableState ts = tsm.getTableState(tableName); if(!ts.isDisabled()){ LOG.info("Not DISABLED tableState={}; skipping enable; {}", ts.getState(), this); setFailure("master-enable-table", new TableNotDisabledException(ts.toString())); canTableBeEnabled = false; } } // We are done the check. Future actions in this procedure could be done asynchronously. releaseSyncLatch(); return canTableBeEnabled; }
Example 6
Source File: CloneSnapshotProcedure.java From hbase with Apache License 2.0 | 5 votes |
/** * Action before any real action of cloning from snapshot. * @param env MasterProcedureEnv * @throws IOException */ private void prepareClone(final MasterProcedureEnv env) throws IOException { final TableName tableName = getTableName(); if (MetaTableAccessor.tableExists(env.getMasterServices().getConnection(), tableName)) { throw new TableExistsException(getTableName()); } }
Example 7
Source File: DisableTableProcedure.java From hbase with Apache License 2.0 | 5 votes |
/** * Action before any real action of disabling table. Set the exception in the procedure instead * of throwing it. This approach is to deal with backward compatible with 1.0. * @param env MasterProcedureEnv */ private boolean prepareDisable(final MasterProcedureEnv env) throws IOException { boolean canTableBeDisabled = true; if (tableName.equals(TableName.META_TABLE_NAME)) { setFailure("master-disable-table", new ConstraintException("Cannot disable " + this.tableName)); canTableBeDisabled = false; } else if (!MetaTableAccessor.tableExists(env.getMasterServices().getConnection(), tableName)) { setFailure("master-disable-table", new TableNotFoundException(tableName)); canTableBeDisabled = false; } else if (!skipTableStateCheck) { // There could be multiple client requests trying to disable or enable // the table at the same time. Ensure only the first request is honored // After that, no other requests can be accepted until the table reaches // DISABLED or ENABLED. // // Note: in 1.0 release, we called TableStateManager.setTableStateIfInStates() to set // the state to DISABLING from ENABLED. The implementation was done before table lock // was implemented. With table lock, there is no need to set the state here (it will // set the state later on). A quick state check should be enough for us to move forward. TableStateManager tsm = env.getMasterServices().getTableStateManager(); TableState ts = tsm.getTableState(tableName); if (!ts.isEnabled()) { LOG.info("Not ENABLED, state={}, skipping disable; {}", ts.getState(), this); setFailure("master-disable-table", new TableNotEnabledException(ts.toString())); canTableBeDisabled = false; } } // We are done the check. Future actions in this procedure could be done asynchronously. releaseSyncLatch(); return canTableBeDisabled; }
Example 8
Source File: AbstractStateMachineRegionProcedure.java From hbase with Apache License 2.0 | 5 votes |
/** * Check whether a table is modifiable - exists and either offline or online with config set * @param env MasterProcedureEnv * @throws IOException */ @Override protected void checkTableModifiable(final MasterProcedureEnv env) throws IOException { // Checks whether the table exists if (!MetaTableAccessor.tableExists(env.getMasterServices().getConnection(), getTableName())) { throw new TableNotFoundException(getTableName()); } }
Example 9
Source File: AbstractStateMachineTableProcedure.java From hbase with Apache License 2.0 | 5 votes |
/** * Check whether a table is modifiable - exists and either offline or online with config set * @param env MasterProcedureEnv * @throws IOException */ protected void checkTableModifiable(final MasterProcedureEnv env) throws IOException { // Checks whether the table exists if (!MetaTableAccessor.tableExists(env.getMasterServices().getConnection(), getTableName())) { throw new TableNotFoundException(getTableName()); } }
Example 10
Source File: RestoreSnapshotProcedure.java From hbase with Apache License 2.0 | 5 votes |
/** * Action before any real action of restoring from snapshot. * @param env MasterProcedureEnv * @throws IOException */ private void prepareRestore(final MasterProcedureEnv env) throws IOException { final TableName tableName = getTableName(); // Checks whether the table exists if (!MetaTableAccessor.tableExists(env.getMasterServices().getConnection(), tableName)) { throw new TableNotFoundException(tableName); } // Check whether table is disabled. env.getMasterServices().checkTableModifiable(tableName); // Check that we have at least 1 CF if (modifiedTableDescriptor.getColumnFamilyCount() == 0) { throw new DoNotRetryIOException("Table " + getTableName().toString() + " should have at least one column family."); } if (!getTableName().isSystemTable()) { // Table already exist. Check and update the region quota for this table namespace. final MasterFileSystem mfs = env.getMasterServices().getMasterFileSystem(); SnapshotManifest manifest = SnapshotManifest.open( env.getMasterConfiguration(), mfs.getFileSystem(), SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshot, mfs.getRootDir()), snapshot); int snapshotRegionCount = manifest.getRegionManifestsMap().size(); int tableRegionCount = ProcedureSyncWait.getMasterQuotaManager(env).getRegionCountOfTable(tableName); if (snapshotRegionCount > 0 && tableRegionCount != snapshotRegionCount) { ProcedureSyncWait.getMasterQuotaManager(env).checkAndUpdateNamespaceRegionQuota( tableName, snapshotRegionCount); } } }
Example 11
Source File: MasterQuotaManager.java From hbase with Apache License 2.0 | 5 votes |
public void start() throws IOException { // If the user doesn't want the quota support skip all the initializations. if (!QuotaUtil.isQuotaEnabled(masterServices.getConfiguration())) { LOG.info("Quota support disabled"); return; } // Create the quota table if missing if (!MetaTableAccessor.tableExists(masterServices.getConnection(), QuotaUtil.QUOTA_TABLE_NAME)) { LOG.info("Quota table not found. Creating..."); createQuotaTable(); } LOG.info("Initializing quota support"); namespaceLocks = new NamedLock<>(); tableLocks = new NamedLock<>(); userLocks = new NamedLock<>(); regionServerLocks = new NamedLock<>(); regionSizes = new ConcurrentHashMap<>(); namespaceQuotaManager = new NamespaceAuditor(masterServices); namespaceQuotaManager.start(); initialized = true; rpcThrottleStorage = new RpcThrottleStorage(masterServices.getZooKeeper(), masterServices.getConfiguration()); }
Example 12
Source File: LocalIndexSplitter.java From phoenix with Apache License 2.0 | 4 votes |
@Override public void preSplitBeforePONR(ObserverContext<RegionCoprocessorEnvironment> ctx, byte[] splitKey, List<Mutation> metaEntries) throws IOException { RegionCoprocessorEnvironment environment = ctx.getEnvironment(); HTableDescriptor tableDesc = ctx.getEnvironment().getRegion().getTableDesc(); if (SchemaUtil.isSystemTable(tableDesc.getName())) { return; } RegionServerServices rss = ctx.getEnvironment().getRegionServerServices(); if (tableDesc.getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_BYTES) == null || !Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(tableDesc .getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_BYTES)))) { TableName indexTable = TableName.valueOf(MetaDataUtil.getLocalIndexPhysicalName(tableDesc.getName())); if (!MetaTableAccessor.tableExists(rss.getConnection(), indexTable)) return; HRegion indexRegion = IndexUtil.getIndexRegion(environment); if (indexRegion == null) { LOG.warn("Index region corresponindg to data region " + environment.getRegion() + " not in the same server. So skipping the split."); ctx.bypass(); return; } try { int encodedVersion = VersionUtil.encodeVersion(environment.getHBaseVersion()); if(encodedVersion >= SPLIT_TXN_MINIMUM_SUPPORTED_VERSION) { st = new SplitTransaction(indexRegion, splitKey); st.useZKForAssignment = environment.getConfiguration().getBoolean("hbase.assignment.usezk", true); } else { st = new IndexSplitTransaction(indexRegion, splitKey); } if (!st.prepare()) { LOG.error("Prepare for the table " + indexRegion.getTableDesc().getNameAsString() + " failed. So returning null. "); ctx.bypass(); return; } indexRegion.forceSplit(splitKey); daughterRegions = st.stepsBeforePONR(rss, rss, false); HRegionInfo copyOfParent = new HRegionInfo(indexRegion.getRegionInfo()); copyOfParent.setOffline(true); copyOfParent.setSplit(true); // Put for parent Put putParent = MetaTableAccessor.makePutFromRegionInfo(copyOfParent); MetaTableAccessor.addDaughtersToPut(putParent, daughterRegions.getFirst().getRegionInfo(), daughterRegions.getSecond().getRegionInfo()); metaEntries.add(putParent); // Puts for daughters Put putA = MetaTableAccessor.makePutFromRegionInfo( daughterRegions.getFirst().getRegionInfo()); Put putB = MetaTableAccessor.makePutFromRegionInfo( daughterRegions.getSecond().getRegionInfo()); st.addLocation(putA, rss.getServerName(), 1); st.addLocation(putB, rss.getServerName(), 1); metaEntries.add(putA); metaEntries.add(putB); } catch (Exception e) { ctx.bypass(); LOG.warn("index region splitting failed with the exception ", e); if (st != null){ st.rollback(rss, rss); st = null; daughterRegions = null; } } } }
Example 13
Source File: HMaster.java From hbase with Apache License 2.0 | 4 votes |
private void checkTableExists(final TableName tableName) throws IOException, TableNotFoundException { if (!MetaTableAccessor.tableExists(getConnection(), tableName)) { throw new TableNotFoundException(tableName); } }
Example 14
Source File: ModifyTableProcedure.java From hbase with Apache License 2.0 | 4 votes |
/** * Check conditions before any real action of modifying a table. */ private void prepareModify(final MasterProcedureEnv env) throws IOException { // Checks whether the table exists if (!MetaTableAccessor.tableExists(env.getMasterServices().getConnection(), getTableName())) { throw new TableNotFoundException(getTableName()); } // check that we have at least 1 CF if (modifiedTableDescriptor.getColumnFamilyCount() == 0) { throw new DoNotRetryIOException("Table " + getTableName().toString() + " should have at least one column family."); } // If descriptor check is enabled, check whether the table descriptor when procedure was // submitted matches with the current // table descriptor of the table, else retrieve the old descriptor // for comparison in order to update the descriptor. if (shouldCheckDescriptor) { if (TableDescriptor.COMPARATOR.compare(unmodifiedTableDescriptor, env.getMasterServices().getTableDescriptors().get(getTableName())) != 0) { LOG.error("Error while modifying table '" + getTableName().toString() + "' Skipping procedure : " + this); throw new ConcurrentTableModificationException( "Skipping modify table operation on table '" + getTableName().toString() + "' as it has already been modified by some other concurrent operation, " + "Please retry."); } } else { this.unmodifiedTableDescriptor = env.getMasterServices().getTableDescriptors().get(getTableName()); } if (env.getMasterServices().getTableStateManager() .isTableState(getTableName(), TableState.State.ENABLED)) { if (modifiedTableDescriptor.getRegionReplication() != unmodifiedTableDescriptor .getRegionReplication()) { throw new TableNotDisabledException( "REGION_REPLICATION change is not supported for enabled tables"); } } this.deleteColumnFamilyInModify = isDeleteColumnFamily(unmodifiedTableDescriptor, modifiedTableDescriptor); if (!unmodifiedTableDescriptor.getRegionServerGroup() .equals(modifiedTableDescriptor.getRegionServerGroup())) { Supplier<String> forWhom = () -> "table " + getTableName(); RSGroupInfo rsGroupInfo = MasterProcedureUtil.checkGroupExists( env.getMasterServices().getRSGroupInfoManager()::getRSGroup, modifiedTableDescriptor.getRegionServerGroup(), forWhom); MasterProcedureUtil.checkGroupNotEmpty(rsGroupInfo, forWhom); } }
Example 15
Source File: SnapshotManager.java From hbase with Apache License 2.0 | 4 votes |
/** * Restore or Clone the specified snapshot * @param reqSnapshot * @param nonceKey unique identifier to prevent duplicated RPC * @throws IOException */ public long restoreOrCloneSnapshot(final SnapshotDescription reqSnapshot, final NonceKey nonceKey, final boolean restoreAcl) throws IOException { FileSystem fs = master.getMasterFileSystem().getFileSystem(); Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(reqSnapshot, rootDir); // check if the snapshot exists if (!fs.exists(snapshotDir)) { LOG.error("A Snapshot named '" + reqSnapshot.getName() + "' does not exist."); throw new SnapshotDoesNotExistException( ProtobufUtil.createSnapshotDesc(reqSnapshot)); } // Get snapshot info from file system. The reqSnapshot is a "fake" snapshotInfo with // just the snapshot "name" and table name to restore. It does not contains the "real" snapshot // information. SnapshotDescription snapshot = SnapshotDescriptionUtils.readSnapshotInfo(fs, snapshotDir); SnapshotManifest manifest = SnapshotManifest.open(master.getConfiguration(), fs, snapshotDir, snapshot); TableDescriptor snapshotTableDesc = manifest.getTableDescriptor(); TableName tableName = TableName.valueOf(reqSnapshot.getTable()); // sanity check the new table descriptor TableDescriptorChecker.sanityCheck(master.getConfiguration(), snapshotTableDesc); // stop tracking "abandoned" handlers cleanupSentinels(); // Verify snapshot validity SnapshotReferenceUtil.verifySnapshot(master.getConfiguration(), fs, manifest); // Execute the restore/clone operation long procId; if (MetaTableAccessor.tableExists(master.getConnection(), tableName)) { procId = restoreSnapshot(reqSnapshot, tableName, snapshot, snapshotTableDesc, nonceKey, restoreAcl); } else { procId = cloneSnapshot(reqSnapshot, tableName, snapshot, snapshotTableDesc, nonceKey, restoreAcl); } return procId; }
Example 16
Source File: SnapshotScannerHDFSAclCleaner.java From hbase with Apache License 2.0 | 4 votes |
private boolean tableExists(TableName tableName) throws IOException { return master != null && MetaTableAccessor.tableExists(master.getConnection(), tableName); }
Example 17
Source File: LocalIndexMerger.java From phoenix with Apache License 2.0 | 4 votes |
@Override public void preMergeCommit(ObserverContext<RegionServerCoprocessorEnvironment> ctx, HRegion regionA, HRegion regionB, List<Mutation> metaEntries) throws IOException { HTableDescriptor tableDesc = regionA.getTableDesc(); if (SchemaUtil.isSystemTable(tableDesc.getName())) { return; } RegionServerServices rss = ctx.getEnvironment().getRegionServerServices(); HRegionServer rs = (HRegionServer) rss; if (tableDesc.getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_BYTES) == null || !Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(tableDesc .getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_BYTES)))) { TableName indexTable = TableName.valueOf(MetaDataUtil.getLocalIndexPhysicalName(tableDesc.getName())); if (!MetaTableAccessor.tableExists(rs.getConnection(), indexTable)) return; HRegion indexRegionA = IndexUtil.getIndexRegion(regionA, ctx.getEnvironment()); if (indexRegionA == null) { LOG.warn("Index region corresponindg to data region " + regionA + " not in the same server. So skipping the merge."); ctx.bypass(); return; } HRegion indexRegionB = IndexUtil.getIndexRegion(regionB, ctx.getEnvironment()); if (indexRegionB == null) { LOG.warn("Index region corresponindg to region " + regionB + " not in the same server. So skipping the merge."); ctx.bypass(); return; } try { rmt = new RegionMergeTransaction(indexRegionA, indexRegionB, false); if (!rmt.prepare(rss)) { LOG.error("Prepare for the index regions merge [" + indexRegionA + "," + indexRegionB + "] failed. So returning null. "); ctx.bypass(); return; } this.mergedRegion = rmt.stepsBeforePONR(rss, rss, false); rmt.prepareMutationsForMerge(mergedRegion.getRegionInfo(), indexRegionA.getRegionInfo(), indexRegionB.getRegionInfo(), rss.getServerName(), metaEntries, 1); } catch (Exception e) { ctx.bypass(); LOG.warn("index regions merge failed with the exception ", e); if (rmt != null) { rmt.rollback(rss, rss); rmt = null; mergedRegion = null; } } } }
Example 18
Source File: SpaceQuotaRefresherChore.java From hbase with Apache License 2.0 | 2 votes |
/** * Checks if hbase:quota exists in hbase:meta * * @return true if hbase:quota table is in meta, else returns false. * @throws IOException throws IOException */ boolean checkQuotaTableExists() throws IOException { return MetaTableAccessor.tableExists(getConnection(), QuotaUtil.QUOTA_TABLE_NAME); }