| 156 | |
| 157 | impl 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, |