MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / put_operation

Method put_operation

atomic-core/src/pristine/txn/write/operation.rs:158–191  ·  view source on GitHub ↗
(&mut self, operation: &Operation)

Source from the content-addressed store, hash-verified

156
157impl OperationMutTxnT for WriteTxn<'_> {
158 fn put_operation(&mut self, operation: &Operation) -> PristineResult<()> {
159 let encoded = encode_operation(operation).map_err(operation_serialization_error)?;
160 for parent in &operation.payload().parents {
161 if OperationTxnT::get_operation(self, *parent)?.is_none() {
162 return Err(PristineError::OperationParentNotFound {
163 operation: operation.id().to_string(),
164 parent: parent.to_string(),
165 });
166 }
167 }
168
169 let mut table = match self.txn.open_table(OPERATIONS) {
170 Ok(table) => table,
171 Err(redb::TableError::TableDoesNotExist(_)) => {
172 return Err(PristineError::OperationSchemaUnavailable);
173 }
174 Err(error) => return Err(error.into()),
175 };
176 if let Some(existing) = table.get(operation.id().as_bytes())? {
177 let existing_bytes = existing.value();
178 decode_operation_row(operation.id().as_bytes(), existing_bytes)?;
179 if existing_bytes != encoded.as_slice() {
180 return Err(PristineError::Inconsistent {
181 message: format!(
182 "append-only OPERATIONS row {} already contains different bytes",
183 operation.id()
184 ),
185 });
186 }
187 return Ok(());
188 }
189 table.insert(operation.id().as_bytes(), encoded.as_slice())?;
190 Ok(())
191 }
192
193 fn compare_and_set_operation_heads(
194 &mut self,

Calls 10

encode_operationFunction · 0.85
is_noneMethod · 0.80
valueMethod · 0.80
decode_operation_rowFunction · 0.70
getMethod · 0.65
payloadMethod · 0.45
idMethod · 0.45
as_bytesMethod · 0.45
as_sliceMethod · 0.45
insertMethod · 0.45