private void redirect() throws IOException { final ContentRepository backupRepo = getBackupRepository(); if (backupRepo == null) { throw new IOException("Content Repository is out of space"); } final ContentClaim backupClaim = backupRepo.create(true); backupRepoClaimMap.put(claim, backupClaim); out = backupRepo.write(backupClaim); amos.writeTo(out); amos.destroy(); amos = null; }
/** * Destroys a ContentClaim that was being written to but is no longer needed * * @param claim claim to destroy */ private void destroyContent(final ContentClaim claim) { if (claim == null) { return; } final int decrementedClaimCount = context.getContentRepository().decrementClaimantCount(claim); if (decrementedClaimCount <= 0) { resetWriteClaims(); // Have to ensure that we are not currently writing to the claim before we can destroy it. context.getContentRepository().remove(claim); } }
public String getContentRepoFileStoreName(final String containerName) { return contentRepository.getContainerFileStoreName(containerName); }
public ContentClaim getContentClaim() throws IOException { final ContentClaim contentClaim = queue.poll(); if (contentClaim != null) { contentRepo.incrementClaimaintCount(contentClaim); return contentClaim; } final ContentClaim claim = contentRepo.create(false); registerStream(claim); return claim; }
while (isMoreFlowFiles(dataIn, protocolVersion)) { if (contentClaim == null) { contentClaim = contentRepository.create(false); contentClaimOut = contentRepository.write(contentClaim); contentRepository.incrementClaimaintCount(flowFile.getFlowFile().getContentClaim()); final int count = contentRepository.decrementClaimantCount(contentClaim); contentRepository.remove(contentClaim); contentRepository.decrementClaimantCount(remoteFlowFile.getFlowFile().getContentClaim()); contentRepository.remove(contentClaim);
final Set<String> containerNames = contentRepo.getContainerNames(); final Map<String, StorageUsage> fileRepositoryUsage = new LinkedHashMap<>(containerNames.size()); for (final String containerName : containerNames) { containerFree = contentRepo.getContainerUsableSpace(containerName); containerCapacity = contentRepo.getContainerCapacity(containerName); } catch (final IOException ioe) { logger.warn("Unable to determine Content Repository usage for container {} due to {}", containerName, ioe.toString());
final ContentClaim newClaim; try { newClaim = contentRepo.create(context.getConnectable().isLossTolerant()); claimLog.debug("Creating ContentClaim {} for 'merge' for {}", newClaim, destinationRecord.getCurrent()); } catch (final IOException e) { try (final OutputStream rawOut = contentRepo.write(newClaim); final OutputStream out = new BufferedOutputStream(rawOut)) { final StandardRepositoryRecord sourceRecord = getRecord(source); final long copied = contentRepo.exportTo(sourceRecord.getCurrentClaim(), out, sourceRecord.getCurrentClaimOffset(), source.getSize()); writtenCount += copied; readCount += copied;
newClaim = context.getContentRepository().create(context.getConnectable().isLossTolerant()); claimLog.debug("Creating ContentClaim {} for 'importFrom' for {}", newClaim, destination); } catch (final IOException e) { long newSize = 0L; try { newSize = context.getContentRepository().importFrom(source, newClaim); bytesWritten += newSize; bytesRead += newSize;
private void decrementClaimCount(final ContentClaim claim) { if (claim == null) { return; } context.getContentRepository().decrementClaimantCount(claim); }
@Override public ContentClaim create(boolean lossTolerant) throws IOException { if (lossTolerant) { return createLossTolerant(); } else { final ContentRepository backupRepo = getBackupRepository(); if (backupRepo == null) { // TODO: Loss Tolerance is not yet configurable. // Therefore, since this is an in-memory content repository, assume that this claim is loss-tolerant if there // is not a backup repository return createLossTolerant(); } final ContentClaim backupClaim = backupRepo.create(lossTolerant); backupRepoClaimMap.put(backupClaim, backupClaim); return backupClaim; } }
@Override public int getClaimantCount(final ContentClaim claim) { if (claim == null) { return 0; } final ContentClaim backupClaim = getBackupClaim(claim); if (backupClaim == null) { return claimManager.getClaimantCount(resolveClaim(claim).getResourceClaim()); } else { return getBackupRepository().getClaimantCount(backupClaim); } }
@Override public long importFrom(final InputStream in, final ContentClaim claim) throws IOException { final ContentClaim backupClaim = getBackupClaim(claim); if (backupClaim == null) { final ContentBlock content = getContent(claim); content.reset(); return StreamUtils.copy(in, content.write()); } else { return getBackupRepository().importFrom(in, claim); } }
@Override public void exportTo(FlowFile source, final Path destination, final boolean append) { verifyTaskActive(); source = validateRecordState(source); final StandardRepositoryRecord record = getRecord(source); try { ensureNotAppending(record.getCurrentClaim()); claimCache.flush(record.getCurrentClaim()); final long copyCount = context.getContentRepository().exportTo(record.getCurrentClaim(), destination, append, record.getCurrentClaimOffset(), source.getSize()); bytesRead += copyCount; bytesWritten += copyCount; } catch (final ContentNotFoundException nfe) { handleContentNotFound(nfe, record); } catch (final Throwable t) { throw new FlowFileAccessException("Failed to export " + source + " to " + destination + " due to " + t.toString(), t); } }
contentRepository.cleanup();
try { try { newClaim = context.getContentRepository().create(context.getConnectable().isLossTolerant()); claimLog.debug("Creating ContentClaim {} for 'importFrom' for {}", newClaim, destination); newSize = context.getContentRepository().importFrom(createTaskTerminationStream(source), newClaim); bytesWritten += newSize; } catch (final IOException e) {
@Override public int decrementClaimantCount(final ContentClaim claim) { if (claim == null) { return 0; } final ContentClaim backupClaim = getBackupClaim(claim); if (backupClaim == null) { return claimManager.decrementClaimantCount(resolveClaim(claim).getResourceClaim()); } else { return getBackupRepository().decrementClaimantCount(backupClaim); } }
newClaim = context.getContentRepository().create(context.getConnectable().isLossTolerant()); claimLog.debug("Creating ContentClaim {} for 'append' for {}", newClaim, source); final OutputStream rawOutStream = context.getContentRepository().write(newClaim); final OutputStream bufferedOutStream = new BufferedOutputStream(rawOutStream); outStream = new ByteCountingOutputStream(bufferedOutStream);
contentRepo.decrementClaimantCount(expiredRecord.getCurrentClaim());
context.getContentRepository().decrementClaimantCount(record.getWorkingClaim()); record.addTransientClaim(record.getWorkingClaim());