/** * Get the correct number of transactions since last edit log roll. * This method holds a lock of FSEditLog and must not be used for metrics. */ private long getCorrectTransactionsSinceLastLogRoll() { if (isInStandbyState() || !getEditLog().isSegmentOpen()) { return 0; } else { return getEditLog().getLastWrittenTxId() - getEditLog().getCurSegmentTxId() + 1; } }
@Metric({"TransactionsSinceLastLogRoll", "Number of transactions since last edit log roll"}) public long getTransactionsSinceLastLogRoll() { if (isInStandbyState() || !getEditLog().isSegmentOpenWithoutLock()) { return 0; } else { return getEditLog().getLastWrittenTxIdWithoutLock() - getEditLog().getCurSegmentTxIdWithoutLock() + 1; } }
private void logReassignLease(String leaseHolder, String src, String newHolder) { assert hasWriteLock(); getEditLog().logReassignLease(leaseHolder, src, newHolder); }
@Metric({"LastWrittenTransactionId", "Transaction ID written to the edit log"}) public long getLastWrittenTransactionId() { return getEditLog().getLastWrittenTxIdWithoutLock(); }
/** * Close file. * @param path * @param file */ private void closeFile(String path, INodeFile file) { assert hasWriteLock(); // file is closed getEditLog().logCloseFile(path, file); NameNode.stateChangeLog.debug("closeFile: {} with {} blocks is persisted" + " to the file system", path, file.getBlocks().length); }
/** * Log the updateMasterKey operation to edit logs * * @param key new delegation key. */ public void logUpdateMasterKey(DelegationKey key) { assert !isInSafeMode() : "this should never be called while in safemode, since we stop " + "the DT manager before entering safemode!"; // edit log rolling is not thread-safe and must be protected by the // fsn lock. not updating namespace so read lock is sufficient. assert hasReadLock(); getEditLog().logUpdateMasterKey(key); getEditLog().logSync(); }
@Override // ClientProtocol public long getCurrentEditLogTxid() throws IOException { checkNNStartup(); namesystem.checkOperation(OperationCategory.READ); // only active namesystem.checkSuperuserPrivilege(); // if it's not yet open for write, we may be in the process of transitioning // from standby to active and may not yet know what the latest committed // txid is return namesystem.getEditLog().isOpenForWrite() ? namesystem.getEditLog().getLastWrittenTxId() : -1; }
/** * Remove an erasure coding policy. * * @param fsn namespace * @param ecPolicyName the name of the policy to be removed * @param logRetryCache whether to record RPC ids in editlog for retry cache * rebuilding * @throws IOException */ static void removeErasureCodingPolicy(final FSNamesystem fsn, String ecPolicyName, final boolean logRetryCache) throws IOException { Preconditions.checkNotNull(ecPolicyName); fsn.getErasureCodingPolicyManager().removePolicy(ecPolicyName); fsn.getEditLog().logRemoveErasureCodingPolicy(ecPolicyName, logRetryCache); }
/** * Persist the new block (the last block of the given file). */ private static void persistNewBlock( FSNamesystem fsn, String path, INodeFile file) { Preconditions.checkArgument(file.isUnderConstruction()); fsn.getEditLog().logAddBlock(path, file); if (NameNode.stateChangeLog.isDebugEnabled()) { NameNode.stateChangeLog.debug("persistNewBlock: " + path + " with new block " + file.getLastBlock().toString() + ", current total block count is " + file.getBlocks().length); } }
static void modifyCacheDirective( FSNamesystem fsn, CacheManager cacheManager, CacheDirectiveInfo directive, EnumSet<CacheFlag> flags, boolean logRetryCache) throws IOException { final FSPermissionChecker pc = getFsPermissionChecker(fsn); cacheManager.modifyDirective(directive, pc, flags); fsn.getEditLog().logModifyCacheDirectiveInfo(directive, logRetryCache); }
static void removeCacheDirective( FSNamesystem fsn, CacheManager cacheManager, long id, boolean logRetryCache) throws IOException { final FSPermissionChecker pc = getFsPermissionChecker(fsn); cacheManager.removeDirective(id, pc); fsn.getEditLog().logRemoveCacheDirectiveInfo(id, logRetryCache); }
/** * Log the cancellation of expired tokens to edit logs * * @param id token identifier to cancel */ public void logExpireDelegationToken(DelegationTokenIdentifier id) { assert !isInSafeMode() : "this should never be called while in safemode, since we stop " + "the DT manager before entering safemode!"; // edit log rolling is not thread-safe and must be protected by the // fsn lock. not updating namespace so read lock is sufficient. assert hasReadLock(); // do not logSync so expiration edits are batched getEditLog().logCancelDelegationToken(id); }
static CacheDirectiveInfo addCacheDirective( FSNamesystem fsn, CacheManager cacheManager, CacheDirectiveInfo directive, EnumSet<CacheFlag> flags, boolean logRetryCache) throws IOException { final FSPermissionChecker pc = getFsPermissionChecker(fsn); if (directive.getId() != null) { throw new IOException("addDirective: you cannot specify an ID " + "for this operation."); } CacheDirectiveInfo effectiveDirective = cacheManager.addDirective(directive, pc, flags); fsn.getEditLog().logAddCacheDirectiveInfo(effectiveDirective, logRetryCache); return effectiveDirective; }
static void modifyCachePool( FSNamesystem fsn, CacheManager cacheManager, CachePoolInfo req, boolean logRetryCache) throws IOException { final FSPermissionChecker pc = getFsPermissionChecker(fsn); if (pc != null) { pc.checkSuperuserPrivilege(); } cacheManager.modifyCachePool(req); fsn.getEditLog().logModifyCachePool(req, logRetryCache); }
static CachePoolInfo addCachePool( FSNamesystem fsn, CacheManager cacheManager, CachePoolInfo req, boolean logRetryCache) throws IOException { final FSPermissionChecker pc = getFsPermissionChecker(fsn); if (pc != null) { pc.checkSuperuserPrivilege(); } CachePoolInfo info = cacheManager.addCachePool(req); fsn.getEditLog().logAddCachePool(info, logRetryCache); return info; }
@Override // NamenodeProtocol public RemoteEditLogManifest getEditLogManifest(long sinceTxId) throws IOException { checkNNStartup(); namesystem.checkOperation(OperationCategory.READ); namesystem.checkSuperuserPrivilege(); return namesystem.getEditLog().getEditLogManifest(sinceTxId); }
static void removeCachePool( FSNamesystem fsn, CacheManager cacheManager, String cachePoolName, boolean logRetryCache) throws IOException { final FSPermissionChecker pc = getFsPermissionChecker(fsn); if (pc != null) { pc.checkSuperuserPrivilege(); } cacheManager.removeCachePool(cachePoolName); fsn.getEditLog().logRemoveCachePool(cachePoolName, logRetryCache); }
/** * Increments, logs and then returns the block ID * @param blockType is the file under striping or contiguous layout? */ private long nextBlockId(BlockType blockType) throws IOException { assert hasWriteLock(); checkNameNodeSafeMode("Cannot get next block ID"); final long blockId = blockManager.nextBlockId(blockType); getEditLog().logAllocateBlockId(blockId); // NB: callers sync the log return blockId; }
@Override public void startSecretManagerIfNecessary() { assert hasWriteLock() : "Starting secret manager needs write lock"; boolean shouldRun = shouldUseDelegationTokens() && !isInSafeMode() && getEditLog().isOpenForWrite(); boolean running = dtSecretManager.isRunning(); if (shouldRun && !running) { startSecretManager(); } }
NamenodeCommand startCheckpoint(NamenodeRegistration backupNode, NamenodeRegistration activeNamenode) throws IOException { checkOperation(OperationCategory.CHECKPOINT); writeLock(); try { checkOperation(OperationCategory.CHECKPOINT); checkNameNodeSafeMode("Checkpoint not started"); LOG.info("Start checkpoint for " + backupNode.getAddress()); NamenodeCommand cmd = getFSImage().startCheckpoint(backupNode, activeNamenode, getEffectiveLayoutVersion()); getEditLog().logSync(); return cmd; } finally { writeUnlock("startCheckpoint"); } }