Search in sources :

Example 1 with RestrictedApi

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();
}
Also used : Pattern(java.util.regex.Pattern) IOException(java.io.IOException) PatternSyntaxException(java.util.regex.PatternSyntaxException) RestrictedApi(com.google.errorprone.annotations.RestrictedApi)

Example 2 with RestrictedApi

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;
}
Also used : HashMap(java.util.HashMap) ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) RestrictedApi(com.google.errorprone.annotations.RestrictedApi)

Example 3 with RestrictedApi

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);
}
Also used : MultiRowMutationEndpoint(org.apache.hadoop.hbase.coprocessor.MultiRowMutationEndpoint) RestrictedApi(com.google.errorprone.annotations.RestrictedApi)

Example 4 with RestrictedApi

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;
}
Also used : Path(org.apache.hadoop.fs.Path) TableName(org.apache.hadoop.hbase.TableName) IOException(java.io.IOException) RestrictedApi(com.google.errorprone.annotations.RestrictedApi)

Example 5 with RestrictedApi

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);
}
Also used : Path(org.apache.hadoop.fs.Path) RestrictedApi(com.google.errorprone.annotations.RestrictedApi)

Aggregations

RestrictedApi (com.google.errorprone.annotations.RestrictedApi)7 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Pattern (java.util.regex.Pattern)2 Path (org.apache.hadoop.fs.Path)2 BugPattern (com.google.errorprone.BugPattern)1 Category (com.google.errorprone.BugPattern.Category)1 SeverityLevel (com.google.errorprone.BugPattern.SeverityLevel)1 VisitorState (com.google.errorprone.VisitorState)1 MethodInvocationTreeMatcher (com.google.errorprone.bugpatterns.BugChecker.MethodInvocationTreeMatcher)1 NewClassTreeMatcher (com.google.errorprone.bugpatterns.BugChecker.NewClassTreeMatcher)1 Description (com.google.errorprone.matchers.Description)1 Matcher (com.google.errorprone.matchers.Matcher)1 Matchers (com.google.errorprone.matchers.Matchers)1 ASTHelpers (com.google.errorprone.util.ASTHelpers)1 MethodInvocationTree (com.sun.source.tree.MethodInvocationTree)1 NewClassTree (com.sun.source.tree.NewClassTree)1 Tree (com.sun.source.tree.Tree)1 MethodSymbol (com.sun.tools.javac.code.Symbol.MethodSymbol)1