use of com.google.errorprone.annotations.RestrictedApi in project hbase by apache.
the class HeterogeneousRegionCountCostFunction method loadRules.
/**
* used to load the rule files.
*/
@RestrictedApi(explanation = "Should only be called in tests", link = "", allowedOnPath = ".*(/src/test/.*|HeterogeneousRegionCountCostFunction).java")
void loadRules() {
final List<String> lines = readFile(this.rulesPath);
if (null == lines) {
LOG.warn("cannot load rules file, keeping latest rules file which has " + this.limitPerRule.size() + " rules");
return;
}
LOG.info("loading rules file '" + this.rulesPath + "'");
this.limitPerRule.clear();
for (final String line : lines) {
try {
if (line.length() == 0) {
continue;
}
if (line.startsWith("#")) {
continue;
}
final List<String> splits = Splitter.on(' ').splitToList(line);
if (splits.size() != 2) {
throw new IOException("line '" + line + "' is malformated, " + "expected [regexp] [limit]. Skipping line");
}
final Pattern pattern = Pattern.compile(splits.get(0));
final Integer limit = Integer.parseInt(splits.get(1));
this.limitPerRule.put(pattern, limit);
} catch (final IOException | NumberFormatException | PatternSyntaxException e) {
LOG.error("error on line: " + e);
}
}
this.rebuildCache();
}
use of com.google.errorprone.annotations.RestrictedApi in project hbase by apache.
the class RegionHDFSBlockLocationFinder method mapHostNameToServerName.
/**
* Map hostname to ServerName, The output ServerName list will have the same order as input hosts.
* @param hosts the list of hosts
* @return ServerName list
*/
@RestrictedApi(explanation = "Should only be called in tests", link = "", allowedOnPath = ".*/src/test/.*|.*/RegionHDFSBlockLocationFinder.java")
List<ServerName> mapHostNameToServerName(List<String> hosts) {
if (hosts == null || status == null) {
if (hosts == null) {
LOG.warn("RegionLocationFinder top hosts is null");
}
return Collections.emptyList();
}
List<ServerName> topServerNames = new ArrayList<>();
Collection<ServerName> regionServers = status.getLiveServerMetrics().keySet();
// create a mapping from hostname to ServerName for fast lookup
Map<String, List<ServerName>> hostToServerName = new HashMap<>();
for (ServerName sn : regionServers) {
String host = sn.getHostname();
if (!hostToServerName.containsKey(host)) {
hostToServerName.put(host, new ArrayList<>());
}
hostToServerName.get(host).add(sn);
}
for (String host : hosts) {
if (!hostToServerName.containsKey(host)) {
continue;
}
for (ServerName sn : hostToServerName.get(host)) {
// but RS is down ( thus sn is null )
if (sn != null) {
topServerNames.add(sn);
}
}
}
return topServerNames;
}
use of com.google.errorprone.annotations.RestrictedApi in project hbase by apache.
the class FSTableDescriptors method getTableInfoSequenceIdAndFileLength.
/**
* Returns the current sequence id and file length or 0 if none found.
* @param p Path to a <code>.tableinfo</code> file.
*/
@RestrictedApi(explanation = "Should only be called in tests or self", link = "", allowedOnPath = ".*/src/test/.*|.*/FSTableDescriptors\\.java")
static SequenceIdAndFileLength getTableInfoSequenceIdAndFileLength(Path p) {
String name = p.getName();
if (!name.startsWith(TABLEINFO_FILE_PREFIX)) {
throw new IllegalArgumentException("Invalid table descriptor file name: " + name);
}
int firstDot = name.indexOf('.', TABLEINFO_FILE_PREFIX.length());
if (firstDot < 0) {
// oldest style where we do not have both sequence id and file length
return new SequenceIdAndFileLength(0, 0);
}
int secondDot = name.indexOf('.', firstDot + 1);
if (secondDot < 0) {
// old stype where we do not have file length
int sequenceId = Integer.parseInt(name.substring(firstDot + 1));
return new SequenceIdAndFileLength(sequenceId, 0);
}
int sequenceId = Integer.parseInt(name.substring(firstDot + 1, secondDot));
int fileLength = Integer.parseInt(name.substring(secondDot + 1));
return new SequenceIdAndFileLength(sequenceId, fileLength);
}
use of com.google.errorprone.annotations.RestrictedApi in project hbase by apache.
the class FSTableDescriptors method updateTableDescriptor.
@RestrictedApi(explanation = "Should only be called in tests or self", link = "", allowedOnPath = ".*/src/test/.*|.*/FSTableDescriptors\\.java")
Path updateTableDescriptor(TableDescriptor td) throws IOException {
TableName tableName = td.getTableName();
Path tableDir = getTableDir(tableName);
Path p = writeTableDescriptor(fs, td, tableDir, getTableDescriptorFromFs(fs, tableDir, fsreadonly).map(Pair::getFirst).orElse(null));
if (p == null) {
throw new IOException("Failed update");
}
LOG.info("Updated tableinfo=" + p);
return p;
}
use of com.google.errorprone.annotations.RestrictedApi in project hbase by apache.
the class FSTableDescriptors method deleteTableDescriptors.
@RestrictedApi(explanation = "Should only be called in tests", link = "", allowedOnPath = ".*/src/test/.*")
public static void deleteTableDescriptors(FileSystem fs, Path tableDir) throws IOException {
Path tableInfoDir = new Path(tableDir, TABLEINFO_DIR);
deleteTableDescriptorFiles(fs, tableInfoDir, Integer.MAX_VALUE);
}
Aggregations