Search in sources :

Example 81 with VisibleForTesting

use of com.google.common.annotations.VisibleForTesting in project hadoop by apache.

the class EntityGroupFSTimelineStore method scanActiveLogs.

@InterfaceAudience.Private
@VisibleForTesting
int scanActiveLogs() throws IOException {
    long startTime = Time.monotonicNow();
    RemoteIterator<FileStatus> iter = list(activeRootPath);
    int logsToScanCount = 0;
    while (iter.hasNext()) {
        FileStatus stat = iter.next();
        String name = stat.getPath().getName();
        ApplicationId appId = parseApplicationId(name);
        if (appId != null) {
            LOG.debug("scan logs for {} in {}", appId, stat.getPath());
            logsToScanCount++;
            AppLogs logs = getAndSetActiveLog(appId, stat.getPath());
            executor.execute(new ActiveLogParser(logs));
        } else {
            LOG.debug("Unable to parse entry {}", name);
        }
    }
    metrics.addActiveLogDirScanTime(Time.monotonicNow() - startTime);
    return logsToScanCount;
}
Also used : FileStatus(org.apache.hadoop.fs.FileStatus) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 82 with VisibleForTesting

use of com.google.common.annotations.VisibleForTesting in project hbase by apache.

the class HFileBlock method sanityCheck.

/**
   * Checks if the block is internally consistent, i.e. the first
   * {@link HConstants#HFILEBLOCK_HEADER_SIZE} bytes of the buffer contain a
   * valid header consistent with the fields. Assumes a packed block structure.
   * This function is primary for testing and debugging, and is not
   * thread-safe, because it alters the internal buffer pointer.
   * Used by tests only.
   */
@VisibleForTesting
void sanityCheck() throws IOException {
    // Duplicate so no side-effects
    ByteBuff dup = this.buf.duplicate().rewind();
    sanityCheckAssertion(BlockType.read(dup), blockType);
    sanityCheckAssertion(dup.getInt(), onDiskSizeWithoutHeader, "onDiskSizeWithoutHeader");
    sanityCheckAssertion(dup.getInt(), uncompressedSizeWithoutHeader, "uncompressedSizeWithoutHeader");
    sanityCheckAssertion(dup.getLong(), prevBlockOffset, "prevBlockOffset");
    if (this.fileContext.isUseHBaseChecksum()) {
        sanityCheckAssertion(dup.get(), this.fileContext.getChecksumType().getCode(), "checksumType");
        sanityCheckAssertion(dup.getInt(), this.fileContext.getBytesPerChecksum(), "bytesPerChecksum");
        sanityCheckAssertion(dup.getInt(), onDiskDataSizeWithHeader, "onDiskDataSizeWithHeader");
    }
    int cksumBytes = totalChecksumBytes();
    int expectedBufLimit = onDiskDataSizeWithHeader + cksumBytes;
    if (dup.limit() != expectedBufLimit) {
        throw new AssertionError("Expected limit " + expectedBufLimit + ", got " + dup.limit());
    }
    // We might optionally allocate HFILEBLOCK_HEADER_SIZE more bytes to read the next
    // block's header, so there are two sensible values for buffer capacity.
    int hdrSize = headerSize();
    if (dup.capacity() != expectedBufLimit && dup.capacity() != expectedBufLimit + hdrSize) {
        throw new AssertionError("Invalid buffer capacity: " + dup.capacity() + ", expected " + expectedBufLimit + " or " + (expectedBufLimit + hdrSize));
    }
}
Also used : MultiByteBuff(org.apache.hadoop.hbase.nio.MultiByteBuff) SingleByteBuff(org.apache.hadoop.hbase.nio.SingleByteBuff) ByteBuff(org.apache.hadoop.hbase.nio.ByteBuff) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 83 with VisibleForTesting

use of com.google.common.annotations.VisibleForTesting in project hbase by apache.

the class SnapshotFileCache method getSnapshotsInProgress.

