Skip to content

Commit d41db94

Browse files
committed
docs: Add documentation for Disruptor implementation based on LMAX Disruptor
Added JavaDoc comments to all Disruptor-related classes to clarify that this implementation is based on LMAX Disruptor (https://github.com/LMAX-Exchange/disruptor) and adapted for IoTDB's Pipe module. Modified files: - BatchEventProcessor.java - Disruptor.java - EventFactory.java - EventHandler.java - ExceptionHandler.java - MultiProducerSequencer.java - RingBuffer.java - Sequence.java - SequenceBarrier.java - SequenceGroups.java Each class now includes clear documentation about: 1. Origin from LMAX Disruptor 2. Key features preserved from the original 3. Simplifications made for IoTDB's use case
1 parent ae5f570 commit d41db94

10 files changed

Lines changed: 49 additions & 11 deletions

File tree

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/source/dataregion/realtime/disruptor/BatchEventProcessor.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@
2525
/**
2626
* Batch event processor for consuming events
2727
*
28-
* <p>Simplified from Disruptor (removed complex lifecycle management)
28+
* <p>This implementation is based on LMAX Disruptor (https://github.com/LMAX-Exchange/disruptor)
29+
* and simplified for IoTDB's Pipe module (removed complex lifecycle management).
2930
*
30-
* <p>CORE algorithm (MUST preserve):
31+
* <p>Core algorithm preserved from LMAX Disruptor:
3132
*
3233
* <ul>
3334
* <li>Batch processing loop

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/source/dataregion/realtime/disruptor/Disruptor.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,17 @@
2525
import java.util.concurrent.ThreadFactory;
2626

2727
/**
28-
* High-level API for setting up a lock-free event processing pipeline
28+
* Simplified Disruptor implementation for IoTDB Pipe
2929
*
30-
* <p>Provides a fluent interface for configuring producers and consumers. Internally manages a
31-
* RingBuffer and event processor thread.
30+
* <p>This implementation is based on LMAX Disruptor (https://github.com/LMAX-Exchange/disruptor)
31+
* and simplified for IoTDB's specific use case in the Pipe module.
3232
*
33-
* <p>Configuration is simplified to multi-producer mode with blocking wait strategy.
33+
* <p>Key simplifications:
34+
* <ul>
35+
* <li>Single event handler support (no complex dependency graphs)
36+
* <li>Simplified lifecycle management
37+
* <li>Removed wait strategies (using simple sleep-based waiting)
38+
* </ul>
3439
*
3540
* @param <T> event type
3641
*/
@@ -88,7 +93,6 @@ public void setDefaultExceptionHandler(ExceptionHandler<? super T> exceptionHand
8893
}
8994
}
9095

