Simplify cfg
attributes around codebase (#4695)
Co-authored-by: Tobie Morgan Hitchcock <tobie@surrealdb.com>
This commit is contained in:
parent
06b4f95198
commit
dc06603d5b
10 changed files with 35 additions and 279 deletions
|
@ -52,14 +52,7 @@ pub static SCRIPTING_MAX_MEMORY_LIMIT: LazyLock<usize> =
|
|||
pub static INSECURE_FORWARD_ACCESS_ERRORS: LazyLock<bool> =
|
||||
lazy_env_parse!("SURREAL_INSECURE_FORWARD_ACCESS_ERRORS", bool, false);
|
||||
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
/// Specifies the buffer limit for external sorting.
|
||||
pub static EXTERNAL_SORTING_BUFFER_LIMIT: LazyLock<usize> =
|
||||
lazy_env_parse!("SURREAL_EXTERNAL_SORTING_BUFFER_LIMIT", usize, 50_000);
|
||||
|
|
|
@ -16,14 +16,7 @@ use channel::Sender;
|
|||
use std::borrow::Cow;
|
||||
use std::collections::HashMap;
|
||||
use std::fmt::{self, Debug};
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
use std::path::PathBuf;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Arc;
|
||||
|
@ -71,14 +64,7 @@ pub struct MutableContext {
|
|||
index_builder: Option<IndexBuilder>,
|
||||
// Capabilities
|
||||
capabilities: Arc<Capabilities>,
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
// The temporary directory
|
||||
temporary_directory: Option<Arc<PathBuf>>,
|
||||
// An optional transaction
|
||||
|
@ -118,15 +104,7 @@ impl MutableContext {
|
|||
capabilities: Capabilities,
|
||||
index_stores: IndexStores,
|
||||
#[cfg(not(target_arch = "wasm32"))] index_builder: IndexBuilder,
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
temporary_directory: Option<Arc<PathBuf>>,
|
||||
#[cfg(storage)] temporary_directory: Option<Arc<PathBuf>>,
|
||||
) -> Result<MutableContext, Error> {
|
||||
let mut ctx = Self {
|
||||
values: HashMap::default(),
|
||||
|
@ -141,14 +119,7 @@ impl MutableContext {
|
|||
index_stores,
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
index_builder: Some(index_builder),
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
temporary_directory,
|
||||
transaction: None,
|
||||
isolated: false,
|
||||
|
@ -173,14 +144,7 @@ impl MutableContext {
|
|||
index_stores: IndexStores::default(),
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
index_builder: None,
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
temporary_directory: None,
|
||||
transaction: None,
|
||||
isolated: false,
|
||||
|
@ -201,14 +165,7 @@ impl MutableContext {
|
|||
index_stores: parent.index_stores.clone(),
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
index_builder: parent.index_builder.clone(),
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
temporary_directory: parent.temporary_directory.clone(),
|
||||
transaction: parent.transaction.clone(),
|
||||
isolated: false,
|
||||
|
@ -240,13 +197,7 @@ impl MutableContext {
|
|||
index_stores: parent.index_stores.clone(),
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
index_builder: parent.index_builder.clone(),
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
temporary_directory: parent.temporary_directory.clone(),
|
||||
transaction: parent.transaction.clone(),
|
||||
isolated: true,
|
||||
|
@ -268,13 +219,7 @@ impl MutableContext {
|
|||
index_stores: from.index_stores.clone(),
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
index_builder: from.index_builder.clone(),
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
temporary_directory: from.temporary_directory.clone(),
|
||||
transaction: None,
|
||||
isolated: false,
|
||||
|
@ -409,14 +354,7 @@ impl MutableContext {
|
|||
matches!(self.done(), Some(Reason::Timedout))
|
||||
}
|
||||
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
/// Return the location of the temporary directory if any
|
||||
pub fn temporary_directory(&self) -> Option<&Arc<PathBuf>> {
|
||||
self.temporary_directory.as_ref()
|
||||
|
|
|
@ -301,14 +301,7 @@ impl Iterator {
|
|||
self.setup_start(stk, &cancel_ctx, opt, stm).await?;
|
||||
// Prepare the results with possible optimisations on groups
|
||||
self.results = self.results.prepare(
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
ctx,
|
||||
stm,
|
||||
)?;
|
||||
|
|
|
@ -1,14 +1,7 @@
|
|||
use crate::ctx::Context;
|
||||
use crate::dbs::group::GroupsCollector;
|
||||
use crate::dbs::plan::Explanation;
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
use crate::dbs::store::file_store::FileCollector;
|
||||
use crate::dbs::store::MemoryCollector;
|
||||
use crate::dbs::{Options, Statement};
|
||||
|
@ -19,14 +12,7 @@ use reblessive::tree::Stk;
|
|||
pub(super) enum Results {
|
||||
None,
|
||||
Memory(MemoryCollector),
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
File(Box<FileCollector>),
|
||||
Groups(GroupsCollector),
|
||||
}
|
||||
|
@ -34,28 +20,13 @@ pub(super) enum Results {
|
|||
impl Results {
|
||||
pub(super) fn prepare(
|
||||
&mut self,
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
ctx: &Context,
|
||||
#[cfg(storage)] ctx: &Context,
|
||||
stm: &Statement<'_>,
|
||||
) -> Result<Self, Error> {
|
||||
if stm.expr().is_some() && stm.group().is_some() {
|
||||
return Ok(Self::Groups(GroupsCollector::new(stm)));
|
||||
}
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
if stm.tempfiles() {
|
||||
if let Some(temp_dir) = ctx.temporary_directory() {
|
||||
return Ok(Self::File(Box::new(FileCollector::new(temp_dir)?)));
|
||||
|
@ -77,14 +48,7 @@ impl Results {
|
|||
Self::Memory(s) => {
|
||||
s.push(val);
|
||||
}
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
Self::File(e) => {
|
||||
e.push(val)?;
|
||||
}
|
||||
|
@ -98,14 +62,7 @@ impl Results {
|
|||
pub(super) fn sort(&mut self, orders: &Orders) {
|
||||
match self {
|
||||
Self::Memory(m) => m.sort(orders),
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
Self::File(f) => f.sort(orders),
|
||||
_ => {}
|
||||
}
|
||||
|
@ -115,14 +72,7 @@ impl Results {
|
|||
match self {
|
||||
Self::None => {}
|
||||
Self::Memory(m) => m.start_limit(start, limit),
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
Self::File(f) => f.start_limit(start, limit),
|
||||
Self::Groups(_) => {}
|
||||
}
|
||||
|
@ -132,14 +82,7 @@ impl Results {
|
|||
match self {
|
||||
Self::None => 0,
|
||||
Self::Memory(s) => s.len(),
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
Self::File(e) => e.len(),
|
||||
Self::Groups(g) => g.len(),
|
||||
}
|
||||
|
@ -148,14 +91,7 @@ impl Results {
|
|||
pub(super) fn take(&mut self) -> Result<Vec<Value>, Error> {
|
||||
Ok(match self {
|
||||
Self::Memory(m) => m.take_vec(),
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
Self::File(f) => f.take_vec()?,
|
||||
_ => vec![],
|
||||
})
|
||||
|
@ -167,14 +103,7 @@ impl Results {
|
|||
Self::Memory(s) => {
|
||||
s.explain(exp);
|
||||
}
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
Self::File(e) => {
|
||||
e.explain(exp);
|
||||
}
|
||||
|
|
|
@ -246,14 +246,7 @@ impl<'a> Statement<'a> {
|
|||
|
||||
/// Returns any TEMPFILES clause if specified
|
||||
#[inline]
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
pub fn tempfiles(&self) -> bool {
|
||||
match self {
|
||||
Statement::Select(v) => v.tempfiles,
|
||||
|
|
|
@ -53,14 +53,7 @@ impl From<Vec<Value>> for MemoryCollector {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
pub(super) mod file_store {
|
||||
use crate::cnf::EXTERNAL_SORTING_BUFFER_LIMIT;
|
||||
use crate::dbs::plan::Explanation;
|
||||
|
|
|
@ -9,14 +9,7 @@ use crate::syn::error::RenderedError as RenderedParserError;
|
|||
use crate::vs::Error as VersionstampError;
|
||||
use base64::DecodeError as Base64Error;
|
||||
use bincode::Error as BincodeError;
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
use ext_sort::SortError;
|
||||
use fst::Error as FstError;
|
||||
use jsonwebtoken::errors::Error as JWTError;
|
||||
|
@ -1217,14 +1210,7 @@ impl From<reqwest::Error> for Error {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
impl<S, D, I> From<SortError<S, D, I>> for Error
|
||||
where
|
||||
S: std::error::Error,
|
||||
|
|
|
@ -27,14 +27,7 @@ use channel::{Receiver, Sender};
|
|||
use futures::Future;
|
||||
use reblessive::TreeStack;
|
||||
use std::fmt;
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
@ -83,14 +76,7 @@ pub struct Datastore {
|
|||
#[cfg(feature = "jwks")]
|
||||
// The JWKS object cache
|
||||
jwks_cache: Arc<RwLock<JwksCache>>,
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
// The temporary directory
|
||||
temporary_directory: Option<Arc<PathBuf>>,
|
||||
}
|
||||
|
@ -273,13 +259,7 @@ impl Datastore {
|
|||
index_builder: IndexBuilder::new(self.transaction_factory.clone()),
|
||||
#[cfg(feature = "jwks")]
|
||||
jwks_cache: Arc::new(Default::default()),
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
temporary_directory: self.temporary_directory,
|
||||
transaction_factory: self.transaction_factory,
|
||||
}
|
||||
|
@ -439,14 +419,7 @@ impl Datastore {
|
|||
index_builder: IndexBuilder::new(tf),
|
||||
#[cfg(feature = "jwks")]
|
||||
jwks_cache: Arc::new(RwLock::new(JwksCache::new())),
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
temporary_directory: None,
|
||||
}
|
||||
})
|
||||
|
@ -494,14 +467,7 @@ impl Datastore {
|
|||
self
|
||||
}
|
||||
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
/// Set a temporary directory for ordering of large result sets
|
||||
pub fn with_temporary_directory(mut self, path: Option<PathBuf>) -> Self {
|
||||
self.temporary_directory = path.map(Arc::new);
|
||||
|
@ -856,14 +822,7 @@ impl Datastore {
|
|||
self.index_stores.clone(),
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
self.index_builder.clone(),
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
self.temporary_directory.clone(),
|
||||
)?;
|
||||
// Setup the notification channel
|
||||
|
|
|
@ -108,14 +108,7 @@ pub(crate) async fn run_router(
|
|||
.with_transaction_timeout(address.config.transaction_timeout)
|
||||
.with_capabilities(address.config.capabilities);
|
||||
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
let kvs = kvs.with_temporary_directory(address.config.temporary_directory);
|
||||
|
||||
let kvs = Arc::new(kvs);
|
||||
|
|
|
@ -1,12 +1,5 @@
|
|||
use crate::opt::capabilities::Capabilities;
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
use std::path::PathBuf;
|
||||
use std::time::Duration;
|
||||
use surrealdb_core::{dbs::Capabilities as CoreCapabilities, iam::Level};
|
||||
|
@ -27,14 +20,7 @@ pub struct Config {
|
|||
pub(crate) password: String,
|
||||
pub(crate) tick_interval: Option<Duration>,
|
||||
pub(crate) capabilities: CoreCapabilities,
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
pub(crate) temporary_directory: Option<PathBuf>,
|
||||
}
|
||||
|
||||
|
@ -124,14 +110,7 @@ impl Config {
|
|||
self
|
||||
}
|
||||
|
||||
#[cfg(any(
|
||||
feature = "kv-mem",
|
||||
feature = "kv-surrealkv",
|
||||
feature = "kv-rocksdb",
|
||||
feature = "kv-fdb",
|
||||
feature = "kv-tikv",
|
||||
feature = "kv-surrealcs",
|
||||
))]
|
||||
#[cfg(storage)]
|
||||
pub fn temporary_directory(mut self, path: Option<PathBuf>) -> Self {
|
||||
self.temporary_directory = path;
|
||||
self
|
||||
|
|
Loading…
Reference in a new issue