Fixed tests for FDB and SQL stores

This commit is contained in:
mdecimus
2025-05-23 17:07:36 +02:00
parent 2eb99ed3bd
commit c19d2ceb43
16 changed files with 113 additions and 42 deletions

View File

@@ -50,7 +50,9 @@ impl MysqlStore {
&& start.elapsed() < MAX_COMMIT_TIME => {}
CommitError::Retry => {
if retry_count > MAX_COMMIT_ATTEMPTS || start.elapsed() > MAX_COMMIT_TIME {
return Err(trc::StoreEvent::AssertValueFailed.into());
return Err(trc::StoreEvent::AssertValueFailed
.into_err()
.caused_by(trc::location!()));
}
}
CommitError::Mysql(err) => {
@@ -168,6 +170,7 @@ impl MysqlStore {
trx.rollback().await?;
return Err(trc::StoreEvent::AssertValueFailed
.into_err()
.caused_by(trc::location!())
.into());
}
}
@@ -219,6 +222,11 @@ impl MysqlStore {
);
}
ValueOp::Clear => {
// Update asserted value
if let Some(exists) = asserted_values.get_mut(&key) {
*exists = false;
}
let s = trx
.prep(format!("DELETE FROM {} WHERE k = ?", table))
.await?;
@@ -304,7 +312,10 @@ impl MysqlStore {
.unwrap_or_else(|| (false, assert_value.is_none()));
if !matches {
trx.rollback().await?;
return Err(trc::StoreEvent::AssertValueFailed.into_err().into());
return Err(trc::StoreEvent::AssertValueFailed
.into_err()
.caused_by(trc::location!())
.into());
}
asserted_values.insert(key, exists);
}

View File

@@ -48,7 +48,9 @@ impl PostgresStore {
) if retry_count < MAX_COMMIT_ATTEMPTS
&& start.elapsed() < MAX_COMMIT_TIME => {}
Some(&SqlState::UNIQUE_VIOLATION) => {
return Err(trc::StoreEvent::AssertValueFailed.into());
return Err(trc::StoreEvent::AssertValueFailed
.into_err()
.caused_by(trc::location!()));
}
_ => return Err(into_error(err)),
},
@@ -57,7 +59,9 @@ impl PostgresStore {
if retry_count > MAX_COMMIT_ATTEMPTS
|| start.elapsed() > MAX_COMMIT_TIME
{
return Err(trc::StoreEvent::AssertValueFailed.into());
return Err(trc::StoreEvent::AssertValueFailed
.into_err()
.caused_by(trc::location!()));
}
}
}
@@ -165,7 +169,10 @@ impl PostgresStore {
};
if trx.execute(&s, &[&key, &(*value)]).await? == 0 {
return Err(trc::StoreEvent::AssertValueFailed.into_err().into());
return Err(trc::StoreEvent::AssertValueFailed
.into_err()
.caused_by(trc::location!())
.into());
}
}
ValueOp::AtomicAdd(by) => {
@@ -210,6 +217,11 @@ impl PostgresStore {
.prepare_cached(&format!("DELETE FROM {} WHERE k = $1", table))
.await?;
trx.execute(&s, &[&key]).await?;
// Update asserted value
if let Some(exists) = asserted_values.get_mut(&key) {
*exists = false;
}
}
}
}
@@ -298,7 +310,10 @@ impl PostgresStore {
})
.unwrap_or_else(|| (false, assert_value.is_none()));
if !matches {
return Err(trc::StoreEvent::AssertValueFailed.into_err().into());
return Err(trc::StoreEvent::AssertValueFailed
.into_err()
.caused_by(trc::location!())
.into());
}
asserted_values.insert(key, exists);
}

View File

