The code base of TxnAgent: Achieve Efficient Serializability via Self-adaptive Fine-Grained Isolation Level Selection.
TxnAgent works in the middle tier between database and application. It meets three requirements:
- It requires minimal modifications to client applications and database kernels, ensuring low implementation overhead.
- It must be efficient to handle dangerous structures under various lower isolation levels while ensuring SER.
- It must adaptively select the optimal isolation level to maximize performance in response to dynamic workloads.
Key modules and corresponding source code:
| Module | Source Files |
|---|---|
| Analyzer | src/.../worker/OfflineWorker, src/.../analysis/* |
| Executor | src/.../worker/OnlineWorker, src/.../execution/validation/* |
| Adapter | src/.../worker/{Adapter, Flusher}, src/.../execution/sample/* |
| RL Agent | agent/agent.py, agent/rl_model.py, adapter.py |
| Partition | src/.../execution/isolation/PartitionManager.java, PartitionConfig.java |
Note:
...represents the filepathmain/java/org/dbiir/txnagent.
- JDK 21 and Gradle 9+
- Python 3.9+ with packages:
torch,numpy,tensorboard - PostgreSQL 17+ (with data pre-loaded for your benchmark)
./gradlew buildThe fat jar will be placed at build/libs/TxnSailsServer-fat-2.0-all.jar.
┌────────────┐ TCP :7654 ┌───────────────────┐ TCP :9876 ┌────────────┐
│ adapter.py │◄────────────│ TxnSailsServer │◄────────────│ Client │
│ (RL Agent) │────────────►│ (Java Server) │────────────►│ (TriStar) │
└────────────┘ actions │ StatisticsWorker │ txn reqs └────────────┘
└───────────────────┘
Startup order matters: the adapter must be listening before the server starts (StatisticsWorker connects to the adapter on init).
python3 adapter.py -w ycsbThis starts the Python RL agent, which:
- Initializes the MAML-based PPO model
- Loads checkpoint (priority:
models/final_online.pt→models/best_meta_ppo.pt→ fresh start) - Listens on port 7654 for the Java
StatisticsWorkerconnection
Arguments:
| Flag | Description |
|---|---|
-w, --workload |
Required. Workload name: ycsb, tpcc, or smallbank |
-f, --filepath |
Optional. File path for offline training data |
-p, --phase |
Optional. offline or online (default: online) |
java -jar build/libs/TxnAgentServer-fat-2.0-all.jar \
-c config/ycsb.xml \
-s config/ycsb.sql \
-t config/partition/ycsb/partition.yaml \
-p onlineThis starts the Java server, which:
- Loads the workload configuration from the XML file
- Initializes
PartitionManagerwith partition layout from the YAML file - Starts
StatisticsWorker(connects to the adapter on port 7654) - Listens on port 9876 for client connections
Arguments:
| Flag | Description |
|---|---|
-c, --config |
Required. Workload XML configuration file |
-s, --schema |
Required. Database schema SQL file |
-t, --partition |
Partition configuration YAML file (enables partitioning) |
-d, --directory |
Base directory for result/meta files |
-p, --phase |
online (RL-driven) or offline (static stages) |
Use your benchmark client (e.g., TriStar) to connect to port 9876 and send workload:
java -cp target/tristar/tristar/lib/ -jar target/tristar/tristar/tristar.jar \
-b ycsb \
-c config/ycsb/hotspot-128/postgresql/ycsb_cc_FS.xml \
--execute=true \
-d results/ycsb/hotspot-128There are two modes controlled by whether the YAML file contains stages:
Online mode (RL agent controls isolation levels — no stages):
workload:
name: ycsb
scalaFactor: 1000
relations:
- name: usertable
partitionSize: 1000
partitionCount: 1000For running full test suites (adapter → server → client lifecycle), use:
python3 run_tests.py -w ycsb -e postgresql -f skew-128See python3 run_tests.py -h for all options.
Transitions (s, a, r, s') are automatically recorded during online runs and saved to metas/transitions/ on shutdown. To run offline MAML meta-training:
python -m agent.offline_train_rl --data_dir metas/transitions --epochs 200Parse adapter logs to extract throughput, reward, and action metrics:
python parse_adapter_log.py <logfile> --csv metrics.csv --plot