MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / append

Method append

nodedb-cluster/src/raft_storage.rs:87–127  ·  view source on GitHub ↗
(&mut self, entries: &[LogEntry])

Source from the content-addressed store, hash-verified

85
86impl LogStorage for RedbLogStorage {
87 fn append(&mut self, entries: &[LogEntry]) -> nodedb_raft::error::Result<()> {
88 if entries.is_empty() {
89 return Ok(());
90 }
91
92 let write_txn =
93 self.db
94 .begin_write()
95 .map_err(|e| nodedb_raft::error::RaftError::Storage {
96 detail: format!("write txn: {e}"),
97 })?;
98 {
99 let mut table = write_txn.open_table(ENTRIES).map_err(|e| {
100 nodedb_raft::error::RaftError::Storage {
101 detail: format!("open entries: {e}"),
102 }
103 })?;
104
105 for entry in entries {
106 let key = index_key(entry.index);
107 let value = encode_versioned(entry).map_err(|e| {
108 nodedb_raft::error::RaftError::Storage {
109 detail: format!("serialize entry: {e}"),
110 }
111 })?;
112 table
113 .insert(key.as_slice(), value.as_slice())
114 .map_err(|e| nodedb_raft::error::RaftError::Storage {
115 detail: format!("insert entry: {e}"),
116 })?;
117 }
118 }
119 write_txn
120 .commit()
121 .map_err(|e| nodedb_raft::error::RaftError::Storage {
122 detail: format!("commit append: {e}"),
123 })?;
124
125 debug!(count = entries.len(), "raft log appended");
126 Ok(())
127 }
128
129 fn truncate(&mut self, index: u64) -> nodedb_raft::error::Result<()> {
130 let write_txn =

Callers 5

append_and_loadFunction · 0.45
truncate_removes_tailFunction · 0.45
compact_removes_prefixFunction · 0.45
versioned_roundtripFunction · 0.45
survives_reopenFunction · 0.45

Calls 7

encode_versionedFunction · 0.85
begin_writeMethod · 0.80
index_keyFunction · 0.70
is_emptyMethod · 0.45
insertMethod · 0.45
as_sliceMethod · 0.45
commitMethod · 0.45

Tested by 5

append_and_loadFunction · 0.36
truncate_removes_tailFunction · 0.36
compact_removes_prefixFunction · 0.36
versioned_roundtripFunction · 0.36
survives_reopenFunction · 0.36