-
Notifications
You must be signed in to change notification settings - Fork 0
WorkerThread
PawnDB utilizes worker threads to handle transaction processing, ensuring isolation and efficient resource management for concurrent database operations.
Each worker thread is responsible for managing a single transaction throughout its lifecycle. This design provides strong isolation guarantees and simplifies transaction management by dedicating computational resources to individual transactions.
Each worker is initialized with a WorkerContext that is built by the main thread. The WorkerContext contains essential information required for transaction execution:
- Server socket file descriptor - For network communication
- Communication channels - For inter-thread messaging
- Unique transaction ID - For transaction identification and tracking
Once started, the worker encapsulates the WorkerContext along with a WorkerRuntime. The WorkerRuntime manages the transaction's execution state and contains:
Tracks all locks acquired during the transaction runtime. This ensures proper lock management and prevents lock leaks.
Stores rollback actions that must be executed if the transaction is aborted. Actions are stored in reverse order to ensure proper rollback sequence.
Stores commit actions that must be executed when the transaction is successfully committed. This ensures all changes are properly persisted.
This worker thread design provides several key advantages:
- Transaction Isolation - Each transaction runs in its own dedicated worker, preventing interference between concurrent transactions
- Resource Management - Dedicated threads ensure predictable resource allocation and cleanup
- Lock Management - Centralized lock tracking within each worker simplifies lock acquisition and release
- Controlled Commit/Rollback - Structured queues ensure proper transaction completion procedures
-
Initialization - Main thread creates
WorkerContextand spawns worker thread -
Runtime Setup - Worker initializes
WorkerRuntimewith empty lock table, rollback stack, and commit queue - Transaction Processing - Worker executes transaction operations while maintaining state
- Cleanup - Worker performs either commit or rollback operations and releases resourcesd