Repository navigation
fix(l1,l2): allow non-empty datadir without existing DB - #6061
Forostovec wants to merge 1 commit into
Conversation
Greptile OverviewGreptile SummaryThis PR fixes a startup issue where ethrex would refuse to start if the datadir contained any files (like JWT tokens) but no database metadata file. The solution replaces the empty-directory check with a more precise check for RocksDB marker files ( The changes are focused and surgical:
This approach correctly distinguishes between a directory with auxiliary files (like JWTs) and a directory with an actual database that lacks metadata. Confidence Score: 4/5
|
| Filename | Overview |
|---|---|
| crates/storage/store.rs | Replaced empty directory check with RocksDB marker file detection to allow non-DB files in datadir |
Sequence Diagram
sequenceDiagram
participant App as Application
participant Store as Store::new()
participant Validate as validate_store_schema_version()
participant Check as dir_contains_db_files()
participant FS as File System
participant Init as init_metadata_file()
App->>Store: new(datadir_path, engine_type)
Store->>Validate: validate_store_schema_version(datadir_path)
Validate->>FS: Check if metadata file exists
alt Metadata file exists
FS-->>Validate: File exists
Validate->>Validate: Read and validate schema version
Validate-->>Store: Ok() or Version Error
else Metadata file missing
FS-->>Validate: File does not exist
Validate->>Check: dir_contains_db_files(datadir_path)
Check->>FS: Check for CURRENT file
Check->>FS: Check for IDENTITY file
Check->>FS: Check for LOCK file
alt Any RocksDB marker found
FS-->>Check: Marker file exists
Check-->>Validate: true
Validate-->>Store: Error: Old DB without metadata
else No markers found (JWT files OK)
FS-->>Check: No marker files
Check-->>Validate: false
Validate->>Init: init_metadata_file()
Init->>FS: Create metadata file
Init-->>Validate: Ok()
Validate-->>Store: Ok()
end
end
Store-->>App: Store instance or Error
| fn dir_contains_db_files(path: &Path) -> Result<bool, StoreError> { | ||
| // RocksDB creates these marker files when initializing a database. | ||
| // If any of these exist, we likely have an old database without metadata. | ||
| const ROCKSDB_MARKER_FILES: &[&str] = &["CURRENT", "IDENTITY", "LOCK"]; |
There was a problem hiding this comment.
Consider checking for CURRENT first or primarily, as it's the most reliable RocksDB marker file. The LOCK file alone might exist without an actual database (e.g., if it was left behind), though this is rare. Current implementation is overly cautious rather than risky.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Prompt To Fix With AI
This is a comment left during a code review.
Path: crates/storage/store.rs
Line: 2981:2981
Comment:
Consider checking for `CURRENT` first or primarily, as it's the most reliable RocksDB marker file. The `LOCK` file alone might exist without an actual database (e.g., if it was left behind), though this is rare. Current implementation is overly cautious rather than risky.
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise.| fn dir_contains_db_files(path: &Path) -> Result<bool, StoreError> { | ||
| // RocksDB creates these marker files when initializing a database. | ||
| // If any of these exist, we likely have an old database without metadata. | ||
| const ROCKSDB_MARKER_FILES: &[&str] = &["CURRENT", "IDENTITY", "LOCK"]; |
There was a problem hiding this comment.
nit: LOCK is a fairly generic filename — other tools or processes could create a LOCK file in the datadir. Since CURRENT alone is sufficient to identify a RocksDB database (it's always created first and is the most distinctive marker), you could consider dropping LOCK from this list to avoid a false positive. Very minor though — the combination of all three being present by coincidence is extremely unlikely.
Motivation
Before this change, ethrex refused to start if the datadir directory was not empty and the metadata file was missing. This broke setups like EthDocker that store JWT and other auxiliary files in the same directory, even when no old database was present.
Description
Updated the schema validation to look for RocksDB marker files (CURRENT, IDENTITY, LOCK) instead of requiring an empty directory, so we still detect legacy databases without metadata but allow non-empty datadirs that only contain non-DB files.
Resolves #5680