Skip to content

Commit e00dea1

Browse files
committed
Force sled to fsync after all controldb writes
1 parent dfff904 commit e00dea1

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

crates/standalone/src/control_db.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ impl ControlDb {
167167
let identity_bytes = database_identity.to_byte_array();
168168
let tree = self.db.open_tree("dns")?;
169169
tree.insert(domain.to_lowercase(), &identity_bytes)?;
170+
tree.flush()?;
170171

171172
let tree = self.db.open_tree("reverse_dns")?;
172173
match tree.get(identity_bytes)? {
@@ -179,6 +180,7 @@ impl ControlDb {
179180
tree.insert(identity_bytes, serde_json::to_string(&vec![&domain])?.as_bytes())?;
180181
}
181182
}
183+
tree.flush()?;
182184

183185
Ok(InsertDomainResult::Success {
184186
domain,
@@ -272,6 +274,10 @@ impl ControlDb {
272274
}
273275
rev_tx.insert(&database_identity_bytes, serde_json::to_vec(domain_names).unwrap())?;
274276

277+
dns_tx.flush();
278+
tld_tx.flush();
279+
rev_tx.flush();
280+
275281
Ok::<_, ConflictableTransactionError<AbortWith>>(())
276282
});
277283

@@ -309,6 +315,7 @@ impl ControlDb {
309315
}
310316
None => {
311317
tree.insert(key, &owner_identity.to_byte_array())?;
318+
tree.flush()?;
312319
Ok(RegisterTldResult::Success { domain: tld })
313320
}
314321
}
@@ -372,9 +379,11 @@ impl ControlDb {
372379
let buf = sled::IVec::from(compat::Database::from(database).to_vec()?);
373380

374381
tree.insert(key, buf.clone())?;
382+
tree.flush()?;
375383

376384
let tree = self.db.open_tree("database")?;
377385
tree.insert(id.to_be_bytes(), buf)?;
386+
tree.flush()?;
378387

379388
Ok(id)
380389
}
@@ -387,9 +396,11 @@ impl ControlDb {
387396
let tree = self.db.open_tree("database_by_identity")?;
388397
let buf = sled::IVec::from(compat::Database::from(database).to_vec()?);
389398
tree.insert(stored_database.database_identity.to_be_byte_array(), buf.clone())?;
399+
tree.flush()?;
390400

391401
let tree = self.db.open_tree("database")?;
392402
tree.insert(stored_database.id.to_be_bytes(), buf)?;
403+
tree.flush()?;
393404

394405
Ok(())
395406
}
@@ -404,6 +415,7 @@ impl ControlDb {
404415

405416
tree_by_identity.remove(&key[..])?;
406417
tree.remove(id.to_be_bytes())?;
418+
tree.flush()?;
407419
return Ok(Some(id));
408420
}
409421

@@ -466,13 +478,15 @@ impl ControlDb {
466478
let buf = bsatn::to_vec(&replica).unwrap();
467479

468480
tree.insert(id.to_be_bytes(), buf)?;
481+
tree.flush()?;
469482

470483
Ok(id)
471484
}
472485

473486
pub fn delete_replica(&self, id: u64) -> Result<()> {
474487
let tree = self.db.open_tree("replica")?;
475488
tree.remove(id.to_be_bytes())?;
489+
tree.flush()?;
476490
Ok(())
477491
}
478492

@@ -509,6 +523,7 @@ impl ControlDb {
509523
let buf = bsatn::to_vec(&node).unwrap();
510524

511525
tree.insert(id.to_be_bytes(), buf)?;
526+
tree.flush()?;
512527

513528
Ok(id)
514529
}
@@ -519,12 +534,14 @@ impl ControlDb {
519534
let buf = bsatn::to_vec(&node)?;
520535

521536
tree.insert(node.id.to_be_bytes(), buf)?;
537+
tree.flush()?;
522538
Ok(())
523539
}
524540

525541
pub fn _delete_node(&self, id: u64) -> Result<()> {
526542
let tree = self.db.open_tree("node")?;
527543
tree.remove(id.to_be_bytes())?;
544+
tree.flush()?;
528545
Ok(())
529546
}
530547

@@ -580,6 +597,7 @@ impl ControlDb {
580597
pub fn set_energy_balance(&self, identity: Identity, energy_balance: energy::EnergyBalance) -> Result<()> {
581598
let tree = self.db.open_tree("energy_budget")?;
582599
tree.insert(identity.to_byte_array(), &energy_balance.get().to_be_bytes())?;
600+
tree.flush()?;
583601

584602
Ok(())
585603
}

0 commit comments

Comments
 (0)