ClusterSchemaServiceImpl(final MasterServices masterServices) { this.masterServices = masterServices; this.tableNamespaceManager = new TableNamespaceManager(masterServices); }
/** * Action before any real action of adding namespace. * @param env MasterProcedureEnv * @throws IOException */ private boolean prepareModify(final MasterProcedureEnv env) throws IOException { if (getTableNamespaceManager(env).doesNamespaceExist(newNsDescriptor.getName()) == false) { setFailure("master-modify-namespace", new NamespaceNotFoundException(newNsDescriptor.getName())); return false; } try { getTableNamespaceManager(env).validateTableAndRegionCount(newNsDescriptor); } catch (ConstraintException e) { setFailure("master-modify-namespace", e); return false; } // This is used for rollback oldNsDescriptor = getTableNamespaceManager(env).get(newNsDescriptor.getName()); return true; } }
public void validateTableAndRegionCount(NamespaceDescriptor desc) throws IOException { if (getMaxRegions(desc) <= 0) { throw new ConstraintException( "The max region quota for " + desc.getName() + " is less than or equal to zero."); } if (getMaxTables(desc) <= 0) { throw new ConstraintException( "The max tables quota for " + desc.getName() + " is less than or equal to zero."); } }
/** * Action before any real action of creating namespace. * @param env MasterProcedureEnv */ private boolean prepareCreate(final MasterProcedureEnv env) throws IOException { if (getTableNamespaceManager(env).doesNamespaceExist(nsDescriptor.getName())) { setFailure("master-create-namespace", new NamespaceExistException("Namespace " + nsDescriptor.getName() + " already exists")); return false; } getTableNamespaceManager(env).validateTableAndRegionCount(nsDescriptor); return true; }
private void create(Table table, NamespaceDescriptor ns) throws IOException { if (get(table, ns.getName()) != null) { throw new NamespaceExistException(ns.getName()); } validateTableAndRegionCount(ns); FileSystem fs = masterServices.getMasterFileSystem().getFileSystem(); fs.mkdirs(FSUtils.getNamespaceDir( masterServices.getMasterFileSystem().getRootDir(), ns.getName())); upsert(table, ns); if (this.masterServices.isInitialized()) { this.masterServices.getMasterQuotaManager().setNamespaceQuota(ns); } }
currentStatus = getState(namespace); int regionCount = currentStatus.getRegionCount(); long maxRegionCount = TableNamespaceManager.getMaxRegions(nspdesc); if (incr > 0 && regionCount >= maxRegionCount) { LOG.warn("The region " + Bytes.toStringBinary(regionName)
void initNamespace() throws IOException { //create namespace manager tableNamespaceManager = new TableNamespaceManager(this); tableNamespaceManager.start(); }
public synchronized void update(NamespaceDescriptor ns) throws IOException { Table table = getNamespaceTable(); if (get(table, ns.getName()) == null) { throw new NamespaceNotFoundException(ns.getName()); } upsert(table, ns); }
if (isTableAssigned()) { try { nsTable = this.masterServices.getConnection().getTable(TableName.NAMESPACE_TABLE_NAME); zkNamespaceManager.start(); if (get(nsTable, NamespaceDescriptor.DEFAULT_NAMESPACE.getName()) == null) { create(nsTable, NamespaceDescriptor.DEFAULT_NAMESPACE); if (get(nsTable, NamespaceDescriptor.SYSTEM_NAMESPACE.getName()) == null) { create(nsTable, NamespaceDescriptor.SYSTEM_NAMESPACE);
@Override public NamespaceDescriptor getNamespace(String name) throws IOException { NamespaceDescriptor nsd = getTableNamespaceManager().get(name); if (nsd == null) throw new NamespaceNotFoundException(name); return nsd; }
if (getTableNamespaceManager(env).doesNamespaceExist(namespaceName) == false) { setFailure("master-delete-namespace", new NamespaceNotFoundException(namespaceName)); return false; nsDescriptor = getTableNamespaceManager(env).get(namespaceName); return true;
public void start() throws IOException { if (!MetaTableAccessor.tableExists(masterServices.getConnection(), TableName.NAMESPACE_TABLE_NAME)) { LOG.info("Namespace table not found. Creating..."); createNamespaceTable(masterServices); } try { // Wait for the namespace table to be assigned. // If timed out, we will move ahead without initializing it. // So that it should be initialized later on lazily. long startTime = EnvironmentEdgeManager.currentTime(); int timeout = conf.getInt(NS_INIT_TIMEOUT, DEFAULT_NS_INIT_TIMEOUT); while (!isTableAssigned()) { if (EnvironmentEdgeManager.currentTime() - startTime + 100 > timeout) { // We can't do anything if ns is not online. throw new IOException("Timedout " + timeout + "ms waiting for namespace table to " + "be assigned"); } Thread.sleep(100); } } catch (InterruptedException e) { throw (InterruptedIOException)new InterruptedIOException().initCause(e); } // initialize namespace table isTableAvailableAndInitialized(); }
public synchronized void remove(String name) throws IOException { if (get(name) == null) { throw new NamespaceNotFoundException(name); getNamespaceTable().delete(d);
@Override public List<NamespaceDescriptor> getNamespaces() throws IOException { checkIsRunning(); return getTableNamespaceManager().list().stream() .sorted(NamespaceDescriptor.NAMESPACE_DESCRIPTOR_COMPARATOR) .collect(ImmutableList.toImmutableList()); } }
@Override public synchronized void doStart() { try { notifyStarted(); this.tableNamespaceManager.start(); } catch (IOException ioe) { notifyFailed(ioe); } }
public synchronized void create(NamespaceDescriptor ns) throws IOException { create(getNamespaceTable(), ns); }
private void upsert(Table table, NamespaceDescriptor ns) throws IOException { validateTableAndRegionCount(ns); Put p = new Put(Bytes.toBytes(ns.getName())); p.addImmutable(HTableDescriptor.NAMESPACE_FAMILY_INFO_BYTES, HTableDescriptor.NAMESPACE_COL_DESC_BYTES, ProtobufUtil.toProtoNamespaceDescriptor(ns).toByteArray()); table.put(p); try { zkNamespaceManager.update(ns); } catch(IOException ex) { String msg = "Failed to update namespace information in ZK. Aborting."; LOG.fatal(msg, ex); masterServices.abort(msg, ex); } }
/** * Insert/update the row into the ns family of meta table. * @param env MasterProcedureEnv */ protected static void addOrUpdateNamespace(MasterProcedureEnv env, NamespaceDescriptor ns) throws IOException { getTableNamespaceManager(env).addOrUpdateNamespace(ns); }
@Override public void createNamespace(NamespaceDescriptor descriptor) throws IOException { TableName.isLegalNamespaceName(Bytes.toBytes(descriptor.getName())); checkNamespaceManagerReady(); if (cpHost != null) { if (cpHost.preCreateNamespace(descriptor)) { return; } } LOG.info(getClientIdAuditPrefix() + " creating " + descriptor); tableNamespaceManager.create(descriptor); if (cpHost != null) { cpHost.postCreateNamespace(descriptor); } }
/** * Check and update region count for an existing table. To handle scenarios like restore snapshot * @param name name of the table for region count needs to be checked and updated * @param incr count of regions * @throws QuotaExceededException if quota exceeds for the number of regions allowed in a * namespace * @throws IOException Signals that an I/O exception has occurred. */ synchronized void checkAndUpdateNamespaceRegionCount(TableName name, int incr) throws IOException { String namespace = name.getNamespaceAsString(); NamespaceDescriptor nspdesc = getNamespaceDescriptor(namespace); if (nspdesc != null) { NamespaceTableAndRegionInfo currentStatus = getState(namespace); int regionCountOfTable = currentStatus.getRegionCountOfTable(name); if ((currentStatus.getRegionCount() - regionCountOfTable + incr) > TableNamespaceManager .getMaxRegions(nspdesc)) { throw new QuotaExceededException("The table " + name.getNameAsString() + " region count cannot be updated as it would exceed maximum number " + "of regions allowed in the namespace. The total number of regions permitted is " + TableNamespaceManager.getMaxRegions(nspdesc)); } currentStatus.removeTable(name); currentStatus.addTable(name, incr); } }