You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The reaper routine performs periodic cleanup of old transactions to prevent memory/storage bloat and maintain optimal performance. It runs as a background goroutine alongside the broadcaster and confirmer.
411
+
412
+
#### Responsibilities
413
+
414
+
-**Periodic Cleanup**: Remove old finalized and failed transactions based on configured retention periods
415
+
-**Storage Optimization**: Prevent unbounded growth of transaction storage
416
+
-**Performance Maintenance**: Keep transaction queries fast by limiting dataset size
417
+
-**Resource Management**: Free memory and storage resources from completed transactions
418
+
419
+
#### Implementation Details
420
+
421
+
The reaper runs on a jittered ticker similar to the confirmer to avoid thundering herd problems.
422
+
423
+
#### Cleanup Logic
424
+
425
+
The cleanup function implements the core reaper logic by querying for finalized and failed transactions, calculating their age based on the `LastUpdatedAt` timestamp, and removing those that exceed the configured retention period.
426
+
427
+
#### Cleanup Criteria
428
+
429
+
The reaper applies specific criteria for transaction cleanup:
430
+
431
+
-**Finalized Transactions**: Removed after `TransactionRetentionSecs` seconds from last update
432
+
-**Failed Transactions**: Removed after `TransactionRetentionSecs` seconds from last update
433
+
-**Active Transactions**: Never cleaned up (Pending, Submitted, Retriable states)
434
+
-**Time Calculation**: Uses `LastUpdatedAt` timestamp to determine age
435
+
-**Boundary Logic**: Only transactions where `timeDiff > TransactionRetentionSecs` are cleaned up
436
+
437
+
#### Safety Features
438
+
439
+
The reaper includes several safety mechanisms:
440
+
441
+
-**State Filtering**: Only targets terminal states (Finalized, Failed)
442
+
-**Conservative Timing**: Uses strict greater-than comparison for retention period
443
+
-**Error Isolation**: Individual transaction cleanup failures don't stop the entire process
444
+
-**Graceful Shutdown**: Responds to stop signals and context cancellation
445
+
-**Logging**: Comprehensive logging for monitoring and debugging
446
+
447
+
#### Configuration Integration
448
+
449
+
The reaper uses the existing TXM configuration structure with `ReaperPollSecs` controlling how often the reaper runs and `TransactionRetentionSecs` determining how long to keep finalized/failed transactions. Default values are 10 seconds for both polling interval and retention period.
450
+
451
+
#### Performance Considerations
452
+
453
+
-**Jittered Timing**: Prevents multiple instances from running cleanup simultaneously
454
+
-**Batch Processing**: Processes all eligible transactions in a single pass
455
+
-**Efficient Queries**: Uses state-based filtering to minimize database load
456
+
-**Non-blocking**: Runs independently without affecting transaction processing
457
+
-**Resource Bounded**: Only processes existing transactions, no unbounded operations
458
+
459
+
### 5. Retry Manager
399
460
400
461
Implements sophisticated retry logic using pluggable strategy functions for different error types.
0 commit comments