FoundationDB changes.

This commit is contained in:
mdecimus
2023-07-07 09:27:22 +02:00
parent fac3273f10
commit 6ba892f7d6
12 changed files with 71 additions and 59 deletions

View File

@@ -1,6 +1,6 @@
[package]
name = "imap"
version = "0.1.0"
version = "0.3.0"
edition = "2021"
resolver = "2"

View File

@@ -1,6 +1,6 @@
[package]
name = "jmap"
version = "0.1.0"
version = "0.3.0"
edition = "2021"
resolver = "2"

View File

@@ -46,7 +46,7 @@ pub mod authenticate;
pub mod oauth;
pub mod rate_limit;
#[derive(Debug, Clone)]
#[derive(Debug, Clone, Default)]
pub struct AccessToken {
pub primary_id: u32,
pub member_of: Vec<u32>,

View File

@@ -31,7 +31,8 @@ tracing = "0.1"
jemallocator = "0.5.0"
[features]
default = ["sqlite"]
#default = ["sqlite"]
default = ["foundationdb"]
sqlite = ["store/sqlite"]
foundationdb = ["store/foundation"]

View File

@@ -8,7 +8,7 @@ resolver = "2"
utils = { path = "../utils" }
maybe-async = { path = "../maybe-async" }
rocksdb = { version = "0.20.1", optional = true }
foundationdb = { version = "0.8.0", optional = true }
foundationdb = { version = "0.8.0", features = ["embedded-fdb-include"], optional = true }
rusqlite = { version = "0.29.0", features = ["bundled"], optional = true }
rust-s3 = { version = "0.33.0", default-features = false, features = ["tokio-rustls-tls"] }
tokio = { version = "1.23", features = ["sync", "fs", "io-util"] }

View File

@@ -438,7 +438,8 @@ impl Store {
if (key.len() == 4
&& value.len() == 8
&& u32::deserialize(key).is_ok()
&& u64::deserialize(value).is_ok()) || &key[0..4] == u32::MAX.to_be_bytes() {
&& u64::deserialize(value).is_ok())
|| &key[0..4] == u32::MAX.to_be_bytes()
{
continue;
}

View File

@@ -34,7 +34,7 @@ use rand::Rng;
use crate::{
write::{
key::{DeserializeBigEndian, KeySerializer},
now, Batch, Operation,
now, Batch, Operation, ValueClass,
},
AclKey, BitmapKey, Deserialize, IndexKey, LogKey, Serialize, Store, ValueKey, SUBSPACE_QUOTAS,
SUBSPACE_VALUES,
@@ -94,15 +94,30 @@ impl Store {
} => {
document_id = *document_id_;
}
Operation::Value { family, field, set } => {
let key = ValueKey {
account_id,
collection,
document_id,
family: *family,
field: *field,
}
.serialize();
Operation::Value { class, set } => {
let key = match class {
ValueClass::Property { field, family } => ValueKey {
account_id,
collection,
document_id,
family: *family,
field: *field,
}
.serialize(),
ValueClass::Acl { grant_account_id } => AclKey {
grant_account_id: *grant_account_id,
to_account_id: account_id,
to_collection: collection,
to_document_id: document_id,
}
.serialize(),
ValueClass::Custom { bytes } => {
let mut key = Vec::with_capacity(1 + bytes.len());
key.push(SUBSPACE_VALUES);
key.extend_from_slice(bytes);
key
}
};
if let Some(value) = set {
trx.set(&key, value);
} else {
@@ -151,23 +166,6 @@ impl Store {
.set(document_id);
}
}
Operation::Acl {
grant_account_id,
set,
} => {
let key = AclKey {
grant_account_id: *grant_account_id,
to_account_id: account_id,
to_collection: collection,
to_document_id: document_id,
}
.serialize();
if let Some(value) = set {
trx.set(&key, value);
} else {
trx.clear(&key);
}
}
Operation::Log {
collection,
change_id,
@@ -182,24 +180,38 @@ impl Store {
trx.set(&key, set);
}
Operation::AssertValue {
field,
family,
class,
assert_value,
} => {
let key = ValueKey {
account_id,
collection,
document_id,
family: *family,
field: *field,
}
.serialize();
let key = match class {
ValueClass::Property { field, family } => ValueKey {
account_id,
collection,
document_id,
family: *family,
field: *field,
}
.serialize(),
ValueClass::Acl { grant_account_id } => AclKey {
grant_account_id: *grant_account_id,
to_account_id: account_id,
to_collection: collection,
to_document_id: document_id,
}
.serialize(),
ValueClass::Custom { bytes } => {
let mut key = Vec::with_capacity(1 + bytes.len());
key.push(SUBSPACE_VALUES);
key.extend_from_slice(bytes);
key
}
};
let matches = if let Ok(bytes) = trx.get(&key, false).await {
if let Some(bytes) = bytes {
assert_value.matches(bytes.as_ref())
} else {
assert_value.is_none();
assert_value.is_none()
}
} else {
false
@@ -315,7 +327,6 @@ impl Store {
let collection = collection.into();
loop {
//let mut assign_source = 0;
// First try to reuse an expired assigned id
let begin = IndexKey {
account_id,
@@ -375,10 +386,8 @@ impl Store {
// Obtain a random id from the expired ids
if expired_ids.len() > 1 {
document_id = expired_ids[rand::thread_rng().gen_range(0..expired_ids.len())];
//assign_source = 1;
} else {
document_id = expired_ids[0];
//assign_source = 2;
}
} else {
// Find the next available id
@@ -420,8 +429,6 @@ impl Store {
for document_id_ in 0..BITS_PER_BLOCK {
if !reserved_ids.contains(&document_id_) {
document_id = document_id_;
//assign_source = 4;
break;
}
}
@@ -441,8 +448,6 @@ impl Store {
match trx.commit().await {
Ok(_) => {
//println!("assigned id: {document_id} {assign_source}");
return Ok(document_id);
}
Err(err) => {