Class StandardProcessSession
java.lang.Object
org.apache.nifi.controller.repository.StandardProcessSession
- All Implemented Interfaces:
ProvenanceEventEnricher,org.apache.nifi.processor.ProcessSession
public class StandardProcessSession
extends Object
implements org.apache.nifi.processor.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) 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 updateAttributesAndContent, 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) voidprivate voidformatNanos(long nanos, StringBuilder sb) get()get(int maxResults) get(StandardProcessSession.ConnectionPoller poller, boolean lockAllQueues) get(org.apache.nifi.processor.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(org.apache.nifi.processor.ProcessSession newOwner) voidmigrate(org.apache.nifi.processor.ProcessSession newOwner, Collection<FlowFile> flowFiles) putAllAttributes(FlowFile flowFile, Map<String, String> attributes) putAttribute(FlowFile flowFile, String key, String value) voidprivate 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, org.apache.nifi.processor.Relationship relationship) voidvoidprivate 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 voidMethods inherited from class java.lang.Object
clone, equals, finalize, 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 interfaceorg.apache.nifi.processor.ProcessSession
-
commitAsync
public void commitAsync()- Specified by:
commitAsyncin interfaceorg.apache.nifi.processor.ProcessSession
-
commitAsync
- Specified by:
commitAsyncin interfaceorg.apache.nifi.processor.ProcessSession
-
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 updateAttributesAndContent, 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 interfaceorg.apache.nifi.processor.ProcessSession
-
rollback
public void rollback(boolean penalize) - Specified by:
rollbackin interfaceorg.apache.nifi.processor.ProcessSession
-
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
public void migrate(org.apache.nifi.processor.ProcessSession newOwner) - Specified by:
migratein interfaceorg.apache.nifi.processor.ProcessSession
-
migrate
public void migrate(org.apache.nifi.processor.ProcessSession newOwner, Collection<FlowFile> flowFiles) - Specified by:
migratein interfaceorg.apache.nifi.processor.ProcessSession
-
migrate
-
summarizeEvents
-
formatNanos
-
incrementConnectionInputCounts
-
incrementConnectionInputCounts
-
incrementConnectionOutputCounts
-
incrementConnectionOutputCounts
-
registerDequeuedRecord
-
handleConflictingId
private void handleConflictingId(FlowFileRecord flowFile, Connection connection, StandardRepositoryRecord conflict) -
adjustCounter
- Specified by:
adjustCounterin interfaceorg.apache.nifi.processor.ProcessSession
-
adjustCounter
-
get
- Specified by:
getin interfaceorg.apache.nifi.processor.ProcessSession
-
get
- Specified by:
getin interfaceorg.apache.nifi.processor.ProcessSession
-
get
- Specified by:
getin interfaceorg.apache.nifi.processor.ProcessSession
-
get
-
getQueueSize
- Specified by:
getQueueSizein interfaceorg.apache.nifi.processor.ProcessSession
-
create
- Specified by:
createin interfaceorg.apache.nifi.processor.ProcessSession
-
create
- Specified by:
createin interfaceorg.apache.nifi.processor.ProcessSession
-
create
- Specified by:
createin interfaceorg.apache.nifi.processor.ProcessSession
-
clone
- Specified by:
clonein interfaceorg.apache.nifi.processor.ProcessSession
-
clone
- Specified by:
clonein interfaceorg.apache.nifi.processor.ProcessSession
-
registerForkEvent
-
registerJoinEvent
-
penalize
- Specified by:
penalizein interfaceorg.apache.nifi.processor.ProcessSession
-
penalize
-
putAttribute
- Specified by:
putAttributein interfaceorg.apache.nifi.processor.ProcessSession
-
putAllAttributes
- Specified by:
putAllAttributesin interfaceorg.apache.nifi.processor.ProcessSession
-
removeAttribute
- Specified by:
removeAttributein interfaceorg.apache.nifi.processor.ProcessSession
-
removeAllAttributes
- Specified by:
removeAllAttributesin interfaceorg.apache.nifi.processor.ProcessSession
-
removeAllAttributes
- Specified by:
removeAllAttributesin interfaceorg.apache.nifi.processor.ProcessSession
-
updateLastQueuedDate
-
updateLastQueuedDate
-
transfer
- Specified by:
transferin interfaceorg.apache.nifi.processor.ProcessSession
-
transfer
- Specified by:
transferin interfaceorg.apache.nifi.processor.ProcessSession
-
transfer
- Specified by:
transferin interfaceorg.apache.nifi.processor.ProcessSession
-
transfer
public void transfer(Collection<FlowFile> flowFiles, org.apache.nifi.processor.Relationship relationship) - Specified by:
transferin interfaceorg.apache.nifi.processor.ProcessSession
-
remove
- Specified by:
removein interfaceorg.apache.nifi.processor.ProcessSession
-
remove
- Specified by:
removein interfaceorg.apache.nifi.processor.ProcessSession
-
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 interfaceorg.apache.nifi.processor.ProcessSession
-
read
- Specified by:
readin interfaceorg.apache.nifi.processor.ProcessSession
-
createTaskTerminationStream
-
createTaskTerminationStream
-
incrementReadCount
-
decrementReadCount
-
merge
- Specified by:
mergein interfaceorg.apache.nifi.processor.ProcessSession
-
merge
public FlowFile merge(Collection<FlowFile> sources, FlowFile destination, byte[] header, byte[] footer, byte[] demarcator) - Specified by:
mergein interfaceorg.apache.nifi.processor.ProcessSession
-
ensureNotAppending
- Throws:
IOException
-
write
- Specified by:
writein interfaceorg.apache.nifi.processor.ProcessSession
-
write
- Specified by:
writein interfaceorg.apache.nifi.processor.ProcessSession
-
append
- Specified by:
appendin interfaceorg.apache.nifi.processor.ProcessSession
-
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 interfaceorg.apache.nifi.processor.ProcessSession
-
importFrom
- Specified by:
importFromin interfaceorg.apache.nifi.processor.ProcessSession
-
importFrom
- Specified by:
importFromin interfaceorg.apache.nifi.processor.ProcessSession
-
exportTo
- Specified by:
exportToin interfaceorg.apache.nifi.processor.ProcessSession
-
exportTo
- Specified by:
exportToin interfaceorg.apache.nifi.processor.ProcessSession
-
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
-
getProvenanceReporter
- Specified by:
getProvenanceReporterin interfaceorg.apache.nifi.processor.ProcessSession
-
setState
- Specified by:
setStatein interfaceorg.apache.nifi.processor.ProcessSession- Throws:
IOException
-
setState
-
getState
- Specified by:
getStatein interfaceorg.apache.nifi.processor.ProcessSession- Throws:
IOException
-
replaceState
public boolean replaceState(StateMap oldValue, Map<String, String> newValue, Scope scope) throws IOException- Specified by:
replaceStatein interfaceorg.apache.nifi.processor.ProcessSession- Throws:
IOException
-
clearState
- Specified by:
clearStatein interfaceorg.apache.nifi.processor.ProcessSession
-
toString
-
getIncrementedVersion
-