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;
}
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));
}
}
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;
}
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 > 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;
}
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);
}
Aggregations