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
| Modifier and Type | Class and Description |
|---|---|
protected static class |
StandardProcessSession.Checkpoint |
private static interface |
StandardProcessSession.ConnectionPoller
Callback interface used to poll a FlowFileQueue, in order to perform
functional programming-type of polling a queue
|
| Constructor and Description |
|---|
StandardProcessSession(RepositoryContext context,
TaskTermination taskTermination) |
| Modifier and Type | Method and Description |
|---|---|
private void |
acknowledgeRecords() |
private void |
addEventType(Map<String,BitSet> map,
String id,
ProvenanceEventType eventType) |
void |
adjustCounter(String name,
long delta,
boolean immediate) |
private void |
adjustCounter(String name,
long delta,
Map<String,Long> map) |
FlowFile |
append(FlowFile source,
OutputStreamCallback writer) |
void |
checkpoint() |
private void |
checkpoint(boolean copyCollections) |
void |
clearState(Scope scope) |
FlowFile |
clone(FlowFile example) |
FlowFile |
clone(FlowFile example,
long offset,
long size) |
private void |
closeStreams(Map<FlowFile,? extends Closeable> streamMap,
String action,
String streamType) |
private Map<String,Long> |
combineCounters(Map<String,Long> first,
Map<String,Long> second) |
void |
commit() |
protected void |
commit(StandardProcessSession.Checkpoint checkpoint) |
FlowFile |
create() |
FlowFile |
create(Collection<FlowFile> parents) |
FlowFile |
create(FlowFile parent) |
private InputStream |
createTaskTerminationStream(InputStream delegate) |
private OutputStream |
createTaskTerminationStream(OutputStream delegate) |
private void |
decrementClaimCount(ContentClaim claim) |
private void |
decrementReadCount(FlowFile flowFile) |
private void |
destroyContent(ContentClaim claim,
StandardRepositoryRecord repoRecord)
Destroys a ContentClaim that was being written to but is no longer needed
|
ProvenanceEventRecord |
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 ProvenanceEventRecord |
enrich(ProvenanceEventRecord rawEvent,
Map<String,FlowFileRecord> flowFileRecordMap,
Map<Long,StandardRepositoryRecord> records,
boolean updateAttributes,
long commitNanos) |
private void |
ensureNotAppending(ContentClaim claim) |
void |
expireFlowFiles() |
void |
exportTo(FlowFile source,
OutputStream destination) |
void |
exportTo(FlowFile source,
Path destination,
boolean append) |
protected void |
finalize() |
private void |
formatNanos(long nanos,
StringBuilder sb) |
FlowFile |
get() |
List<FlowFile> |
get(FlowFileFilter filter) |
List<FlowFile> |
get(int maxResults) |
private List<FlowFile> |
get(StandardProcessSession.ConnectionPoller poller,
boolean lockAllQueues) |
private InputStream |
getInputStream(FlowFile flowFile,
ContentClaim claim,
long offset,
boolean allowCachingOfStream) |
private FlowFile |
getMostRecent(FlowFile flowFile) |
ProvenanceReporter |
getProvenanceReporter() |
QueueSize |
getQueueSize() |
private StandardRepositoryRecord |
getRecord(FlowFile flowFile) |
protected long |
getSessionId() |
StateMap |
getState(Scope scope) |
private void |
handleConflictingId(FlowFileRecord flowFile,
Connection connection,
StandardRepositoryRecord conflict) |
private void |
handleContentNotFound(ContentNotFoundException nfe,
Collection<StandardRepositoryRecord> suspectRecords) |
private void |
handleContentNotFound(ContentNotFoundException nfe,
StandardRepositoryRecord suspectRecord) |
FlowFile |
importFrom(InputStream source,
FlowFile destination) |
FlowFile |
importFrom(Path source,
boolean keepSourceFile,
FlowFile destination) |
private void |
incrementConnectionInputCounts(Connection connection,
RepositoryRecord record) |
private void |
incrementConnectionInputCounts(String connectionId,
int flowFileCount,
long bytes) |
private void |
incrementConnectionOutputCounts(Connection connection,
FlowFileRecord record) |
private void |
incrementConnectionOutputCounts(String connectionId,
int flowFileCount,
long bytes) |
private void |
incrementReadCount(FlowFile flowFile) |
private static Map<String,String> |
intersectAttributes(Collection<FlowFile> flowFileList)
Returns the attributes that are common to every FlowFile given.
|
(package private) boolean |
isFlowFileKnown(FlowFile flowFile)
Checks if a FlowFile is known in this session.
|
private boolean |
isSpuriousForkEvent(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 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.
|
private String |
loggableFlowfileInfo() |
FlowFile |
merge(Collection<FlowFile> sources,
FlowFile destination) |
FlowFile |
merge(Collection<FlowFile> sources,
FlowFile destination,
byte[] header,
byte[] footer,
byte[] demarcator) |
void |
migrate(ProcessSession newOwner,
Collection<FlowFile> flowFiles) |
private void |
migrate(StandardProcessSession newOwner,
Collection<FlowFile> flowFiles) |
FlowFile |
penalize(FlowFile flowFile) |
FlowFile |
putAllAttributes(FlowFile flowFile,
Map<String,String> attributes) |
FlowFile |
putAttribute(FlowFile flowFile,
String key,
String value) |
InputStream |
read(FlowFile source) |
void |
read(FlowFile source,
boolean allowSessionStreamManagement,
InputStreamCallback reader) |
void |
read(FlowFile source,
InputStreamCallback reader) |
private void |
registerDequeuedRecord(FlowFileRecord flowFile,
Connection connection) |
private void |
registerForkEvent(FlowFile parent,
FlowFile child) |
private void |
registerJoinEvent(FlowFile child,
Collection<FlowFile> parents) |
void |
remove(Collection<FlowFile> flowFiles) |
void |
remove(FlowFile flowFile) |
FlowFile |
removeAllAttributes(FlowFile flowFile,
Pattern keyPattern) |
FlowFile |
removeAllAttributes(FlowFile flowFile,
Set<String> keys) |
FlowFile |
removeAttribute(FlowFile flowFile,
String key) |
private void |
removeExpired(Set<FlowFileRecord> flowFiles,
Connection connection) |
private void |
removeForkEvents(FlowFile flowFile) |
private void |
removeTemporaryClaim(StandardRepositoryRecord record)
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.
|
boolean |
replaceState(StateMap oldValue,
Map<String,String> newValue,
Scope scope) |
private void |
resetReadClaim() |
private void |
resetState() |
private void |
resetWriteClaims() |
private void |
resetWriteClaims(boolean suppressExceptions) |
void |
rollback() |
void |
rollback(boolean penalize) |
protected void |
rollback(boolean penalize,
boolean rollbackCheckpoint) |
protected void |
rollbackRecord(StandardRepositoryRecord record,
boolean penalize)
Rolls back the Record in a manner that is appropriate for the context.
|
void |
setState(Map<String,String> state,
Scope scope) |
private void |
setState(StateMap stateMap,
Scope scope) |
private String |
summarizeEvents(StandardProcessSession.Checkpoint checkpoint) |
String |
toString() |
void |
transfer(Collection<FlowFile> flowFiles) |
void |
transfer(Collection<FlowFile> flowFiles,
Relationship relationship) |
void |
transfer(FlowFile flowFile) |
void |
transfer(FlowFile flowFile,
Relationship relationship) |
private void |
updateEventContentClaims(ProvenanceEventBuilder builder,
FlowFile flowFile,
StandardRepositoryRecord repoRecord) |
private void |
updateEventRepository(StandardProcessSession.Checkpoint checkpoint) |
private void |
updateLastQueuedDate(StandardRepositoryRecord record) |
private void |
updateLastQueuedDate(StandardRepositoryRecord record,
Long lastQueueDate) |
protected void |
updateProvenanceRepo(StandardProcessSession.Checkpoint checkpoint) |
private List<FlowFile> |
validateRecordState(Collection<FlowFile> flowFiles) |
private FlowFile |
validateRecordState(FlowFile flowFile) |
private FlowFile |
validateRecordState(FlowFile flowFile,
boolean allowRecursiveRead) |
private void |
verifyTaskActive() |
OutputStream |
write(FlowFile source) |
FlowFile |
write(FlowFile source,
OutputStreamCallback writer) |
FlowFile |
write(FlowFile source,
StreamCallback writer) |
private static final AtomicLong idGenerator
private static final AtomicLong enqueuedIndex
private static final StateMap EMPTY_STATE_MAP
public static final int VERBOSE_LOG_THRESHOLD
public static final String DEFAULT_FLOWFILE_PATH
private static final org.slf4j.Logger LOG
private static final org.slf4j.Logger claimLog
private static final int MAX_ROLLBACK_FLOWFILES_TO_LOG
private final Map<Long,StandardRepositoryRecord> records
private final Map<String,StandardFlowFileEvent> connectionCounts
private final Map<FlowFileQueue,Set<FlowFileRecord>> unacknowledgedFlowFiles
private final Map<ContentClaim,org.apache.nifi.stream.io.ByteCountingOutputStream> appendableStreams
private final RepositoryContext context
private final TaskTermination taskTermination
private final long sessionId
private final String connectableDescription
private final InternalProvenanceReporter provenanceReporter
private int removedCount
private long removedBytes
private long bytesRead
private long bytesWritten
private int flowFilesIn
private int flowFilesOut
private long contentSizeIn
private long contentSizeOut
private ContentClaim currentReadClaim
private ContentClaimInputStream currentReadClaimStream
private long processingStartTime
private final Map<FlowFile,InputStream> openInputStreams
private final Map<FlowFile,OutputStream> openOutputStreams
private final Map<FlowFile,List<ProvenanceEventRecord>> generatedProvenanceEvents
private final Map<FlowFile,ProvenanceEventBuilder> forkEventBuilders
private StandardProcessSession.Checkpoint checkpoint
private final ContentClaimWriteCache claimCache
private StateMap localState
private StateMap clusterState
public StandardProcessSession(RepositoryContext context, TaskTermination taskTermination)
private void verifyTaskActive()
protected long getSessionId()
private void closeStreams(Map<FlowFile,? extends Closeable> streamMap, String action, String streamType)
public void checkpoint()
private void checkpoint(boolean copyCollections)
public void commit()
commit in interface ProcessSessionprotected void commit(StandardProcessSession.Checkpoint checkpoint)
private void updateEventRepository(StandardProcessSession.Checkpoint checkpoint)
private Map<String,Long> combineCounters(Map<String,Long> first, Map<String,Long> second)
private void addEventType(Map<String,BitSet> map, String id, ProvenanceEventType eventType)
private StandardRepositoryRecord getRecord(FlowFile flowFile)
protected void updateProvenanceRepo(StandardProcessSession.Checkpoint checkpoint)
private void updateEventContentClaims(ProvenanceEventBuilder builder, FlowFile flowFile, StandardRepositoryRecord repoRecord)
public ProvenanceEventRecord enrich(ProvenanceEventRecord rawEvent, FlowFile flowFile, long commitNanos)
ProvenanceEventEnricherenrich in interface ProvenanceEventEnricherrawEvent - recordflowFile - flowfilecommitNanos - the time (in nanoseconds) when the associated session was committedprivate ProvenanceEventRecord enrich(ProvenanceEventRecord rawEvent, Map<String,FlowFileRecord> flowFileRecordMap, Map<Long,StandardRepositoryRecord> records, boolean updateAttributes, long commitNanos)
private boolean isSpuriousForkEvent(ProvenanceEventRecord event, Set<String> removedFlowFiles)
event - eventprivate boolean isSpuriousRouteEvent(ProvenanceEventRecord event, Map<Long,StandardRepositoryRecord> records)
event - eventrecords - recordspublic void rollback()
rollback in interface ProcessSessionpublic void rollback(boolean penalize)
rollback in interface ProcessSessionprotected void rollback(boolean penalize,
boolean rollbackCheckpoint)
protected void rollbackRecord(StandardRepositoryRecord record, boolean penalize)
record - the Record that is to be rolled backpenalize - whether or not the Record should be penalizedprivate String loggableFlowfileInfo()
private void decrementClaimCount(ContentClaim claim)
private void destroyContent(ContentClaim claim, StandardRepositoryRecord repoRecord)
claim - claim to destroyprivate void resetState()
private void acknowledgeRecords()
public void migrate(ProcessSession newOwner, Collection<FlowFile> flowFiles)
migrate in interface ProcessSessionprivate void migrate(StandardProcessSession newOwner, Collection<FlowFile> flowFiles)
private String summarizeEvents(StandardProcessSession.Checkpoint checkpoint)
private void formatNanos(long nanos,
StringBuilder sb)
private void incrementConnectionInputCounts(Connection connection, RepositoryRecord record)
private void incrementConnectionInputCounts(String connectionId, int flowFileCount, long bytes)
private void incrementConnectionOutputCounts(Connection connection, FlowFileRecord record)
private void incrementConnectionOutputCounts(String connectionId, int flowFileCount, long bytes)
private void registerDequeuedRecord(FlowFileRecord flowFile, Connection connection)
private void handleConflictingId(FlowFileRecord flowFile, Connection connection, StandardRepositoryRecord conflict)
public void adjustCounter(String name, long delta, boolean immediate)
adjustCounter in interface ProcessSessionpublic FlowFile get()
get in interface ProcessSessionpublic List<FlowFile> get(int maxResults)
get in interface ProcessSessionpublic List<FlowFile> get(FlowFileFilter filter)
get in interface ProcessSessionprivate List<FlowFile> get(StandardProcessSession.ConnectionPoller poller, boolean lockAllQueues)
public QueueSize getQueueSize()
getQueueSize in interface ProcessSessionpublic FlowFile create()
create in interface ProcessSessionpublic FlowFile create(FlowFile parent)
create in interface ProcessSessionpublic FlowFile create(Collection<FlowFile> parents)
create in interface ProcessSessionpublic FlowFile clone(FlowFile example)
clone in interface ProcessSessionpublic FlowFile clone(FlowFile example, long offset, long size)
clone in interface ProcessSessionprivate void registerJoinEvent(FlowFile child, Collection<FlowFile> parents)
public FlowFile penalize(FlowFile flowFile)
penalize in interface ProcessSessionpublic FlowFile putAttribute(FlowFile flowFile, String key, String value)
putAttribute in interface ProcessSessionpublic FlowFile putAllAttributes(FlowFile flowFile, Map<String,String> attributes)
putAllAttributes in interface ProcessSessionpublic FlowFile removeAttribute(FlowFile flowFile, String key)
removeAttribute in interface ProcessSessionpublic FlowFile removeAllAttributes(FlowFile flowFile, Set<String> keys)
removeAllAttributes in interface ProcessSessionpublic FlowFile removeAllAttributes(FlowFile flowFile, Pattern keyPattern)
removeAllAttributes in interface ProcessSessionprivate void updateLastQueuedDate(StandardRepositoryRecord record, Long lastQueueDate)
private void updateLastQueuedDate(StandardRepositoryRecord record)
public void transfer(FlowFile flowFile, Relationship relationship)
transfer in interface ProcessSessionpublic void transfer(FlowFile flowFile)
transfer in interface ProcessSessionpublic void transfer(Collection<FlowFile> flowFiles)
transfer in interface ProcessSessionpublic void transfer(Collection<FlowFile> flowFiles, Relationship relationship)
transfer in interface ProcessSessionpublic void remove(FlowFile flowFile)
remove in interface ProcessSessionpublic void remove(Collection<FlowFile> flowFiles)
remove in interface ProcessSessionprivate void removeForkEvents(FlowFile flowFile)
public void expireFlowFiles()
private void removeExpired(Set<FlowFileRecord> flowFiles, Connection connection)
private InputStream getInputStream(FlowFile flowFile, ContentClaim claim, long offset, boolean allowCachingOfStream) throws ContentNotFoundException
ContentNotFoundExceptionpublic void read(FlowFile source, InputStreamCallback reader)
read in interface ProcessSessionpublic void read(FlowFile source, boolean allowSessionStreamManagement, InputStreamCallback reader)
read in interface ProcessSessionpublic InputStream read(FlowFile source)
read in interface ProcessSessionprivate InputStream createTaskTerminationStream(InputStream delegate)
private OutputStream createTaskTerminationStream(OutputStream delegate)
private void incrementReadCount(FlowFile flowFile)
private void decrementReadCount(FlowFile flowFile)
public FlowFile merge(Collection<FlowFile> sources, FlowFile destination)
merge in interface ProcessSessionpublic FlowFile merge(Collection<FlowFile> sources, FlowFile destination, byte[] header, byte[] footer, byte[] demarcator)
merge in interface ProcessSessionprivate void ensureNotAppending(ContentClaim claim) throws IOException
IOExceptionpublic OutputStream write(FlowFile source)
write in interface ProcessSessionpublic FlowFile write(FlowFile source, OutputStreamCallback writer)
write in interface ProcessSessionpublic FlowFile append(FlowFile source, OutputStreamCallback writer)
append in interface ProcessSessionprivate void removeTemporaryClaim(StandardRepositoryRecord record)
record - recordprivate void resetWriteClaims()
private void resetWriteClaims(boolean suppressExceptions)
private void resetReadClaim()
public FlowFile write(FlowFile source, StreamCallback writer)
write in interface ProcessSessionpublic FlowFile importFrom(Path source, boolean keepSourceFile, FlowFile destination)
importFrom in interface ProcessSessionpublic FlowFile importFrom(InputStream source, FlowFile destination)
importFrom in interface ProcessSessionpublic void exportTo(FlowFile source, Path destination, boolean append)
exportTo in interface ProcessSessionpublic void exportTo(FlowFile source, OutputStream destination)
exportTo in interface ProcessSessionprivate void handleContentNotFound(ContentNotFoundException nfe, Collection<StandardRepositoryRecord> suspectRecords)
private void handleContentNotFound(ContentNotFoundException nfe, StandardRepositoryRecord suspectRecord)
private FlowFile validateRecordState(FlowFile flowFile, boolean allowRecursiveRead)
private List<FlowFile> validateRecordState(Collection<FlowFile> flowFiles)
boolean isFlowFileKnown(FlowFile flowFile)
flowFile - the FlowFile to checktrue if the FlowFile is known in this session,
false otherwise.private static Map<String,String> intersectAttributes(Collection<FlowFile> flowFileList)
flowFileList - a list of FlowFilesprotected void finalize()
throws Throwable
public ProvenanceReporter getProvenanceReporter()
getProvenanceReporter in interface ProcessSessionpublic void setState(Map<String,String> state, Scope scope) throws IOException
setState in interface ProcessSessionIOExceptionpublic StateMap getState(Scope scope) throws IOException
getState in interface ProcessSessionIOExceptionpublic boolean replaceState(StateMap oldValue, Map<String,String> newValue, Scope scope) throws IOException
replaceState in interface ProcessSessionIOExceptionpublic void clearState(Scope scope)
clearState in interface ProcessSessionCopyright © 2021 Apache NiFi Project. All rights reserved.