fix(core): Back up and restore FST buckets again

Since 27a1b2b ("chore(core): Flatten FST store code"), the bucket loop in
`FstStorePool::dump_action` checked the type and name of the collection
entry instead of the bucket entry. As a collection is a directory, every
bucket was skipped: `TRIGGER backup` answered `OK` but wrote no FST, and
`TRIGGER restore` restored none.

Add a test which backs up a consolidated FST and restores it.
This commit is contained in:
dualfroz committed 2026-10-03 17:33:05 +02:00
1 parent 322b72ed1f
commit 73692bcfdb
2 files changed
+48 -2

No files matched your search

+2 -2
View File
@@ -88,7 +88,7 @@ impl FstStorePool {
let bucket_entry = bucket_entry?;
// Actual bucket found?
let file_type = collection_entry.file_type()?;
let file_type = bucket_entry.file_type()?;
if !file_type.is_file() {
tracing::trace!(
?file_type,
@@ -97,7 +97,7 @@ impl FstStorePool {
continue 'buckets;
}
let file_name = collection_entry.file_name();
let file_name = bucket_entry.file_name();
let Some(bucket_file_name) = file_name.to_str() else {
tracing::warn!(
file_name_bytes = ?file_name.as_encoded_bytes(),
+46
View File
@@ -0,0 +1,46 @@
// Sonic
//
// Fast, lightweight and schema-less search backend
// Copyright: 2026, DualFroz <me@dualfroz.com>
// License: Mozilla Public License v2.0 (MPL v2.0)
//! Feature: Data backup
mod common;
use crate::common::util::unique_hex;
use crate::common::*;
/// Consolidated FST stores are backed up, and can be restored.
#[test]
fn test_fst_backup_and_restore() {
init_logging();
let executor = make_test_executor(|_| {});
exec!(executor -> PUSH "messages" "user:1" "chat:1" "Hello world");
exec!(executor -> TRIGGER consolidate);
let backup_path = std::path::Path::new(env!("CARGO_TARGET_TMPDIR"))
.join(unique_hex().unwrap())
.join("fst-backup");
executor.fst_pool.backup(&backup_path).unwrap();
let backup_files = std::fs::read_dir(&backup_path)
.unwrap()
.flat_map(|collection| std::fs::read_dir(collection.unwrap().path()).unwrap())
.map(|bucket| bucket.unwrap().path())
.collect::<Vec<_>>();
assert_eq!(backup_files.len(), 1, "got: {backup_files:?}");
assert!(
backup_files[0].to_string_lossy().ends_with(".fst.bck"),
"got: {backup_files:?}"
);
let restored_executor = make_test_executor(|_| {});
restored_executor.fst_pool.restore(&backup_path).unwrap();
let response = exec!(restored_executor -> LIST "messages" "user:1");
assert_contains!(response, ["hello", "world"]);
}