Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(record-store): ensure record sync before marking as stored #2591

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
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
16 changes: 10 additions & 6 deletions ant-networking/src/record_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,17 +687,18 @@ impl NodeRecordStore {
spawn(async move {
let key = r.key.clone();
if let Some(bytes) = Self::prepare_record_bytes(r, encryption_details) {
let cmd = match fs::write(&file_path, bytes) {
let cmd = match fs::write(&file_path, bytes)
.and_then(|_| fs::File::open(&file_path).and_then(|f| f.sync_all()))
{
Ok(_) => {
// vdash metric (if modified please notify at https://github.com/happybeing/vdash/issues):
info!("Wrote record {record_key2:?} to disk! filename: {filename}");

LocalSwarmCmd::AddLocalRecordAsStored { key, record_type }
}
Err(err) => {
error!(
"Error writing record {record_key2:?} filename: {filename}, error: {err:?}"
);
"Error writing/syncing record {record_key2:?} filename: {filename}, error: {err:?}"
);
LocalSwarmCmd::RemoveFailedLocalRecord { key }
}
};
Expand Down Expand Up @@ -1057,11 +1058,14 @@ mod tests {

async fn testing_thread(r: ArbitraryRecord) {
let r = r.0;
let self_id = PeerId::random();

// Create channels with proper receivers
let (network_event_sender, mut network_event_receiver) = mpsc::channel(1);
let (swarm_cmd_sender, _) = mpsc::channel(1);
let (swarm_cmd_sender, mut swarm_cmd_receiver) = mpsc::channel(1);

let mut store = NodeRecordStore::with_config(
PeerId::random(),
self_id,
Default::default(),
network_event_sender,
swarm_cmd_sender,
Expand Down
Loading