Add improved instrumentation to kvs module layer (#4418)

This commit is contained in:
Tobie Morgan Hitchcock 2024-07-30 06:51:28 +01:00 committed by GitHub
parent fed79d4808
commit bf2eb32f01
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 364 additions and 384 deletions

View file

@ -1,7 +1,6 @@
use crate::err::Error; use crate::err::Error;
use crate::key::change; use crate::key::change;
#[cfg(debug_assertions)] use crate::key::debug::Sprintable;
use crate::key::debug::sprint;
use crate::kvs::Transaction; use crate::kvs::Transaction;
use crate::vs; use crate::vs;
use crate::vs::Versionstamp; use crate::vs::Versionstamp;
@ -84,8 +83,8 @@ pub async fn gc_range(
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
trace!( trace!(
"Performing garbage collection on {ns}:{db} for watermark {watermark:?}, between {} and {}", "Performing garbage collection on {ns}:{db} for watermark {watermark:?}, between {} and {}",
sprint(&beg), beg.sprint(),
sprint(&end) end.sprint()
); );
// Delete the entire range in grouped batches // Delete the entire range in grouped batches
tx.delr(beg..end).await?; tx.delr(beg..end).await?;

View file

@ -1,8 +1,7 @@
use crate::cf::{ChangeSet, DatabaseMutation, TableMutations}; use crate::cf::{ChangeSet, DatabaseMutation, TableMutations};
use crate::err::Error; use crate::err::Error;
use crate::key::change; use crate::key::change;
#[cfg(debug_assertions)] use crate::key::debug::Sprintable;
use crate::key::debug::sprint;
use crate::kvs::Transaction; use crate::kvs::Transaction;
use crate::sql::statements::show::ShowSince; use crate::sql::statements::show::ShowSince;
use crate::vs; use crate::vs;
@ -52,7 +51,7 @@ pub async fn read(
// iterate over _x and put decoded elements to r // iterate over _x and put decoded elements to r
for (k, v) in tx.scan(beg..end, limit).await? { for (k, v) in tx.scan(beg..end, limit).await? {
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
trace!("Reading change feed entry: {}", sprint(&k)); trace!("Reading change feed entry: {}", k.sprint());
// Decode the changefeed entry key // Decode the changefeed entry key
let dec = crate::key::change::Cf::decode(&k).unwrap(); let dec = crate::key::change::Cf::decode(&k).unwrap();
// Check the change is for the desired table // Check the change is for the desired table

View file

@ -1,12 +1,53 @@
/// Displays a key in a human-readable format. use std::ops::Range;
#[cfg(debug_assertions)]
pub fn sprint<T>(key: &T) -> String pub trait Sprintable {
where fn sprint(&self) -> String;
T: AsRef<[u8]>, }
{
key.as_ref() impl Sprintable for &str {
.iter() fn sprint(&self) -> String {
self.to_string()
}
}
impl Sprintable for String {
fn sprint(&self) -> String {
self.to_string()
}
}
impl Sprintable for Vec<u8> {
fn sprint(&self) -> String {
self.iter()
.flat_map(|&byte| std::ascii::escape_default(byte)) .flat_map(|&byte| std::ascii::escape_default(byte))
.map(|byte| byte as char) .map(|byte| byte as char)
.collect::<String>() .collect::<String>()
}
}
impl Sprintable for &[u8] {
fn sprint(&self) -> String {
self.iter()
.flat_map(|&byte| std::ascii::escape_default(byte))
.map(|byte| byte as char)
.collect::<String>()
}
}
impl<T> Sprintable for Vec<T>
where
T: Sprintable,
{
fn sprint(&self) -> String {
self.iter().map(Sprintable::sprint).collect::<Vec<_>>().join(" + ")
}
}
impl<T> Sprintable for Range<T>
where
T: Sprintable,
{
fn sprint(&self) -> String {
format!("{}..{}", self.start.sprint(), self.end.sprint())
}
} }

View file

@ -2,6 +2,7 @@ use super::kv::Add;
use super::tr::Check; use super::tr::Check;
use crate::cnf::NORMAL_FETCH_SIZE; use crate::cnf::NORMAL_FETCH_SIZE;
use crate::err::Error; use crate::err::Error;
use crate::key::debug::Sprintable;
use crate::kvs::batch::Batch; use crate::kvs::batch::Batch;
use crate::kvs::Key; use crate::kvs::Key;
use crate::kvs::Val; use crate::kvs::Val;
@ -50,40 +51,40 @@ pub trait Transaction {
/// Check if a key exists in the datastore. /// Check if a key exists in the datastore.
async fn exists<K>(&mut self, key: K) -> Result<bool, Error> async fn exists<K>(&mut self, key: K) -> Result<bool, Error>
where where
K: Into<Key> + Debug; K: Into<Key> + Sprintable + Debug;
/// Fetch a key from the datastore. /// Fetch a key from the datastore.
async fn get<K>(&mut self, key: K) -> Result<Option<Val>, Error> async fn get<K>(&mut self, key: K) -> Result<Option<Val>, Error>
where where
K: Into<Key> + Debug; K: Into<Key> + Sprintable + Debug;
/// Insert or update a key in the datastore. /// Insert or update a key in the datastore.
async fn set<K, V>(&mut self, key: K, val: V) -> Result<(), Error> async fn set<K, V>(&mut self, key: K, val: V) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug; V: Into<Val> + Debug;
/// Insert a key if it doesn't exist in the datastore. /// Insert a key if it doesn't exist in the datastore.
async fn put<K, V>(&mut self, key: K, val: V) -> Result<(), Error> async fn put<K, V>(&mut self, key: K, val: V) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug; V: Into<Val> + Debug;
/// Update a key in the datastore if the current value matches a condition. /// Update a key in the datastore if the current value matches a condition.
async fn putc<K, V>(&mut self, key: K, val: V, chk: Option<V>) -> Result<(), Error> async fn putc<K, V>(&mut self, key: K, val: V, chk: Option<V>) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug; V: Into<Val> + Debug;
/// Delete a key from the datastore. /// Delete a key from the datastore.
async fn del<K>(&mut self, key: K) -> Result<(), Error> async fn del<K>(&mut self, key: K) -> Result<(), Error>
where where
K: Into<Key> + Debug; K: Into<Key> + Sprintable + Debug;
/// Delete a key from the datastore if the current value matches a condition. /// Delete a key from the datastore if the current value matches a condition.
async fn delc<K, V>(&mut self, key: K, chk: Option<V>) -> Result<(), Error> async fn delc<K, V>(&mut self, key: K, chk: Option<V>) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug; V: Into<Val> + Debug;
/// Retrieve a specific range of keys from the datastore. /// Retrieve a specific range of keys from the datastore.
@ -91,21 +92,22 @@ pub trait Transaction {
/// This function fetches the full range of keys without values, in a single request to the underlying datastore. /// This function fetches the full range of keys without values, in a single request to the underlying datastore.
async fn keys<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<Key>, Error> async fn keys<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<Key>, Error>
where where
K: Into<Key> + Debug; K: Into<Key> + Sprintable + Debug;
/// Retrieve a specific range of keys from the datastore. /// Retrieve a specific range of keys from the datastore.
/// ///
/// This function fetches the full range of key-value pairs, in a single request to the underlying datastore. /// This function fetches the full range of key-value pairs, in a single request to the underlying datastore.
async fn scan<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<(Key, Val)>, Error> async fn scan<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<(Key, Val)>, Error>
where where
K: Into<Key> + Debug; K: Into<Key> + Sprintable + Debug;
/// Fetch many keys from the datastore. /// Fetch many keys from the datastore.
/// ///
/// This function fetches all matching keys pairs from the underlying datastore concurrently. /// This function fetches all matching keys pairs from the underlying datastore concurrently.
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(keys = keys.sprint()))]
async fn getm<K>(&mut self, keys: Vec<K>) -> Result<Vec<Val>, Error> async fn getm<K>(&mut self, keys: Vec<K>) -> Result<Vec<Val>, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.closed() { if self.closed() {
@ -126,9 +128,10 @@ pub trait Transaction {
/// Retrieve a range of prefixed keys from the datastore. /// Retrieve a range of prefixed keys from the datastore.
/// ///
/// This function fetches all matching key-value pairs from the underlying datastore in grouped batches. /// This function fetches all matching key-value pairs from the underlying datastore in grouped batches.
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn getp<K>(&mut self, key: K) -> Result<Vec<(Key, Val)>, Error> async fn getp<K>(&mut self, key: K) -> Result<Vec<(Key, Val)>, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.closed() { if self.closed() {
@ -143,9 +146,10 @@ pub trait Transaction {
/// Retrieve a range of keys from the datastore. /// Retrieve a range of keys from the datastore.
/// ///
/// This function fetches all matching key-value pairs from the underlying datastore in grouped batches. /// This function fetches all matching key-value pairs from the underlying datastore in grouped batches.
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(rng = rng.sprint()))]
async fn getr<K>(&mut self, rng: Range<K>) -> Result<Vec<(Key, Val)>, Error> async fn getr<K>(&mut self, rng: Range<K>) -> Result<Vec<(Key, Val)>, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.closed() { if self.closed() {
@ -169,9 +173,10 @@ pub trait Transaction {
/// Delete a range of prefixed keys from the datastore. /// Delete a range of prefixed keys from the datastore.
/// ///
/// This function deletes all matching key-value pairs from the underlying datastore in grouped batches. /// This function deletes all matching key-value pairs from the underlying datastore in grouped batches.
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn delp<K>(&mut self, key: K) -> Result<(), Error> async fn delp<K>(&mut self, key: K) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.closed() { if self.closed() {
@ -190,9 +195,10 @@ pub trait Transaction {
/// Delete a range of keys from the datastore. /// Delete a range of keys from the datastore.
/// ///
/// This function deletes all matching key-value pairs from the underlying datastore in grouped batches. /// This function deletes all matching key-value pairs from the underlying datastore in grouped batches.
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(rng = rng.sprint()))]
async fn delr<K>(&mut self, rng: Range<K>) -> Result<(), Error> async fn delr<K>(&mut self, rng: Range<K>) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.closed() { if self.closed() {
@ -219,9 +225,10 @@ pub trait Transaction {
/// Retrieve a batched scan over a specific range of keys in the datastore. /// Retrieve a batched scan over a specific range of keys in the datastore.
/// ///
/// This function fetches keys or key-value pairs, in batches, with multiple requests to the underlying datastore. /// This function fetches keys or key-value pairs, in batches, with multiple requests to the underlying datastore.
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(rng = rng.sprint()))]
async fn batch<K>(&mut self, rng: Range<K>, batch: u32, values: bool) -> Result<Batch, Error> async fn batch<K>(&mut self, rng: Range<K>, batch: u32, values: bool) -> Result<Batch, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.closed() { if self.closed() {
@ -269,9 +276,10 @@ pub trait Transaction {
/// NOTE: This should be called when composing the change feed entries for this transaction, /// NOTE: This should be called when composing the change feed entries for this transaction,
/// which should be done immediately before the transaction commit. /// which should be done immediately before the transaction commit.
/// That is to keep other transactions commit delay(pessimistic) or conflict(optimistic) as less as possible. /// That is to keep other transactions commit delay(pessimistic) or conflict(optimistic) as less as possible.
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn get_timestamp<K>(&mut self, key: K) -> Result<Versionstamp, Error> async fn get_timestamp<K>(&mut self, key: K) -> Result<Versionstamp, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.closed() { if self.closed() {
@ -299,6 +307,7 @@ pub trait Transaction {
} }
/// Insert the versionstamped key into the datastore. /// Insert the versionstamped key into the datastore.
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(ts_key = ts_key.sprint()))]
async fn set_versionstamp<K, V>( async fn set_versionstamp<K, V>(
&mut self, &mut self,
ts_key: K, ts_key: K,
@ -307,7 +316,7 @@ pub trait Transaction {
val: V, val: V,
) -> Result<(), Error> ) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug, V: Into<Val> + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed

View file

@ -390,7 +390,7 @@ impl Datastore {
} }
// Initialise the cluster and run bootstrap utilities // Initialise the cluster and run bootstrap utilities
#[instrument(err, level = "debug", target = "surrealdb::core::kvs::ds", skip_all)] #[instrument(err, level = "trace", target = "surrealdb::core::kvs::ds", skip_all)]
pub async fn bootstrap(&self) -> Result<(), Error> { pub async fn bootstrap(&self) -> Result<(), Error> {
// Insert this node in the cluster // Insert this node in the cluster
self.insert_node(self.id).await?; self.insert_node(self.id).await?;
@ -401,8 +401,8 @@ impl Datastore {
} }
/// Setup the initial cluster access credentials /// Setup the initial cluster access credentials
#[instrument(err, level = "debug", target = "surrealdb::core::kvs::ds", skip_all)] #[instrument(err, level = "trace", target = "surrealdb::core::kvs::ds", skip_all)]
pub async fn setup_initial_creds(&self, user: &str, pass: &str) -> Result<(), Error> { pub async fn initialise_credentials(&self, user: &str, pass: &str) -> Result<(), Error> {
// Start a new writeable transaction // Start a new writeable transaction
let txn = self.transaction(Write, Optimistic).await?.enclose(); let txn = self.transaction(Write, Optimistic).await?.enclose();
// Fetch the root users from the storage // Fetch the root users from the storage
@ -429,7 +429,7 @@ impl Datastore {
// tick is called periodically to perform maintenance tasks. // tick is called periodically to perform maintenance tasks.
// This is called every TICK_INTERVAL. // This is called every TICK_INTERVAL.
#[instrument(level = "debug", skip(self))] #[instrument(err, level = "trace", target = "surrealdb::core::kvs::ds", skip(self))]
pub async fn tick(&self) -> Result<(), Error> { pub async fn tick(&self) -> Result<(), Error> {
let now = SystemTime::now().duration_since(UNIX_EPOCH).map_err(|e| { let now = SystemTime::now().duration_since(UNIX_EPOCH).map_err(|e| {
Error::Internal(format!("Clock may have gone backwards: {:?}", e.duration())) Error::Internal(format!("Clock may have gone backwards: {:?}", e.duration()))
@ -442,7 +442,7 @@ impl Datastore {
// tick_at is the utility function that is called by tick. // tick_at is the utility function that is called by tick.
// It is handy for testing, because it allows you to specify the timestamp, // It is handy for testing, because it allows you to specify the timestamp,
// without depending on a system clock. // without depending on a system clock.
#[instrument(level = "debug", skip(self))] #[instrument(level = "trace", target = "surrealdb::core::kvs::ds", skip(self))]
pub async fn tick_at(&self, ts: u64) -> Result<(), Error> { pub async fn tick_at(&self, ts: u64) -> Result<(), Error> {
trace!(target: TARGET, "Ticking at timestamp {ts} ({:?})", conv::u64_to_versionstamp(ts)); trace!(target: TARGET, "Ticking at timestamp {ts} ({:?})", conv::u64_to_versionstamp(ts));
let _vs = self.save_timestamp_for_versionstamp(ts).await?; let _vs = self.save_timestamp_for_versionstamp(ts).await?;
@ -621,7 +621,7 @@ impl Datastore {
/// Ok(()) /// Ok(())
/// } /// }
/// ``` /// ```
#[instrument(level = "debug", skip_all)] #[instrument(level = "debug", target = "surrealdb::core::kvs::ds", skip_all)]
pub async fn execute( pub async fn execute(
&self, &self,
txt: &str, txt: &str,
@ -651,7 +651,7 @@ impl Datastore {
/// Ok(()) /// Ok(())
/// } /// }
/// ``` /// ```
#[instrument(level = "debug", skip_all)] #[instrument(level = "debug", target = "surrealdb::core::kvs::ds", skip_all)]
pub async fn process( pub async fn process(
&self, &self,
ast: Query, ast: Query,
@ -727,7 +727,7 @@ impl Datastore {
/// Ok(()) /// Ok(())
/// } /// }
/// ``` /// ```
#[instrument(level = "debug", skip_all)] #[instrument(level = "debug", target = "surrealdb::core::kvs::ds", skip_all)]
pub async fn compute( pub async fn compute(
&self, &self,
val: Value, val: Value,
@ -814,7 +814,7 @@ impl Datastore {
/// Ok(()) /// Ok(())
/// } /// }
/// ``` /// ```
#[instrument(level = "debug", skip_all)] #[instrument(level = "debug", target = "surrealdb::core::kvs::ds", skip_all)]
pub async fn evaluate( pub async fn evaluate(
&self, &self,
val: Value, val: Value,
@ -888,13 +888,13 @@ impl Datastore {
/// Ok(()) /// Ok(())
/// } /// }
/// ``` /// ```
#[instrument(level = "debug", skip_all)] #[instrument(level = "debug", target = "surrealdb::core::kvs::ds", skip_all)]
pub fn notifications(&self) -> Option<Receiver<Notification>> { pub fn notifications(&self) -> Option<Receiver<Notification>> {
self.notification_channel.as_ref().map(|v| v.1.clone()) self.notification_channel.as_ref().map(|v| v.1.clone())
} }
/// Performs a database import from SQL /// Performs a database import from SQL
#[instrument(level = "debug", skip_all)] #[instrument(level = "debug", target = "surrealdb::core::kvs::ds", skip_all)]
pub async fn import(&self, sql: &str, sess: &Session) -> Result<Vec<Response>, Error> { pub async fn import(&self, sql: &str, sess: &Session) -> Result<Vec<Response>, Error> {
// Check if the session has expired // Check if the session has expired
if sess.expired() { if sess.expired() {
@ -905,7 +905,7 @@ impl Datastore {
} }
/// Performs a full database export as SQL /// Performs a full database export as SQL
#[instrument(level = "debug", skip_all)] #[instrument(level = "debug", target = "surrealdb::core::kvs::ds", skip_all)]
pub async fn export( pub async fn export(
&self, &self,
sess: &Session, sess: &Session,
@ -929,7 +929,7 @@ impl Datastore {
} }
/// Checks the required permissions level for this session /// Checks the required permissions level for this session
#[instrument(level = "debug", skip(self, sess))] #[instrument(level = "trace", target = "surrealdb::core::kvs::ds", skip(self, sess))]
pub fn check(&self, sess: &Session, action: Action, resource: Resource) -> Result<(), Error> { pub fn check(&self, sess: &Session, action: Action, resource: Resource) -> Result<(), Error> {
// Check if the session has expired // Check if the session has expired
if sess.expired() { if sess.expired() {

View file

@ -3,6 +3,7 @@
mod cnf; mod cnf;
use crate::err::Error; use crate::err::Error;
use crate::key::debug::Sprintable;
use crate::kvs::Check; use crate::kvs::Check;
use crate::kvs::Key; use crate::kvs::Key;
use crate::kvs::Val; use crate::kvs::Val;
@ -176,6 +177,7 @@ impl super::api::Transaction for Transaction {
} }
/// Cancel a transaction /// Cancel a transaction
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self))]
async fn cancel(&mut self) -> Result<(), Error> { async fn cancel(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -193,6 +195,7 @@ impl super::api::Transaction for Transaction {
} }
/// Commit a transaction /// Commit a transaction
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self))]
async fn commit(&mut self) -> Result<(), Error> { async fn commit(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -214,9 +217,10 @@ impl super::api::Transaction for Transaction {
} }
/// Check if a key exists /// Check if a key exists
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn exists<K>(&mut self, key: K) -> Result<bool, Error> async fn exists<K>(&mut self, key: K) -> Result<bool, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -229,9 +233,10 @@ impl super::api::Transaction for Transaction {
} }
/// Fetch a key from the database /// Fetch a key from the database
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn get<K>(&mut self, key: K) -> Result<Option<Val>, Error> async fn get<K>(&mut self, key: K) -> Result<Option<Val>, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -250,9 +255,10 @@ impl super::api::Transaction for Transaction {
} }
/// Inserts or update a key in the database /// Inserts or update a key in the database
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn set<K, V>(&mut self, key: K, val: V) -> Result<(), Error> async fn set<K, V>(&mut self, key: K, val: V) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug, V: Into<Val> + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
@ -270,9 +276,10 @@ impl super::api::Transaction for Transaction {
} }
/// Insert a key if it doesn't exist in the database /// Insert a key if it doesn't exist in the database
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn put<K, V>(&mut self, key: K, val: V) -> Result<(), Error> async fn put<K, V>(&mut self, key: K, val: V) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug, V: Into<Val> + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
@ -298,9 +305,10 @@ impl super::api::Transaction for Transaction {
} }
/// Insert a key if the current value matches a condition. /// Insert a key if the current value matches a condition.
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn putc<K, V>(&mut self, key: K, val: V, chk: Option<V>) -> Result<(), Error> async fn putc<K, V>(&mut self, key: K, val: V, chk: Option<V>) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug, V: Into<Val> + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
@ -328,9 +336,10 @@ impl super::api::Transaction for Transaction {
} }
/// Delete a key /// Delete a key
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn del<K>(&mut self, key: K) -> Result<(), Error> async fn del<K>(&mut self, key: K) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -347,9 +356,10 @@ impl super::api::Transaction for Transaction {
} }
/// Delete a key if the current value matches a condition. /// Delete a key if the current value matches a condition.
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn delc<K, V>(&mut self, key: K, chk: Option<V>) -> Result<(), Error> async fn delc<K, V>(&mut self, key: K, chk: Option<V>) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug, V: Into<Val> + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
@ -376,9 +386,10 @@ impl super::api::Transaction for Transaction {
} }
/// Delete a range of keys from the databases /// Delete a range of keys from the databases
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(rng = rng.sprint()))]
async fn delr<K>(&mut self, rng: Range<K>) -> Result<(), Error> async fn delr<K>(&mut self, rng: Range<K>) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -395,9 +406,10 @@ impl super::api::Transaction for Transaction {
} }
/// Retrieve a range of keys from the databases /// Retrieve a range of keys from the databases
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(rng = rng.sprint()))]
async fn keys<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<Key>, Error> async fn keys<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<Key>, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -430,9 +442,10 @@ impl super::api::Transaction for Transaction {
} }
/// Retrieve a range of keys from the databases /// Retrieve a range of keys from the databases
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(rng = rng.sprint()))]
async fn scan<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<(Key, Val)>, Error> async fn scan<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<(Key, Val)>, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -465,7 +478,11 @@ impl super::api::Transaction for Transaction {
} }
/// Obtain a new change timestamp for a key /// Obtain a new change timestamp for a key
async fn get_timestamp<K>(&mut self, _: K) -> Result<Versionstamp, Error> { #[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn get_timestamp<K>(&mut self, key: K) -> Result<Versionstamp, Error>
where
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
return Err(Error::TxFinished); return Err(Error::TxFinished);
@ -479,15 +496,16 @@ impl super::api::Transaction for Transaction {
} }
// Sets the value for a versionstamped key prefixed with the user-supplied key. // Sets the value for a versionstamped key prefixed with the user-supplied key.
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(ts_key = ts_key.sprint()))]
async fn set_versionstamp<K, V>( async fn set_versionstamp<K, V>(
&mut self, &mut self,
_: K, ts_key: K,
prefix: K, prefix: K,
suffix: K, suffix: K,
val: V, val: V,
) -> Result<(), Error> ) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug, V: Into<Val> + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed

View file

@ -1,9 +1,11 @@
#![cfg(feature = "kv-indxdb")] #![cfg(feature = "kv-indxdb")]
use crate::err::Error; use crate::err::Error;
use crate::key::debug::Sprintable;
use crate::kvs::Check; use crate::kvs::Check;
use crate::kvs::Key; use crate::kvs::Key;
use crate::kvs::Val; use crate::kvs::Val;
use std::fmt::Debug;
use std::ops::Range; use std::ops::Range;
#[non_exhaustive] #[non_exhaustive]
@ -100,6 +102,7 @@ impl super::api::Transaction for Transaction {
} }
/// Cancel a transaction /// Cancel a transaction
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self))]
async fn cancel(&mut self) -> Result<(), Error> { async fn cancel(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -114,6 +117,7 @@ impl super::api::Transaction for Transaction {
} }
/// Commit a transaction /// Commit a transaction
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self))]
async fn commit(&mut self) -> Result<(), Error> { async fn commit(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -132,9 +136,10 @@ impl super::api::Transaction for Transaction {
} }
/// Check if a key exists /// Check if a key exists
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn exists<K>(&mut self, key: K) -> Result<bool, Error> async fn exists<K>(&mut self, key: K) -> Result<bool, Error>
where where
K: Into<Key>, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -147,9 +152,10 @@ impl super::api::Transaction for Transaction {
} }
/// Fetch a key from the database /// Fetch a key from the database
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn get<K>(&mut self, key: K) -> Result<Option<Val>, Error> async fn get<K>(&mut self, key: K) -> Result<Option<Val>, Error>
where where
K: Into<Key>, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -162,10 +168,11 @@ impl super::api::Transaction for Transaction {
} }
/// Insert or update a key in the database /// Insert or update a key in the database
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn set<K, V>(&mut self, key: K, val: V) -> Result<(), Error> async fn set<K, V>(&mut self, key: K, val: V) -> Result<(), Error>
where where
K: Into<Key>, K: Into<Key> + Sprintable + Debug,
V: Into<Val>, V: Into<Val> + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -182,10 +189,11 @@ impl super::api::Transaction for Transaction {
} }
/// Insert a key if it doesn't exist in the database /// Insert a key if it doesn't exist in the database
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn put<K, V>(&mut self, key: K, val: V) -> Result<(), Error> async fn put<K, V>(&mut self, key: K, val: V) -> Result<(), Error>
where where
K: Into<Key>, K: Into<Key> + Sprintable + Debug,
V: Into<Val>, V: Into<Val> + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -202,10 +210,11 @@ impl super::api::Transaction for Transaction {
} }
/// Insert a key if the current value matches a condition /// Insert a key if the current value matches a condition
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn putc<K, V>(&mut self, key: K, val: V, chk: Option<V>) -> Result<(), Error> async fn putc<K, V>(&mut self, key: K, val: V, chk: Option<V>) -> Result<(), Error>
where where
K: Into<Key>, K: Into<Key> + Sprintable + Debug,
V: Into<Val>, V: Into<Val> + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -222,9 +231,10 @@ impl super::api::Transaction for Transaction {
} }
/// Delete a key /// Delete a key
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn del<K>(&mut self, key: K) -> Result<(), Error> async fn del<K>(&mut self, key: K) -> Result<(), Error>
where where
K: Into<Key>, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -241,10 +251,11 @@ impl super::api::Transaction for Transaction {
} }
/// Delete a key if the current value matches a condition /// Delete a key if the current value matches a condition
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn delc<K, V>(&mut self, key: K, chk: Option<V>) -> Result<(), Error> async fn delc<K, V>(&mut self, key: K, chk: Option<V>) -> Result<(), Error>
where where
K: Into<Key>, K: Into<Key> + Sprintable + Debug,
V: Into<Val>, V: Into<Val> + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -261,9 +272,10 @@ impl super::api::Transaction for Transaction {
} }
/// Retrieve a range of keys from the databases /// Retrieve a range of keys from the databases
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(rng = rng.sprint()))]
async fn keys<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<Key>, Error> async fn keys<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<Key>, Error>
where where
K: Into<Key>, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -281,9 +293,10 @@ impl super::api::Transaction for Transaction {
} }
/// Retrieve a range of keys from the databases /// Retrieve a range of keys from the databases
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(rng = rng.sprint()))]
async fn scan<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<(Key, Val)>, Error> async fn scan<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<(Key, Val)>, Error>
where where
K: Into<Key>, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {

View file

@ -1,6 +1,7 @@
#![cfg(feature = "kv-mem")] #![cfg(feature = "kv-mem")]
use crate::err::Error; use crate::err::Error;
use crate::key::debug::Sprintable;
use crate::kvs::Check; use crate::kvs::Check;
use crate::kvs::Key; use crate::kvs::Key;
use crate::kvs::Val; use crate::kvs::Val;
@ -98,6 +99,7 @@ impl super::api::Transaction for Transaction {
} }
/// Cancel a transaction /// Cancel a transaction
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self))]
async fn cancel(&mut self) -> Result<(), Error> { async fn cancel(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -112,6 +114,7 @@ impl super::api::Transaction for Transaction {
} }
/// Commit a transaction /// Commit a transaction
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self))]
async fn commit(&mut self) -> Result<(), Error> { async fn commit(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -130,9 +133,10 @@ impl super::api::Transaction for Transaction {
} }
/// Check if a key exists /// Check if a key exists
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn exists<K>(&mut self, key: K) -> Result<bool, Error> async fn exists<K>(&mut self, key: K) -> Result<bool, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -145,9 +149,10 @@ impl super::api::Transaction for Transaction {
} }
/// Fetch a key from the database /// Fetch a key from the database
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn get<K>(&mut self, key: K) -> Result<Option<Val>, Error> async fn get<K>(&mut self, key: K) -> Result<Option<Val>, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -160,9 +165,10 @@ impl super::api::Transaction for Transaction {
} }
/// Insert or update a key in the database /// Insert or update a key in the database
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn set<K, V>(&mut self, key: K, val: V) -> Result<(), Error> async fn set<K, V>(&mut self, key: K, val: V) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug, V: Into<Val> + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
@ -180,9 +186,10 @@ impl super::api::Transaction for Transaction {
} }
/// Insert a key if it doesn't exist in the database /// Insert a key if it doesn't exist in the database
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn put<K, V>(&mut self, key: K, val: V) -> Result<(), Error> async fn put<K, V>(&mut self, key: K, val: V) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug, V: Into<Val> + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
@ -200,9 +207,10 @@ impl super::api::Transaction for Transaction {
} }
/// Insert a key if the current value matches a condition /// Insert a key if the current value matches a condition
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn putc<K, V>(&mut self, key: K, val: V, chk: Option<V>) -> Result<(), Error> async fn putc<K, V>(&mut self, key: K, val: V, chk: Option<V>) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug, V: Into<Val> + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
@ -220,9 +228,10 @@ impl super::api::Transaction for Transaction {
} }
/// Delete a key /// Delete a key
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn del<K>(&mut self, key: K) -> Result<(), Error> async fn del<K>(&mut self, key: K) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -239,9 +248,10 @@ impl super::api::Transaction for Transaction {
} }
/// Delete a key if the current value matches a condition /// Delete a key if the current value matches a condition
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn delc<K, V>(&mut self, key: K, chk: Option<V>) -> Result<(), Error> async fn delc<K, V>(&mut self, key: K, chk: Option<V>) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug, V: Into<Val> + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
@ -259,9 +269,10 @@ impl super::api::Transaction for Transaction {
} }
/// Retrieve a range of keys from the databases /// Retrieve a range of keys from the databases
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(rng = rng.sprint()))]
async fn keys<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<Key>, Error> async fn keys<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<Key>, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -279,9 +290,10 @@ impl super::api::Transaction for Transaction {
} }
/// Retrieve a range of keys from the databases /// Retrieve a range of keys from the databases
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(rng = rng.sprint()))]
async fn scan<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<(Key, Val)>, Error> async fn scan<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<(Key, Val)>, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {

View file

@ -18,7 +18,7 @@ impl Datastore {
/// This function ensures that this node is entered into the clister /// This function ensures that this node is entered into the clister
/// membership entries. This function must be run at server or database /// membership entries. This function must be run at server or database
/// startup, in order to write the initial entry and timestamp to storage. /// startup, in order to write the initial entry and timestamp to storage.
#[instrument(err, level = "debug", target = "surrealdb::core::kvs::node", skip(self))] #[instrument(err, level = "trace", target = "surrealdb::core::kvs::node", skip(self))]
pub async fn insert_node(&self, id: uuid::Uuid) -> Result<(), Error> { pub async fn insert_node(&self, id: uuid::Uuid) -> Result<(), Error> {
// Log when this method is run // Log when this method is run
trace!(target: TARGET, "Inserting node in the cluster"); trace!(target: TARGET, "Inserting node in the cluster");
@ -42,7 +42,7 @@ impl Datastore {
/// This function updates the entry for this node with an up-to-date /// This function updates the entry for this node with an up-to-date
/// timestamp. This ensures that the node is not marked as expired by any /// timestamp. This ensures that the node is not marked as expired by any
/// garbage collection tasks, preventing any data cleanup for this node. /// garbage collection tasks, preventing any data cleanup for this node.
#[instrument(err, level = "debug", target = "surrealdb::core::kvs::node", skip(self))] #[instrument(err, level = "trace", target = "surrealdb::core::kvs::node", skip(self))]
pub async fn update_node(&self, id: uuid::Uuid) -> Result<(), Error> { pub async fn update_node(&self, id: uuid::Uuid) -> Result<(), Error> {
// Log when this method is run // Log when this method is run
trace!(target: TARGET, "Updating node in the cluster"); trace!(target: TARGET, "Updating node in the cluster");
@ -61,7 +61,7 @@ impl Datastore {
/// This function marks the node as archived, ready for garbage collection. /// This function marks the node as archived, ready for garbage collection.
/// Later on when garbage collection is running the live queries assigned /// Later on when garbage collection is running the live queries assigned
/// to this node will be removed, along with the node itself. /// to this node will be removed, along with the node itself.
#[instrument(err, level = "debug", target = "surrealdb::core::kvs::node", skip(self))] #[instrument(err, level = "trace", target = "surrealdb::core::kvs::node", skip(self))]
pub async fn delete_node(&self, id: uuid::Uuid) -> Result<(), Error> { pub async fn delete_node(&self, id: uuid::Uuid) -> Result<(), Error> {
// Log when this method is run // Log when this method is run
trace!(target: TARGET, "Archiving node in the cluster"); trace!(target: TARGET, "Archiving node in the cluster");
@ -80,7 +80,7 @@ impl Datastore {
/// This function marks the node as archived, ready for garbage collection. /// This function marks the node as archived, ready for garbage collection.
/// Later on when garbage collection is running the live queries assigned /// Later on when garbage collection is running the live queries assigned
/// to this node will be removed, along with the node itself. /// to this node will be removed, along with the node itself.
#[instrument(err, level = "debug", target = "surrealdb::core::kvs::node", skip(self))] #[instrument(err, level = "trace", target = "surrealdb::core::kvs::node", skip(self))]
pub async fn expire_nodes(&self) -> Result<(), Error> { pub async fn expire_nodes(&self) -> Result<(), Error> {
// Log when this method is run // Log when this method is run
trace!(target: TARGET, "Archiving expired nodes in the cluster"); trace!(target: TARGET, "Archiving expired nodes in the cluster");
@ -115,7 +115,7 @@ impl Datastore {
/// This function clears up all nodes which have been marked as archived. /// This function clears up all nodes which have been marked as archived.
/// When a matching node is found, all node queries, and table queries are /// When a matching node is found, all node queries, and table queries are
/// garbage collected, before the node itself is completely deleted. /// garbage collected, before the node itself is completely deleted.
#[instrument(err, level = "debug", target = "surrealdb::core::kvs::node", skip(self))] #[instrument(err, level = "trace", target = "surrealdb::core::kvs::node", skip(self))]
pub async fn cleanup_nodes(&self) -> Result<(), Error> { pub async fn cleanup_nodes(&self) -> Result<(), Error> {
// Log when this method is run // Log when this method is run
trace!(target: TARGET, "Cleaning up archived nodes in the cluster"); trace!(target: TARGET, "Cleaning up archived nodes in the cluster");
@ -188,7 +188,7 @@ impl Datastore {
/// in the cluster, from all namespaces, databases, and tables. It uses /// in the cluster, from all namespaces, databases, and tables. It uses
/// a number of transactions in order to prevent failure of large or /// a number of transactions in order to prevent failure of large or
/// long-running transactions on distributed storage engines. /// long-running transactions on distributed storage engines.
#[instrument(err, level = "debug", target = "surrealdb::core::kvs::node", skip(self))] #[instrument(err, level = "trace", target = "surrealdb::core::kvs::node", skip(self))]
pub async fn garbage_collect(&self) -> Result<(), Error> { pub async fn garbage_collect(&self) -> Result<(), Error> {
// Log the node deletion // Log the node deletion
trace!(target: TARGET, "Garbage collecting all miscellaneous data"); trace!(target: TARGET, "Garbage collecting all miscellaneous data");
@ -269,7 +269,7 @@ impl Datastore {
/// are specified by uique live query UUIDs. This is necessary when a /// are specified by uique live query UUIDs. This is necessary when a
/// WebSocket disconnects, and any associated live queries need to be /// WebSocket disconnects, and any associated live queries need to be
/// cleaned up and removed. /// cleaned up and removed.
#[instrument(err, level = "debug", target = "surrealdb::core::kvs::node", skip(self))] #[instrument(err, level = "trace", target = "surrealdb::core::kvs::node", skip(self))]
pub async fn delete_queries(&self, ids: Vec<uuid::Uuid>) -> Result<(), Error> { pub async fn delete_queries(&self, ids: Vec<uuid::Uuid>) -> Result<(), Error> {
// Log the node deletion // Log the node deletion
trace!(target: TARGET, "Deleting live queries for a connection"); trace!(target: TARGET, "Deleting live queries for a connection");

View file

@ -3,6 +3,7 @@
mod cnf; mod cnf;
use crate::err::Error; use crate::err::Error;
use crate::key::debug::Sprintable;
use crate::kvs::Check; use crate::kvs::Check;
use crate::kvs::Key; use crate::kvs::Key;
use crate::kvs::Val; use crate::kvs::Val;
@ -176,6 +177,7 @@ impl super::api::Transaction for Transaction {
} }
/// Cancel a transaction /// Cancel a transaction
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self))]
async fn cancel(&mut self) -> Result<(), Error> { async fn cancel(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -193,6 +195,7 @@ impl super::api::Transaction for Transaction {
} }
/// Commit a transaction /// Commit a transaction
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self))]
async fn commit(&mut self) -> Result<(), Error> { async fn commit(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -214,9 +217,10 @@ impl super::api::Transaction for Transaction {
} }
/// Check if a key exists /// Check if a key exists
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn exists<K>(&mut self, key: K) -> Result<bool, Error> async fn exists<K>(&mut self, key: K) -> Result<bool, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -229,9 +233,10 @@ impl super::api::Transaction for Transaction {
} }
/// Fetch a key from the database /// Fetch a key from the database
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn get<K>(&mut self, key: K) -> Result<Option<Val>, Error> async fn get<K>(&mut self, key: K) -> Result<Option<Val>, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -244,9 +249,10 @@ impl super::api::Transaction for Transaction {
} }
/// Insert or update a key in the database /// Insert or update a key in the database
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn set<K, V>(&mut self, key: K, val: V) -> Result<(), Error> async fn set<K, V>(&mut self, key: K, val: V) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug, V: Into<Val> + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
@ -264,9 +270,10 @@ impl super::api::Transaction for Transaction {
} }
/// Insert a key if it doesn't exist in the database /// Insert a key if it doesn't exist in the database
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn put<K, V>(&mut self, key: K, val: V) -> Result<(), Error> async fn put<K, V>(&mut self, key: K, val: V) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug, V: Into<Val> + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
@ -292,9 +299,10 @@ impl super::api::Transaction for Transaction {
} }
/// Insert a key if the current value matches a condition /// Insert a key if the current value matches a condition
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn putc<K, V>(&mut self, key: K, val: V, chk: Option<V>) -> Result<(), Error> async fn putc<K, V>(&mut self, key: K, val: V, chk: Option<V>) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug, V: Into<Val> + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
@ -322,9 +330,10 @@ impl super::api::Transaction for Transaction {
} }
/// Delete a key /// Delete a key
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn del<K>(&mut self, key: K) -> Result<(), Error> async fn del<K>(&mut self, key: K) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -341,9 +350,10 @@ impl super::api::Transaction for Transaction {
} }
/// Delete a key if the current value matches a condition /// Delete a key if the current value matches a condition
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn delc<K, V>(&mut self, key: K, chk: Option<V>) -> Result<(), Error> async fn delc<K, V>(&mut self, key: K, chk: Option<V>) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug, V: Into<Val> + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
@ -370,9 +380,10 @@ impl super::api::Transaction for Transaction {
} }
/// Retrieve a range of keys from the databases /// Retrieve a range of keys from the databases
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(rng = rng.sprint()))]
async fn keys<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<Key>, Error> async fn keys<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<Key>, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -420,9 +431,10 @@ impl super::api::Transaction for Transaction {
} }
/// Retrieve a range of keys from the databases /// Retrieve a range of keys from the databases
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(rng = rng.sprint()))]
async fn scan<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<(Key, Val)>, Error> async fn scan<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<(Key, Val)>, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {

View file

@ -1,6 +1,7 @@
#![cfg(feature = "kv-surrealkv")] #![cfg(feature = "kv-surrealkv")]
use crate::err::Error; use crate::err::Error;
use crate::key::debug::Sprintable;
use crate::kvs::Check; use crate::kvs::Check;
use crate::kvs::Key; use crate::kvs::Key;
use crate::kvs::Val; use crate::kvs::Val;
@ -107,6 +108,7 @@ impl super::api::Transaction for Transaction {
} }
/// Cancels the transaction. /// Cancels the transaction.
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self))]
async fn cancel(&mut self) -> Result<(), Error> { async fn cancel(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -121,6 +123,7 @@ impl super::api::Transaction for Transaction {
} }
/// Commits the transaction. /// Commits the transaction.
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self))]
async fn commit(&mut self) -> Result<(), Error> { async fn commit(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -139,9 +142,10 @@ impl super::api::Transaction for Transaction {
} }
/// Checks if a key exists in the database. /// Checks if a key exists in the database.
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn exists<K>(&mut self, key: K) -> Result<bool, Error> async fn exists<K>(&mut self, key: K) -> Result<bool, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -154,9 +158,10 @@ impl super::api::Transaction for Transaction {
} }
/// Fetch a key from the database /// Fetch a key from the database
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn get<K>(&mut self, key: K) -> Result<Option<Val>, Error> async fn get<K>(&mut self, key: K) -> Result<Option<Val>, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -169,9 +174,10 @@ impl super::api::Transaction for Transaction {
} }
/// Insert or update a key in the database /// Insert or update a key in the database
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn set<K, V>(&mut self, key: K, val: V) -> Result<(), Error> async fn set<K, V>(&mut self, key: K, val: V) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug, V: Into<Val> + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
@ -189,9 +195,10 @@ impl super::api::Transaction for Transaction {
} }
/// Insert a key if it doesn't exist in the database /// Insert a key if it doesn't exist in the database
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn put<K, V>(&mut self, key: K, val: V) -> Result<(), Error> async fn put<K, V>(&mut self, key: K, val: V) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug, V: Into<Val> + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
@ -215,9 +222,10 @@ impl super::api::Transaction for Transaction {
} }
/// Insert a key if the current value matches a condition /// Insert a key if the current value matches a condition
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn putc<K, V>(&mut self, key: K, val: V, chk: Option<V>) -> Result<(), Error> async fn putc<K, V>(&mut self, key: K, val: V, chk: Option<V>) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug, V: Into<Val> + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
@ -243,9 +251,10 @@ impl super::api::Transaction for Transaction {
} }
/// Deletes a key from the database. /// Deletes a key from the database.
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn del<K>(&mut self, key: K) -> Result<(), Error> async fn del<K>(&mut self, key: K) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -262,9 +271,10 @@ impl super::api::Transaction for Transaction {
} }
/// Delete a key if the current value matches a condition /// Delete a key if the current value matches a condition
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn delc<K, V>(&mut self, key: K, chk: Option<V>) -> Result<(), Error> async fn delc<K, V>(&mut self, key: K, chk: Option<V>) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug, V: Into<Val> + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
@ -289,9 +299,10 @@ impl super::api::Transaction for Transaction {
} }
/// Retrieves a range of key-value pairs from the database. /// Retrieves a range of key-value pairs from the database.
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(rng = rng.sprint()))]
async fn keys<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<Key>, Error> async fn keys<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<Key>, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -309,9 +320,10 @@ impl super::api::Transaction for Transaction {
} }
/// Retrieves a range of key-value pairs from the database. /// Retrieves a range of key-value pairs from the database.
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(rng = rng.sprint()))]
async fn scan<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<(Key, Val)>, Error> async fn scan<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<(Key, Val)>, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {

View file

@ -1,6 +1,7 @@
#![cfg(feature = "kv-tikv")] #![cfg(feature = "kv-tikv")]
use crate::err::Error; use crate::err::Error;
use crate::key::debug::Sprintable;
use crate::kvs::Check; use crate::kvs::Check;
use crate::kvs::Key; use crate::kvs::Key;
use crate::kvs::Val; use crate::kvs::Val;
@ -125,6 +126,7 @@ impl super::api::Transaction for Transaction {
} }
/// Cancel a transaction /// Cancel a transaction
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self))]
async fn cancel(&mut self) -> Result<(), Error> { async fn cancel(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -141,6 +143,7 @@ impl super::api::Transaction for Transaction {
} }
/// Commit a transaction /// Commit a transaction
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self))]
async fn commit(&mut self) -> Result<(), Error> { async fn commit(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -164,9 +167,10 @@ impl super::api::Transaction for Transaction {
} }
/// Check if a key exists /// Check if a key exists
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn exists<K>(&mut self, key: K) -> Result<bool, Error> async fn exists<K>(&mut self, key: K) -> Result<bool, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -179,9 +183,10 @@ impl super::api::Transaction for Transaction {
} }
/// Fetch a key from the database /// Fetch a key from the database
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn get<K>(&mut self, key: K) -> Result<Option<Val>, Error> async fn get<K>(&mut self, key: K) -> Result<Option<Val>, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -194,9 +199,10 @@ impl super::api::Transaction for Transaction {
} }
/// Insert or update a key in the database /// Insert or update a key in the database
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn set<K, V>(&mut self, key: K, val: V) -> Result<(), Error> async fn set<K, V>(&mut self, key: K, val: V) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug, V: Into<Val> + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
@ -214,9 +220,10 @@ impl super::api::Transaction for Transaction {
} }
/// Insert a key if it doesn't exist in the database /// Insert a key if it doesn't exist in the database
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn put<K, V>(&mut self, key: K, val: V) -> Result<(), Error> async fn put<K, V>(&mut self, key: K, val: V) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug, V: Into<Val> + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
@ -241,9 +248,10 @@ impl super::api::Transaction for Transaction {
} }
/// Insert a key if the current value matches a condition /// Insert a key if the current value matches a condition
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn putc<K, V>(&mut self, key: K, val: V, chk: Option<V>) -> Result<(), Error> async fn putc<K, V>(&mut self, key: K, val: V, chk: Option<V>) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug, V: Into<Val> + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
@ -271,9 +279,10 @@ impl super::api::Transaction for Transaction {
} }
/// Delete a key /// Delete a key
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn del<K>(&mut self, key: K) -> Result<(), Error> async fn del<K>(&mut self, key: K) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -290,9 +299,10 @@ impl super::api::Transaction for Transaction {
} }
/// Delete a key if the current value matches a condition /// Delete a key if the current value matches a condition
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn delc<K, V>(&mut self, key: K, chk: Option<V>) -> Result<(), Error> async fn delc<K, V>(&mut self, key: K, chk: Option<V>) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug, V: Into<Val> + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
@ -318,9 +328,10 @@ impl super::api::Transaction for Transaction {
} }
/// Delete a range of keys from the databases /// Delete a range of keys from the databases
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(rng = rng.sprint()))]
async fn delr<K>(&mut self, rng: Range<K>) -> Result<(), Error> async fn delr<K>(&mut self, rng: Range<K>) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -337,9 +348,10 @@ impl super::api::Transaction for Transaction {
} }
/// Delete a range of keys from the database /// Delete a range of keys from the database
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(rng = rng.sprint()))]
async fn keys<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<Key>, Error> async fn keys<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<Key>, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -357,9 +369,10 @@ impl super::api::Transaction for Transaction {
} }
/// Retrieve a range of keys from the database /// Retrieve a range of keys from the database
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(rng = rng.sprint()))]
async fn scan<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<(Key, Val)>, Error> async fn scan<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<(Key, Val)>, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {
@ -377,9 +390,10 @@ impl super::api::Transaction for Transaction {
} }
/// Obtain a new change timestamp for a key /// Obtain a new change timestamp for a key
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(key = key.sprint()))]
async fn get_timestamp<K>(&mut self, key: K) -> Result<Versionstamp, Error> async fn get_timestamp<K>(&mut self, key: K) -> Result<Versionstamp, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Sprintable + Debug,
{ {
// Check to see if transaction is closed // Check to see if transaction is closed
if self.done { if self.done {

View file

@ -5,8 +5,7 @@ use crate::cf;
use crate::dbs::node::Timestamp; use crate::dbs::node::Timestamp;
use crate::err::Error; use crate::err::Error;
use crate::idg::u32::U32; use crate::idg::u32::U32;
#[cfg(debug_assertions)] use crate::key::debug::Sprintable;
use crate::key::debug::sprint;
use crate::kvs::batch::Batch; use crate::kvs::batch::Batch;
use crate::kvs::clock::SizedClock; use crate::kvs::clock::SizedClock;
use crate::kvs::stash::Stash; use crate::kvs::stash::Stash;
@ -21,11 +20,8 @@ use std::fmt::Debug;
use std::ops::Range; use std::ops::Range;
use std::sync::Arc; use std::sync::Arc;
#[cfg(debug_assertions)]
const TARGET: &str = "surrealdb::core::kvs::tr";
/// Used to determine the behaviour when a transaction is not closed correctly /// Used to determine the behaviour when a transaction is not closed correctly
#[derive(Default)] #[derive(Debug, Default)]
pub enum Check { pub enum Check {
#[default] #[default]
None, None,
@ -147,9 +143,8 @@ impl Transactor {
/// transactions, whilst in development we should panic /// transactions, whilst in development we should panic
/// so that any unintended behaviour is detected, and in /// so that any unintended behaviour is detected, and in
/// production we should only log a warning. /// production we should only log a warning.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tr", skip_all)]
pub(crate) fn check_level(&mut self, check: Check) { pub(crate) fn check_level(&mut self, check: Check) {
#[cfg(debug_assertions)]
trace!(target: TARGET, "check_level");
expand_inner!(&mut self.inner, v => { v.check_level(check) }) expand_inner!(&mut self.inner, v => { v.check_level(check) })
} }
@ -159,207 +154,191 @@ impl Transactor {
/// then this function will return [`true`], and any further /// then this function will return [`true`], and any further
/// calls to functions on this transaction will result /// calls to functions on this transaction will result
/// in a [`Error::TxFinished`] error. /// in a [`Error::TxFinished`] error.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tr", skip_all)]
pub async fn closed(&self) -> bool { pub async fn closed(&self) -> bool {
#[cfg(debug_assertions)]
trace!(target: TARGET, "closed");
expand_inner!(&self.inner, v => { v.closed() }) expand_inner!(&self.inner, v => { v.closed() })
} }
/// Cancel a transaction. /// Cancel a transaction.
/// ///
/// This reverses all changes made within the transaction. /// This reverses all changes made within the transaction.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tr", skip_all)]
pub async fn cancel(&mut self) -> Result<(), Error> { pub async fn cancel(&mut self) -> Result<(), Error> {
#[cfg(debug_assertions)]
trace!(target: TARGET, "cancel");
expand_inner!(&mut self.inner, v => { v.cancel().await }) expand_inner!(&mut self.inner, v => { v.cancel().await })
} }
/// Commit a transaction. /// Commit a transaction.
/// ///
/// This attempts to commit all changes made within the transaction. /// This attempts to commit all changes made within the transaction.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tr", skip_all)]
pub async fn commit(&mut self) -> Result<(), Error> { pub async fn commit(&mut self) -> Result<(), Error> {
#[cfg(debug_assertions)]
trace!(target: TARGET, "commit");
expand_inner!(&mut self.inner, v => { v.commit().await }) expand_inner!(&mut self.inner, v => { v.commit().await })
} }
/// Check if a key exists in the datastore. /// Check if a key exists in the datastore.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tr", skip_all)]
pub async fn exists<K>(&mut self, key: K) -> Result<bool, Error> pub async fn exists<K>(&mut self, key: K) -> Result<bool, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Debug,
{ {
let key = key.into(); let key = key.into();
#[cfg(debug_assertions)]
trace!(target: TARGET, "exists {}", sprint(&key));
expand_inner!(&mut self.inner, v => { v.exists(key).await }) expand_inner!(&mut self.inner, v => { v.exists(key).await })
} }
/// Fetch a key from the datastore. /// Fetch a key from the datastore.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tr", skip_all)]
pub async fn get<K>(&mut self, key: K) -> Result<Option<Val>, Error> pub async fn get<K>(&mut self, key: K) -> Result<Option<Val>, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Debug,
{ {
let key = key.into(); let key = key.into();
#[cfg(debug_assertions)]
trace!(target: TARGET, "get {}", sprint(&key));
expand_inner!(&mut self.inner, v => { v.get(key).await }) expand_inner!(&mut self.inner, v => { v.get(key).await })
} }
/// Fetch many keys from the datastore. /// Fetch many keys from the datastore.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tr", skip_all)]
pub async fn getm<K>(&mut self, keys: Vec<K>) -> Result<Vec<Val>, Error> pub async fn getm<K>(&mut self, keys: Vec<K>) -> Result<Vec<Val>, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Debug,
{ {
let keys = keys.into_iter().map(Into::into).collect::<Vec<Key>>(); let keys = keys.into_iter().map(Into::into).collect::<Vec<Key>>();
#[cfg(debug_assertions)]
trace!(target: TARGET, "getm {}", keys.iter().map(sprint).collect::<Vec<_>>().join(" + "));
expand_inner!(&mut self.inner, v => { v.getm(keys).await }) expand_inner!(&mut self.inner, v => { v.getm(keys).await })
} }
/// Retrieve a specific range of keys from the datastore. /// Retrieve a specific range of keys from the datastore.
/// ///
/// This function fetches all matching key-value pairs from the underlying datastore in grouped batches. /// This function fetches all matching key-value pairs from the underlying datastore in grouped batches.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tr", skip_all)]
pub async fn getr<K>(&mut self, rng: Range<K>) -> Result<Vec<(Key, Val)>, Error> pub async fn getr<K>(&mut self, rng: Range<K>) -> Result<Vec<(Key, Val)>, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Debug,
{ {
let beg: Key = rng.start.into(); let beg: Key = rng.start.into();
let end: Key = rng.end.into(); let end: Key = rng.end.into();
#[cfg(debug_assertions)]
trace!(target: TARGET, "getr {}..{}", sprint(&beg), sprint(&end));
expand_inner!(&mut self.inner, v => { v.getr(beg..end).await }) expand_inner!(&mut self.inner, v => { v.getr(beg..end).await })
} }
/// Retrieve a specific prefixed range of keys from the datastore. /// Retrieve a specific prefixed range of keys from the datastore.
/// ///
/// This function fetches all matching key-value pairs from the underlying datastore in grouped batches. /// This function fetches all matching key-value pairs from the underlying datastore in grouped batches.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tr", skip_all)]
pub async fn getp<K>(&mut self, key: K) -> Result<Vec<(Key, Val)>, Error> pub async fn getp<K>(&mut self, key: K) -> Result<Vec<(Key, Val)>, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Debug,
{ {
let key: Key = key.into(); let key: Key = key.into();
#[cfg(debug_assertions)]
trace!(target: TARGET, "getp {}", sprint(&key));
expand_inner!(&mut self.inner, v => { v.getp(key).await }) expand_inner!(&mut self.inner, v => { v.getp(key).await })
} }
/// Insert or update a key in the datastore. /// Insert or update a key in the datastore.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tr", skip_all)]
pub async fn set<K, V>(&mut self, key: K, val: V) -> Result<(), Error> pub async fn set<K, V>(&mut self, key: K, val: V) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Debug,
V: Into<Val> + Debug, V: Into<Val> + Debug,
{ {
let key = key.into(); let key = key.into();
#[cfg(debug_assertions)]
trace!(target: TARGET, "set {} => {:?}", sprint(&key), val);
expand_inner!(&mut self.inner, v => { v.set(key, val).await }) expand_inner!(&mut self.inner, v => { v.set(key, val).await })
} }
/// Insert a key if it doesn't exist in the datastore. /// Insert a key if it doesn't exist in the datastore.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tr", skip_all)]
pub async fn put<K, V>(&mut self, key: K, val: V) -> Result<(), Error> pub async fn put<K, V>(&mut self, key: K, val: V) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Debug,
V: Into<Val> + Debug, V: Into<Val> + Debug,
{ {
let key = key.into(); let key = key.into();
#[cfg(debug_assertions)]
trace!(target: TARGET, "put {} => {:?}", sprint(&key), val);
expand_inner!(&mut self.inner, v => { v.put(key, val).await }) expand_inner!(&mut self.inner, v => { v.put(key, val).await })
} }
/// Update a key in the datastore if the current value matches a condition. /// Update a key in the datastore if the current value matches a condition.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tr", skip_all)]
pub async fn putc<K, V>(&mut self, key: K, val: V, chk: Option<V>) -> Result<(), Error> pub async fn putc<K, V>(&mut self, key: K, val: V, chk: Option<V>) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Debug,
V: Into<Val> + Debug, V: Into<Val> + Debug,
{ {
let key = key.into(); let key = key.into();
#[cfg(debug_assertions)]
trace!(target: TARGET, "putc {} if {:?} => {:?}", sprint(&key), chk, val);
expand_inner!(&mut self.inner, v => { v.putc(key, val, chk).await }) expand_inner!(&mut self.inner, v => { v.putc(key, val, chk).await })
} }
/// Delete a key from the datastore. /// Delete a key from the datastore.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tr", skip_all)]
pub async fn del<K>(&mut self, key: K) -> Result<(), Error> pub async fn del<K>(&mut self, key: K) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Debug,
{ {
let key = key.into(); let key = key.into();
#[cfg(debug_assertions)]
trace!(target: TARGET, "del {}", sprint(&key));
expand_inner!(&mut self.inner, v => { v.del(key).await }) expand_inner!(&mut self.inner, v => { v.del(key).await })
} }
/// Delete a key from the datastore if the current value matches a condition. /// Delete a key from the datastore if the current value matches a condition.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tr", skip_all)]
pub async fn delc<K, V>(&mut self, key: K, chk: Option<V>) -> Result<(), Error> pub async fn delc<K, V>(&mut self, key: K, chk: Option<V>) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Debug,
V: Into<Val> + Debug, V: Into<Val> + Debug,
{ {
let key = key.into(); let key = key.into();
#[cfg(debug_assertions)]
trace!(target: TARGET, "delc {} if {:?}", sprint(&key), chk);
expand_inner!(&mut self.inner, v => { v.delc(key, chk).await }) expand_inner!(&mut self.inner, v => { v.delc(key, chk).await })
} }
/// Delete a range of keys from the datastore. /// Delete a range of keys from the datastore.
/// ///
/// This function deletes all matching key-value pairs from the underlying datastore in grouped batches. /// This function deletes all matching key-value pairs from the underlying datastore in grouped batches.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tr", skip_all)]
pub async fn delr<K>(&mut self, rng: Range<K>) -> Result<(), Error> pub async fn delr<K>(&mut self, rng: Range<K>) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Debug,
{ {
let beg: Key = rng.start.into(); let beg: Key = rng.start.into();
let end: Key = rng.end.into(); let end: Key = rng.end.into();
#[cfg(debug_assertions)]
trace!(target: TARGET, "delr {}..{}", sprint(&beg), sprint(&end));
expand_inner!(&mut self.inner, v => { v.delr(beg..end).await }) expand_inner!(&mut self.inner, v => { v.delr(beg..end).await })
} }
/// Delete a prefixed range of keys from the datastore. /// Delete a prefixed range of keys from the datastore.
/// ///
/// This function deletes all matching key-value pairs from the underlying datastore in grouped batches. /// This function deletes all matching key-value pairs from the underlying datastore in grouped batches.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tr", skip_all)]
pub async fn delp<K>(&mut self, key: K) -> Result<(), Error> pub async fn delp<K>(&mut self, key: K) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Debug,
{ {
let key: Key = key.into(); let key: Key = key.into();
#[cfg(debug_assertions)]
trace!(target: TARGET, "delp {}", sprint(&key));
expand_inner!(&mut self.inner, v => { v.delp(key).await }) expand_inner!(&mut self.inner, v => { v.delp(key).await })
} }
/// Retrieve a specific range of keys from the datastore. /// Retrieve a specific range of keys from the datastore.
/// ///
/// This function fetches the full range of keys without values, in a single request to the underlying datastore. /// This function fetches the full range of keys without values, in a single request to the underlying datastore.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tr", skip_all)]
pub async fn keys<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<Key>, Error> pub async fn keys<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<Key>, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Debug,
{ {
let beg: Key = rng.start.into(); let beg: Key = rng.start.into();
let end: Key = rng.end.into(); let end: Key = rng.end.into();
#[cfg(debug_assertions)]
trace!(target: TARGET, "keys {}..{} (limit: {limit})", sprint(&beg), sprint(&end));
expand_inner!(&mut self.inner, v => { v.keys(beg..end, limit).await }) expand_inner!(&mut self.inner, v => { v.keys(beg..end, limit).await })
} }
/// Retrieve a specific range of keys from the datastore. /// Retrieve a specific range of keys from the datastore.
/// ///
/// This function fetches the full range of key-value pairs, in a single request to the underlying datastore. /// This function fetches the full range of key-value pairs, in a single request to the underlying datastore.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tr", skip_all)]
pub async fn scan<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<(Key, Val)>, Error> pub async fn scan<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<(Key, Val)>, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Debug,
{ {
let beg: Key = rng.start.into(); let beg: Key = rng.start.into();
let end: Key = rng.end.into(); let end: Key = rng.end.into();
#[cfg(debug_assertions)]
trace!(target: TARGET, "scan {}..{} (limit: {limit})", sprint(&beg), sprint(&end));
expand_inner!(&mut self.inner, v => { v.scan(beg..end, limit).await }) expand_inner!(&mut self.inner, v => { v.scan(beg..end, limit).await })
} }
/// Retrieve a batched scan over a specific range of keys in the datastore. /// Retrieve a batched scan over a specific range of keys in the datastore.
/// ///
/// This function fetches keys or key-value pairs, in batches, with multiple requests to the underlying datastore. /// This function fetches keys or key-value pairs, in batches, with multiple requests to the underlying datastore.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tr", skip_all)]
pub async fn batch<K>( pub async fn batch<K>(
&mut self, &mut self,
rng: Range<K>, rng: Range<K>,
@ -371,8 +350,6 @@ impl Transactor {
{ {
let beg: Key = rng.start.into(); let beg: Key = rng.start.into();
let end: Key = rng.end.into(); let end: Key = rng.end.into();
#[cfg(debug_assertions)]
trace!(target: TARGET, "batch {}..{} (batch: {batch})", sprint(&beg), sprint(&end));
expand_inner!(&mut self.inner, v => { v.batch(beg..end, batch, values).await }) expand_inner!(&mut self.inner, v => { v.batch(beg..end, batch, values).await })
} }
@ -381,20 +358,15 @@ impl Transactor {
/// NOTE: This should be called when composing the change feed entries for this transaction, /// NOTE: This should be called when composing the change feed entries for this transaction,
/// which should be done immediately before the transaction commit. /// which should be done immediately before the transaction commit.
/// That is to keep other transactions commit delay(pessimistic) or conflict(optimistic) as less as possible. /// That is to keep other transactions commit delay(pessimistic) or conflict(optimistic) as less as possible.
#[allow(unused)]
pub async fn get_timestamp<K>(&mut self, key: K) -> Result<Versionstamp, Error> pub async fn get_timestamp<K>(&mut self, key: K) -> Result<Versionstamp, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Debug,
{ {
// We convert to byte slice as its easier at this level
let key = key.into(); let key = key.into();
#[cfg(debug_assertions)]
trace!(target: TARGET, "get_timestamp {}", sprint(&key));
expand_inner!(&mut self.inner, v => { v.get_timestamp(key).await }) expand_inner!(&mut self.inner, v => { v.get_timestamp(key).await })
} }
/// Insert or update a key in the datastore. /// Insert or update a key in the datastore.
#[allow(unused_variables)]
pub async fn set_versionstamped<K, V>( pub async fn set_versionstamped<K, V>(
&mut self, &mut self,
ts_key: K, ts_key: K,
@ -409,14 +381,6 @@ impl Transactor {
let ts_key = ts_key.into(); let ts_key = ts_key.into();
let prefix = prefix.into(); let prefix = prefix.into();
let suffix = suffix.into(); let suffix = suffix.into();
#[cfg(debug_assertions)]
trace!(
target: TARGET,
"set_versionstamp ts={} prefix={} suffix={}",
sprint(&ts_key),
sprint(&prefix),
sprint(&suffix)
);
expand_inner!(&mut self.inner, v => { v.set_versionstamp(ts_key, prefix, suffix, val).await }) expand_inner!(&mut self.inner, v => { v.set_versionstamp(ts_key, prefix, suffix, val).await })
} }
@ -605,7 +569,7 @@ impl Transactor {
ts, ts,
ns, ns,
db, db,
sprint(k) k.sprint()
); );
let k = crate::key::database::ts::Ts::decode(k)?; let k = crate::key::database::ts::Ts::decode(k)?;
let latest_ts = k.ts; let latest_ts = k.ts;

View file

@ -36,9 +36,6 @@ use std::ops::Range;
use std::sync::Arc; use std::sync::Arc;
use uuid::Uuid; use uuid::Uuid;
#[cfg(debug_assertions)]
const TARGET: &str = "surrealdb::core::kvs::tx";
#[non_exhaustive] #[non_exhaustive]
pub struct Transaction { pub struct Transaction {
/// The underlying transactor /// The underlying transactor
@ -52,7 +49,11 @@ impl Transaction {
pub fn new(tx: Transactor) -> Transaction { pub fn new(tx: Transactor) -> Transaction {
Transaction { Transaction {
tx: Mutex::new(tx), tx: Mutex::new(tx),
cache: Cache::with_weighter(*TRANSACTION_CACHE_SIZE, 10_000, EntryWeighter), cache: Cache::with_weighter(
*TRANSACTION_CACHE_SIZE,
*TRANSACTION_CACHE_SIZE as u64,
EntryWeighter,
),
} }
} }
@ -84,6 +85,7 @@ impl Transaction {
/// Cancel a transaction. /// Cancel a transaction.
/// ///
/// This reverses all changes made within the transaction. /// This reverses all changes made within the transaction.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip_all)]
pub async fn cancel(&self) -> Result<(), Error> { pub async fn cancel(&self) -> Result<(), Error> {
self.lock().await.cancel().await self.lock().await.cancel().await
} }
@ -91,11 +93,13 @@ impl Transaction {
/// Commit a transaction. /// Commit a transaction.
/// ///
/// This attempts to commit all changes made within the transaction. /// This attempts to commit all changes made within the transaction.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip_all)]
pub async fn commit(&self) -> Result<(), Error> { pub async fn commit(&self) -> Result<(), Error> {
self.lock().await.commit().await self.lock().await.commit().await
} }
/// Check if a key exists in the datastore. /// Check if a key exists in the datastore.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip_all)]
pub async fn exists<K>(&self, key: K) -> Result<bool, Error> pub async fn exists<K>(&self, key: K) -> Result<bool, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Debug,
@ -104,6 +108,7 @@ impl Transaction {
} }
/// Fetch a key from the datastore. /// Fetch a key from the datastore.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip_all)]
pub async fn get<K>(&self, key: K) -> Result<Option<Val>, Error> pub async fn get<K>(&self, key: K) -> Result<Option<Val>, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Debug,
@ -112,6 +117,7 @@ impl Transaction {
} }
/// Retrieve a batch set of keys from the datastore. /// Retrieve a batch set of keys from the datastore.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip_all)]
pub async fn getm<K>(&self, keys: Vec<K>) -> Result<Vec<Val>, Error> pub async fn getm<K>(&self, keys: Vec<K>) -> Result<Vec<Val>, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Debug,
@ -122,6 +128,7 @@ impl Transaction {
/// Retrieve a specific prefix of keys from the datastore. /// Retrieve a specific prefix of keys from the datastore.
/// ///
/// This function fetches key-value pairs from the underlying datastore in grouped batches. /// This function fetches key-value pairs from the underlying datastore in grouped batches.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip_all)]
pub async fn getp<K>(&self, key: K) -> Result<Vec<(Key, Val)>, Error> pub async fn getp<K>(&self, key: K) -> Result<Vec<(Key, Val)>, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Debug,
@ -132,6 +139,7 @@ impl Transaction {
/// Retrieve a specific range of keys from the datastore. /// Retrieve a specific range of keys from the datastore.
/// ///
/// This function fetches key-value pairs from the underlying datastore in grouped batches. /// This function fetches key-value pairs from the underlying datastore in grouped batches.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip_all)]
pub async fn getr<K>(&self, rng: Range<K>) -> Result<Vec<(Key, Val)>, Error> pub async fn getr<K>(&self, rng: Range<K>) -> Result<Vec<(Key, Val)>, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Debug,
@ -140,6 +148,7 @@ impl Transaction {
} }
/// Delete a key from the datastore. /// Delete a key from the datastore.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip_all)]
pub async fn del<K>(&self, key: K) -> Result<(), Error> pub async fn del<K>(&self, key: K) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Debug,
@ -148,6 +157,7 @@ impl Transaction {
} }
/// Delete a key from the datastore if the current value matches a condition. /// Delete a key from the datastore if the current value matches a condition.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip_all)]
pub async fn delc<K, V>(&self, key: K, chk: Option<V>) -> Result<(), Error> pub async fn delc<K, V>(&self, key: K, chk: Option<V>) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Debug,
@ -159,6 +169,7 @@ impl Transaction {
/// Delete a range of keys from the datastore. /// Delete a range of keys from the datastore.
/// ///
/// This function deletes entries from the underlying datastore in grouped batches. /// This function deletes entries from the underlying datastore in grouped batches.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip_all)]
pub async fn delr<K>(&self, rng: Range<K>) -> Result<(), Error> pub async fn delr<K>(&self, rng: Range<K>) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Debug,
@ -169,6 +180,7 @@ impl Transaction {
/// Delete a prefix of keys from the datastore. /// Delete a prefix of keys from the datastore.
/// ///
/// This function deletes entries from the underlying datastore in grouped batches. /// This function deletes entries from the underlying datastore in grouped batches.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip_all)]
pub async fn delp<K>(&self, key: K) -> Result<(), Error> pub async fn delp<K>(&self, key: K) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Debug,
@ -177,6 +189,7 @@ impl Transaction {
} }
/// Insert or update a key in the datastore. /// Insert or update a key in the datastore.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip_all)]
pub async fn set<K, V>(&self, key: K, val: V) -> Result<(), Error> pub async fn set<K, V>(&self, key: K, val: V) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Debug,
@ -186,6 +199,7 @@ impl Transaction {
} }
/// Insert a key if it doesn't exist in the datastore. /// Insert a key if it doesn't exist in the datastore.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip_all)]
pub async fn put<K, V>(&self, key: K, val: V) -> Result<(), Error> pub async fn put<K, V>(&self, key: K, val: V) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Debug,
@ -195,6 +209,7 @@ impl Transaction {
} }
/// Update a key in the datastore if the current value matches a condition. /// Update a key in the datastore if the current value matches a condition.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip_all)]
pub async fn putc<K, V>(&self, key: K, val: V, chk: Option<V>) -> Result<(), Error> pub async fn putc<K, V>(&self, key: K, val: V, chk: Option<V>) -> Result<(), Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Debug,
@ -206,6 +221,7 @@ impl Transaction {
/// Retrieve a specific range of keys from the datastore. /// Retrieve a specific range of keys from the datastore.
/// ///
/// This function fetches the full range of keys, in a single request to the underlying datastore. /// This function fetches the full range of keys, in a single request to the underlying datastore.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip_all)]
pub async fn keys<K>(&self, rng: Range<K>, limit: u32) -> Result<Vec<Key>, Error> pub async fn keys<K>(&self, rng: Range<K>, limit: u32) -> Result<Vec<Key>, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Debug,
@ -216,6 +232,7 @@ impl Transaction {
/// Retrieve a specific range of keys from the datastore. /// Retrieve a specific range of keys from the datastore.
/// ///
/// This function fetches the full range of key-value pairs, in a single request to the underlying datastore. /// This function fetches the full range of key-value pairs, in a single request to the underlying datastore.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip_all)]
pub async fn scan<K>(&self, rng: Range<K>, limit: u32) -> Result<Vec<(Key, Val)>, Error> pub async fn scan<K>(&self, rng: Range<K>, limit: u32) -> Result<Vec<(Key, Val)>, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Debug,
@ -226,6 +243,7 @@ impl Transaction {
/// Retrieve a batched scan over a specific range of keys in the datastore. /// Retrieve a batched scan over a specific range of keys in the datastore.
/// ///
/// This function fetches the key-value pairs in batches, with multiple requests to the underlying datastore. /// This function fetches the key-value pairs in batches, with multiple requests to the underlying datastore.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip_all)]
pub async fn batch<K>(&self, rng: Range<K>, batch: u32, values: bool) -> Result<Batch, Error> pub async fn batch<K>(&self, rng: Range<K>, batch: u32, values: bool) -> Result<Batch, Error>
where where
K: Into<Key> + Debug, K: Into<Key> + Debug,
@ -236,6 +254,7 @@ impl Transaction {
/// Retrieve a stream over a specific range of keys in the datastore. /// Retrieve a stream over a specific range of keys in the datastore.
/// ///
/// This function fetches the key-value pairs in batches, with multiple requests to the underlying datastore. /// This function fetches the key-value pairs in batches, with multiple requests to the underlying datastore.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip_all)]
pub fn stream<K>(&self, rng: Range<K>) -> impl Stream<Item = Result<(Key, Val), Error>> + '_ pub fn stream<K>(&self, rng: Range<K>) -> impl Stream<Item = Result<(Key, Val), Error>> + '_
where where
K: Into<Key> + Debug, K: Into<Key> + Debug,
@ -276,11 +295,9 @@ impl Transaction {
// Cache methods // Cache methods
// -------------------------------------------------- // --------------------------------------------------
/// Retrieve all nodes belonging to this cluster.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn all_nodes(&self) -> Result<Arc<[Node]>, Error> { pub async fn all_nodes(&self) -> Result<Arc<[Node]>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "all_nodes");
// Continue with the function logic
let key = crate::key::root::nd::prefix(); let key = crate::key::root::nd::prefix();
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -298,11 +315,8 @@ impl Transaction {
} }
/// Retrieve all ROOT level users in a datastore. /// Retrieve all ROOT level users in a datastore.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn all_root_users(&self) -> Result<Arc<[DefineUserStatement]>, Error> { pub async fn all_root_users(&self) -> Result<Arc<[DefineUserStatement]>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "all_root_users");
// Continue with the function logic
let key = crate::key::root::us::prefix(); let key = crate::key::root::us::prefix();
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -321,10 +335,6 @@ impl Transaction {
/// Retrieve all ROOT level accesses in a datastore. /// Retrieve all ROOT level accesses in a datastore.
pub async fn all_root_accesses(&self) -> Result<Arc<[DefineAccessStatement]>, Error> { pub async fn all_root_accesses(&self) -> Result<Arc<[DefineAccessStatement]>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "all_root_accesses");
// Continue with the function logic
let key = crate::key::root::ac::prefix(); let key = crate::key::root::ac::prefix();
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -342,11 +352,8 @@ impl Transaction {
} }
/// Retrieve all namespace definitions in a datastore. /// Retrieve all namespace definitions in a datastore.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn all_ns(&self) -> Result<Arc<[DefineNamespaceStatement]>, Error> { pub async fn all_ns(&self) -> Result<Arc<[DefineNamespaceStatement]>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "all_ns");
// Continue with the function logic
let key = crate::key::root::ns::prefix(); let key = crate::key::root::ns::prefix();
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -364,11 +371,8 @@ impl Transaction {
} }
/// Retrieve all namespace user definitions for a specific namespace. /// Retrieve all namespace user definitions for a specific namespace.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn all_ns_users(&self, ns: &str) -> Result<Arc<[DefineUserStatement]>, Error> { pub async fn all_ns_users(&self, ns: &str) -> Result<Arc<[DefineUserStatement]>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "all_ns_users {ns}");
// Continue with the function logic
let key = crate::key::namespace::us::prefix(ns); let key = crate::key::namespace::us::prefix(ns);
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -386,11 +390,8 @@ impl Transaction {
} }
/// Retrieve all namespace access definitions for a specific namespace. /// Retrieve all namespace access definitions for a specific namespace.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn all_ns_accesses(&self, ns: &str) -> Result<Arc<[DefineAccessStatement]>, Error> { pub async fn all_ns_accesses(&self, ns: &str) -> Result<Arc<[DefineAccessStatement]>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "all_ns_accesses {ns}");
// Continue with the function logic
let key = crate::key::namespace::ac::prefix(ns); let key = crate::key::namespace::ac::prefix(ns);
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -408,11 +409,8 @@ impl Transaction {
} }
/// Retrieve all database definitions for a specific namespace. /// Retrieve all database definitions for a specific namespace.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn all_db(&self, ns: &str) -> Result<Arc<[DefineDatabaseStatement]>, Error> { pub async fn all_db(&self, ns: &str) -> Result<Arc<[DefineDatabaseStatement]>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "all_db {ns}");
// Continue with the function logic
let key = crate::key::namespace::db::prefix(ns); let key = crate::key::namespace::db::prefix(ns);
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -430,15 +428,12 @@ impl Transaction {
} }
/// Retrieve all database user definitions for a specific database. /// Retrieve all database user definitions for a specific database.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn all_db_users( pub async fn all_db_users(
&self, &self,
ns: &str, ns: &str,
db: &str, db: &str,
) -> Result<Arc<[DefineUserStatement]>, Error> { ) -> Result<Arc<[DefineUserStatement]>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "all_db_users {ns} {db}");
// Continue with the function logic
let key = crate::key::database::us::prefix(ns, db); let key = crate::key::database::us::prefix(ns, db);
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -456,15 +451,12 @@ impl Transaction {
} }
/// Retrieve all database access definitions for a specific database. /// Retrieve all database access definitions for a specific database.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn all_db_accesses( pub async fn all_db_accesses(
&self, &self,
ns: &str, ns: &str,
db: &str, db: &str,
) -> Result<Arc<[DefineAccessStatement]>, Error> { ) -> Result<Arc<[DefineAccessStatement]>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "all_db_accesses {ns} {db}");
// Continue with the function logic
let key = crate::key::database::ac::prefix(ns, db); let key = crate::key::database::ac::prefix(ns, db);
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -482,15 +474,12 @@ impl Transaction {
} }
/// Retrieve all analyzer definitions for a specific database. /// Retrieve all analyzer definitions for a specific database.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn all_db_analyzers( pub async fn all_db_analyzers(
&self, &self,
ns: &str, ns: &str,
db: &str, db: &str,
) -> Result<Arc<[DefineAnalyzerStatement]>, Error> { ) -> Result<Arc<[DefineAnalyzerStatement]>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "all_db_analyzers {ns} {db}");
// Continue with the function logic
let key = crate::key::database::az::prefix(ns, db); let key = crate::key::database::az::prefix(ns, db);
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -508,15 +497,12 @@ impl Transaction {
} }
/// Retrieve all function definitions for a specific database. /// Retrieve all function definitions for a specific database.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn all_db_functions( pub async fn all_db_functions(
&self, &self,
ns: &str, ns: &str,
db: &str, db: &str,
) -> Result<Arc<[DefineFunctionStatement]>, Error> { ) -> Result<Arc<[DefineFunctionStatement]>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "all_db_functions {ns} {db}");
// Continue with the function logic
let key = crate::key::database::fc::prefix(ns, db); let key = crate::key::database::fc::prefix(ns, db);
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -534,15 +520,12 @@ impl Transaction {
} }
/// Retrieve all param definitions for a specific database. /// Retrieve all param definitions for a specific database.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn all_db_params( pub async fn all_db_params(
&self, &self,
ns: &str, ns: &str,
db: &str, db: &str,
) -> Result<Arc<[DefineParamStatement]>, Error> { ) -> Result<Arc<[DefineParamStatement]>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "all_db_params {ns} {db}");
// Continue with the function logic
let key = crate::key::database::pa::prefix(ns, db); let key = crate::key::database::pa::prefix(ns, db);
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -560,15 +543,12 @@ impl Transaction {
} }
/// Retrieve all model definitions for a specific database. /// Retrieve all model definitions for a specific database.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn all_db_models( pub async fn all_db_models(
&self, &self,
ns: &str, ns: &str,
db: &str, db: &str,
) -> Result<Arc<[DefineModelStatement]>, Error> { ) -> Result<Arc<[DefineModelStatement]>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "all_db_models {ns} {db}");
// Continue with the function logic
let key = crate::key::database::ml::prefix(ns, db); let key = crate::key::database::ml::prefix(ns, db);
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -586,11 +566,8 @@ impl Transaction {
} }
/// Retrieve all table definitions for a specific database. /// Retrieve all table definitions for a specific database.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn all_tb(&self, ns: &str, db: &str) -> Result<Arc<[DefineTableStatement]>, Error> { pub async fn all_tb(&self, ns: &str, db: &str) -> Result<Arc<[DefineTableStatement]>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "all_tb {ns} {db}");
// Continue with the function logic
let key = crate::key::database::tb::prefix(ns, db); let key = crate::key::database::tb::prefix(ns, db);
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -608,16 +585,13 @@ impl Transaction {
} }
/// Retrieve all event definitions for a specific table. /// Retrieve all event definitions for a specific table.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn all_tb_events( pub async fn all_tb_events(
&self, &self,
ns: &str, ns: &str,
db: &str, db: &str,
tb: &str, tb: &str,
) -> Result<Arc<[DefineEventStatement]>, Error> { ) -> Result<Arc<[DefineEventStatement]>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "all_tb_events {ns} {db} {tb}");
// Continue with the function logic
let key = crate::key::table::ev::prefix(ns, db, tb); let key = crate::key::table::ev::prefix(ns, db, tb);
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -635,16 +609,13 @@ impl Transaction {
} }
/// Retrieve all field definitions for a specific table. /// Retrieve all field definitions for a specific table.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn all_tb_fields( pub async fn all_tb_fields(
&self, &self,
ns: &str, ns: &str,
db: &str, db: &str,
tb: &str, tb: &str,
) -> Result<Arc<[DefineFieldStatement]>, Error> { ) -> Result<Arc<[DefineFieldStatement]>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "all_tb_fields {ns} {db} {tb}");
// Continue with the function logic
let key = crate::key::table::fd::prefix(ns, db, tb); let key = crate::key::table::fd::prefix(ns, db, tb);
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -662,16 +633,13 @@ impl Transaction {
} }
/// Retrieve all index definitions for a specific table. /// Retrieve all index definitions for a specific table.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn all_tb_indexes( pub async fn all_tb_indexes(
&self, &self,
ns: &str, ns: &str,
db: &str, db: &str,
tb: &str, tb: &str,
) -> Result<Arc<[DefineIndexStatement]>, Error> { ) -> Result<Arc<[DefineIndexStatement]>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "all_tb_indexes {ns} {db} {tb}");
// Continue with the function logic
let key = crate::key::table::ix::prefix(ns, db, tb); let key = crate::key::table::ix::prefix(ns, db, tb);
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -689,16 +657,13 @@ impl Transaction {
} }
/// Retrieve all view definitions for a specific table. /// Retrieve all view definitions for a specific table.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn all_tb_views( pub async fn all_tb_views(
&self, &self,
ns: &str, ns: &str,
db: &str, db: &str,
tb: &str, tb: &str,
) -> Result<Arc<[DefineTableStatement]>, Error> { ) -> Result<Arc<[DefineTableStatement]>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "all_tb_views {ns} {db} {tb}");
// Continue with the function logic
let key = crate::key::table::ft::prefix(ns, db, tb); let key = crate::key::table::ft::prefix(ns, db, tb);
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -716,16 +681,13 @@ impl Transaction {
} }
/// Retrieve all live definitions for a specific table. /// Retrieve all live definitions for a specific table.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn all_tb_lives( pub async fn all_tb_lives(
&self, &self,
ns: &str, ns: &str,
db: &str, db: &str,
tb: &str, tb: &str,
) -> Result<Arc<[LiveStatement]>, Error> { ) -> Result<Arc<[LiveStatement]>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "all_tb_lives {ns} {db} {tb}");
// Continue with the function logic
let key = crate::key::table::lq::prefix(ns, db, tb); let key = crate::key::table::lq::prefix(ns, db, tb);
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -743,11 +705,8 @@ impl Transaction {
} }
/// Retrieve a specific namespace definition. /// Retrieve a specific namespace definition.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_node(&self, id: Uuid) -> Result<Arc<Node>, Error> { pub async fn get_node(&self, id: Uuid) -> Result<Arc<Node>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "get_node {id}");
// Continue with the function logic
let key = crate::key::root::nd::new(id).encode()?; let key = crate::key::root::nd::new(id).encode()?;
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -766,18 +725,15 @@ impl Transaction {
} }
/// Retrieve a specific namespace user definition. /// Retrieve a specific namespace user definition.
pub async fn get_root_user(&self, user: &str) -> Result<Arc<DefineUserStatement>, Error> { #[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
// Log this function call in development pub async fn get_root_user(&self, us: &str) -> Result<Arc<DefineUserStatement>, Error> {
#[cfg(debug_assertions)] let key = crate::key::root::us::new(us).encode()?;
trace!(target: TARGET, "get_root_user {user}");
// Continue with the function logic
let key = crate::key::root::us::new(user).encode()?;
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
Ok(val) => val, Ok(val) => val,
Err(cache) => { Err(cache) => {
let val = self.get(key).await?.ok_or(Error::UserRootNotFound { let val = self.get(key).await?.ok_or(Error::UserRootNotFound {
value: user.to_owned(), value: us.to_owned(),
})?; })?;
let val: DefineUserStatement = val.into(); let val: DefineUserStatement = val.into();
let val = Entry::Any(Arc::new(val)); let val = Entry::Any(Arc::new(val));
@ -790,10 +746,6 @@ impl Transaction {
/// Retrieve a specific namespace user definition. /// Retrieve a specific namespace user definition.
pub async fn get_root_access(&self, user: &str) -> Result<Arc<DefineAccessStatement>, Error> { pub async fn get_root_access(&self, user: &str) -> Result<Arc<DefineAccessStatement>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "get_root_access {user}");
// Continue with the function logic
let key = crate::key::root::ac::new(user).encode()?; let key = crate::key::root::ac::new(user).encode()?;
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -812,11 +764,8 @@ impl Transaction {
} }
/// Retrieve a specific namespace definition. /// Retrieve a specific namespace definition.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_ns(&self, ns: &str) -> Result<Arc<DefineNamespaceStatement>, Error> { pub async fn get_ns(&self, ns: &str) -> Result<Arc<DefineNamespaceStatement>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "get_ns {ns}");
// Continue with the function logic
let key = crate::key::root::ns::new(ns).encode()?; let key = crate::key::root::ns::new(ns).encode()?;
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -835,22 +784,15 @@ impl Transaction {
} }
/// Retrieve a specific namespace user definition. /// Retrieve a specific namespace user definition.
pub async fn get_ns_user( #[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
&self, pub async fn get_ns_user(&self, ns: &str, us: &str) -> Result<Arc<DefineUserStatement>, Error> {
ns: &str, let key = crate::key::namespace::us::new(ns, us).encode()?;
user: &str,
) -> Result<Arc<DefineUserStatement>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "get_ns_user {ns} {user}");
// Continue with the function logic
let key = crate::key::namespace::us::new(ns, user).encode()?;
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
Ok(val) => val, Ok(val) => val,
Err(cache) => { Err(cache) => {
let val = self.get(key).await?.ok_or(Error::UserNsNotFound { let val = self.get(key).await?.ok_or(Error::UserNsNotFound {
value: user.to_owned(), value: us.to_owned(),
ns: ns.to_owned(), ns: ns.to_owned(),
})?; })?;
let val: DefineUserStatement = val.into(); let val: DefineUserStatement = val.into();
@ -863,15 +805,12 @@ impl Transaction {
} }
/// Retrieve a specific namespace access definition. /// Retrieve a specific namespace access definition.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_ns_access( pub async fn get_ns_access(
&self, &self,
ns: &str, ns: &str,
na: &str, na: &str,
) -> Result<Arc<DefineAccessStatement>, Error> { ) -> Result<Arc<DefineAccessStatement>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "get_ns_access {ns} {na}");
// Continue with the function logic
let key = crate::key::namespace::ac::new(ns, na).encode()?; let key = crate::key::namespace::ac::new(ns, na).encode()?;
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -891,11 +830,8 @@ impl Transaction {
} }
/// Retrieve a specific database definition. /// Retrieve a specific database definition.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_db(&self, ns: &str, db: &str) -> Result<Arc<DefineDatabaseStatement>, Error> { pub async fn get_db(&self, ns: &str, db: &str) -> Result<Arc<DefineDatabaseStatement>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "get_db {ns} {db}");
// Continue with the function logic
let key = crate::key::namespace::db::new(ns, db).encode()?; let key = crate::key::namespace::db::new(ns, db).encode()?;
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -914,23 +850,20 @@ impl Transaction {
} }
/// Retrieve a specific user definition from a database. /// Retrieve a specific user definition from a database.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_db_user( pub async fn get_db_user(
&self, &self,
ns: &str, ns: &str,
db: &str, db: &str,
user: &str, us: &str,
) -> Result<Arc<DefineUserStatement>, Error> { ) -> Result<Arc<DefineUserStatement>, Error> {
// Log this function call in development let key = crate::key::database::us::new(ns, db, us).encode()?;
#[cfg(debug_assertions)]
trace!(target: TARGET, "get_db_user {ns} {db} {user}");
// Continue with the function logic
let key = crate::key::database::us::new(ns, db, user).encode()?;
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
Ok(val) => val, Ok(val) => val,
Err(cache) => { Err(cache) => {
let val = self.get(key).await?.ok_or(Error::UserDbNotFound { let val = self.get(key).await?.ok_or(Error::UserDbNotFound {
value: user.to_owned(), value: us.to_owned(),
ns: ns.to_owned(), ns: ns.to_owned(),
db: db.to_owned(), db: db.to_owned(),
})?; })?;
@ -944,16 +877,13 @@ impl Transaction {
} }
/// Retrieve a specific database access definition. /// Retrieve a specific database access definition.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_db_access( pub async fn get_db_access(
&self, &self,
ns: &str, ns: &str,
db: &str, db: &str,
da: &str, da: &str,
) -> Result<Arc<DefineAccessStatement>, Error> { ) -> Result<Arc<DefineAccessStatement>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "get_db_access {ns} {db} {da}");
// Continue with the function logic
let key = crate::key::database::ac::new(ns, db, da).encode()?; let key = crate::key::database::ac::new(ns, db, da).encode()?;
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -974,6 +904,7 @@ impl Transaction {
} }
/// Retrieve a specific model definition from a database. /// Retrieve a specific model definition from a database.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_db_model( pub async fn get_db_model(
&self, &self,
ns: &str, ns: &str,
@ -981,10 +912,6 @@ impl Transaction {
ml: &str, ml: &str,
vn: &str, vn: &str,
) -> Result<Arc<DefineModelStatement>, Error> { ) -> Result<Arc<DefineModelStatement>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "get_db_model {ns} {db} {ml} {vn}");
// Continue with the function logic
let key = crate::key::database::ml::new(ns, db, ml, vn).encode()?; let key = crate::key::database::ml::new(ns, db, ml, vn).encode()?;
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -1003,16 +930,13 @@ impl Transaction {
} }
/// Retrieve a specific analyzer definition. /// Retrieve a specific analyzer definition.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_db_analyzer( pub async fn get_db_analyzer(
&self, &self,
ns: &str, ns: &str,
db: &str, db: &str,
az: &str, az: &str,
) -> Result<Arc<DefineAnalyzerStatement>, Error> { ) -> Result<Arc<DefineAnalyzerStatement>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "get_db_analyzer {ns} {db} {az}");
// Continue with the function logic
let key = crate::key::database::az::new(ns, db, az).encode()?; let key = crate::key::database::az::new(ns, db, az).encode()?;
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -1031,16 +955,13 @@ impl Transaction {
} }
/// Retrieve a specific function definition from a database. /// Retrieve a specific function definition from a database.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_db_function( pub async fn get_db_function(
&self, &self,
ns: &str, ns: &str,
db: &str, db: &str,
fc: &str, fc: &str,
) -> Result<Arc<DefineFunctionStatement>, Error> { ) -> Result<Arc<DefineFunctionStatement>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "get_db_function {ns} {db} {fc}");
// Continue with the function logic
let key = crate::key::database::fc::new(ns, db, fc).encode()?; let key = crate::key::database::fc::new(ns, db, fc).encode()?;
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -1059,16 +980,13 @@ impl Transaction {
} }
/// Retrieve a specific function definition from a database. /// Retrieve a specific function definition from a database.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_db_param( pub async fn get_db_param(
&self, &self,
ns: &str, ns: &str,
db: &str, db: &str,
pa: &str, pa: &str,
) -> Result<Arc<DefineParamStatement>, Error> { ) -> Result<Arc<DefineParamStatement>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "get_db_param {ns} {db} {pa}");
// Continue with the function logic
let key = crate::key::database::pa::new(ns, db, pa).encode()?; let key = crate::key::database::pa::new(ns, db, pa).encode()?;
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -1087,16 +1005,13 @@ impl Transaction {
} }
/// Retrieve a specific table definition. /// Retrieve a specific table definition.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_tb( pub async fn get_tb(
&self, &self,
ns: &str, ns: &str,
db: &str, db: &str,
tb: &str, tb: &str,
) -> Result<Arc<DefineTableStatement>, Error> { ) -> Result<Arc<DefineTableStatement>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "get_tb {ns} {db} {tb}");
// Continue with the function logic
let key = crate::key::database::tb::new(ns, db, tb).encode()?; let key = crate::key::database::tb::new(ns, db, tb).encode()?;
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -1115,6 +1030,7 @@ impl Transaction {
} }
/// Retrieve an event for a table. /// Retrieve an event for a table.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_tb_event( pub async fn get_tb_event(
&self, &self,
ns: &str, ns: &str,
@ -1122,10 +1038,6 @@ impl Transaction {
tb: &str, tb: &str,
ev: &str, ev: &str,
) -> Result<Arc<DefineEventStatement>, Error> { ) -> Result<Arc<DefineEventStatement>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "get_tb_event {ns} {db} {tb} {ev}");
// Continue with the function logic
let key = crate::key::table::ev::new(ns, db, tb, ev).encode()?; let key = crate::key::table::ev::new(ns, db, tb, ev).encode()?;
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -1144,6 +1056,7 @@ impl Transaction {
} }
/// Retrieve a field for a table. /// Retrieve a field for a table.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_tb_field( pub async fn get_tb_field(
&self, &self,
ns: &str, ns: &str,
@ -1151,10 +1064,6 @@ impl Transaction {
tb: &str, tb: &str,
fd: &str, fd: &str,
) -> Result<Arc<DefineFieldStatement>, Error> { ) -> Result<Arc<DefineFieldStatement>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "get_tb_field {ns} {db} {tb} {fd}");
// Continue with the function logic
let key = crate::key::table::fd::new(ns, db, tb, fd).encode()?; let key = crate::key::table::fd::new(ns, db, tb, fd).encode()?;
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -1173,6 +1082,7 @@ impl Transaction {
} }
/// Retrieve an index for a table. /// Retrieve an index for a table.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_tb_index( pub async fn get_tb_index(
&self, &self,
ns: &str, ns: &str,
@ -1180,10 +1090,6 @@ impl Transaction {
tb: &str, tb: &str,
ix: &str, ix: &str,
) -> Result<Arc<DefineIndexStatement>, Error> { ) -> Result<Arc<DefineIndexStatement>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "get_tb_index {ns} {db} {tb} {ix}");
// Continue with the function logic
let key = crate::key::table::ix::new(ns, db, tb, ix).encode()?; let key = crate::key::table::ix::new(ns, db, tb, ix).encode()?;
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res { Ok(match res {
@ -1202,6 +1108,7 @@ impl Transaction {
} }
/// Fetch a specific record value. /// Fetch a specific record value.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_record( pub async fn get_record(
&self, &self,
ns: &str, ns: &str,
@ -1209,10 +1116,6 @@ impl Transaction {
tb: &str, tb: &str,
id: &Id, id: &Id,
) -> Result<Arc<Value>, Error> { ) -> Result<Arc<Value>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "get_record {ns} {db} {tb} {id}");
// Continue with the function logic
let key = crate::key::thing::new(ns, db, tb, id).encode()?; let key = crate::key::thing::new(ns, db, tb, id).encode()?;
let res = self.cache.get_value_or_guard_async(&key).await; let res = self.cache.get_value_or_guard_async(&key).await;
match res { match res {
@ -1232,6 +1135,7 @@ impl Transaction {
} }
} }
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn set_record( pub async fn set_record(
&self, &self,
ns: &str, ns: &str,
@ -1240,10 +1144,6 @@ impl Transaction {
id: &Id, id: &Id,
val: Value, val: Value,
) -> Result<(), Error> { ) -> Result<(), Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "set_record {ns} {db} {tb} {id} {val}");
// Continue with the function logic
let key = crate::key::thing::new(ns, db, tb, id); let key = crate::key::thing::new(ns, db, tb, id);
let enc = crate::key::thing::new(ns, db, tb, id).encode()?; let enc = crate::key::thing::new(ns, db, tb, id).encode()?;
// Set the value in the datastore // Set the value in the datastore
@ -1255,33 +1155,28 @@ impl Transaction {
} }
/// Get or add a namespace with a default configuration, only if we are in dynamic mode. /// Get or add a namespace with a default configuration, only if we are in dynamic mode.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_or_add_ns( pub async fn get_or_add_ns(
&self, &self,
ns: &str, ns: &str,
strict: bool, strict: bool,
) -> Result<Arc<DefineNamespaceStatement>, Error> { ) -> Result<Arc<DefineNamespaceStatement>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "get_or_add_ns {ns}");
// Continue with the function logic
self.get_or_add_ns_upwards(ns, strict, false).await self.get_or_add_ns_upwards(ns, strict, false).await
} }
/// Get or add a database with a default configuration, only if we are in dynamic mode. /// Get or add a database with a default configuration, only if we are in dynamic mode.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_or_add_db( pub async fn get_or_add_db(
&self, &self,
ns: &str, ns: &str,
db: &str, db: &str,
strict: bool, strict: bool,
) -> Result<Arc<DefineDatabaseStatement>, Error> { ) -> Result<Arc<DefineDatabaseStatement>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "get_or_add_db {ns} {db}");
// Continue with the function logic
self.get_or_add_db_upwards(ns, db, strict, false).await self.get_or_add_db_upwards(ns, db, strict, false).await
} }
/// Get or add a table with a default configuration, only if we are in dynamic mode. /// Get or add a table with a default configuration, only if we are in dynamic mode.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_or_add_tb( pub async fn get_or_add_tb(
&self, &self,
ns: &str, ns: &str,
@ -1289,14 +1184,11 @@ impl Transaction {
tb: &str, tb: &str,
strict: bool, strict: bool,
) -> Result<Arc<DefineTableStatement>, Error> { ) -> Result<Arc<DefineTableStatement>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "get_or_add_tb {ns} {db} {tb}");
// Continue with the function logic
self.get_or_add_tb_upwards(ns, db, tb, strict, false).await self.get_or_add_tb_upwards(ns, db, tb, strict, false).await
} }
/// Ensures that a table, database, and namespace are all fully defined. /// Ensures that a table, database, and namespace are all fully defined.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
#[inline(always)] #[inline(always)]
pub async fn ensure_ns_db_tb( pub async fn ensure_ns_db_tb(
&self, &self,
@ -1305,14 +1197,11 @@ impl Transaction {
tb: &str, tb: &str,
strict: bool, strict: bool,
) -> Result<Arc<DefineTableStatement>, Error> { ) -> Result<Arc<DefineTableStatement>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "ensure_ns_db_tb {ns} {db} {tb}");
// Continue with the function logic
self.get_or_add_tb_upwards(ns, db, tb, strict, true).await self.get_or_add_tb_upwards(ns, db, tb, strict, true).await
} }
/// Ensure a specific table (and database, and namespace) exist. /// Ensure a specific table (and database, and namespace) exist.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
#[inline(always)] #[inline(always)]
pub(crate) async fn check_ns_db_tb( pub(crate) async fn check_ns_db_tb(
&self, &self,
@ -1321,10 +1210,6 @@ impl Transaction {
tb: &str, tb: &str,
strict: bool, strict: bool,
) -> Result<(), Error> { ) -> Result<(), Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "check_ns_db_tb {ns} {db} {tb}");
// Continue with the function logic
match strict { match strict {
// Strict mode is disabled // Strict mode is disabled
false => Ok(()), false => Ok(()),
@ -1373,6 +1258,7 @@ impl Transaction {
} }
/// Clears all keys from the transaction cache. /// Clears all keys from the transaction cache.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
#[inline(always)] #[inline(always)]
pub fn clear(&self) { pub fn clear(&self) {
self.cache.clear() self.cache.clear()
@ -1383,6 +1269,7 @@ impl Transaction {
// -------------------------------------------------- // --------------------------------------------------
/// Get or add a namespace with a default configuration, only if we are in dynamic mode. /// Get or add a namespace with a default configuration, only if we are in dynamic mode.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
async fn get_or_add_ns_upwards( async fn get_or_add_ns_upwards(
&self, &self,
ns: &str, ns: &str,
@ -1434,6 +1321,7 @@ impl Transaction {
} }
/// Get or add a database with a default configuration, only if we are in dynamic mode. /// Get or add a database with a default configuration, only if we are in dynamic mode.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
async fn get_or_add_db_upwards( async fn get_or_add_db_upwards(
&self, &self,
ns: &str, ns: &str,
@ -1500,6 +1388,7 @@ impl Transaction {
} }
/// Get or add a table with a default configuration, only if we are in dynamic mode. /// Get or add a table with a default configuration, only if we are in dynamic mode.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
async fn get_or_add_tb_upwards( async fn get_or_add_tb_upwards(
&self, &self,
ns: &str, ns: &str,

View file

@ -86,7 +86,7 @@ pub(crate) async fn run_router(
} }
// If a root user is specified, setup the initial datastore credentials // If a root user is specified, setup the initial datastore credentials
if let Some(root) = configured_root { if let Some(root) = configured_root {
if let Err(error) = kvs.setup_initial_creds(root.username, root.password).await { if let Err(error) = kvs.initialise_credentials(root.username, root.password).await {
let _ = conn_tx.send(Err(error.into())).await; let _ = conn_tx.send(Err(error.into())).await;
return; return;
} }

View file

@ -82,7 +82,7 @@ pub(crate) async fn run_router(
} }
// If a root user is specified, setup the initial datastore credentials // If a root user is specified, setup the initial datastore credentials
if let Some(root) = configured_root { if let Some(root) = configured_root {
if let Err(error) = kvs.setup_initial_creds(root.username, root.password).await { if let Err(error) = kvs.initialise_credentials(root.username, root.password).await {
let _ = conn_tx.send(Err(error.into())).await; let _ = conn_tx.send(Err(error.into())).await;
return; return;
} }

View file

@ -17,10 +17,9 @@ Y88b d88P Y88b 888 888 888 Y8b. 888 888 888 888 .d88P 888 d88P
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
pub const DEBUG_BUILD_WARNING: &str = "\ pub const DEBUG_BUILD_WARNING: &str = "\
!!! THIS IS A DEBUG BUILD !!! !!! THIS IS A DEVELOPMENT BUILD !!!
Debug builds are not intended for production use and include Development builds are not intended for production use and include
tooling and features that we would not recommend people run on tooling and features that may affect the performance of the database. |
live data.
"; ";
/// The publicly visible name of the server /// The publicly visible name of the server

View file

@ -241,7 +241,7 @@ pub async fn init(
.with_capabilities(capabilities); .with_capabilities(capabilities);
// Setup initial server auth credentials // Setup initial server auth credentials
if let (Some(user), Some(pass)) = (opt.user.as_ref(), opt.pass.as_ref()) { if let (Some(user), Some(pass)) = (opt.user.as_ref(), opt.pass.as_ref()) {
dbs.setup_initial_creds(user, pass).await?; dbs.initialise_credentials(user, pass).await?;
} }
// Bootstrap the datastore // Bootstrap the datastore
dbs.bootstrap().await?; dbs.bootstrap().await?;
@ -275,7 +275,7 @@ mod tests {
ds.transaction(Read, Optimistic).await.unwrap().all_root_users().await.unwrap().len(), ds.transaction(Read, Optimistic).await.unwrap().all_root_users().await.unwrap().len(),
0 0
); );
ds.setup_initial_creds(creds.username, creds.password).await.unwrap(); ds.initialise_credentials(creds.username, creds.password).await.unwrap();
assert_eq!( assert_eq!(
ds.transaction(Read, Optimistic).await.unwrap().all_root_users().await.unwrap().len(), ds.transaction(Read, Optimistic).await.unwrap().all_root_users().await.unwrap().len(),
1 1
@ -297,7 +297,7 @@ mod tests {
.hash .hash
.clone(); .clone();
ds.setup_initial_creds(creds.username, creds.password).await.unwrap(); ds.initialise_credentials(creds.username, creds.password).await.unwrap();
assert_eq!( assert_eq!(
pass_hash, pass_hash,
ds.transaction(Read, Optimistic) ds.transaction(Read, Optimistic)

View file

@ -28,7 +28,7 @@ where
.with_line_number(true) .with_line_number(true)
.with_thread_ids(false) .with_thread_ids(false)
.with_thread_names(false) .with_thread_names(false)
.with_span_events(FmtSpan::NONE) .with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
.with_writer(std::io::stderr) .with_writer(std::io::stderr)
.with_filter(filter.0) .with_filter(filter.0)
.boxed() .boxed()

View file

@ -108,10 +108,10 @@ pub fn filter_from_value(v: &str) -> Result<EnvFilter, ParseError> {
"info" => Ok(EnvFilter::default().add_directive(Level::INFO.into())), "info" => Ok(EnvFilter::default().add_directive(Level::INFO.into())),
// Otherwise, let's show debugs and above // Otherwise, let's show debugs and above
"debug" => EnvFilter::builder() "debug" => EnvFilter::builder()
.parse("warn,surreal=debug,surrealdb=debug,surrealdb::core::kvs=info"), .parse("warn,surreal=debug,surrealdb=debug,surrealdb::core::kvs=debug"),
// Specify the log level for each code area // Specify the log level for each code area
"trace" => EnvFilter::builder() "trace" => EnvFilter::builder()
.parse("warn,surreal=trace,surrealdb=trace,surrealdb::core::kvs=info"), .parse("warn,surreal=trace,surrealdb=trace,surrealdb::core::kvs=debug"),
// Check if we should show all surreal logs // Check if we should show all surreal logs
"full" => EnvFilter::builder().parse("debug,surreal=trace,surrealdb=trace"), "full" => EnvFilter::builder().parse("debug,surreal=trace,surrealdb=trace"),
// Check if we should show all module logs // Check if we should show all module logs

View file

@ -82,12 +82,12 @@ mod cli_integration {
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
{ {
info!("* Debug builds contain debug message"); info!("* Development builds contain debug message");
let args = format!( let args = format!(
"sql --conn http://{addr} {creds} --ns {ns} --db {db} --multi --hide-welcome" "sql --conn http://{addr} {creds} --ns {ns} --db {db} --multi --hide-welcome"
); );
let output = common::run(&args).input("CREATE any:any;\n").output().unwrap(); let output = common::run(&args).input("CREATE any:any;\n").output().unwrap();
assert!(output.contains("Debug builds are not intended for production use")); assert!(output.contains("Development builds are not intended for production use"));
} }
info!("* Create a record"); info!("* Create a record");
@ -1456,10 +1456,9 @@ fn remove_debug_info(output: String) -> String {
// Look... sometimes you just gotta copy paste // Look... sometimes you just gotta copy paste
let output_warning = "\ let output_warning = "\
!!! THIS IS A DEBUG BUILD !!! !!! THIS IS A DEVELOPMENT BUILD !!!
Debug builds are not intended for production use and include Development builds are not intended for production use and include
tooling and features that we would not recommend people run on tooling and features that may affect the performance of the database. |
live data.
"; ";
// The last line in the above is important // The last line in the above is important