Database Operations and Lifecycle Management
← Back to SHAMap and NodeStore: Data Persistence and State Management
Introduction
Beyond the cache layer, the Database class orchestrates the complete lifecycle of NodeStore operations:
Initialization on startup
Runtime fetch/store operations
Asynchronous background operations
Graceful shutdown
Database rotation and archival
This chapter covers these operational aspects that are critical for production XRPL nodes.
Core Database Interface
The Database class provides higher-level operations above Backend:
Key Responsibilities:
class Database {
public:
// Synchronous operations
std::shared_ptr<NodeObject> fetchNodeObject(
uint256 const& hash,
std::uint32_t ledgerSeq = 0);
void store(std::shared_ptr<NodeObject> const& obj);
void storeBatch(std::vector<std::shared_ptr<NodeObject>> const& batch);
// Asynchronous operations
void asyncFetch(
uint256 const& hash,
std::function<void(std::shared_ptr<NodeObject>)> callback);
// Management
void open(std::string const& path);
void close();
// Metrics and diagnostics
Json::Value getCountsJson() const;
};DatabaseNodeImp: Single Backend Implementation
The standard implementation for most XRPL validators:
Architecture:
Storage Flow:
Fetch Flow:
Batch Operations
Batch operations improve efficiency:
Batch Store:
Benefits:
Batch Size Limits:
Asynchronous Operations
Background threads handle expensive operations without blocking:
Asynchronous Fetch:
Use Cases:
Initialization and Shutdown
Startup Sequence:
Shutdown Sequence:
DatabaseRotatingImp: Advanced Rotation
For production systems needing online deletion:
Problem Solved:
Without deletion, database grows unbounded:
Rotation Architecture:
Rotation Process:
Dual Fetch Logic:
Benefits:
Metrics and Monitoring
NodeStore exposes comprehensive metrics for monitoring:
Monitoring Typical Values:
Alert Thresholds:
Summary
Key Operational Components:
Fetch/Store: Core operations with caching
Batch Operations: Efficient bulk operations
Async Operations: Background threads for non-blocking I/O
Lifecycle: Startup, shutdown, error handling
Rotation: Online deletion and archival
Metrics: Monitoring and diagnostics
Design Properties:
Reliability: Graceful error handling, no data loss
Performance: Batch operations, async threading
Scalability: Online rotation enables unbounded operation
Observability: Comprehensive metrics for diagnostics
Flexibility: Different database backends, configurations
The Database layer transforms raw backend capabilities into a reliable, performant storage system that can handle blockchain-scale data volumes while maintaining the responsiveness required for real-time validation.
Last updated