91-
/** Start - MUST keep for IoTDB */
9296
public RingBuffer<T> start() {
9397
if (started) {
9498
throw new IllegalStateException("Disruptor already started");

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/source/dataregion/realtime/disruptor/EventFactory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
/**
2323
* Event factory for pre-allocating events in RingBuffer
2424
*
25+
* <p>This interface is based on LMAX Disruptor (https://github.com/LMAX-Exchange/disruptor)
26+
* and adapted for IoTDB's Pipe module.
27+
*
2528
* @param <T> event type
2629
*/
2730
@FunctionalInterface

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/source/dataregion/realtime/disruptor/EventHandler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
/**
2323
* Event handler for processing events from RingBuffer
2424
*
25+
* <p>This interface is based on LMAX Disruptor (https://github.com/LMAX-Exchange/disruptor)
26+
* and adapted for IoTDB's Pipe module.
27+
*
2528
* @param <T> event type
2629
*/
2730
@FunctionalInterface

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/source/dataregion/realtime/disruptor/ExceptionHandler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
/**
2323
* Exception handler for event processing errors
2424
*
25+
* <p>This interface is based on LMAX Disruptor (https://github.com/LMAX-Exchange/disruptor)
26+
* and adapted for IoTDB's Pipe module.
27+
*
2528
* @param <T> event type
2629
*/
2730
public interface ExceptionHandler<T> {

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/source/dataregion/realtime/disruptor/MultiProducerSequencer.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@
2222
import java.util.concurrent.atomic.AtomicIntegerArray;
2323
import java.util.concurrent.locks.LockSupport;
2424

25+
/**
26+
* Multi-producer sequencer for coordinating concurrent publishers
27+
*
28+
* <p>This implementation is based on LMAX Disruptor (https://github.com/LMAX-Exchange/disruptor)
29+
* and preserves the core lock-free multi-producer algorithm for IoTDB's Pipe module.
30+
*
31+
* <p>Key features preserved from LMAX Disruptor:
32+
* <ul>
33+
* <li>Lock-free CAS-based sequence claiming
34+
* <li>Availability buffer for out-of-order publishing detection
35+
* <li>Backpressure via gating sequences
36+
* <li>Cache line padding to prevent false sharing
37+
* </ul>
38+
*/
2539
public final class MultiProducerSequencer {
2640

2741
/** Ring buffer size (must be power of 2) - immutable after construction */

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/source/dataregion/realtime/disruptor/RingBuffer.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ protected final E elementAt(long sequence) {
9898
/**
9999
* Lock-free ring buffer for storing pre-allocated event objects
100100
*
101+
* <p>This implementation is based on LMAX Disruptor (https://github.com/LMAX-Exchange/disruptor)
102+
* and preserves the core ring buffer algorithm for IoTDB's Pipe module.
103+
*
101104
* <p>Supports multi-producer concurrent access with zero-garbage design. Events are pre-allocated
102105
* and reused, avoiding GC pressure. Uses cache line padding to prevent false sharing.
103106
*

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/source/dataregion/realtime/disruptor/Sequence.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,14 @@ class RhsPadding extends Value {
3939
/**
4040
* Lock-free sequence counter with cache line padding
4141
*
42+
* <p>This implementation is based on LMAX Disruptor (https://github.com/LMAX-Exchange/disruptor)
43+
* and preserves the core sequence tracking mechanism for IoTDB's Pipe module.
44+
*
4245
* <p>Key design features:
4346
*
4447
* <ul>
4548
* <li>Three-level inheritance ensures proper field ordering for padding
46-
* <li>Uses volatile long with Unsafe for direct memory access
49+
* <li>Uses AtomicLong for thread-safe atomic operations
4750
* <li>Cache line padding prevents false sharing between CPU cores
4851
* <li>Supports both ordered writes (cheaper) and volatile writes (stronger)
4952
* </ul>

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/source/dataregion/realtime/disruptor/SequenceBarrier.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222
/**
2323
* Sequence barrier for consumer coordination
2424
*
25-
* <p>Simplified from Disruptor (removed Alert mechanism - IoTDB doesn't need it)
25+
* <p>This implementation is based on LMAX Disruptor (https://github.com/LMAX-Exchange/disruptor)
26+
* and simplified for IoTDB's Pipe module (removed Alert mechanism - IoTDB doesn't need it).
2627
*
27-
* <p>MUST preserve:
28+
* <p>Core features preserved from LMAX Disruptor:
2829
*
2930
* <ul>
3031
* <li>waitFor() logic for waiting sequences

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/source/dataregion/realtime/disruptor/SequenceGroups.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@
2424
/**
2525
* Utility for atomic management of sequence arrays
2626
*
27+
* <p>This implementation is based on LMAX Disruptor (https://github.com/LMAX-Exchange/disruptor)
28+
* and adapted for IoTDB's Pipe module.
29+
*
2730
* <p>Provides thread-safe operations for adding and removing sequences from gating sequence arrays
28-
* used to track consumer progress
31+
* used to track consumer progress.
2932
*/
3033
final class SequenceGroups {
3134

0 commit comments

Comments
 (0)