Implement delete and add impls required for other dml queries
parent
361acccc09
commit
2488053318
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Created on Sat May 06 2023
|
||||
*
|
||||
* This file is a part of Skytable
|
||||
* Skytable (formerly known as TerrabaseDB or Skybase) is a free and open-source
|
||||
* NoSQL database written by Sayan Nandan ("the Author") with the
|
||||
* vision to provide flexibility in data modelling without compromising
|
||||
* on performance, queryability or scalability.
|
||||
*
|
||||
* Copyright (c) 2023, Sayan Nandan <ohsayan@outlook.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
use crate::engine::{
|
||||
core::GlobalNS,
|
||||
error::{DatabaseError, DatabaseResult},
|
||||
ql::dml::del::DeleteStatement,
|
||||
sync,
|
||||
};
|
||||
|
||||
pub fn delete(gns: &GlobalNS, mut delete: DeleteStatement) -> DatabaseResult<()> {
|
||||
gns.with_model(delete.entity(), |model| {
|
||||
let g = sync::atm::cpin();
|
||||
if model
|
||||
.primary_index()
|
||||
.remove(model.resolve_where(delete.clauses_mut())?, &g)
|
||||
{
|
||||
Ok(())
|
||||
} else {
|
||||
Err(DatabaseError::DmlEntryNotFound)
|
||||
}
|
||||
})
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Created on Tue May 02 2023
|
||||
*
|
||||
* This file is a part of Skytable
|
||||
* Skytable (formerly known as TerrabaseDB or Skybase) is a free and open-source
|
||||
* NoSQL database written by Sayan Nandan ("the Author") with the
|
||||
* vision to provide flexibility in data modelling without compromising
|
||||
* on performance, queryability or scalability.
|
||||
*
|
||||
* Copyright (c) 2023, Sayan Nandan <ohsayan@outlook.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
☢ ISOLATION WARNING ☢
|
||||
----------------
|
||||
I went with a rather suboptimal solution for v1. Once we have CC
|
||||
we can do much better (at the cost of more complexity, ofcourse).
|
||||
|
||||
We'll roll that out in 0.8.1, I think.
|
||||
|
||||
FIXME(@ohsayan): Fix this
|
||||
*/
|
||||
|
||||
use {
|
||||
crate::engine::core::index::{DcFieldIndex, PrimaryIndexKey, Row, RowData},
|
||||
parking_lot::RwLockReadGuard,
|
||||
};
|
||||
|
||||
pub struct RowSnapshot<'a> {
|
||||
key: &'a PrimaryIndexKey,
|
||||
data: RwLockReadGuard<'a, RowData>,
|
||||
}
|
||||
|
||||
impl<'a> RowSnapshot<'a> {
|
||||
/// The moment you take a snapshot, you essentially "freeze" the row and prevent any changes from happening.
|
||||
///
|
||||
/// HOWEVER: This is very inefficient subject to isolation level scrutiny
|
||||
#[inline(always)]
|
||||
pub fn snapshot(row: &'a Row) -> RowSnapshot<'a> {
|
||||
Self::new_manual(row.d_key(), row.d_data().read())
|
||||
}
|
||||
pub fn new_manual(key: &'a PrimaryIndexKey, data: RwLockReadGuard<'a, RowData>) -> Self {
|
||||
Self { key, data }
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn row_key(&self) -> &'a PrimaryIndexKey {
|
||||
self.key
|
||||
}
|
||||
#[inline(always)]
|
||||
pub fn row_data(&self) -> &DcFieldIndex {
|
||||
&self.data.fields()
|
||||
}
|
||||
}
|
@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Created on Mon May 08 2023
|
||||
*
|
||||
* This file is a part of Skytable
|
||||
* Skytable (formerly known as TerrabaseDB or Skybase) is a free and open-source
|
||||
* NoSQL database written by Sayan Nandan ("the Author") with the
|
||||
* vision to provide flexibility in data modelling without compromising
|
||||
* on performance, queryability or scalability.
|
||||
*
|
||||
* Copyright (c) 2023, Sayan Nandan <ohsayan@outlook.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
use super::IndexSTSeqDllMetrics;
|
||||
|
||||
use {
|
||||
super::{config::Config, IndexSTSeqDll},
|
||||
crate::engine::{
|
||||
idx::{AsKey, AsValue, IndexBaseSpec},
|
||||
sync::smart::EArc,
|
||||
},
|
||||
std::{
|
||||
mem::ManuallyDrop,
|
||||
ops::{Deref, DerefMut},
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct OrderedIdxRC<K, V, C: Config<K, V>> {
|
||||
base: ManuallyDrop<IndexSTSeqDll<K, V, C>>,
|
||||
rc: EArc,
|
||||
}
|
||||
|
||||
impl<K, V, C: Config<K, V>> OrderedIdxRC<K, V, C> {
|
||||
fn new() -> Self {
|
||||
Self::new_with(IndexSTSeqDll::new())
|
||||
}
|
||||
fn new_with(idx: IndexSTSeqDll<K, V, C>) -> Self {
|
||||
Self {
|
||||
base: ManuallyDrop::new(idx),
|
||||
rc: unsafe {
|
||||
// UNSAFE(@ohsayan): we'll clean this up
|
||||
EArc::new()
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, V, C: Config<K, V>> Deref for OrderedIdxRC<K, V, C> {
|
||||
type Target = IndexSTSeqDll<K, V, C>;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.base
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, V, C: Config<K, V>> DerefMut for OrderedIdxRC<K, V, C> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.base
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, V, C: Config<K, V>> Clone for OrderedIdxRC<K, V, C> {
|
||||
fn clone(&self) -> Self {
|
||||
let rc = unsafe {
|
||||
// UNSAFE(@ohsayan): called at clone position
|
||||
self.rc.rc_clone()
|
||||
};
|
||||
Self {
|
||||
base: unsafe {
|
||||
// UNSAFE(@ohsayan): just a raw clone. no big deal since this is an RC
|
||||
core::mem::transmute_copy(&self.base)
|
||||
},
|
||||
rc,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, V, C: Config<K, V>> Drop for OrderedIdxRC<K, V, C> {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
// UNSAFE(@ohsayan): this is the dtor
|
||||
self.rc.rc_drop(|| ManuallyDrop::drop(&mut self.base))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<K, V, C: Config<K, V>> IndexBaseSpec for OrderedIdxRC<K, V, C> {
|
||||
const PREALLOC: bool = true;
|
||||
#[cfg(debug_assertions)]
|
||||
type Metrics = IndexSTSeqDllMetrics;
|
||||
|
||||
fn idx_init_cap(cap: usize) -> Self {
|
||||
Self::new_with(IndexSTSeqDll::with_capacity(cap))
|
||||
}
|
||||
|
||||
fn idx_init() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
|
||||
fn idx_init_with(s: Self) -> Self {
|
||||
s
|
||||
}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
fn idx_metrics(&self) -> &Self::Metrics {
|
||||
self.base.idx_metrics()
|
||||
}
|
||||
}
|
||||
|
||||
impl<K: AsKey, V: AsValue + PartialEq, C: Config<K, V>> PartialEq for OrderedIdxRC<K, V, C> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.len() == other.len()
|
||||
&& self
|
||||
._iter_unord_kv()
|
||||
.all(|(k, v)| other._get(k).unwrap().eq(v))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue