Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/command/persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,21 @@ pub fn bgrewriteaof_start(aof_tx: &channel::MpscSender<AofMessage>, db: SharedDa
}
}

/// Start BGREWRITEAOF in sharded mode using ShardDatabases.
pub fn bgrewriteaof_start_sharded(
aof_tx: &channel::MpscSender<AofMessage>,
shard_databases: std::sync::Arc<crate::shard::shared_databases::ShardDatabases>,
) -> Frame {
match aof_tx.try_send(AofMessage::RewriteSharded(shard_databases)) {
Ok(()) => Frame::SimpleString(Bytes::from_static(
b"Background append only file rewriting started",
)),
Err(_) => Frame::Error(Bytes::from_static(
b"ERR Background AOF rewrite failed to start",
)),
}
}

/// SAVE command: synchronous save to disk. Blocks until complete.
///
/// Clones all entries under read locks (same as BGSAVE), then serializes
Expand Down
37 changes: 37 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,43 @@ fn main() -> anyhow::Result<()> {
})
.collect();

// Multi-part AOF replay layered on top of v2/v3 recovery.
// Priority: if appendonlydir/ manifest exists → load multi-part (skip legacy v2 fallback).
// Otherwise v2 already handled legacy appendonly.aof during restore_from_persistence.
if config.appendonly == "yes" {
if let Some(ref dir) = persistence_dir {
use moon::persistence::aof_manifest::AofManifest;
use moon::persistence::replay::DispatchReplayEngine;
let base_dir = std::path::PathBuf::from(dir);
if let Some(manifest) = AofManifest::load(&base_dir) {
if num_shards == 1 {
match moon::persistence::aof_manifest::replay_multi_part(
&mut shards[0].databases,
&manifest,
&DispatchReplayEngine,
) {
Ok(n) => info!(
"AOF multi-part loaded (seq {}): {} entries",
manifest.seq, n
),
Err(e) => tracing::error!("Multi-part AOF load failed: {}", e),
}
} else {
tracing::warn!(
"Multi-part AOF skipped in multi-shard mode (not yet supported)"
);
}
}
Comment thread
qodo-code-review[bot] marked this conversation as resolved.
Outdated
// Initialize manifest for writer thread (safe — recovery is complete).
// On fresh/legacy upgrade, writer is blocked waiting for this file.
if AofManifest::load(&base_dir).is_none() {
if let Err(e) = AofManifest::initialize(&base_dir) {
tracing::error!("Failed to initialize AOF manifest: {}", e);
}
}
Comment thread
qodo-code-review[bot] marked this conversation as resolved.
Outdated
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

// Extract databases from all shards and wrap in ShardDatabases
let all_dbs: Vec<Vec<moon::storage::Database>> = shards
.iter_mut()
Expand Down
Loading
Loading