Skip to content

Commit

Permalink
fix: only write to storage when after sync in test_cmd
Browse files Browse the repository at this point in the history
Signed-off-by: bsbds <[email protected]>
  • Loading branch information
bsbds authored and Phoenix500526 committed Jul 19, 2023
1 parent e03c4f0 commit cca9204
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions curp-test-utils/src/test_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,17 +213,7 @@ impl CommandExecutor<TestCommand> for TestCE {
.collect_vec();
(value, revision)
}
TestCommandType::Put(ref v) => {
let value = v.to_be_bytes().to_vec();
let wr_ops = keys
.into_iter()
.map(|key| WriteOperation::new_put(TEST_TABLE, key, value.clone()))
.collect();
self.store
.write_batch(wr_ops, true)
.map_err(|e| ExecuteError(e.to_string()))?;
TestCommandResult::default()
}
TestCommandType::Put(_) => TestCommandResult::default(),
};

self.exe_sender
Expand All @@ -245,23 +235,26 @@ impl CommandExecutor<TestCommand> for TestCE {
self.after_sync_sender
.send((cmd.clone(), index))
.expect("failed to send after sync msg");
if let TestCommandType::Put(_) = cmd.cmd_type {
if let TestCommandType::Put(v) = cmd.cmd_type {
debug!(
"cmd {:?}-{} revision is {}",
cmd.cmd_type,
cmd.id(),
revision
);
let wr_ops = cmd
let value = v.to_be_bytes().to_vec();
let keys = cmd
.keys
.iter()
.map(|key| {
WriteOperation::new_put(
REVISION_TABLE,
key.to_be_bytes().to_vec(),
revision.to_be_bytes().to_vec(),
)
})
.map(|k| k.to_be_bytes().to_vec())
.collect_vec();
let wr_ops = keys
.clone()
.into_iter()
.map(|key| WriteOperation::new_put(TEST_TABLE, key, value.clone()))
.chain(keys.into_iter().map(|key| {
WriteOperation::new_put(REVISION_TABLE, key, revision.to_be_bytes().to_vec())
}))
.collect();
self.store
.write_batch(wr_ops, true)
Expand Down

0 comments on commit cca9204

Please sign in to comment.