use of diskCacheV111.util.FileIsNewCacheException in project dcache by dCache.
the class ConsistentReplicaStore method get.
/**
* Retrieves a CacheRepositoryEntry from the wrapped meta data store. If the entry is missing or
* fails consistency checks, the entry is reconstructed with information from PNFS.
*/
@Override
public ReplicaRecord get(PnfsId id) throws IllegalArgumentException, CacheException {
ReplicaRecord entry = _replicaStore.get(id);
if (entry != null && isBroken(entry)) {
LOGGER.warn("Recovering {}...", id);
try {
/* It is safe to remove FROM_STORE/FROM_POOL replicas: We have
* another copy anyway. Files in REMOVED or DESTROYED
* were about to be deleted, so we can finish the job.
*/
switch(entry.getState()) {
case FROM_POOL:
case FROM_STORE:
case REMOVED:
case DESTROYED:
_replicaStore.remove(id);
_pnfsHandler.clearCacheLocation(id);
LOGGER.info("Recovering: Removed {} because it was not fully staged.", id);
return null;
}
entry = rebuildEntry(entry);
} catch (IOException e) {
throw new DiskErrorCacheException("I/O error in healer: " + messageOrClassName(e), e);
} catch (FileNotFoundCacheException e) {
_replicaStore.remove(id);
LOGGER.warn("Recovering: Removed {} because name space entry was deleted.", id);
return null;
} catch (FileIsNewCacheException e) {
_replicaStore.remove(id);
LOGGER.warn("Recovering: Removed {}: {}", id, e.getMessage());
return null;
} catch (TimeoutCacheException e) {
throw e;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new CacheException("Pool is shutting down", e);
} catch (CacheException | NoSuchAlgorithmException e) {
entry.update("Failed to recover replica: " + e.getMessage(), r -> r.setState(ReplicaState.BROKEN));
LOGGER.error(AlarmMarkerFactory.getMarker(PredefinedAlarm.BROKEN_FILE, id.toString(), _poolName), "Marked {} bad: {}.", id, e.getMessage());
}
}
return entry;
}
use of diskCacheV111.util.FileIsNewCacheException in project dcache by dCache.
the class ChimeraNameSpaceProvider method commitUpload.
@Override
public FileAttributes commitUpload(Subject subject, FsPath temporaryPath, FsPath finalPath, Set<CreateOption> options, Set<FileAttribute> attributesToFetch) throws CacheException {
try {
FsPath temporaryDir = getParentOfFile(temporaryPath);
FsPath finalDir = getParentOfFile(finalPath);
checkIsTemporaryDirectory(temporaryPath, temporaryDir);
/* File must have been created...
*/
ExtendedInode uploadDirInode;
ExtendedInode temporaryDirInode;
ExtendedInode inodeOfFile;
try {
uploadDirInode = new ExtendedInode(_fs, _fs.path2inode(temporaryDir.parent().toString()));
temporaryDirInode = uploadDirInode.inodeOf(temporaryDir.name(), STAT);
inodeOfFile = temporaryDirInode.inodeOf(temporaryPath.name(), STAT);
} catch (FileNotFoundChimeraFsException e) {
throw new FileNotFoundCacheException("No such file or directory: " + temporaryPath, e);
}
/* ...and upload must have completed...
*/
ImmutableList<StorageLocatable> locations = inodeOfFile.getLocations();
if (locations.isEmpty()) {
throw new FileIsNewCacheException("Upload has not completed.");
}
/* ...and it must have the correct size.
*/
ImmutableList<String> size = inodeOfFile.getTag(TAG_EXPECTED_SIZE);
if (!size.isEmpty()) {
long expectedSize = Long.parseLong(size.get(0));
long actualSize = inodeOfFile.statCache().getSize();
if (expectedSize != actualSize) {
throw new FileCorruptedCacheException(expectedSize, actualSize);
}
}
/* Target directory must exist.
*/
ExtendedInode finalDirInode;
try {
finalDirInode = new ExtendedInode(_fs, _fs.path2inode(finalDir.toString()));
} catch (FileNotFoundChimeraFsException e) {
throw new FileNotFoundCacheException("No such file or directory: " + finalDir, e);
}
/* File must not exist unless overwrite is enabled.
*/
try {
ExtendedInode inodeOfExistingFile = finalDirInode.inodeOf(finalPath.name(), STAT);
if (!options.contains(CreateOption.OVERWRITE_EXISTING)) {
throw new FileExistsCacheException("File exists: " + finalPath);
}
/* User must be authorized to delete existing file.
*/
if (!Subjects.isExemptFromNamespaceChecks(subject)) {
FileAttributes attributesOfParent = getFileAttributesForPermissionHandler(finalDirInode);
FileAttributes attributesOfFile = getFileAttributesForPermissionHandler(inodeOfExistingFile);
if (_permissionHandler.canDeleteFile(subject, attributesOfParent, attributesOfFile) != ACCESS_ALLOWED) {
throw new PermissionDeniedCacheException("Overwrite denied: " + finalPath);
}
}
} catch (FileNotFoundChimeraFsException ignored) {
}
/* Read file attributes before moving the file. Otherwise the cached parent will
* be gone.
*/
FileAttributes attributes = getFileAttributes(inodeOfFile, attributesToFetch);
/* File is moved to correct directory.
*/
_fs.rename(inodeOfFile, temporaryDirInode, temporaryPath.name(), finalDirInode, finalPath.name());
/* Delete temporary upload directory and any files in it.
*/
removeRecursively(uploadDirInode, temporaryDir.name(), temporaryDirInode, i -> {
});
return attributes;
} catch (ChimeraFsException e) {
throw new CacheException(CacheException.UNEXPECTED_SYSTEM_EXCEPTION, e.getMessage());
} catch (NumberFormatException e) {
throw new FileCorruptedCacheException("Failed to commit file: " + e.getMessage());
}
}
use of diskCacheV111.util.FileIsNewCacheException in project dcache by dCache.
the class Storage method putDone.
@Override
public void putDone(SRMUser user, String localTransferPath, URI surl, boolean overwrite) throws SRMException {
try {
Subject subject = asDcacheUser(user).getSubject();
Restriction restriction = asDcacheUser(user).getRestriction();
FsPath fullPath = getPath(surl);
checkNonBrokenUpload(localTransferPath);
EnumSet<CreateOption> options = EnumSet.noneOf(CreateOption.class);
if (overwrite) {
options.add(CreateOption.OVERWRITE_EXISTING);
}
PnfsCommitUpload msg = new PnfsCommitUpload(subject, restriction, FsPath.create(localTransferPath), fullPath, options, EnumSet.of(PNFSID, SIZE, STORAGEINFO));
msg = _pnfsStub.sendAndWait(msg);
DoorRequestInfoMessage infoMsg = new DoorRequestInfoMessage(getCellAddress());
infoMsg.setSubject(subject);
infoMsg.setBillingPath(fullPath.toString());
infoMsg.setTransferPath(localTransferPath);
infoMsg.setTransaction(CDC.getSession());
infoMsg.setPnfsId(msg.getFileAttributes().getPnfsId());
infoMsg.setResult(0, "");
infoMsg.setFileSize(msg.getFileAttributes().getSizeIfPresent().orElse(0L));
infoMsg.setStorageInfo(msg.getFileAttributes().getStorageInfo());
Origin origin = Subjects.getOrigin(subject);
if (origin != null) {
infoMsg.setClient(origin.getAddress().getHostAddress());
}
_billingStub.notify(infoMsg);
} catch (FileNotFoundCacheException e) {
throw new SRMInvalidPathException(e.getMessage(), e);
} catch (FileIsNewCacheException | FileCorruptedCacheException e) {
throw new SRMException(e.getMessage(), e);
} catch (PermissionDeniedCacheException e) {
throw new SRMAuthorizationException("Permission denied.", e);
} catch (FileExistsCacheException e) {
throw new SRMDuplicationException(surl + " exists.", e);
} catch (CacheException e) {
throw new SRMInternalErrorException(e.getMessage(), e);
} catch (InterruptedException e) {
throw new SRMInternalErrorException("Operation interrupted", e);
} catch (NoRouteToCellException e) {
throw new SRMInternalErrorException("Internal communication failure", e);
}
}
use of diskCacheV111.util.FileIsNewCacheException in project dcache by dCache.
the class Transfer method readNameSpaceEntryAsync.
private ListenableFuture<Void> readNameSpaceEntryAsync(boolean allowWrite, long timeout) {
Set<FileAttribute> attr = EnumSet.of(PNFSID, TYPE, STORAGEINFO, SIZE);
attr.addAll(_additionalAttributes);
attr.addAll(PoolMgrSelectReadPoolMsg.getRequiredAttributes());
Set<AccessMask> mask;
if (allowWrite) {
mask = EnumSet.of(AccessMask.READ_DATA, AccessMask.WRITE_DATA);
} else {
mask = EnumSet.of(AccessMask.READ_DATA);
}
PnfsId pnfsId = getPnfsId();
PnfsGetFileAttributes request;
if (pnfsId != null) {
request = new PnfsGetFileAttributes(pnfsId, attr);
if (_path != null) {
// Needed for restriction check.
request.setPnfsPath(_path.toString());
}
} else {
request = new PnfsGetFileAttributes(_path.toString(), attr);
}
request.setAccessMask(mask);
request.setUpdateAtime(true);
ListenableFuture<PnfsGetFileAttributes> reply = _pnfs.requestAsync(request, timeout);
setStatusUntil("PnfsManager: Fetching storage info", reply);
return CellStub.transformAsync(reply, msg -> {
FileAttributes attributes = msg.getFileAttributes();
/* We can only transfer regular files.
*/
FileType type = attributes.getFileType();
if (type == FileType.DIR || type == FileType.SPECIAL) {
throw new NotFileCacheException("Not a regular file");
}
/* I/O mode must match completeness of the file.
*/
if (!attributes.getStorageInfo().isCreatedOnly()) {
setWrite(false);
} else if (allowWrite) {
setWrite(true);
} else {
throw new FileIsNewCacheException();
}
setFileAttributes(attributes);
return immediateFuture(null);
});
}
use of diskCacheV111.util.FileIsNewCacheException in project dcache by dCache.
the class TransferManagerHandler method success.
@Override
public void success(Message message) {
try {
if (message instanceof PnfsCreateEntryMessage) {
PnfsCreateEntryMessage create_msg = (PnfsCreateEntryMessage) message;
if (state == WAITING_FOR_PNFS_ENTRY_CREATION_INFO_STATE) {
setState(RECEIVED_PNFS_ENTRY_CREATION_INFO_STATE);
createEntryResponseArrived(create_msg);
return;
}
LOGGER.error(this.toString() + " got unexpected PnfsCreateEntryMessage " + " : " + create_msg + " ; Ignoring");
} else if (message instanceof PnfsGetFileAttributes) {
PnfsGetFileAttributes attributesMessage = (PnfsGetFileAttributes) message;
if (state == WAITING_FOR_PNFS_INFO_STATE) {
setState(RECEIVED_PNFS_INFO_STATE);
FileAttributes attributes = attributesMessage.getFileAttributes();
if (!attributes.isDefined(SIZE)) {
sendErrorReply(CacheException.FILE_IS_NEW, new FileIsNewCacheException());
return;
}
storageInfoArrived(attributesMessage.getPnfsId(), attributes);
return;
} else if (state == WAITING_FOR_PNFS_CHECK_BEFORE_DELETE_STATE) {
state = RECEIVED_PNFS_CHECK_BEFORE_DELETE_STATE;
deletePnfsEntry();
return;
} else if (state == WAITING_FOR_CREATED_FILE_INFO_STATE) {
state = RECEIVED_CREATED_FILE_INFO_STATE;
getFileAttributesArrived(attributesMessage.getFileAttributes());
return;
}
LOGGER.error(this.toString() + " got unexpected PnfsGetStorageInfoMessage " + " : " + attributesMessage + " ; Ignoring");
} else if (message instanceof PoolMgrSelectPoolMsg) {
PoolMgrSelectPoolMsg select_pool_msg = (PoolMgrSelectPoolMsg) message;
if (state == WAITING_FOR_POOL_INFO_STATE) {
setState(RECEIVED_POOL_INFO_STATE);
poolInfoArrived(select_pool_msg);
return;
}
LOGGER.error(this.toString() + " got unexpected PoolMgrSelectPoolMsg " + " : " + select_pool_msg + " ; Ignoring");
} else if (message instanceof PoolIoFileMessage) {
PoolIoFileMessage first_pool_reply = (PoolIoFileMessage) message;
if (state == WAITING_FIRST_POOL_REPLY_STATE) {
setState(RECEIVED_FIRST_POOL_REPLY_STATE);
poolFirstReplyArrived(first_pool_reply);
return;
}
LOGGER.error(this.toString() + " got unexpected PoolIoFileMessage " + " : " + first_pool_reply + " ; Ignoring");
} else if (message instanceof PnfsDeleteEntryMessage) {
PnfsDeleteEntryMessage deleteReply = (PnfsDeleteEntryMessage) message;
if (state == WAITING_FOR_PNFS_ENTRY_DELETE) {
setState(RECEIVED_PNFS_ENTRY_DELETE);
LOGGER.debug("Received PnfsDeleteEntryMessage, Deleted : {}", deleteReply.getPnfsPath());
sendErrorReply();
}
}
manager.persist(this);
} catch (RuntimeException e) {
LOGGER.error("Bug detected in transfermanager, please report this to <support@dCache.org>", e);
failure(1, "Bug detected: " + e);
}
}
Aggregations