Class StandardProcessSession
java.lang.Object
org.apache.nifi.controller.repository.StandardProcessSession
- All Implemented Interfaces:
ProvenanceEventEnricher,ProcessSession
public class StandardProcessSession
extends Object
implements ProcessSession, ProvenanceEventEnricher
Provides a ProcessSession that ensures all accesses, changes and transfers occur in an atomic manner for all FlowFiles including their contents and attributes
NOT THREAD SAFE
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classprivate static interfaceCallback interface used to poll a FlowFileQueue, in order to perform functional programming-type of polling a queueprivate static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map<ContentClaim, ByteCountingOutputStream> private longprivate longprivate final ContentClaimWriteCacheprivate static final org.slf4j.Loggerprivate StateMapprivate final Stringprivate final Map<String, StandardFlowFileEvent> private longprivate longprivate final RepositoryContextprivate ResourceClaimprivate ByteCountingInputStreamstatic final Stringprivate static final StateMapprivate static final AtomicLongprivate final StandardProcessSession.FlowFileLinkageprivate intprivate intprivate final Map<FlowFile, ProvenanceEventBuilder> private final Map<FlowFile, List<ProvenanceEventRecord>> private static final AtomicLongprivate static final Stringprivate StateMapprivate static final org.slf4j.Loggerprivate static final intprivate final Map<FlowFile, InputStream> private final Map<FlowFile, OutputStream> private final PerformanceTrackerprivate longprivate final InternalProvenanceReporterprivate final Map<Long, StandardRepositoryRecord> private longprivate intprivate final Stringprivate final longprivate final TaskTerminationprivate final Map<FlowFileQueue, Set<FlowFileRecord>> static final intprivate static final long -
Constructor Summary
ConstructorsConstructorDescriptionStandardProcessSession(RepositoryContext context, TaskTermination taskTermination, PerformanceTracker performanceTracker) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidprivate voidaddEventType(Map<String, BitSet> map, String id, ProvenanceEventType eventType) voidadjustCounter(String name, long delta, boolean immediate) private voidadjustCounter(String name, long delta, Map<String, Long> map) append(FlowFile source, OutputStreamCallback writer) private longcalculateBackoffTime(int retryCount, long maxBackoffPeriod, long baseBackoffTime) voidprivate voidcheckpoint(boolean copyCollections) voidclearState(Scope scope) private voidvoidcommit()private voidcommit(boolean asynchronous) protected voidcommit(StandardProcessSession.Checkpoint checkpoint, boolean asynchronous) Commits the given checkpoint, updating repositories as necessary, and performing any necessary cleanup of resources, etc.voidvoidcommitAsync(Runnable onSuccess, Consumer<Throwable> onFailure) create()create(Collection<FlowFile> parents) private InputStreamcreateTaskTerminationStream(InputStream delegate) private OutputStreamcreateTaskTerminationStream(OutputStream delegate) private voiddecrementClaimCount(ContentClaim claim) private voiddecrementReadCount(FlowFile flowFile) private voiddestroyContent(ContentClaim claim, StandardRepositoryRecord repoRecord) Destroys a ContentClaim that was being written to but is no longer neededprivate ProvenanceEventRecordenrich(ProvenanceEventRecord rawEvent, Map<String, FlowFileRecord> flowFileRecordMap, Map<Long, StandardRepositoryRecord> records, boolean updateAttributes, long commitNanos) enrich(ProvenanceEventRecord rawEvent, FlowFile flowFile, long commitNanos) Returns a new Provenance event that has been updated to contain the original and updated FlowFile attributes and content claim information.private voidensureNotAppending(ContentClaim claim) voidvoidexportTo(FlowFile source, OutputStream destination) voidprotected voidfinalize()private voidformatNanos(long nanos, StringBuilder sb) get()get(int maxResults) get(StandardProcessSession.ConnectionPoller poller, boolean lockAllQueues) get(FlowFileFilter filter) private StringgetIncrementedVersion(String currentVersion) private InputStreamgetInputStream(FlowFile flowFile, ContentClaim claim, long contentClaimOffset, boolean allowCachingOfStream) private FlowFilegetMostRecent(FlowFile flowFile) private StandardRepositoryRecordprotected RepositoryContextprivate intgetRetries(FlowFile flowFile) protected longprivate voidhandleConflictingId(FlowFileRecord flowFile, Connection connection, StandardRepositoryRecord conflict) private voidhandleContentNotFound(ContentNotFoundException nfe, Collection<StandardRepositoryRecord> suspectRecords) private voidhandleContentNotFound(ContentNotFoundException nfe, StandardRepositoryRecord suspectRecord) importFrom(InputStream source, FlowFile destination) importFrom(Path source, boolean keepSourceFile, FlowFile destination) private voidincrementConnectionInputCounts(String connectionId, int flowFileCount, long bytes) private voidincrementConnectionInputCounts(Connection connection, RepositoryRecord record) private voidincrementConnectionOutputCounts(String connectionId, int flowFileCount, long bytes) private voidincrementConnectionOutputCounts(Connection connection, FlowFileRecord record) private voidincrementReadCount(FlowFile flowFile) intersectAttributes(Collection<FlowFile> flowFileList) Returns the attributes that are common to every FlowFile given.(package private) booleanisFlowFileKnown(FlowFile flowFile) Checks if a FlowFile is known in this session.private booleanisRetry(StandardRepositoryRecord record) private booleanisSpuriousForkEvent(ProvenanceEventRecord event, Set<String> removedFlowFiles) Checks if the given event is a spurious FORK, meaning that the FORK has a single child and that child was removed in this session.private booleanisSpuriousRouteEvent(ProvenanceEventRecord event, Map<Long, StandardRepositoryRecord> records) Checks if the given event is a spurious ROUTE, meaning that the ROUTE indicates that a FlowFile was routed to a relationship with only 1 connection and that Connection is the Connection from which the FlowFile was pulled.private Stringmerge(Collection<FlowFile> sources, FlowFile destination) merge(Collection<FlowFile> sources, FlowFile destination, byte[] header, byte[] footer, byte[] demarcator) private voidmigrate(StandardProcessSession newOwner, Collection<FlowFile> flowFiles) voidmigrate(ProcessSession newOwner) voidmigrate(ProcessSession newOwner, Collection<FlowFile> flowFiles) putAllAttributes(FlowFile flowFile, Map<String, String> attributes) putAttribute(FlowFile flowFile, String key, String value) voidread(FlowFile source, InputStreamCallback reader) private voidregisterDequeuedRecord(FlowFileRecord flowFile, Connection connection) private voidregisterForkEvent(FlowFile parent, FlowFile child) private voidregisterJoinEvent(FlowFile child, Collection<FlowFile> parents) voidremove(Collection<FlowFile> flowFiles) voidremoveAllAttributes(FlowFile flowFile, Pattern keyPattern) removeAllAttributes(FlowFile flowFile, Set<String> keys) removeAttribute(FlowFile flowFile, String key) private voidremoveExpired(Set<FlowFileRecord> flowFiles, Connection connection) private voidremoveForkEvents(FlowFile flowFile) private voidChecks if the ContentClaim associated with this record should be removed, since the record is about to be updated to point to a new content claim.booleanprivate voidprivate voidprivate voidprivate voidresetWriteClaims(boolean suppressExceptions) private voidretry(StandardRepositoryRecord record, long maxBackoffMillis) voidrollback()voidrollback(boolean penalize) protected voidrollback(boolean penalize, boolean rollbackCheckpoint) protected voidrollbackRecord(StandardRepositoryRecord record, boolean penalize) Rolls back the Record in a manner that is appropriate for the context.voidprivate voidprivate StringsummarizeEvents(StandardProcessSession.Checkpoint checkpoint) toString()voidtransfer(Collection<FlowFile> flowFiles) voidtransfer(Collection<FlowFile> flowFiles, Relationship relationship) voidvoidtransfer(FlowFile flowFile, Relationship relationship) private voidupdateEventContentClaims(ProvenanceEventBuilder builder, FlowFile flowFile, StandardRepositoryRecord repoRecord) private voidprivate voidprivate voidupdateLastQueuedDate(StandardRepositoryRecord record, Long lastQueueDate) protected voidprivate voidvalidateRecordState(Collection<FlowFile> flowFiles) private FlowFilevalidateRecordState(FlowFile flowFile) private FlowFilevalidateRecordState(FlowFile flowFile, boolean allowRecursiveRead) private voidwrite(FlowFile source, OutputStreamCallback writer) write(FlowFile source, StreamCallback writer) Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.nifi.processor.ProcessSession
commitAsync
-
Field Details
-
REQUIRED_ATTRIBUTES
-
VERSION_INCREMENT
private static final long VERSION_INCREMENT- See Also:
-
INITIAL_VERSION
-
idGenerator
-
enqueuedIndex
-
EMPTY_STATE_MAP
-
VERBOSE_LOG_THRESHOLD
public static final int VERBOSE_LOG_THRESHOLD- See Also:
-
DEFAULT_FLOWFILE_PATH
- See Also:
-
LOG
private static final org.slf4j.Logger LOG -
claimLog
private static final org.slf4j.Logger claimLog -
MAX_ROLLBACK_FLOWFILES_TO_LOG
private static final int MAX_ROLLBACK_FLOWFILES_TO_LOG- See Also:
-
records
-
connectionCounts
-
unacknowledgedFlowFiles
-
appendableStreams
-
context
-
taskTermination
-
readRecursionSet
-
writeRecursionSet
-
deleteOnCommit
-
sessionId
private final long sessionId -
connectableDescription
-
performanceTracker
-
countersOnCommit
-
immediateCounters
-
removedFlowFiles
-
createdFlowFiles
-
createdFlowFilesWithoutLineage
-
provenanceReporter
-
removedCount
private int removedCount -
removedBytes
private long removedBytes -
bytesRead
private long bytesRead -
bytesWritten
private long bytesWritten -
flowFilesIn
private int flowFilesIn -
flowFilesOut
private int flowFilesOut -
contentSizeIn
private long contentSizeIn -
contentSizeOut
private long contentSizeOut -
currentReadClaim
-
currentReadClaimStream
-
processingStartTime
private long processingStartTime -
openInputStreams
-
openOutputStreams
-
generatedProvenanceEvents
-
forkEventBuilders
-
checkpoint
-
claimCache
-
localState
-
clusterState
-
retryAttribute
-
flowFileLinkage
-
-
Constructor Details
-
StandardProcessSession
public StandardProcessSession(RepositoryContext context, TaskTermination taskTermination, PerformanceTracker performanceTracker)
-
-
Method Details
-
verifyTaskActive
private void verifyTaskActive() -
getRepositoryContext
-
getSessionId
protected long getSessionId() -
closeStreams
-
checkpoint
public void checkpoint() -
validateCommitState
private void validateCommitState() -
checkpoint
private void checkpoint(boolean copyCollections) -
isRetry
-
retry
-
getRetries
-
calculateBackoffTime
private long calculateBackoffTime(int retryCount, long maxBackoffPeriod, long baseBackoffTime) -
commit
public void commit()- Specified by:
commitin interfaceProcessSession
-
commitAsync
public void commitAsync()- Specified by:
commitAsyncin interfaceProcessSession
-
commitAsync
- Specified by:
commitAsyncin interfaceProcessSession
-
commit
private void commit(boolean asynchronous) -
commit
Commits the given checkpoint, updating repositories as necessary, and performing any necessary cleanup of resources, etc. Subclasses may choose to perform these tasks asynchronously if the asynchronous flag indicates that it is acceptable to do so. However, this implementation will perform the commit synchronously, regardless of theasynchronousflag.- Parameters:
checkpoint- the session checkpoint to commitasynchronous- whether or not the commit is allowed to be performed asynchronously.
-
updateEventRepository
-
combineCounters
-
addEventType
-
getRecord
-
updateProvenanceRepo
-
updateEventContentClaims
private void updateEventContentClaims(ProvenanceEventBuilder builder, FlowFile flowFile, StandardRepositoryRecord repoRecord) -
enrich
public ProvenanceEventRecord enrich(ProvenanceEventRecord rawEvent, FlowFile flowFile, long commitNanos) Description copied from interface:ProvenanceEventEnricherReturns a new Provenance event that has been updated to contain the original and updated FlowFile attributes and content claim information.- Specified by:
enrichin interfaceProvenanceEventEnricher- Parameters:
rawEvent- recordflowFile- flowfilecommitNanos- the time (in nanoseconds) when the associated session was committed- Returns:
- new event record
-
enrich
private ProvenanceEventRecord enrich(ProvenanceEventRecord rawEvent, Map<String, FlowFileRecord> flowFileRecordMap, Map<Long, StandardRepositoryRecord> records, boolean updateAttributes, long commitNanos) -
isSpuriousForkEvent
Checks if the given event is a spurious FORK, meaning that the FORK has a single child and that child was removed in this session. This happens when a Processor calls #create(FlowFile) and then removes the created FlowFile.- Parameters:
event- event- Returns:
- true if spurious fork
-
isSpuriousRouteEvent
private boolean isSpuriousRouteEvent(ProvenanceEventRecord event, Map<Long, StandardRepositoryRecord> records) Checks if the given event is a spurious ROUTE, meaning that the ROUTE indicates that a FlowFile was routed to a relationship with only 1 connection and that Connection is the Connection from which the FlowFile was pulled. I.e., the FlowFile was really routed nowhere.- Parameters:
event- eventrecords- records- Returns:
- true if spurious route
-
rollback
public void rollback()- Specified by:
rollbackin interfaceProcessSession
-
rollback
public void rollback(boolean penalize) - Specified by:
rollbackin interfaceProcessSession
-
rollback
protected void rollback(boolean penalize, boolean rollbackCheckpoint) -
rollbackRecord
Rolls back the Record in a manner that is appropriate for the context. The default implementation is to place the queue back on its original queue, if it exists, or just ignore it if it has no original queue. However, subclasses may wish to change the behavior for how Records are handled when a rollback occurs.- Parameters:
record- the Record that is to be rolled backpenalize- whether or not the Record should be penalized
-
loggableFlowfileInfo
-
decrementClaimCount
-
destroyContent
Destroys a ContentClaim that was being written to but is no longer needed- Parameters:
claim- claim to destroy
-
resetState
private void resetState() -
acknowledgeRecords
private void acknowledgeRecords() -
migrate
- Specified by:
migratein interfaceProcessSession
-
migrate
- Specified by:
migratein interfaceProcessSession
-
migrate
-
summarizeEvents
-
formatNanos
-
incrementConnectionInputCounts
-
incrementConnectionInputCounts
-
incrementConnectionOutputCounts
-
incrementConnectionOutputCounts
-
registerDequeuedRecord
-
handleConflictingId
private void handleConflictingId(FlowFileRecord flowFile, Connection connection, StandardRepositoryRecord conflict) -
adjustCounter
- Specified by:
adjustCounterin interfaceProcessSession
-
adjustCounter
-
get
- Specified by:
getin interfaceProcessSession
-
get
- Specified by:
getin interfaceProcessSession
-
get
- Specified by:
getin interfaceProcessSession
-
get
-
getQueueSize
- Specified by:
getQueueSizein interfaceProcessSession
-
create
- Specified by:
createin interfaceProcessSession
-
create
- Specified by:
createin interfaceProcessSession
-
create
- Specified by:
createin interfaceProcessSession
-
clone
- Specified by:
clonein interfaceProcessSession
-
clone
- Specified by:
clonein interfaceProcessSession
-
registerForkEvent
-
registerJoinEvent
-
penalize
- Specified by:
penalizein interfaceProcessSession
-
penalize
-
putAttribute
- Specified by:
putAttributein interfaceProcessSession
-
putAllAttributes
- Specified by:
putAllAttributesin interfaceProcessSession
-
removeAttribute
- Specified by:
removeAttributein interfaceProcessSession
-
removeAllAttributes
- Specified by:
removeAllAttributesin interfaceProcessSession
-
removeAllAttributes
- Specified by:
removeAllAttributesin interfaceProcessSession
-
updateLastQueuedDate
-
updateLastQueuedDate
-
transfer
- Specified by:
transferin interfaceProcessSession
-
transfer
- Specified by:
transferin interfaceProcessSession
-
transfer
- Specified by:
transferin interfaceProcessSession
-
transfer
- Specified by:
transferin interfaceProcessSession
-
remove
- Specified by:
removein interfaceProcessSession
-
remove
- Specified by:
removein interfaceProcessSession
-
removeForkEvents
-
expireFlowFiles
public void expireFlowFiles() -
removeExpired
-
getInputStream
private InputStream getInputStream(FlowFile flowFile, ContentClaim claim, long contentClaimOffset, boolean allowCachingOfStream) throws ContentNotFoundException - Throws:
ContentNotFoundException
-
read
- Specified by:
readin interfaceProcessSession
-
read
- Specified by:
readin interfaceProcessSession
-
createTaskTerminationStream
-
createTaskTerminationStream
-
incrementReadCount
-
decrementReadCount
-
merge
- Specified by:
mergein interfaceProcessSession
-
merge
public FlowFile merge(Collection<FlowFile> sources, FlowFile destination, byte[] header, byte[] footer, byte[] demarcator) - Specified by:
mergein interfaceProcessSession
-
ensureNotAppending
- Throws:
IOException
-
write
- Specified by:
writein interfaceProcessSession
-
write
- Specified by:
writein interfaceProcessSession
-
append
- Specified by:
appendin interfaceProcessSession
-
removeTemporaryClaim
Checks if the ContentClaim associated with this record should be removed, since the record is about to be updated to point to a new content claim. If so, removes the working claim. This happens if invalid input: '&' only if the content of this FlowFile has been modified since it was last committed to the FlowFile repository, because this indicates that the content is no longer needed and should be cleaned up.- Parameters:
record- record
-
resetWriteClaims
private void resetWriteClaims() -
resetWriteClaims
private void resetWriteClaims(boolean suppressExceptions) -
resetReadClaim
private void resetReadClaim() -
write
- Specified by:
writein interfaceProcessSession
-
importFrom
- Specified by:
importFromin interfaceProcessSession
-
importFrom
- Specified by:
importFromin interfaceProcessSession
-
exportTo
- Specified by:
exportToin interfaceProcessSession
-
exportTo
- Specified by:
exportToin interfaceProcessSession
-
handleContentNotFound
private void handleContentNotFound(ContentNotFoundException nfe, Collection<StandardRepositoryRecord> suspectRecords) -
handleContentNotFound
private void handleContentNotFound(ContentNotFoundException nfe, StandardRepositoryRecord suspectRecord) -
validateRecordState
-
validateRecordState
-
validateRecordState
-
isFlowFileKnown
Checks if a FlowFile is known in this session.- Parameters:
flowFile- the FlowFile to check- Returns:
trueif the FlowFile is known in this session,falseotherwise.
-
getMostRecent
-
intersectAttributes
Returns the attributes that are common to every FlowFile given. The key and value must match exactly.- Parameters:
flowFileList- a list of FlowFiles- Returns:
- the common attributes
-
finalize
-
getProvenanceReporter
- Specified by:
getProvenanceReporterin interfaceProcessSession
-
setState
- Specified by:
setStatein interfaceProcessSession- Throws:
IOException
-
setState
-
getState
- Specified by:
getStatein interfaceProcessSession- Throws:
IOException
-
replaceState
public boolean replaceState(StateMap oldValue, Map<String, String> newValue, Scope scope) throws IOException- Specified by:
replaceStatein interfaceProcessSession- Throws:
IOException
-
clearState
- Specified by:
clearStatein interfaceProcessSession
-
toString
-
getIncrementedVersion
-