From 49fa843eb2c5b3cb10c9b1209b70de45716946a8 Mon Sep 17 00:00:00 2001 From: Sayan Nandan Date: Wed, 28 Jul 2021 18:57:53 +0530 Subject: [PATCH] Parse the `swapks` header if it is provided --- CHANGELOG.md | 8 ++++-- CONTRIBUTING.md | 4 +-- README.md | 4 ++- server/src/queryengine/mod.rs | 48 +++++++++++++++++++++++------------ 4 files changed, 43 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92469398..bceaf233 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,13 +12,15 @@ All changes in this project will be noted in this file. ```sql CREATE KEYSPACE ``` - - The `system` keyspace is reserved for the system + - The `system` keyspace is reserved for the system while the `default` keyspace is + the one available by default. The `system` or `default` keyspace cannot be removed - Keyspaces can be deleted with: ```sql DROP KEYSPACE ``` - **Multiple tables**: - - Tables hold the actual data + - Tables hold the actual data. When you connect to the server, you are connected to the `default` + table in the `default` keyspace. This table is non-removable - Tables can be created with: ```sql CREATE TABLE (modelargs) @@ -102,6 +104,8 @@ All changes in this project will be noted in this file. - Zero length argument causing runtime panic in `skysh` - Panic on incorrect data type in `skyd` +- `sky-bench` no longer affects your personal data because it creates a random temporary table + under the `default` keyspace ## Version 0.6.3 [2021-06-27] diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bcd0e6dc..012e4155 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -82,7 +82,7 @@ Skytable uses a Makefile for builds and running the test suite along with a numb make release ``` -> **TIP**: You can explicitly specificy a target triple by setting a `TARGET` environment variable +> **TIP**: You can explicitly specify a target triple by setting a `TARGET` environment variable **Testing** @@ -92,4 +92,4 @@ Testing is simple: just run this: make test ``` -> **NOTE**: Make sure port 2003 is not used by any applications +> **NOTE**: Make sure port 2003 is not used by any applications and make sure your own instance isn't running on port 2003! The test suite creates a `testsuite` keyspace and some tables within it to run all the tests. diff --git a/README.md b/README.md index 8d886329..ed83ef5a 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,9 @@ You can learn more about installation [here](https://docs.skytable.io/getting-st ## Features - **Insanely fast**: Scale to millions of queries per second per node -- **Key/value store**: `GET` , `SET` , `UPDATE` and [all that stuff](https://docs.skytable.io/actions-overview) +- **Multiple keyspaces/tables**: Seamlessly integrates with actions to provide a SQL-like experience +- **Key/value store**: `GET` , `SET` , `UPDATE` and [all that stuff](https://docs.skytable.io/actions-overview). With the `str` and `binstr` types. +- **Volatile tables**: For all the caching you need - **Snapshots**: Automated (and tunable) snapshots for stress-free backups - **Secure**: Secure connections are built into Skytable with SSL/TLS - **Multithreaded**: Designed to exploit all CPU cores diff --git a/server/src/queryengine/mod.rs b/server/src/queryengine/mod.rs index 8a3981da..f346f7cd 100644 --- a/server/src/queryengine/mod.rs +++ b/server/src/queryengine/mod.rs @@ -67,6 +67,29 @@ macro_rules! gen_constants_and_matches { }; } +macro_rules! swap_entity { + ($con:expr, $handle:expr, $entity:expr) => { + match parser::get_query_entity(&$entity) { + Ok(e) => match $handle.swap_entity(e) { + Ok(()) => $con.write_response(responses::groups::OKAY).await?, + Err(DdlError::ObjectNotFound) => { + $con.write_response(responses::groups::CONTAINER_NOT_FOUND) + .await? + } + Err(DdlError::DefaultNotFound) => { + $con.write_response(responses::groups::DEFAULT_UNSET) + .await? + } + Err(_) => unsafe { + // we know Corestore::swap_entity doesn't return anything else + impossible!() + }, + }, + Err(e) => $con.write_response(e).await?, + } + }; +} + /// Execute a simple(*) query pub async fn execute_simple( db: &mut Corestore, @@ -77,10 +100,13 @@ where T: ProtocolConnectionExt, Strm: AsyncReadExt + AsyncWriteExt + Unpin + Send + Sync, { - let buf = if let Element::FlatArray(arr) = buf { - arr - } else { - return con.write_response(responses::groups::WRONGTYPE_ERR).await; + let buf = match buf { + Element::FlatArray(a) => a, + Element::SwapKSHeader(swapks) => { + swap_entity!(con, db, swapks); + return Ok(()); + } + _ => return con.write_response(responses::groups::WRONGTYPE_ERR).await, }; let mut buf = buf.into_iter(); gen_constants_and_matches!( @@ -113,20 +139,10 @@ where } action! { + /// Handle `use ` like queries fn entity_swap(handle: &mut Corestore, con: &mut T, mut act: ActionIter) { match act.next() { - Some(entity) => match parser::get_query_entity(&entity) { - Ok(e) => match handle.swap_entity(e) { - Ok(()) => con.write_response(responses::groups::OKAY).await?, - Err(DdlError::ObjectNotFound) => con.write_response(responses::groups::CONTAINER_NOT_FOUND).await?, - Err(DdlError::DefaultNotFound) => con.write_response(responses::groups::DEFAULT_UNSET).await?, - Err(_) => unsafe { - // we know Corestore::swap_entity doesn't return anything else - impossible!() - } - }, - Err(e) => con.write_response(e).await?, - }, + Some(entity) => swap_entity!(con, handle, entity), None => con.write_response(responses::groups::ACTION_ERR).await?, } Ok(())