/** * Add a new encryption zone. * <p/> * Called while holding the FSDirectory lock. * * @param inodeId of the encryption zone * @param keyName encryption zone key name */ void addEncryptionZone(Long inodeId, CipherSuite suite, CryptoProtocolVersion version, String keyName) { assert dir.hasWriteLock(); unprotectedAddEncryptionZone(inodeId, suite, version, keyName); }
/** * update quota of each inode and check to see if quota is exceeded. * See {@link #updateCount(INodesInPath, int, QuotaCounts, boolean)} */ void updateCountNoQuotaCheck(INodesInPath inodesInPath, int numOfINodes, QuotaCounts counts) { assert hasWriteLock(); try { updateCount(inodesInPath, numOfINodes, counts, false); } catch (QuotaExceededException e) { NameNode.LOG.error("BUG: unexpected exception ", e); } }
boolean hasReadLock() { return this.dirLock.getReadHoldCount() > 0 || hasWriteLock(); }
/** * Stop the re-encryption updater thread, as well as all EDEK re-encryption * tasks submitted. */ void stopThreads() { assert dir.hasWriteLock(); synchronized (this) { for (ZoneSubmissionTracker zst : submissions.values()) { zst.cancelAllTasks(); } } if (updaterExecutor != null) { updaterExecutor.shutdownNow(); } }
void removeZone(final long zoneId) { assert dir.hasWriteLock(); LOG.info("Removing zone {} from re-encryption.", zoneId); removeZoneTrackerStopTasks(zoneId); getReencryptionStatus().removeZone(zoneId); }
private synchronized void checkPauseForTesting() throws InterruptedException { assert !dir.hasWriteLock(); assert !dir.getFSNamesystem().hasWriteLock(); if (pauseAfterNthCheckpoint != 0) { ZoneSubmissionTracker tracker = handler.unprotectedGetTracker(pauseZoneId); if (tracker != null) { if (tracker.numFutureDone == pauseAfterNthCheckpoint) { shouldPauseForTesting = true; pauseAfterNthCheckpoint = 0; } } } while (shouldPauseForTesting) { LOG.info("Sleeping in the re-encryption updater for unit test."); wait(); LOG.info("Continuing re-encryption updater after pausing."); } }
static void unprotectedSetPermission( FSDirectory fsd, INodesInPath iip, FsPermission permissions) throws FileNotFoundException, UnresolvedLinkException, QuotaExceededException, SnapshotAccessControlException { assert fsd.hasWriteLock(); final INode inode = FSDirectory.resolveLastINode(iip); int snapshotId = iip.getLatestSnapshotId(); inode.setPermission(permissions, snapshotId); }
/** * Remove xattrs from the inode, and return the <em>removed</em> xattrs. * @return the <em>removed</em> xattrs. */ static List<XAttr> unprotectedRemoveXAttrs( FSDirectory fsd, final INodesInPath iip, final List<XAttr> toRemove) throws IOException { assert fsd.hasWriteLock(); INode inode = FSDirectory.resolveLastINode(iip); int snapshotId = iip.getLatestSnapshotId(); List<XAttr> existingXAttrs = XAttrStorage.readINodeXAttrs(inode); List<XAttr> removedXAttrs = Lists.newArrayListWithCapacity(toRemove.size()); List<XAttr> newXAttrs = filterINodeXAttrs(existingXAttrs, toRemove, removedXAttrs); if (existingXAttrs.size() != newXAttrs.size()) { XAttrStorage.updateINodeXAttrs(inode, newXAttrs, snapshotId); return removedXAttrs; } return null; }
void cancelZone(final long zoneId, final String zoneName) throws IOException { assert dir.hasWriteLock(); final ZoneReencryptionStatus zs = getReencryptionStatus().getZoneStatus(zoneId); if (zs == null || zs.getState() == State.Completed) { throw new IOException("Zone " + zoneName + " is not under re-encryption"); } zs.cancel(); removeZoneTrackerStopTasks(zoneId); }
/** * Remove an encryption zone. * <p/> * Called while holding the FSDirectory lock. */ void removeEncryptionZone(Long inodeId) { assert dir.hasWriteLock(); if (hasCreatedEncryptionZone()) { if (encryptionZones.remove(inodeId) == null || !getReencryptionStatus().hasRunningZone(inodeId)) { return; } if (reencryptionHandler != null) { reencryptionHandler.removeZone(inodeId); } } }
static void mkdirForEditLog(FSDirectory fsd, long inodeId, String src, PermissionStatus permissions, List<AclEntry> aclEntries, long timestamp) throws QuotaExceededException, UnresolvedLinkException, AclException, FileAlreadyExistsException, ParentNotDirectoryException, AccessControlException { assert fsd.hasWriteLock(); INodesInPath iip = fsd.getINodesInPath(src, DirOp.WRITE_LINK); final byte[] localName = iip.getLastLocalName(); final INodesInPath existing = iip.getParentINodesInPath(); Preconditions.checkState(existing.getLastINode() != null); unprotectedMkdir(fsd, inodeId, existing, localName, permissions, aclEntries, timestamp); }
static INodeSymlink unprotectedAddSymlink(FSDirectory fsd, INodesInPath iip, byte[] localName, long id, String target, long mtime, long atime, PermissionStatus perm) throws UnresolvedLinkException, QuotaExceededException { assert fsd.hasWriteLock(); final INodeSymlink symlink = new INodeSymlink(id, null, perm, mtime, atime, target); symlink.setLocalName(localName); return fsd.addINode(iip, symlink, perm.getPermission()) != null ? symlink : null; }
static void unprotectedSetOwner( FSDirectory fsd, INodesInPath iip, String username, String groupname) throws FileNotFoundException, UnresolvedLinkException, QuotaExceededException, SnapshotAccessControlException { assert fsd.hasWriteLock(); final INode inode = FSDirectory.resolveLastINode(iip); if (username != null) { inode.setUser(username, iip.getLatestSnapshotId()); } if (groupname != null) { inode.setGroup(groupname, iip.getLatestSnapshotId()); } }
static List<AclEntry> unprotectedSetAcl(FSDirectory fsd, INodesInPath iip, List<AclEntry> aclSpec, boolean fromEdits) throws IOException { assert fsd.hasWriteLock(); // ACL removal is logged to edits as OP_SET_ACL with an empty list. if (aclSpec.isEmpty()) { unprotectedRemoveAcl(fsd, iip); return AclFeature.EMPTY_ENTRY_LIST; } INode inode = FSDirectory.resolveLastINode(iip); int snapshotId = iip.getLatestSnapshotId(); List<AclEntry> newAcl = aclSpec; if (!fromEdits) { List<AclEntry> existingAcl = AclStorage.readINodeLogicalAcl(inode); newAcl = AclTransformation.replaceAclEntries(existingAcl, aclSpec); } AclStorage.updateINodeAcl(inode, newAcl, snapshotId); return newAcl; }
/** * Cancels the currently-running re-encryption of the given encryption zone. * If the given path is not the root of an encryption zone, * * an exception is thrown. */ List<XAttr> cancelReencryptEncryptionZone(final INodesInPath zoneIIP) throws IOException { assert dir.hasWriteLock(); if (reencryptionHandler == null) { throw new IOException("No key provider configured, re-encryption " + "operation is rejected"); } final long zoneId = zoneIIP.getLastINode().getId(); final String zoneName = zoneIIP.getPath(); checkEncryptionZoneRoot(zoneIIP.getLastINode(), zoneName); reencryptionHandler.cancelZone(zoneId, zoneName); LOG.info("Cancelled zone {}({}) for re-encryption.", zoneName, zoneId); return FSDirEncryptionZoneOp.updateReencryptionFinish(dir, zoneIIP, reencryptionStatus.getZoneStatus(zoneId)); }
List<XAttr> completeReencryption(final INode zoneNode) throws IOException { assert dir.hasWriteLock(); assert dir.getFSNamesystem().hasWriteLock(); final Long zoneId = zoneNode.getId(); ZoneReencryptionStatus zs = getReencryptionStatus().getZoneStatus(zoneId); assert zs != null; LOG.info("Re-encryption completed on zone {}. Re-encrypted {} files," + " failures encountered: {}.", zoneNode.getFullPathName(), zs.getFilesReencrypted(), zs.getNumReencryptionFailures()); synchronized (this) { submissions.remove(zoneId); } return FSDirEncryptionZoneOp .updateReencryptionFinish(dir, INodesInPath.fromINode(zoneNode), zs); }
private static INodesInPath createSingleDirectory(FSDirectory fsd, INodesInPath existing, byte[] localName, PermissionStatus perm) throws IOException { assert fsd.hasWriteLock(); existing = unprotectedMkdir(fsd, fsd.allocateNewInodeId(), existing, localName, perm, null, now()); if (existing == null) { return null; } final INode newNode = existing.getLastINode(); // Directory creation also count towards FilesCreated // to match count of FilesDeleted metric. NameNode.getNameNodeMetrics().incrFilesCreated(); String cur = existing.getPath(); fsd.getEditLog().logMkDir(cur, newNode); if (NameNode.stateChangeLog.isDebugEnabled()) { NameNode.stateChangeLog.debug("mkdirs: created directory " + cur); } return existing; }
/** * Save the batch's edeks to file xattrs. */ static void saveFileXAttrsForBatch(FSDirectory fsd, List<FileEdekInfo> batch) { assert fsd.getFSNamesystem().hasWriteLock(); assert !fsd.hasWriteLock(); if (batch != null && !batch.isEmpty()) { for (FileEdekInfo entry : batch) { final INode inode = fsd.getInode(entry.getInodeId()); // no dir lock, so inode could be removed. no-op if so. if (inode == null) { NameNode.LOG.info("Cannot find inode {}, skip saving xattr for" + " re-encryption", entry.getInodeId()); continue; } fsd.getEditLog().logSetXAttrs(inode.getFullPathName(), inode.getXAttrFeature().getXAttrs(), false); } } }
static boolean unprotectedSetTimes( FSDirectory fsd, INodesInPath iip, long mtime, long atime, boolean force) throws QuotaExceededException { assert fsd.hasWriteLock(); boolean status = false; INode inode = iip.getLastINode(); int latest = iip.getLatestSnapshotId(); if (mtime != -1) { inode = inode.setModificationTime(mtime, latest); status = true; } // if the last access time update was within the last precision interval, // then no need to store access time if (atime != -1 && (status || force || atime > inode.getAccessTime() + fsd.getAccessTimePrecision())) { inode.setAccessTime(atime, latest, fsd.getFSNamesystem().getSnapshotManager(). getSkipCaptureAccessTimeOnlyChange()); status = true; } return status; } }
/** * create a directory at path specified by parent */ private static INodesInPath unprotectedMkdir(FSDirectory fsd, long inodeId, INodesInPath parent, byte[] name, PermissionStatus permission, List<AclEntry> aclEntries, long timestamp) throws QuotaExceededException, AclException, FileAlreadyExistsException { assert fsd.hasWriteLock(); assert parent.getLastINode() != null; if (!parent.getLastINode().isDirectory()) { throw new FileAlreadyExistsException("Parent path is not a directory: " + parent.getPath() + " " + DFSUtil.bytes2String(name)); } final INodeDirectory dir = new INodeDirectory(inodeId, name, permission, timestamp); INodesInPath iip = fsd.addLastINode(parent, dir, permission.getPermission(), true); if (iip != null && aclEntries != null) { AclStorage.updateINodeAcl(dir, aclEntries, Snapshot.CURRENT_STATE_ID); } return iip; } }