Skip to content

Commit 8f2ebcd

Browse files
committed
feat(processor): processor destination processing pipeline
1 parent 78e104c commit 8f2ebcd

11 files changed

Lines changed: 1154 additions & 67 deletions

app/apphandlers/embeddedAppHandler.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ func (a *embeddedApp) StartRudderCore(ctx context.Context, shutdownFn func(), op
289289
if config.GetBoolVar(false, "Processor.DestinationIsolation.enabled") {
290290
procRWHandle := jobsdb.NewForReadWrite(
291291
"proc",
292+
jobsdb.WithMultiConsumer(),
292293
jobsdb.WithClearDB(options.ClearDB),
293294
jobsdb.WithDSLimit(a.config.procDSLimit),
294295
jobsdb.WithSkipMaintenanceErr(config.GetBoolVar(false, "Processor.jobsDB.skipMaintenanceError")),
@@ -299,7 +300,7 @@ func (a *embeddedApp) StartRudderCore(ctx context.Context, shutdownFn func(), op
299300
jobsdb.WithNumPartitions(partitionCount),
300301
)
301302
defer procRWHandle.Close()
302-
procRWDB = jobsdb.NewPendingEventsJobsDB(procRWHandle, pendingEventsRegistry)
303+
procRWDB = jobsdb.NewPendingEventsJobsDB(procRWHandle, pendingEventsRegistry, jobsdb.WithConsumerAsDestinationID())
303304
}
304305

305306
var schemaForwarder schema_forwarder.Forwarder

app/apphandlers/processorAppHandler.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ func (a *processorApp) StartRudderCore(ctx context.Context, shutdownFn func(), o
273273
if config.GetBoolVar(false, "Processor.DestinationIsolation.enabled") {
274274
procRWHandle := jobsdb.NewForReadWrite(
275275
"proc",
276+
jobsdb.WithMultiConsumer(),
276277
jobsdb.WithClearDB(options.ClearDB),
277278
jobsdb.WithDSLimit(a.config.procDSLimit),
278279
jobsdb.WithSkipMaintenanceErr(config.GetBoolVar(false, "Processor.jobsDB.skipMaintenanceError")),
@@ -283,7 +284,7 @@ func (a *processorApp) StartRudderCore(ctx context.Context, shutdownFn func(), o
283284
jobsdb.WithNumPartitions(partitionCount),
284285
)
285286
defer procRWHandle.Close()
286-
procRWDB = jobsdb.NewPendingEventsJobsDB(procRWHandle, pendingEventsRegistry)
287+
procRWDB = jobsdb.NewPendingEventsJobsDB(procRWHandle, pendingEventsRegistry, jobsdb.WithConsumerAsDestinationID())
287288
}
288289

289290
var schemaForwarder schema_forwarder.Forwarder
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,39 @@ import (
1919
"github.com/rudderlabs/rudder-server/utils/tracing"
2020
)
2121

22-
type partitionWorker struct {
22+
type gwPartitionWorker struct {
2323
partition string
24-
pipelines []*pipelineWorker
24+
pipelines []*gwPipelineWorker
2525
logger logger.Logger
2626
stats *processorStats
2727
tracer *tracing.Tracer
2828
handle workerHandle
2929
statsFactory stats.Stats
3030
}
3131

32-
// newPartitionWorker creates a new worker for the specified partition
33-
func newPartitionWorker(partition string, h workerHandle, t stats.Tracer, statsFactory stats.Stats) *partitionWorker {
34-
w := &partitionWorker{
32+
// newGwPartitionWorker creates a new worker for the specified partition
33+
func newGwPartitionWorker(partition string, h workerHandle, t stats.Tracer, statsFactory stats.Stats) *gwPartitionWorker {
34+
w := &gwPartitionWorker{
3535
partition: partition,
3636
logger: h.logger().Child(partition),
3737
stats: h.stats(),
38-
tracer: tracing.New(t, tracing.WithNamePrefix("partitionWorker")),
38+
tracer: tracing.New(t, tracing.WithNamePrefix("gwPartitionWorker")),
3939
handle: h,
4040
statsFactory: statsFactory,
4141
}
4242
// Create workers for each pipeline
4343
pipelinesPerPartition := h.config().pipelinesPerPartition
44-
w.pipelines = make([]*pipelineWorker, pipelinesPerPartition)
44+
w.pipelines = make([]*gwPipelineWorker, pipelinesPerPartition)
4545
for i := range pipelinesPerPartition {
46-
w.pipelines[i] = newPipelineWorker(i, partition, h, tracing.New(t, tracing.WithNamePrefix("pipelineWorker")))
46+
w.pipelines[i] = newGwPipelineWorker(i, partition, h, tracing.New(t, tracing.WithNamePrefix("gwPipelineWorker")))
4747
}
4848

4949
return w
5050
}
5151

5252
// Work processes jobs for the specified partition
5353
// Returns true if work was done, false otherwise
54-
func (w *partitionWorker) Work() bool {
54+
func (w *gwPartitionWorker) Work() bool {
5555
// If pipelining is disabled, use the legacy job handling path
5656
if !w.handle.config().enablePipelining {
5757
return w.handle.handlePendingGatewayJobs(w.partition)
@@ -106,24 +106,24 @@ func (w *partitionWorker) Work() bool {
106106
}
107107

108108
// SleepDurations returns the min and max sleep durations for the worker
109-
func (w *partitionWorker) SleepDurations() (min, max time.Duration) {
109+
func (w *gwPartitionWorker) SleepDurations() (min, max time.Duration) {
110110
return w.handle.config().readLoopSleep.Load(), w.handle.config().maxLoopSleep.Load()
111111
}
112112

113113
// Stop stops the worker and waits until all its goroutines have stopped
114-
func (w *partitionWorker) Stop() {
114+
func (w *gwPartitionWorker) Stop() {
115115
var wg sync.WaitGroup
116116
for _, pipeline := range w.pipelines {
117117
wg.Add(1)
118-
go func(p *pipelineWorker) {
118+
go func(p *gwPipelineWorker) {
119119
defer wg.Done()
120120
p.Stop()
121121
}(pipeline)
122122
}
123123
wg.Wait() // Wait for all stop operations to complete
124124
}
125125

126-
func (w *partitionWorker) sendToPreProcess(ctx context.Context, jobsByPipeline map[int][]*jobsdb.JobT) error {
126+
func (w *gwPartitionWorker) sendToPreProcess(ctx context.Context, jobsByPipeline map[int][]*jobsdb.JobT) error {
127127
spanTags := stats.Tags{"partition": w.partition}
128128
_, span := w.tracer.Trace(ctx, "Work.sendToPreProcess", tracing.WithTraceTags(spanTags))
129129
defer span.End()
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"github.com/rudderlabs/rudder-server/utils/workerpool"
2222
)
2323

24-
func TestWorkerPool(t *testing.T) {
24+
func TestGwWorkerPool(t *testing.T) {
2525
run := func(t *testing.T, pipelining, limitsReached, shouldProcessMultipleSubJobs bool) {
2626
wh := &mockWorkerHandle{
2727
pipelining: pipelining,
@@ -61,7 +61,7 @@ func TestWorkerPool(t *testing.T) {
6161

6262
// create a worker pool
6363
wp := workerpool.New(poolCtx, func(partition string) workerpool.Worker {
64-
return newPartitionWorker(partition, wh, stats.NOP.NewTracer(""), stats.NOP)
64+
return newGwPartitionWorker(partition, wh, stats.NOP.NewTracer(""), stats.NOP)
6565
}, logger.NOP)
6666

6767
// start pinging for work for 100 partitions
@@ -116,7 +116,7 @@ func TestWorkerPool(t *testing.T) {
116116
})
117117
}
118118

119-
func TestWorkerPoolIdle(t *testing.T) {
119+
func TestGwWorkerPoolIdle(t *testing.T) {
120120
wh := &mockWorkerHandle{
121121
pipelining: true,
122122
log: logger.NewLogger(),
@@ -138,7 +138,7 @@ func TestWorkerPoolIdle(t *testing.T) {
138138
// create a worker pool
139139
wp := workerpool.New(poolCtx,
140140
func(partition string) workerpool.Worker {
141-
return newPartitionWorker(partition, wh, stats.NOP.NewTracer(""), stats.NOP)
141+
return newGwPartitionWorker(partition, wh, stats.NOP.NewTracer(""), stats.NOP)
142142
},
143143
logger.NOP,
144144
workerpool.WithCleanupPeriod(200*time.Millisecond),
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import (
1515
"github.com/rudderlabs/rudder-server/utils/tracing"
1616
)
1717

18-
// newPipelineWorker new worker which manages a single pipeline of a partition
19-
func newPipelineWorker(index int, partition string, h workerHandle, t *tracing.Tracer) *pipelineWorker {
20-
w := &pipelineWorker{
18+
// newGwPipelineWorker new worker which manages a single pipeline of a partition
19+
func newGwPipelineWorker(index int, partition string, h workerHandle, t *tracing.Tracer) *gwPipelineWorker {
20+
w := &gwPipelineWorker{
2121
index: index,
2222
handle: h,
2323
logger: h.logger().Withn(logger.NewStringField("partition", partition)),
@@ -45,12 +45,12 @@ func newPipelineWorker(index int, partition string, h workerHandle, t *tracing.T
4545
return w
4646
}
4747

48-
// pipelineWorker performs all processing steps of a partition's pipeline:
48+
// gwPipelineWorker performs all processing steps of a partition's pipeline:
4949
// 1. preprocess
5050
// 2. preTransform
5151
// 3. transform
5252
// 4. store
53-
type pipelineWorker struct {
53+
type gwPipelineWorker struct {
5454
index int
5555
partition string
5656
handle workerHandle
@@ -73,7 +73,7 @@ type pipelineWorker struct {
7373
}
7474

7575
// start launches the various worker goroutines for the pipelined processing
76-
func (w *pipelineWorker) start() {
76+
func (w *gwPipelineWorker) start() {
7777
// Setup context cancellation handler
7878
w.lifecycle.wg.Add(1)
7979
rruntime.Go(func() {
@@ -230,7 +230,7 @@ func (w *pipelineWorker) start() {
230230
}
231231

232232
// Stop gracefully terminates the worker by canceling its context and waiting for goroutines to finish
233-
func (w *pipelineWorker) Stop() {
233+
func (w *gwPipelineWorker) Stop() {
234234
w.lifecycle.cancel()
235235
w.lifecycle.wg.Wait()
236236
}

0 commit comments

Comments
 (0)