Class StreamAppenderatorDriver
java.lang.Object
org.apache.druid.segment.realtime.appenderator.BaseAppenderatorDriver
org.apache.druid.segment.realtime.appenderator.StreamAppenderatorDriver
- All Implemented Interfaces:
Closeable,AutoCloseable
This class is specialized for streaming ingestion. In streaming ingestion, the segment lifecycle is like:
APPENDING -> APPEND_FINISHED -> PUBLISHED
- APPENDING: Segment is available for appending.
- APPEND_FINISHED: Segment cannot be updated (data cannot be added anymore) and is waiting for being published.
- PUBLISHED: Segment is pushed to deep storage, its metadata is published to metastore, and finally the segment is dropped from local storage
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.druid.segment.realtime.appenderator.BaseAppenderatorDriver
BaseAppenderatorDriver.SegmentsForSequence -
Field Summary
Fields inherited from class org.apache.druid.segment.realtime.appenderator.BaseAppenderatorDriver
appenderator, executor, segments -
Constructor Summary
ConstructorsConstructorDescriptionStreamAppenderatorDriver(Appenderator appenderator, SegmentAllocator segmentAllocator, SegmentHandoffNotifierFactory handoffNotifierFactory, PublishedSegmentRetriever segmentRetriever, DataSegmentKiller dataSegmentKiller, com.fasterxml.jackson.databind.ObjectMapper objectMapper, SegmentGenerationMetrics metrics) Create a driver. -
Method Summary
Modifier and TypeMethodDescriptionadd(InputRow row, String sequenceName, com.google.common.base.Supplier<Committer> committerSupplier) add(InputRow row, String sequenceName, com.google.common.base.Supplier<Committer> committerSupplier, boolean skipSegmentLineageCheck, boolean allowIncrementalPersists) Add a row.voidclose()Closes this driver.voidmoveSegmentOut(String sequenceName, List<SegmentIdWithShardSpec> identifiers) Move a set of identifiers out from "active", making way for newer segments.Persist all data indexed through this driver so far.com.google.common.util.concurrent.ListenableFuture<Object>persistAsync(Committer committer) Persist all data indexed through this driver so far.com.google.common.util.concurrent.ListenableFuture<SegmentsAndCommitMetadata>publish(TransactionalSegmentPublisher publisher, Committer committer, Collection<String> sequenceNames) Execute a task in background to publish all segments corresponding to the given sequence names.com.google.common.util.concurrent.ListenableFuture<SegmentsAndCommitMetadata>publishAndRegisterHandoff(TransactionalSegmentPublisher publisher, Committer committer, Collection<String> sequenceNames) com.google.common.util.concurrent.ListenableFuture<SegmentsAndCommitMetadata>registerHandoff(SegmentsAndCommitMetadata segmentsAndCommitMetadata) Register the segments in the givenSegmentsAndCommitMetadatato be handed off and execute a background task which waits until the hand off completes.startJob(AppenderatorDriverSegmentLockHelper lockHelper) Perform any initial setup and return currently persisted commit metadata.Methods inherited from class org.apache.druid.segment.realtime.appenderator.BaseAppenderatorDriver
append, clear, getSegments
-
Constructor Details
-
StreamAppenderatorDriver
public StreamAppenderatorDriver(Appenderator appenderator, SegmentAllocator segmentAllocator, SegmentHandoffNotifierFactory handoffNotifierFactory, PublishedSegmentRetriever segmentRetriever, DataSegmentKiller dataSegmentKiller, com.fasterxml.jackson.databind.ObjectMapper objectMapper, SegmentGenerationMetrics metrics) Create a driver.- Parameters:
appenderator- appenderatorsegmentAllocator- segment allocatorhandoffNotifierFactory- handoff notifier factorysegmentRetriever- used segment checkerobjectMapper- object mapper, used for serde of commit metadatametrics- Firedepartment metrics
-
-
Method Details
-
startJob
Description copied from class:BaseAppenderatorDriverPerform any initial setup and return currently persisted commit metadata.Note that this method returns the same metadata you've passed in with your Committers, even though this class stores extra metadata on disk.
- Specified by:
startJobin classBaseAppenderatorDriver- Returns:
- currently persisted commit metadata
-
add
public AppenderatorDriverAddResult add(InputRow row, String sequenceName, com.google.common.base.Supplier<Committer> committerSupplier) throws IOException - Throws:
IOException
-
add
public AppenderatorDriverAddResult add(InputRow row, String sequenceName, com.google.common.base.Supplier<Committer> committerSupplier, boolean skipSegmentLineageCheck, boolean allowIncrementalPersists) throws IOException Add a row. Must not be called concurrently from multiple threads.- Parameters:
row- the row to addsequenceName- sequenceName for this row's segmentcommitterSupplier- supplier of a committer associated with all data that has been added, including this row if is set to false then this will not be usedskipSegmentLineageCheck- Should be setfalseto perform lineage validation using previousSegmentId for this sequence. Note that for Kafka Streams we should disable this check and set this parameter totrue. iftrue, skips, does not enforce, lineage validation.allowIncrementalPersists- whether to allow persist to happen when maxRowsInMemory or intermediate persist period threshold is hit- Returns:
AppenderatorDriverAddResult- Throws:
IOException- if there is an I/O error while allocating or writing to a segment
-
moveSegmentOut
Move a set of identifiers out from "active", making way for newer segments. This method is to support KafkaIndexTask's legacy mode and will be removed in the future. See KakfaIndexTask.runLegacy(). -
persist
Persist all data indexed through this driver so far. Blocks until complete.Should be called after all data has been added through
add(InputRow, String, Supplier, boolean, boolean).- Parameters:
committer- committer representing all data that has been added so far- Returns:
- commitMetadata persisted
- Throws:
InterruptedException
-
persistAsync
Persist all data indexed through this driver so far. Returns a future of persisted commitMetadata.Should be called after all data has been added through
add(InputRow, String, Supplier, boolean, boolean).- Parameters:
committer- committer representing all data that has been added so far- Returns:
- future containing commitMetadata persisted
-
publish
public com.google.common.util.concurrent.ListenableFuture<SegmentsAndCommitMetadata> publish(TransactionalSegmentPublisher publisher, Committer committer, Collection<String> sequenceNames) Execute a task in background to publish all segments corresponding to the given sequence names. The task internally pushes the segments to the deep storage first, and then publishes the metadata to the metadata storage.- Parameters:
publisher- segment publishercommitter- committersequenceNames- a collection of sequence names to be published- Returns:
- a
ListenableFuturefor the submitted task which removes publishedsequenceNamesfromactiveSegmentsandpublishPendingSegments
-
registerHandoff
public com.google.common.util.concurrent.ListenableFuture<SegmentsAndCommitMetadata> registerHandoff(SegmentsAndCommitMetadata segmentsAndCommitMetadata) Register the segments in the givenSegmentsAndCommitMetadatato be handed off and execute a background task which waits until the hand off completes.- Parameters:
segmentsAndCommitMetadata- the result segments and metadata ofpublish(TransactionalSegmentPublisher, Committer, Collection)- Returns:
- null if the input segmentsAndMetadata is null. Otherwise, a
ListenableFuturefor the submitted task which returnsSegmentsAndCommitMetadatacontaining the segments successfully handed off and the metadata of the caller ofAppenderatorDriverMetadata
-
publishAndRegisterHandoff
public com.google.common.util.concurrent.ListenableFuture<SegmentsAndCommitMetadata> publishAndRegisterHandoff(TransactionalSegmentPublisher publisher, Committer committer, Collection<String> sequenceNames) -
close
public void close()Description copied from class:BaseAppenderatorDriverCloses this driver. Does not close the underlying Appenderator; you should do that yourself.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classBaseAppenderatorDriver
-