@VisibleForTesting
List<String> getSnapshotsInProgress(final SnapshotManager snapshotManager) throws IOException {
    List<String> snapshotInProgress = Lists.newArrayList();
    // only add those files to the cache, but not to the known snapshots
    Path snapshotTmpDir = new Path(snapshotDir, SnapshotDescriptionUtils.SNAPSHOT_TMP_DIR_NAME);
    // only add those files to the cache, but not to the known snapshots
    FileStatus[] running = FSUtils.listStatus(fs, snapshotTmpDir);
    if (running != null) {
        for (FileStatus run : running) {
            ReentrantLock lock = null;
            if (snapshotManager != null) {
                lock = snapshotManager.getLocks().acquireLock(run.getPath().getName());
            }
            try {
                snapshotInProgress.addAll(fileInspector.filesUnderSnapshot(run.getPath()));
            } catch (CorruptedSnapshotException e) {
                // See HBASE-16464
                if (e.getCause() instanceof FileNotFoundException) {
                    // If the snapshot is corrupt, we will delete it
                    fs.delete(run.getPath(), true);
                    LOG.warn("delete the " + run.getPath() + " due to exception:", e.getCause());
                } else {
                    throw e;
                }
            } finally {
                if (lock != null) {
                    lock.unlock();
                }
            }
        }
    }
    return snapshotInProgress;
}
Also used : Path(org.apache.hadoop.fs.Path) ReentrantLock(java.util.concurrent.locks.ReentrantLock) FileStatus(org.apache.hadoop.fs.FileStatus) FileNotFoundException(java.io.FileNotFoundException) CorruptedSnapshotException(org.apache.hadoop.hbase.snapshot.CorruptedSnapshotException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 84 with VisibleForTesting

use of com.google.common.annotations.VisibleForTesting in project hive by apache.

the class SubstitutionVisitor method splitFilter.

/**
   * Maps a condition onto a target.
   *
   * <p>If condition is stronger than target, returns the residue.
   * If it is equal to target, returns the expression that evaluates to
   * the constant {@code true}. If it is weaker than target, returns
   * {@code null}.</p>
   *
   * <p>The terms satisfy the relation</p>
   *
   * <pre>
   *     {@code condition = target AND residue}
   * </pre>
   *
   * <p>and {@code residue} must be as weak as possible.</p>
   *
   * <p>Example #1: condition stronger than target</p>
   * <ul>
   * <li>condition: x = 1 AND y = 2</li>
   * <li>target: x = 1</li>
   * <li>residue: y = 2</li>
   * </ul>
   *
   * <p>Note that residue {@code x &gt; 0 AND y = 2} would also satisfy the
   * relation {@code condition = target AND residue} but is stronger than
   * necessary, so we prefer {@code y = 2}.</p>
   *
   * <p>Example #2: target weaker than condition (valid, but not currently
   * implemented)</p>
   * <ul>
   * <li>condition: x = 1</li>
   * <li>target: x = 1 OR z = 3</li>
   * <li>residue: NOT (z = 3)</li>
   * </ul>
   *
   * <p>Example #3: condition and target are equivalent</p>
   * <ul>
   * <li>condition: x = 1 AND y = 2</li>
   * <li>target: y = 2 AND x = 1</li>
   * <li>residue: TRUE</li>
   * </ul>
   *
   * <p>Example #4: condition weaker than target</p>
   * <ul>
   * <li>condition: x = 1</li>
   * <li>target: x = 1 AND y = 2</li>
   * <li>residue: null (i.e. no match)</li>
   * </ul>
   *
   * <p>There are many other possible examples. It amounts to solving
   * whether {@code condition AND NOT target} can ever evaluate to
   * true, and therefore is a form of the NP-complete
   * <a href="http://en.wikipedia.org/wiki/Satisfiability">Satisfiability</a>
   * problem.</p>
   */
@VisibleForTesting
public static RexNode splitFilter(final RexBuilder rexBuilder, RexNode condition, RexNode target) {
    // First, try splitting into ORs.
    // Given target    c1 OR c2 OR c3 OR c4
    // and condition   c2 OR c4
    // residue is      NOT c1 AND NOT c3
    // Also deals with case target [x] condition [x] yields residue [true].
    RexNode z = splitOr(rexBuilder, condition, target);
    if (z != null) {
        return z;
    }
    RexNode x = andNot(rexBuilder, target, condition);
    if (mayBeSatisfiable(x)) {
        RexNode x2 = andNot(rexBuilder, condition, target);
        return simplify(rexBuilder, x2);
    }
    return null;
}
Also used : RexNode(org.apache.calcite.rex.RexNode) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 85 with VisibleForTesting

use of com.google.common.annotations.VisibleForTesting in project hive by apache.

the class LlapTokenChecker method getTokenInfoInternal.

@VisibleForTesting
static LlapTokenInfo getTokenInfoInternal(String kerberosName, List<LlapTokenIdentifier> tokens) {
    assert (tokens != null && !tokens.isEmpty()) || kerberosName != null;
    if (tokens == null) {
        return new LlapTokenInfo(kerberosName, null, true);
    }
    String userName = kerberosName, appId = null;
    boolean isSigningRequired = false;
    for (LlapTokenIdentifier llapId : tokens) {
        String newUserName = llapId.getOwner().toString();
        if (userName != null && !userName.equals(newUserName)) {
            throw new SecurityException("Ambiguous user name from credentials - " + userName + " and " + newUserName + " from " + llapId + ((kerberosName == null) ? ("; has kerberos credentials for " + kerberosName) : ""));
        }
        userName = newUserName;
        String newAppId = llapId.getAppId();
        if (!StringUtils.isEmpty(newAppId)) {
            if (!StringUtils.isEmpty(appId) && !appId.equals(newAppId)) {
                throw new SecurityException("Ambiguous app ID from credentials - " + appId + " and " + newAppId + " from " + llapId);
            }
            appId = newAppId;
        }
        isSigningRequired = isSigningRequired || llapId.isSigningRequired();
    }
    assert userName != null;
    return new LlapTokenInfo(userName, appId, isSigningRequired);
}
Also used : LlapTokenIdentifier(org.apache.hadoop.hive.llap.security.LlapTokenIdentifier) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)808 IOException (java.io.IOException)135 ArrayList (java.util.ArrayList)67 Map (java.util.Map)52 Path (java.nio.file.Path)47 File (java.io.File)41 HashMap (java.util.HashMap)37 Path (org.apache.hadoop.fs.Path)33 List (java.util.List)29 ImmutableList (com.google.common.collect.ImmutableList)28 Matcher (java.util.regex.Matcher)26 HashSet (java.util.HashSet)23 ImmutableMap (com.google.common.collect.ImmutableMap)21 FileStatus (org.apache.hadoop.fs.FileStatus)21 SourcePath (com.facebook.buck.rules.SourcePath)20 FileHandle (org.apache.hadoop.nfs.nfs3.FileHandle)19 DFSClient (org.apache.hadoop.hdfs.DFSClient)18 Nfs3FileAttributes (org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes)18 ImmutableSet (com.google.common.collect.ImmutableSet)17 LinkedHashMap (java.util.LinkedHashMap)17