Class ComputationRunner
- java.lang.Object
-
- org.nuxeo.lib.stream.computation.log.ComputationRunner
-
- All Implemented Interfaces:
Runnable,RebalanceListener
public class ComputationRunner extends Object implements Runnable, RebalanceListener
Thread driving a Computation- Since:
- 9.3
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classComputationRunner.CheckPointExceptionprotected static classComputationRunner.ReturnCode
-
Field Summary
Fields Modifier and Type Field Description protected CountDownLatchassignmentLatchprotected static intCHECKPOINT_MAX_RETRYprotected static intCHECKPOINT_PAUSE_MSprotected Computationcomputationprotected ComputationContextImplcontextprotected longcounterprotected List<LogPartition>defaultAssignmentprotected booleandrainprotected io.dropwizard.metrics5.CounterfailureCountstatic StringGLOBAL_FAILURE_COUNT_REGISTRY_NAMEprotected io.dropwizard.metrics5.CounterglobalFailureCountprotected static longINACTIVITY_BREAK_MSprotected longinCheckpointRecordsprotected longinRecordsprotected longlastReadTimeprotected io.opencensus.trace.SpanContextlastSpanContextprotected longlastTimerExecutionprotected WatermarkMonotonicIntervallowWatermarkprotected ComputationMetadataMappingmetadatastatic StringNUXEO_METRICS_REGISTRY_NAMEprotected longoutRecordsprotected ComputationPolicypolicyprotected io.dropwizard.metrics5.TimerprocessRecordTimerprotected io.dropwizard.metrics5.TimerprocessTimerTimerstatic DurationREAD_TIMEOUTprotected booleanrecordActivityprotected io.dropwizard.metrics5.CounterrecordSkippedCountprotected io.dropwizard.metrics5.MetricRegistryregistryprotected io.dropwizard.metrics5.CounterrunningCountprotected static AtomicIntegerskipFailuresstatic longSLOW_COMPUTATION_THRESHOLD_NSprotected static longSTARVING_TIMEOUT_MSprotected booleanstopprotected LogStreamManagerstreamManagerprotected Supplier<Computation>supplierprotected LogTailer<Record>tailerprotected StringthreadName
-
Constructor Summary
Constructors Constructor Description ComputationRunner(Supplier<Computation> supplier, ComputationMetadataMapping metadata, List<LogPartition> defaultAssignment, LogStreamManager streamManager, ComputationPolicy policy)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckpoint()protected voidcheckpointIfNecessary()protected voidcheckRecordFlags(Record record)protected voidcheckSourceLowWatermark()protected voidcloseTailer()protected booleancontinueLoop()voiddrain()WatermarkgetLowWatermark()protected io.opencensus.trace.SpangetSpanFromRecord(Record record)protected DurationgetTimeoutDuration()voidonPartitionsAssigned(Collection<LogPartition> partitions)voidonPartitionsRevoked(Collection<LogPartition> partitions)protected voidprocessFallback(ComputationContextImpl context)protected voidprocessLoop()protected booleanprocessRecord()protected voidprocessRecordWithRetry(String from, Record record)protected voidprocessRecordWithTracing(String from, Record record)protected booleanprocessTimer()protected voidprocessTimerWithRetry(String key, Long value)protected booleanprocessTimerWithTracing(long now, LinkedHashMap<String,Long> sortedTimer)protected voidregisterMetrics()voidrun()protected ComputationRunner.ReturnCoderunOnce()protected voidsaveOffsets()protected voidsaveState()protected voidsaveTimers()protected voidsendRecords()protected voidsetThreadName(String message)protected booleanskipFailureForRecovery()voidstop()booleanwaitForAssignments(Duration timeout)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.nuxeo.lib.stream.log.RebalanceListener
onPartitionsLost
-
-
-
-
Field Detail
-
READ_TIMEOUT
public static final Duration READ_TIMEOUT
-
STARVING_TIMEOUT_MS
protected static final long STARVING_TIMEOUT_MS
- See Also:
- Constant Field Values
-
INACTIVITY_BREAK_MS
protected static final long INACTIVITY_BREAK_MS
- See Also:
- Constant Field Values
-
CHECKPOINT_MAX_RETRY
protected static final int CHECKPOINT_MAX_RETRY
- See Also:
- Constant Field Values
-
CHECKPOINT_PAUSE_MS
protected static final int CHECKPOINT_PAUSE_MS
- See Also:
- Constant Field Values
-
SLOW_COMPUTATION_THRESHOLD_NS
public static final long SLOW_COMPUTATION_THRESHOLD_NS
- See Also:
- Constant Field Values
-
streamManager
protected final LogStreamManager streamManager
-
metadata
protected final ComputationMetadataMapping metadata
-
supplier
protected final Supplier<Computation> supplier
-
assignmentLatch
protected final CountDownLatch assignmentLatch
-
lowWatermark
protected final WatermarkMonotonicInterval lowWatermark
-
policy
protected final ComputationPolicy policy
-
context
protected ComputationContextImpl context
-
stop
protected volatile boolean stop
-
drain
protected volatile boolean drain
-
computation
protected Computation computation
-
counter
protected long counter
-
inRecords
protected long inRecords
-
inCheckpointRecords
protected long inCheckpointRecords
-
outRecords
protected long outRecords
-
lastReadTime
protected long lastReadTime
-
lastTimerExecution
protected long lastTimerExecution
-
threadName
protected String threadName
-
defaultAssignment
protected List<LogPartition> defaultAssignment
-
NUXEO_METRICS_REGISTRY_NAME
public static final String NUXEO_METRICS_REGISTRY_NAME
- See Also:
- Constant Field Values
-
GLOBAL_FAILURE_COUNT_REGISTRY_NAME
public static final String GLOBAL_FAILURE_COUNT_REGISTRY_NAME
-
registry
protected final io.dropwizard.metrics5.MetricRegistry registry
-
globalFailureCount
protected io.dropwizard.metrics5.Counter globalFailureCount
-
failureCount
protected io.dropwizard.metrics5.Counter failureCount
-
recordSkippedCount
protected io.dropwizard.metrics5.Counter recordSkippedCount
-
runningCount
protected io.dropwizard.metrics5.Counter runningCount
-
processRecordTimer
protected io.dropwizard.metrics5.Timer processRecordTimer
-
processTimerTimer
protected io.dropwizard.metrics5.Timer processTimerTimer
-
skipFailures
protected static AtomicInteger skipFailures
-
recordActivity
protected boolean recordActivity
-
lastSpanContext
protected io.opencensus.trace.SpanContext lastSpanContext
-
-
Constructor Detail
-
ComputationRunner
public ComputationRunner(Supplier<Computation> supplier, ComputationMetadataMapping metadata, List<LogPartition> defaultAssignment, LogStreamManager streamManager, ComputationPolicy policy)
-
-
Method Detail
-
stop
public void stop()
-
drain
public void drain()
-
waitForAssignments
public boolean waitForAssignments(Duration timeout) throws InterruptedException
- Throws:
InterruptedException
-
runOnce
protected ComputationRunner.ReturnCode runOnce()
-
registerMetrics
protected void registerMetrics()
-
closeTailer
protected void closeTailer()
-
processLoop
protected void processLoop() throws InterruptedException- Throws:
InterruptedException
-
continueLoop
protected boolean continueLoop()
-
processTimer
protected boolean processTimer()
-
processTimerWithTracing
protected boolean processTimerWithTracing(long now, LinkedHashMap<String,Long> sortedTimer)
-
processRecord
protected boolean processRecord() throws InterruptedException- Throws:
InterruptedException
-
getSpanFromRecord
protected io.opencensus.trace.Span getSpanFromRecord(Record record)
-
processFallback
protected void processFallback(ComputationContextImpl context)
-
skipFailureForRecovery
protected boolean skipFailureForRecovery()
-
getTimeoutDuration
protected Duration getTimeoutDuration()
-
checkSourceLowWatermark
protected void checkSourceLowWatermark()
-
checkRecordFlags
protected void checkRecordFlags(Record record)
-
checkpointIfNecessary
protected void checkpointIfNecessary()
-
checkpoint
protected void checkpoint()
-
saveTimers
protected void saveTimers()
-
saveState
protected void saveState()
-
saveOffsets
protected void saveOffsets()
-
sendRecords
protected void sendRecords()
-
getLowWatermark
public Watermark getLowWatermark()
-
setThreadName
protected void setThreadName(String message)
-
onPartitionsRevoked
public void onPartitionsRevoked(Collection<LogPartition> partitions)
- Specified by:
onPartitionsRevokedin interfaceRebalanceListener
-
onPartitionsAssigned
public void onPartitionsAssigned(Collection<LogPartition> partitions)
- Specified by:
onPartitionsAssignedin interfaceRebalanceListener
-
-