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

View file

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

View file

@ -1,12 +1,53 @@
/// Displays a key in a human-readable format.
#[cfg(debug_assertions)]
pub fn sprint<T>(key: &T) -> String
where
T: AsRef<[u8]>,
{
key.as_ref()
.iter()
use std::ops::Range;
pub trait Sprintable {
fn sprint(&self) -> String;
}
impl Sprintable for &str {
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))
.map(|byte| byte as char)
.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 crate::cnf::NORMAL_FETCH_SIZE;
use crate::err::Error;
use crate::key::debug::Sprintable;
use crate::kvs::batch::Batch;
use crate::kvs::Key;
use crate::kvs::Val;
@ -50,40 +51,40 @@ pub trait Transaction {
/// Check if a key exists in the datastore.
async fn exists<K>(&mut self, key: K) -> Result<bool, Error>
where
K: Into<Key> + Debug;
K: Into<Key> + Sprintable + Debug;
/// Fetch a key from the datastore.
async fn get<K>(&mut self, key: K) -> Result<Option<Val>, Error>
where
K: Into<Key> + Debug;
K: Into<Key> + Sprintable + Debug;
/// Insert or update a key in the datastore.
async fn set<K, V>(&mut self, key: K, val: V) -> Result<(), Error>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug;
/// Insert a key if it doesn't exist in the datastore.
async fn put<K, V>(&mut self, key: K, val: V) -> Result<(), Error>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug;
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug;
/// Delete a key from the datastore.
async fn del<K>(&mut self, key: K) -> Result<(), Error>
where
K: Into<Key> + Debug;
K: Into<Key> + Sprintable + Debug;
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug;
/// 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.
async fn keys<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<Key>, Error>
where
K: Into<Key> + Debug;
K: Into<Key> + Sprintable + Debug;
/// 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.
async fn scan<K>(&mut self, rng: Range<K>, limit: u32) -> Result<Vec<(Key, Val)>, Error>
where
K: Into<Key> + Debug;
K: Into<Key> + Sprintable + Debug;
/// Fetch many keys from the datastore.
///
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.closed() {
@ -126,9 +128,10 @@ pub trait Transaction {
/// Retrieve a range of prefixed keys from the datastore.
///
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.closed() {
@ -143,9 +146,10 @@ pub trait Transaction {
/// Retrieve a range of keys from the datastore.
///
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.closed() {
@ -169,9 +173,10 @@ pub trait Transaction {
/// Delete a range of prefixed keys from the datastore.
///
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.closed() {
@ -190,9 +195,10 @@ pub trait Transaction {
/// Delete a range of keys from the datastore.
///
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.closed() {
@ -219,9 +225,10 @@ pub trait Transaction {
/// 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.
#[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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is 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,
/// 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.
#[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> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.closed() {
@ -299,6 +307,7 @@ pub trait Transaction {
}
/// 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>(
&mut self,
ts_key: K,
@ -307,7 +316,7 @@ pub trait Transaction {
val: V,
) -> Result<(), Error>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug,
{
// Check to see if transaction is closed

View file

@ -390,7 +390,7 @@ impl Datastore {
}
// 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> {
// Insert this node in the cluster
self.insert_node(self.id).await?;
@ -401,8 +401,8 @@ impl Datastore {
}
/// Setup the initial cluster access credentials
#[instrument(err, level = "debug", target = "surrealdb::core::kvs::ds", skip_all)]
pub async fn setup_initial_creds(&self, user: &str, pass: &str) -> Result<(), Error> {
#[instrument(err, level = "trace", target = "surrealdb::core::kvs::ds", skip_all)]
pub async fn initialise_credentials(&self, user: &str, pass: &str) -> Result<(), Error> {
// Start a new writeable transaction
let txn = self.transaction(Write, Optimistic).await?.enclose();
// Fetch the root users from the storage
@ -429,7 +429,7 @@ impl Datastore {
// tick is called periodically to perform maintenance tasks.
// 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> {
let now = SystemTime::now().duration_since(UNIX_EPOCH).map_err(|e| {
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.
// It is handy for testing, because it allows you to specify the timestamp,
// 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> {
trace!(target: TARGET, "Ticking at timestamp {ts} ({:?})", conv::u64_to_versionstamp(ts));
let _vs = self.save_timestamp_for_versionstamp(ts).await?;
@ -621,7 +621,7 @@ impl Datastore {
/// Ok(())
/// }
/// ```
#[instrument(level = "debug", skip_all)]
#[instrument(level = "debug", target = "surrealdb::core::kvs::ds", skip_all)]
pub async fn execute(
&self,
txt: &str,
@ -651,7 +651,7 @@ impl Datastore {
/// Ok(())
/// }
/// ```
#[instrument(level = "debug", skip_all)]
#[instrument(level = "debug", target = "surrealdb::core::kvs::ds", skip_all)]
pub async fn process(
&self,
ast: Query,
@ -727,7 +727,7 @@ impl Datastore {
/// Ok(())
/// }
/// ```
#[instrument(level = "debug", skip_all)]
#[instrument(level = "debug", target = "surrealdb::core::kvs::ds", skip_all)]
pub async fn compute(
&self,
val: Value,
@ -814,7 +814,7 @@ impl Datastore {
/// Ok(())
/// }
/// ```
#[instrument(level = "debug", skip_all)]
#[instrument(level = "debug", target = "surrealdb::core::kvs::ds", skip_all)]
pub async fn evaluate(
&self,
val: Value,
@ -888,13 +888,13 @@ impl Datastore {
/// Ok(())
/// }
/// ```
#[instrument(level = "debug", skip_all)]
#[instrument(level = "debug", target = "surrealdb::core::kvs::ds", skip_all)]
pub fn notifications(&self) -> Option<Receiver<Notification>> {
self.notification_channel.as_ref().map(|v| v.1.clone())
}
/// 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> {
// Check if the session has expired
if sess.expired() {
@ -905,7 +905,7 @@ impl Datastore {
}
/// 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(
&self,
sess: &Session,
@ -929,7 +929,7 @@ impl Datastore {
}
/// 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> {
// Check if the session has expired
if sess.expired() {

View file

@ -3,6 +3,7 @@
mod cnf;
use crate::err::Error;
use crate::key::debug::Sprintable;
use crate::kvs::Check;
use crate::kvs::Key;
use crate::kvs::Val;
@ -176,6 +177,7 @@ impl super::api::Transaction for Transaction {
}
/// Cancel a transaction
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self))]
async fn cancel(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed
if self.done {
@ -193,6 +195,7 @@ impl super::api::Transaction for Transaction {
}
/// Commit a transaction
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self))]
async fn commit(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed
if self.done {
@ -214,9 +217,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -229,9 +233,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -250,9 +255,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug,
{
// 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
#[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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug,
{
// 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.
#[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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug,
{
// Check to see if transaction is closed
@ -328,9 +336,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -347,9 +356,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug,
{
// 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
#[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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -395,9 +406,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -430,9 +442,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -465,7 +478,11 @@ impl super::api::Transaction for Transaction {
}
/// 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
if self.done {
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.
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self), fields(ts_key = ts_key.sprint()))]
async fn set_versionstamp<K, V>(
&mut self,
_: K,
ts_key: K,
prefix: K,
suffix: K,
val: V,
) -> Result<(), Error>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug,
{
// Check to see if transaction is closed

View file

@ -1,9 +1,11 @@
#![cfg(feature = "kv-indxdb")]
use crate::err::Error;
use crate::key::debug::Sprintable;
use crate::kvs::Check;
use crate::kvs::Key;
use crate::kvs::Val;
use std::fmt::Debug;
use std::ops::Range;
#[non_exhaustive]
@ -100,6 +102,7 @@ impl super::api::Transaction for Transaction {
}
/// Cancel a transaction
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self))]
async fn cancel(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed
if self.done {
@ -114,6 +117,7 @@ impl super::api::Transaction for Transaction {
}
/// Commit a transaction
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self))]
async fn commit(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed
if self.done {
@ -132,9 +136,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key>,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -147,9 +152,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key>,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -162,10 +168,11 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key>,
V: Into<Val>,
K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -182,10 +189,11 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key>,
V: Into<Val>,
K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -202,10 +210,11 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key>,
V: Into<Val>,
K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -222,9 +231,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key>,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -241,10 +251,11 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key>,
V: Into<Val>,
K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -261,9 +272,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key>,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -281,9 +293,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key>,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {

View file

@ -1,6 +1,7 @@
#![cfg(feature = "kv-mem")]
use crate::err::Error;
use crate::key::debug::Sprintable;
use crate::kvs::Check;
use crate::kvs::Key;
use crate::kvs::Val;
@ -98,6 +99,7 @@ impl super::api::Transaction for Transaction {
}
/// Cancel a transaction
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self))]
async fn cancel(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed
if self.done {
@ -112,6 +114,7 @@ impl super::api::Transaction for Transaction {
}
/// Commit a transaction
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self))]
async fn commit(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed
if self.done {
@ -130,9 +133,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -145,9 +149,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -160,9 +165,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug,
{
// 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
#[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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug,
{
// 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
#[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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug,
{
// Check to see if transaction is closed
@ -220,9 +228,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -239,9 +248,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug,
{
// 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
#[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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -279,9 +290,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {

View file

@ -18,7 +18,7 @@ impl Datastore {
/// This function ensures that this node is entered into the clister
/// membership entries. This function must be run at server or database
/// 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> {
// Log when this method is run
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
/// timestamp. This ensures that the node is not marked as expired by any
/// 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> {
// Log when this method is run
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.
/// Later on when garbage collection is running the live queries assigned
/// 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> {
// Log when this method is run
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.
/// Later on when garbage collection is running the live queries assigned
/// 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> {
// Log when this method is run
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.
/// When a matching node is found, all node queries, and table queries are
/// 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> {
// Log when this method is run
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
/// a number of transactions in order to prevent failure of large or
/// 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> {
// Log the node deletion
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
/// WebSocket disconnects, and any associated live queries need to be
/// 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> {
// Log the node deletion
trace!(target: TARGET, "Deleting live queries for a connection");

View file

@ -3,6 +3,7 @@
mod cnf;
use crate::err::Error;
use crate::key::debug::Sprintable;
use crate::kvs::Check;
use crate::kvs::Key;
use crate::kvs::Val;
@ -176,6 +177,7 @@ impl super::api::Transaction for Transaction {
}
/// Cancel a transaction
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self))]
async fn cancel(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed
if self.done {
@ -193,6 +195,7 @@ impl super::api::Transaction for Transaction {
}
/// Commit a transaction
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self))]
async fn commit(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed
if self.done {
@ -214,9 +217,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -229,9 +233,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -244,9 +249,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug,
{
// 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
#[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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug,
{
// 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
#[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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug,
{
// Check to see if transaction is closed
@ -322,9 +330,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -341,9 +350,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug,
{
// 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
#[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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -420,9 +431,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {

View file

@ -1,6 +1,7 @@
#![cfg(feature = "kv-surrealkv")]
use crate::err::Error;
use crate::key::debug::Sprintable;
use crate::kvs::Check;
use crate::kvs::Key;
use crate::kvs::Val;
@ -107,6 +108,7 @@ impl super::api::Transaction for Transaction {
}
/// Cancels the transaction.
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self))]
async fn cancel(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed
if self.done {
@ -121,6 +123,7 @@ impl super::api::Transaction for Transaction {
}
/// Commits the transaction.
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self))]
async fn commit(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed
if self.done {
@ -139,9 +142,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -154,9 +158,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -169,9 +174,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug,
{
// 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
#[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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug,
{
// 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
#[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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug,
{
// Check to see if transaction is closed
@ -243,9 +251,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -262,9 +271,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug,
{
// 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.
#[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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -309,9 +320,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {

View file

@ -1,6 +1,7 @@
#![cfg(feature = "kv-tikv")]
use crate::err::Error;
use crate::key::debug::Sprintable;
use crate::kvs::Check;
use crate::kvs::Key;
use crate::kvs::Val;
@ -125,6 +126,7 @@ impl super::api::Transaction for Transaction {
}
/// Cancel a transaction
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self))]
async fn cancel(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed
if self.done {
@ -141,6 +143,7 @@ impl super::api::Transaction for Transaction {
}
/// Commit a transaction
#[instrument(level = "trace", target = "surrealdb::core::kvs::api", skip(self))]
async fn commit(&mut self) -> Result<(), Error> {
// Check to see if transaction is closed
if self.done {
@ -164,9 +167,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -179,9 +183,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -194,9 +199,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug,
{
// 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
#[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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug,
{
// 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
#[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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug,
{
// Check to see if transaction is closed
@ -271,9 +279,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -290,9 +299,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
V: Into<Val> + Debug,
{
// 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
#[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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -337,9 +348,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -357,9 +369,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {
@ -377,9 +390,10 @@ impl super::api::Transaction for Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
K: Into<Key> + Sprintable + Debug,
{
// Check to see if transaction is closed
if self.done {

View file

@ -5,8 +5,7 @@ use crate::cf;
use crate::dbs::node::Timestamp;
use crate::err::Error;
use crate::idg::u32::U32;
#[cfg(debug_assertions)]
use crate::key::debug::sprint;
use crate::key::debug::Sprintable;
use crate::kvs::batch::Batch;
use crate::kvs::clock::SizedClock;
use crate::kvs::stash::Stash;
@ -21,11 +20,8 @@ use std::fmt::Debug;
use std::ops::Range;
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
#[derive(Default)]
#[derive(Debug, Default)]
pub enum Check {
#[default]
None,
@ -147,9 +143,8 @@ impl Transactor {
/// transactions, whilst in development we should panic
/// so that any unintended behaviour is detected, and in
/// 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) {
#[cfg(debug_assertions)]
trace!(target: TARGET, "check_level");
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
/// calls to functions on this transaction will result
/// in a [`Error::TxFinished`] error.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tr", skip_all)]
pub async fn closed(&self) -> bool {
#[cfg(debug_assertions)]
trace!(target: TARGET, "closed");
expand_inner!(&self.inner, v => { v.closed() })
}
/// Cancel a 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> {
#[cfg(debug_assertions)]
trace!(target: TARGET, "cancel");
expand_inner!(&mut self.inner, v => { v.cancel().await })
}
/// Commit a 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> {
#[cfg(debug_assertions)]
trace!(target: TARGET, "commit");
expand_inner!(&mut self.inner, v => { v.commit().await })
}
/// 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>
where
K: Into<Key> + Debug,
{
let key = key.into();
#[cfg(debug_assertions)]
trace!(target: TARGET, "exists {}", sprint(&key));
expand_inner!(&mut self.inner, v => { v.exists(key).await })
}
/// 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>
where
K: Into<Key> + Debug,
{
let key = key.into();
#[cfg(debug_assertions)]
trace!(target: TARGET, "get {}", sprint(&key));
expand_inner!(&mut self.inner, v => { v.get(key).await })
}
/// 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>
where
K: Into<Key> + Debug,
{
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 })
}
/// Retrieve a specific range of keys from the datastore.
///
/// 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>
where
K: Into<Key> + Debug,
{
let beg: Key = rng.start.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 })
}
/// 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.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tr", skip_all)]
pub async fn getp<K>(&mut self, key: K) -> Result<Vec<(Key, Val)>, Error>
where
K: Into<Key> + Debug,
{
let key: Key = key.into();
#[cfg(debug_assertions)]
trace!(target: TARGET, "getp {}", sprint(&key));
expand_inner!(&mut self.inner, v => { v.getp(key).await })
}
/// 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>
where
K: Into<Key> + Debug,
V: Into<Val> + Debug,
{
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 })
}
/// 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>
where
K: Into<Key> + Debug,
V: Into<Val> + Debug,
{
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 })
}
/// 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>
where
K: Into<Key> + Debug,
V: Into<Val> + Debug,
{
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 })
}
/// 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>
where
K: Into<Key> + Debug,
{
let key = key.into();
#[cfg(debug_assertions)]
trace!(target: TARGET, "del {}", sprint(&key));
expand_inner!(&mut self.inner, v => { v.del(key).await })
}
/// 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>
where
K: Into<Key> + Debug,
V: Into<Val> + Debug,
{
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 })
}
/// Delete a range of keys from the datastore.
///
/// 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>
where
K: Into<Key> + Debug,
{
let beg: Key = rng.start.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 })
}
/// Delete a prefixed range of keys from the datastore.
///
/// 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>
where
K: Into<Key> + Debug,
{
let key: Key = key.into();
#[cfg(debug_assertions)]
trace!(target: TARGET, "delp {}", sprint(&key));
expand_inner!(&mut self.inner, v => { v.delp(key).await })
}
/// 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.
#[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>
where
K: Into<Key> + Debug,
{
let beg: Key = rng.start.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 })
}
/// 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.
#[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>
where
K: Into<Key> + Debug,
{
let beg: Key = rng.start.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 })
}
/// 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.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tr", skip_all)]
pub async fn batch<K>(
&mut self,
rng: Range<K>,
@ -371,8 +350,6 @@ impl Transactor {
{
let beg: Key = rng.start.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 })
}
@ -381,20 +358,15 @@ impl Transactor {
/// NOTE: This should be called when composing the change feed entries for this transaction,
/// 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.
#[allow(unused)]
pub async fn get_timestamp<K>(&mut self, key: K) -> Result<Versionstamp, Error>
where
K: Into<Key> + Debug,
{
// We convert to byte slice as its easier at this level
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 })
}
/// Insert or update a key in the datastore.
#[allow(unused_variables)]
pub async fn set_versionstamped<K, V>(
&mut self,
ts_key: K,
@ -409,14 +381,6 @@ impl Transactor {
let ts_key = ts_key.into();
let prefix = prefix.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 })
}
@ -605,7 +569,7 @@ impl Transactor {
ts,
ns,
db,
sprint(k)
k.sprint()
);
let k = crate::key::database::ts::Ts::decode(k)?;
let latest_ts = k.ts;

View file

@ -36,9 +36,6 @@ use std::ops::Range;
use std::sync::Arc;
use uuid::Uuid;
#[cfg(debug_assertions)]
const TARGET: &str = "surrealdb::core::kvs::tx";
#[non_exhaustive]
pub struct Transaction {
/// The underlying transactor
@ -52,7 +49,11 @@ impl Transaction {
pub fn new(tx: Transactor) -> Transaction {
Transaction {
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.
///
/// 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> {
self.lock().await.cancel().await
}
@ -91,11 +93,13 @@ impl Transaction {
/// Commit a 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> {
self.lock().await.commit().await
}
/// 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>
where
K: Into<Key> + Debug,
@ -104,6 +108,7 @@ impl Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
@ -112,6 +117,7 @@ impl Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
@ -122,6 +128,7 @@ impl Transaction {
/// Retrieve a specific prefix of keys from the datastore.
///
/// 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>
where
K: Into<Key> + Debug,
@ -132,6 +139,7 @@ impl Transaction {
/// Retrieve a specific range of keys from the datastore.
///
/// 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>
where
K: Into<Key> + Debug,
@ -140,6 +148,7 @@ impl Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
@ -148,6 +157,7 @@ impl Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
@ -159,6 +169,7 @@ impl Transaction {
/// Delete a range of keys from the datastore.
///
/// 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>
where
K: Into<Key> + Debug,
@ -169,6 +180,7 @@ impl Transaction {
/// Delete a prefix of keys from the datastore.
///
/// 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>
where
K: Into<Key> + Debug,
@ -177,6 +189,7 @@ impl Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
@ -186,6 +199,7 @@ impl Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
@ -195,6 +209,7 @@ impl Transaction {
}
/// 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>
where
K: Into<Key> + Debug,
@ -206,6 +221,7 @@ impl Transaction {
/// 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.
#[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>
where
K: Into<Key> + Debug,
@ -216,6 +232,7 @@ impl Transaction {
/// 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.
#[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>
where
K: Into<Key> + Debug,
@ -226,6 +243,7 @@ impl Transaction {
/// 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.
#[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>
where
K: Into<Key> + Debug,
@ -236,6 +254,7 @@ impl Transaction {
/// 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.
#[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>> + '_
where
K: Into<Key> + Debug,
@ -276,11 +295,9 @@ impl Transaction {
// 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> {
// 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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -298,11 +315,8 @@ impl Transaction {
}
/// 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> {
// 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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -321,10 +335,6 @@ impl Transaction {
/// Retrieve all ROOT level accesses in a datastore.
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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -342,11 +352,8 @@ impl Transaction {
}
/// 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> {
// 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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -364,11 +371,8 @@ impl Transaction {
}
/// 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> {
// 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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -386,11 +390,8 @@ impl Transaction {
}
/// 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> {
// 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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -408,11 +409,8 @@ impl Transaction {
}
/// 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> {
// 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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -430,15 +428,12 @@ impl Transaction {
}
/// 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(
&self,
ns: &str,
db: &str,
) -> 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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -456,15 +451,12 @@ impl Transaction {
}
/// 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(
&self,
ns: &str,
db: &str,
) -> 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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -482,15 +474,12 @@ impl Transaction {
}
/// Retrieve all analyzer definitions for a specific database.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn all_db_analyzers(
&self,
ns: &str,
db: &str,
) -> 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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -508,15 +497,12 @@ impl Transaction {
}
/// Retrieve all function definitions for a specific database.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn all_db_functions(
&self,
ns: &str,
db: &str,
) -> 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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -534,15 +520,12 @@ impl Transaction {
}
/// Retrieve all param definitions for a specific database.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn all_db_params(
&self,
ns: &str,
db: &str,
) -> 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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -560,15 +543,12 @@ impl Transaction {
}
/// Retrieve all model definitions for a specific database.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn all_db_models(
&self,
ns: &str,
db: &str,
) -> 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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -586,11 +566,8 @@ impl Transaction {
}
/// 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> {
// 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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -608,16 +585,13 @@ impl Transaction {
}
/// Retrieve all event definitions for a specific table.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn all_tb_events(
&self,
ns: &str,
db: &str,
tb: &str,
) -> 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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -635,16 +609,13 @@ impl Transaction {
}
/// Retrieve all field definitions for a specific table.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn all_tb_fields(
&self,
ns: &str,
db: &str,
tb: &str,
) -> 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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -662,16 +633,13 @@ impl Transaction {
}
/// Retrieve all index definitions for a specific table.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn all_tb_indexes(
&self,
ns: &str,
db: &str,
tb: &str,
) -> 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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -689,16 +657,13 @@ impl Transaction {
}
/// Retrieve all view definitions for a specific table.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn all_tb_views(
&self,
ns: &str,
db: &str,
tb: &str,
) -> 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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -716,16 +681,13 @@ impl Transaction {
}
/// Retrieve all live definitions for a specific table.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn all_tb_lives(
&self,
ns: &str,
db: &str,
tb: &str,
) -> 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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -743,11 +705,8 @@ impl Transaction {
}
/// 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> {
// 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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -766,18 +725,15 @@ impl Transaction {
}
/// Retrieve a specific namespace user definition.
pub async fn get_root_user(&self, user: &str) -> Result<Arc<DefineUserStatement>, Error> {
// Log this function call in development
#[cfg(debug_assertions)]
trace!(target: TARGET, "get_root_user {user}");
// Continue with the function logic
let key = crate::key::root::us::new(user).encode()?;
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_root_user(&self, us: &str) -> Result<Arc<DefineUserStatement>, Error> {
let key = crate::key::root::us::new(us).encode()?;
let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
Ok(val) => val,
Err(cache) => {
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 = Entry::Any(Arc::new(val));
@ -790,10 +746,6 @@ impl Transaction {
/// Retrieve a specific namespace user definition.
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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -812,11 +764,8 @@ impl Transaction {
}
/// 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> {
// 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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -835,22 +784,15 @@ impl Transaction {
}
/// Retrieve a specific namespace user definition.
pub async fn get_ns_user(
&self,
ns: &str,
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()?;
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_ns_user(&self, ns: &str, us: &str) -> Result<Arc<DefineUserStatement>, Error> {
let key = crate::key::namespace::us::new(ns, us).encode()?;
let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
Ok(val) => val,
Err(cache) => {
let val = self.get(key).await?.ok_or(Error::UserNsNotFound {
value: user.to_owned(),
value: us.to_owned(),
ns: ns.to_owned(),
})?;
let val: DefineUserStatement = val.into();
@ -863,15 +805,12 @@ impl Transaction {
}
/// Retrieve a specific namespace access definition.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_ns_access(
&self,
ns: &str,
na: &str,
) -> 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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -891,11 +830,8 @@ impl Transaction {
}
/// 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> {
// 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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -914,23 +850,20 @@ impl Transaction {
}
/// Retrieve a specific user definition from a database.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_db_user(
&self,
ns: &str,
db: &str,
user: &str,
us: &str,
) -> Result<Arc<DefineUserStatement>, Error> {
// Log this function call in development
#[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 key = crate::key::database::us::new(ns, db, us).encode()?;
let res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
Ok(val) => val,
Err(cache) => {
let val = self.get(key).await?.ok_or(Error::UserDbNotFound {
value: user.to_owned(),
value: us.to_owned(),
ns: ns.to_owned(),
db: db.to_owned(),
})?;
@ -944,16 +877,13 @@ impl Transaction {
}
/// Retrieve a specific database access definition.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_db_access(
&self,
ns: &str,
db: &str,
da: &str,
) -> 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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -974,6 +904,7 @@ impl Transaction {
}
/// Retrieve a specific model definition from a database.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_db_model(
&self,
ns: &str,
@ -981,10 +912,6 @@ impl Transaction {
ml: &str,
vn: &str,
) -> 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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -1003,16 +930,13 @@ impl Transaction {
}
/// Retrieve a specific analyzer definition.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_db_analyzer(
&self,
ns: &str,
db: &str,
az: &str,
) -> 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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -1031,16 +955,13 @@ impl Transaction {
}
/// Retrieve a specific function definition from a database.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_db_function(
&self,
ns: &str,
db: &str,
fc: &str,
) -> 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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -1059,16 +980,13 @@ impl Transaction {
}
/// Retrieve a specific function definition from a database.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_db_param(
&self,
ns: &str,
db: &str,
pa: &str,
) -> 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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -1087,16 +1005,13 @@ impl Transaction {
}
/// Retrieve a specific table definition.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_tb(
&self,
ns: &str,
db: &str,
tb: &str,
) -> 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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -1115,6 +1030,7 @@ impl Transaction {
}
/// Retrieve an event for a table.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_tb_event(
&self,
ns: &str,
@ -1122,10 +1038,6 @@ impl Transaction {
tb: &str,
ev: &str,
) -> 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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -1144,6 +1056,7 @@ impl Transaction {
}
/// Retrieve a field for a table.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_tb_field(
&self,
ns: &str,
@ -1151,10 +1064,6 @@ impl Transaction {
tb: &str,
fd: &str,
) -> 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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -1173,6 +1082,7 @@ impl Transaction {
}
/// Retrieve an index for a table.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_tb_index(
&self,
ns: &str,
@ -1180,10 +1090,6 @@ impl Transaction {
tb: &str,
ix: &str,
) -> 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 res = self.cache.get_value_or_guard_async(&key).await;
Ok(match res {
@ -1202,6 +1108,7 @@ impl Transaction {
}
/// Fetch a specific record value.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_record(
&self,
ns: &str,
@ -1209,10 +1116,6 @@ impl Transaction {
tb: &str,
id: &Id,
) -> 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 res = self.cache.get_value_or_guard_async(&key).await;
match res {
@ -1232,6 +1135,7 @@ impl Transaction {
}
}
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn set_record(
&self,
ns: &str,
@ -1240,10 +1144,6 @@ impl Transaction {
id: &Id,
val: Value,
) -> 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 enc = crate::key::thing::new(ns, db, tb, id).encode()?;
// 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.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
pub async fn get_or_add_ns(
&self,
ns: &str,
strict: bool,
) -> 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
}
/// 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(
&self,
ns: &str,
db: &str,
strict: bool,
) -> 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
}
/// 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(
&self,
ns: &str,
@ -1289,14 +1184,11 @@ impl Transaction {
tb: &str,
strict: bool,
) -> 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
}
/// Ensures that a table, database, and namespace are all fully defined.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
#[inline(always)]
pub async fn ensure_ns_db_tb(
&self,
@ -1305,14 +1197,11 @@ impl Transaction {
tb: &str,
strict: bool,
) -> 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
}
/// Ensure a specific table (and database, and namespace) exist.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
#[inline(always)]
pub(crate) async fn check_ns_db_tb(
&self,
@ -1321,10 +1210,6 @@ impl Transaction {
tb: &str,
strict: bool,
) -> 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 {
// Strict mode is disabled
false => Ok(()),
@ -1373,6 +1258,7 @@ impl Transaction {
}
/// Clears all keys from the transaction cache.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
#[inline(always)]
pub fn clear(&self) {
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.
#[instrument(level = "trace", target = "surrealdb::core::kvs::tx", skip(self))]
async fn get_or_add_ns_upwards(
&self,
ns: &str,
@ -1434,6 +1321,7 @@ impl Transaction {
}
/// 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(
&self,
ns: &str,
@ -1500,6 +1388,7 @@ impl Transaction {
}
/// 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(
&self,
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 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;
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 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;
return;
}

View file

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

View file

@ -241,7 +241,7 @@ pub async fn init(
.with_capabilities(capabilities);
// Setup initial server auth credentials
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
dbs.bootstrap().await?;
@ -275,7 +275,7 @@ mod tests {
ds.transaction(Read, Optimistic).await.unwrap().all_root_users().await.unwrap().len(),
0
);
ds.setup_initial_creds(creds.username, creds.password).await.unwrap();
ds.initialise_credentials(creds.username, creds.password).await.unwrap();
assert_eq!(
ds.transaction(Read, Optimistic).await.unwrap().all_root_users().await.unwrap().len(),
1
@ -297,7 +297,7 @@ mod tests {
.hash
.clone();
ds.setup_initial_creds(creds.username, creds.password).await.unwrap();
ds.initialise_credentials(creds.username, creds.password).await.unwrap();
assert_eq!(
pass_hash,
ds.transaction(Read, Optimistic)

View file

@ -28,7 +28,7 @@ where
.with_line_number(true)
.with_thread_ids(false)
.with_thread_names(false)
.with_span_events(FmtSpan::NONE)
.with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
.with_writer(std::io::stderr)
.with_filter(filter.0)
.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())),
// Otherwise, let's show debugs and above
"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
"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
"full" => EnvFilter::builder().parse("debug,surreal=trace,surrealdb=trace"),
// Check if we should show all module logs

View file

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