@@ -398,7 +398,7 @@ impl InMemoryStore {
class: ValueClass::InMemory(InMemoryClass::Key(key)),
op: ValueOp::Clear,
});
if batch.len() >= 1000 {
if batch.is_large_batch() {
store
.write(batch.build_all())
.await
@@ -425,7 +425,7 @@ impl InMemoryStore {
class: ValueClass::InMemory(InMemoryClass::Key(key)),
op: ValueOp::Clear,
});
if batch.len() >= 1000 {
if batch.is_large_batch() {
store
.write(batch.build_all())
.await

View File

@@ -360,7 +360,7 @@ impl Store {
let mut batch = BatchBuilder::new();
for key in delete_keys {
if batch.len() >= 1000 {
if batch.is_large_batch() {
self.write(std::mem::take(&mut batch).build_all())
.await
.caused_by(trc::location!())?;
@@ -638,7 +638,7 @@ impl Store {
class: ValueClass::InMemory(InMemoryClass::Key(key)),
op: ValueOp::Clear,
});
if batch.len() >= 1000 {
if batch.is_large_batch() {
self.write(batch.build_all()).await.unwrap();
batch = BatchBuilder::new();
}
@@ -659,7 +659,7 @@ impl Store {
class: ValueClass::InMemory(InMemoryClass::Key(key)),
op: ValueOp::Clear,
});
if batch.len() >= 1000 {
if batch.is_large_batch() {
self.write(batch.build_all()).await.unwrap();
batch = BatchBuilder::new();
}

View File

@@ -217,7 +217,7 @@ impl Store {
.update_document(document.document_id);
for key in keys.into_iter() {
if batch.len() >= 1000 {
if batch.is_large_batch() {
self.write(batch.build_all()).await?;
batch = BatchBuilder::new();
batch
@@ -311,8 +311,10 @@ impl Store {
batch.update_document(document_id);
for key in keys {
if batch.len() >= 1000 {
self.write(batch.build_all()).await?;
if batch.is_large_batch() {
self.write(batch.build_all())
.await
.caused_by(trc::location!())?;
batch = BatchBuilder::new();
batch
.with_account_id(account_id)
@@ -327,7 +329,9 @@ impl Store {
}
if !batch.is_empty() {
self.write(batch.build_all()).await?;
self.write(batch.build_all())
.await
.caused_by(trc::location!())?;
}
Ok(())

View File

@@ -116,7 +116,7 @@ impl Store {
batch.with_account_id(account_id);
let mut last_collection = u8::MAX;
for (revoke_account_id, acl_item) in delete_keys.into_iter() {
if batch.len() >= 1000 {
if batch.is_large_batch() {
self.write(batch.build_all())
.await
.caused_by(trc::location!())?;

View File

@@ -355,7 +355,7 @@ impl BatchBuilder {
}
pub fn commit_point(&mut self) -> &mut Self {
if self.batch_size > 5_000_000 || self.batch_ops > 1000 {
if self.is_large_batch() {
self.serialize_changes();
self.commit_points.push(self.ops.len());
self.batch_ops = 0;
@@ -370,6 +370,11 @@ impl BatchBuilder {
self
}
#[inline]
pub fn is_large_batch(&self) -> bool {
self.batch_size > 5_000_000 || self.batch_ops > 1000
}
pub fn any_op(&mut self, op: Operation) -> &mut Self {
self.ops.push(op);
self.batch_ops += 1;

View File

@@ -215,7 +215,7 @@ impl Store {
let mut batch = BatchBuilder::new();
let mut last_account_id = u32::MAX;
for (account_id, op) in delete_keys.into_iter() {
if batch.len() >= 1000 {
if batch.is_large_batch() {
last_account_id = u32::MAX;
self.write(batch.build_all())
.await
@@ -290,7 +290,7 @@ impl Store {
batch.with_account_id(account_id);
let mut last_collection = u8::MAX;
for (collection, document_id, op) in delete_keys.into_iter() {
if batch.len() >= 1000 {
if batch.is_large_batch() {
self.write(batch.build_all())
.await
.caused_by(trc::location!())?;