public Set<String> getNamespacesWithQuotas() { Set<String> namespaces = new HashSet<>(); for (TableName tn : tablesWithNamespaceQuotas) { namespaces.add(tn.getNamespaceAsString()); } return namespaces; }
private void addTable(TableName tableName, int regionCount) throws IOException { NamespaceTableAndRegionInfo info = nsStateCache.get(tableName.getNamespaceAsString()); if(info != null) { info.addTable(tableName, regionCount); } else { throw new IOException("Bad state : Namespace quota information not found for namespace : " + tableName.getNamespaceAsString()); } }
synchronized void addTable(TableName tableName, int regionCount) { if (!name.equalsIgnoreCase(tableName.getNamespaceAsString())) { throw new IllegalStateException("Table : " + tableName + " does not belong to namespace " + name); } if (!tableAndRegionInfo.containsKey(tableName)) { tableAndRegionInfo.put(tableName, new AtomicInteger(regionCount)); } else { throw new IllegalStateException("Table already in the cache " + tableName); } }
synchronized void removeTable(TableName tableName) { NamespaceTableAndRegionInfo info = nsStateCache.get(tableName.getNamespaceAsString()); if (info != null) { info.removeTable(tableName); } }
@Override public boolean apply(Entry<RegionInfo,Long> input) { return namespace.equals(input.getKey().getTable().getNamespaceAsString()); } });
@VisibleForTesting public static String qualifyMetricsName(TableName tableName, String metric) { StringBuilder sb = new StringBuilder(); sb.append("Namespace_").append(tableName.getNamespaceAsString()); sb.append("_table_").append(tableName.getQualifierAsString()); sb.append("_metric_").append(metric); return sb.toString(); }
private String getHFilePath(TableName table, BulkLoadDescriptor bld, String storeFile, byte[] family) { return new StringBuilder(100).append(table.getNamespaceAsString()).append(Path.SEPARATOR) .append(table.getQualifierAsString()).append(Path.SEPARATOR) .append(Bytes.toString(bld.getEncodedRegionName().toByteArray())).append(Path.SEPARATOR) .append(Bytes.toString(family)).append(Path.SEPARATOR).append(storeFile).toString(); }
/** * Returns the Table directory under the WALRootDir for the specified table name * @param conf configuration used to get the WALRootDir * @param tableName Table to get the directory for * @return a path to the WAL table directory for the specified table * @throws IOException if there is an exception determining the WALRootDir */ public static Path getWALTableDir(final Configuration conf, final TableName tableName) throws IOException { return new Path(new Path(getWALRootDir(conf), tableName.getNamespaceAsString()), tableName.getQualifierAsString()); }
protected Path getBulkOutputDirForTable(TableName table) { Path tablePath = getBulkOutputDir(); tablePath = new Path(tablePath, table.getNamespaceAsString()); tablePath = new Path(tablePath, table.getQualifierAsString()); return new Path(tablePath, "data"); }
/** * Ideally, getNameAsString should contain namespace within it, * but if the namespace is default, it just returns the name. This method * takes care of this corner case. */ public String getNameWithNamespaceInclAsString() { if(getNamespaceAsString().equals(NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR)) { return NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR + TableName.NAMESPACE_DELIM + getNameAsString(); } return getNameAsString(); }
/** * Returns the {@link org.apache.hadoop.fs.Path} object representing the table directory under * path rootdir * * @param rootdir qualified path of HBase root directory * @param tableName name of table * @return {@link org.apache.hadoop.fs.Path} for table */ public static Path getTableDir(Path rootdir, final TableName tableName) { return new Path(getNamespaceDir(rootdir, tableName.getNamespaceAsString()), tableName.getQualifierAsString()); }
public MetricsTableSourceImpl(String tblName, MetricsTableAggregateSourceImpl aggregate, MetricsTableWrapperAggregate tblWrapperAgg) { LOG.debug("Creating new MetricsTableSourceImpl for table '{}'", tblName); this.tableName = TableName.valueOf(tblName); this.agg = aggregate; this.tableWrapperAgg = tblWrapperAgg; this.registry = agg.getMetricsRegistry(); this.tableNamePrefix = "Namespace_" + this.tableName.getNamespaceAsString() + "_table_" + this.tableName.getQualifierAsString() + "_metric_"; this.hashCode = this.tableName.hashCode(); }
public synchronized void removeRegionFromTable(RegionInfo hri) throws IOException { String namespace = hri.getTable().getNamespaceAsString(); NamespaceTableAndRegionInfo nsInfo = nsStateCache.get(namespace); if (nsInfo != null) { nsInfo.decrementRegionCountForTable(hri.getTable(), 1); } else { throw new IOException("Namespace state found null for namespace : " + namespace); } } }
/** * Returns a view of all tables that reside in a namespace with a namespace * quota, grouped by the namespace itself. */ public Multimap<String,TableName> getTablesByNamespace() { Multimap<String,TableName> tablesByNS = HashMultimap.create(); for (TableName tn : tablesWithNamespaceQuotas) { tablesByNS.put(tn.getNamespaceAsString(), tn); } return tablesByNS; }
@Override public String getNamespace() { TableDescriptor tableDesc = this.region.getTableDescriptor(); if (tableDesc == null) { return UNKNOWN; } return tableDesc.getTableName().getNamespaceAsString(); }
/*********************************** Observer implementations ***********************************/ @Override public void preCreateTable(ObserverContext<MasterCoprocessorEnvironment> c, TableDescriptor desc, RegionInfo[] regions) throws IOException { Set<byte[]> families = desc.getColumnFamilyNames(); Map<byte[], Set<byte[]>> familyMap = new TreeMap<>(Bytes.BYTES_COMPARATOR); for (byte[] family: families) { familyMap.put(family, null); } requireNamespacePermission(c, "createTable", desc.getTableName().getNamespaceAsString(), desc.getTableName(), familyMap, Action.CREATE); }
private TableQueue getTableQueue(TableName tableName) { TableQueue node = AvlTree.get(tableMap, tableName, TABLE_QUEUE_KEY_COMPARATOR); if (node != null) return node; node = new TableQueue(tableName, MasterProcedureUtil.getTablePriority(tableName), locking.getTableLock(tableName), locking.getNamespaceLock(tableName.getNamespaceAsString())); tableMap = AvlTree.insert(tableMap, node); return node; }
@Override public boolean evaluate() throws Exception { SpaceQuotaSnapshot snapshot = (SpaceQuotaSnapshot) conn.getAdmin() .getCurrentSpaceQuotaSnapshot(tn.getNamespaceAsString()); LOG.debug("Namespace snapshot after initial ingest: " + snapshot); if (snapshot == null) { return false; } nsUsage.set(snapshot.getUsage()); return snapshot.getLimit() == nsLimit && snapshot.getUsage() > 0; } });
@Override public boolean evaluate() throws Exception { SpaceQuotaSnapshot snapshot = (SpaceQuotaSnapshot) conn.getAdmin() .getCurrentSpaceQuotaSnapshot(tn.getNamespaceAsString()); LOG.debug("Namespace snapshot after second ingest: " + snapshot); if (snapshot == null) { return false; } return snapshot.getUsage() > nsUsage.get() && !snapshot.getQuotaStatus().isInViolation(); } });
private TableName validateNames(TableName expected, Names names) { assertEquals(expected.getNameAsString(), names.nn); assertArrayEquals(expected.getName(), names.nnb); assertEquals(expected.getQualifierAsString(), names.tn); assertArrayEquals(expected.getQualifier(), names.tnb); assertEquals(expected.getNamespaceAsString(), names.ns); assertArrayEquals(expected.getNamespace(), names.nsb); return expected; }