Skip to content

Feature/wal log#52

Merged
destrex271 merged 15 commits intomainfrom
feature/wal_log
Nov 12, 2025
Merged

Feature/wal log#52
destrex271 merged 15 commits intomainfrom
feature/wal_log

Conversation

@destrex271
Copy link
Owner

#43

  • Adds a basic wal
  • Adds a Control File
  • Adds the option to append to wal
  • Adds the option to flush wal to disk and start writing again

Pending:

  • Control File Initialization
  • Replay over latest checkpoint
  • inspect wal
  • timeline switchover

@deepsource-io
Copy link
Contributor

deepsource-io bot commented Sep 29, 2025

Here's the code health analysis summary for commits 7bb0775..e82f3fe. View details on DeepSource ↗.

Analysis Summary

AnalyzerStatusSummaryLink
DeepSource Rust LogoRust❌ Failure
❗ 50 occurences introduced
🎯 20 occurences resolved
View Check ↗

💡 If you’re a repository administrator, you can configure the quality gates from the settings.

@destrex271 destrex271 closed this Nov 12, 2025
@destrex271 destrex271 reopened this Nov 12, 2025
@destrex271
Copy link
Owner Author

@copilot review this PR

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds Write-Ahead Logging (WAL) functionality to LokiKV, including a control file system for managing WAL timelines and checkpoint metadata.

  • Introduces WALManager for recording and replaying database operations to WAL files
  • Adds ControlFile for persisting configuration and tracking checkpoint/timeline state
  • Integrates WAL recording into the put operations and checkpoint workflow
  • Adds DISPLAY_WAL command for inspecting WAL contents

Reviewed Changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 18 comments.

Show a summary per file
File Description
src/db/loki_kv/wal.rs New WAL implementation with record management, file I/O, and replay functionality
src/db/loki_kv/control.rs New control file implementation for managing WAL timeline and checkpoint metadata
src/db/loki_kv/control.toml Configuration file defining WAL and checkpoint directory paths
src/db/loki_kv/loki_kv.rs Integrates WAL manager into database operations and checkpoint process
src/db/loki_kv/persist.rs Updates persistor to use control file for directory paths
src/db/loki_kv/mod.rs Exports new control and wal modules
src/db/parser/parser.rs Adds DISPLAY_WAL command enum and parsing
src/db/parser/lokiql.pest Adds DISPLAY_WAL to grammar and allows trailing separators
src/db/parser/executor.rs Implements DISPLAY_WAL command execution
src/db/server_multithread/server.rs Changes checkpoint to use write lock instead of read lock, removes unused method
Cargo.toml Adds toml dependency for control file serialization
Cargo.lock Updates dependencies including serde and toml crates

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

for col in self.collections_bmap.iter(){
let pth = format!("{}/{}", get_checkpoint_directory(), get_current_timestamp());
for col in self.collections_bmap.iter() {
let pth = format!("{}/{}", get_checkpoint_directory(), checkpoint_id);
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused variable: The pth variable is created but never used. This appears to be leftover from refactoring when the code was changed to pass get_control_file_path() to Persistor::new() instead of the path. Consider removing these lines.

Copilot uses AI. Check for mistakes.
Comment on lines +26 to +29
timestamp: timestamp,
collection_name: collection_name,
key: key,
value: value,
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Redundant field initialization: When the field name matches the variable name, you can use shorthand syntax (e.g., WALRecord { timestamp, collection_name, key, value }).

Suggested change
timestamp: timestamp,
collection_name: collection_name,
key: key,
value: value,
timestamp,
collection_name,
key,
value,

Copilot uses AI. Check for mistakes.
Comment on lines +55 to +70
pub fn new_without_toml() -> Self {
let control_file = ControlFile::write(
"/home/akshat/lokikv/control.toml".to_string(),
0 as u64,
0 as u64,
"/home/akshat/lokikv/checkpoints".to_string(),
"/home/akshat/lokikv/wal".to_string(),
)
.unwrap();
let timeline = control_file.get_next_timeline_id();
WALManager {
control_file,
wal_records: Vec::new(),
cur_timeline: timeline,
}
}
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded absolute path: This function contains hardcoded paths specific to /home/akshat/lokikv/. These should be configurable via environment variables or the control file path parameter, similar to how the new() method works.

Copilot uses AI. Check for mistakes.
Copy link
Owner Author

@destrex271 destrex271 Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot is it better to just remove the new_without_toml function? I don't see it being used as such

Comment on lines +58 to +59
0 as u64,
0 as u64,
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Redundant type cast: 0 as u64 is unnecessary. Simply use 0 since the type is already specified in the function parameter.

Suggested change
0 as u64,
0 as u64,
0,
0,

Copilot uses AI. Check for mistakes.
Comment on lines +3 to +4
checkpoint_directory_path = "/home/akshat/lokikv/checkpoints"
wal_directory_path = "/home/akshat/lokikv/wal"
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded absolute paths in configuration file: This TOML file contains hardcoded paths specific to /home/akshat/lokikv/. This configuration file should either use relative paths or be generated dynamically, and should not be committed to version control with user-specific absolute paths.

Suggested change
checkpoint_directory_path = "/home/akshat/lokikv/checkpoints"
wal_directory_path = "/home/akshat/lokikv/wal"
checkpoint_directory_path = "./checkpoints"
wal_directory_path = "./wal"

Copilot uses AI. Check for mistakes.
let checkpoint_id = get_current_timestamp_as_u64();

for col in self.collections_bmap_cust.iter() {
let pth = format!("{}/{}", get_checkpoint_directory(), checkpoint_id);
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused variable: The pth variable is created but never used. This appears to be leftover from refactoring when the code was changed to pass get_control_file_path() to Persistor::new() instead of the path. Consider removing these lines.

Copilot uses AI. Check for mistakes.
Comment on lines +570 to +571
let res = self.wal_manager.display_wal();
res
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Redundant return statement: The explicit return is unnecessary here. Simply use res without the return keyword, which is more idiomatic in Rust.

Copilot uses AI. Check for mistakes.
let mut collections_hmap: HashMap<String, Collection> = HashMap::new();
let mut collections_bmap: HashMap<String, CollectionBTree> = HashMap::new();
let mut collections_bmap_cust: HashMap<String, CollectionBTreeCustom> = HashMap::new();
let control_file_path = "/home/akshat/lokikv/control.toml";
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded absolute path: The control file path is hardcoded to /home/akshat/lokikv/control.toml. This path is user-specific and will fail on other systems. Use the get_control_file_path() function that's already defined in this file to make it configurable.

Suggested change
let control_file_path = "/home/akshat/lokikv/control.toml";
let control_file_path = get_control_file_path();

Copilot uses AI. Check for mistakes.

use clap::builder::StringValueParser;
use serde::{Deserialize, Serialize};
use tokio::fs::File;
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import: tokio::fs::File is imported but never used in this file. Consider removing it.

Suggested change
use tokio::fs::File;

Copilot uses AI. Check for mistakes.
@destrex271 destrex271 merged commit b6478c0 into main Nov 12, 2025
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant