Merge remote-tracking branch 'origin/main' into lint-fix

This commit is contained in:
Yuriy Dupyn 2024-02-05 23:54:38 +01:00
commit a3bc0b07e2
14 changed files with 10079 additions and 154 deletions

96
Cargo.lock generated
View file

@ -82,12 +82,6 @@ dependencies = [
"syn 2.0.48",
]
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "backtrace"
version = "0.3.69"
@ -131,12 +125,6 @@ dependencies = [
"virtue",
]
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bytes"
version = "1.5.0"
@ -204,8 +192,6 @@ version = "0.1.0"
dependencies = [
"anyhow",
"clap",
"minisql",
"parser",
"proto",
"tokio",
]
@ -241,9 +227,9 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]]
name = "hermit-abi"
version = "0.3.3"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7"
checksum = "d0c62115964e08cb8039170eb33c1d0e2388a256930279edca206fff675f82c3"
[[package]]
name = "itoa"
@ -257,16 +243,6 @@ version = "0.2.151"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4"
[[package]]
name = "lock_api"
version = "0.4.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45"
dependencies = [
"autocfg",
"scopeguard",
]
[[package]]
name = "memchr"
version = "2.6.4"
@ -366,29 +342,6 @@ dependencies = [
"memchr",
]
[[package]]
name = "parking_lot"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
dependencies = [
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.9.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"smallvec",
"windows-targets 0.48.5",
]
[[package]]
name = "parser"
version = "0.1.0"
@ -509,15 +462,6 @@ dependencies = [
"rand_core",
]
[[package]]
name = "redox_syscall"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa"
dependencies = [
"bitflags",
]
[[package]]
name = "rustc-demangle"
version = "0.1.23"
@ -530,12 +474,6 @@ version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c"
[[package]]
name = "scopeguard"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "serde"
version = "1.0.196"
@ -578,25 +516,9 @@ dependencies = [
"parser",
"proto",
"rand",
"serde_json",
"tokio",
]
[[package]]
name = "signal-hook-registry"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1"
dependencies = [
"libc",
]
[[package]]
name = "smallvec"
version = "1.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970"
[[package]]
name = "socket2"
version = "0.5.5"
@ -647,18 +569,18 @@ dependencies = [
[[package]]
name = "thiserror"
version = "1.0.50"
version = "1.0.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2"
checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.50"
version = "1.0.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8"
checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471"
dependencies = [
"proc-macro2 1.0.78",
"quote 1.0.35",
@ -667,18 +589,16 @@ dependencies = [
[[package]]
name = "tokio"
version = "1.35.1"
version = "1.36.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c89b4efa943be685f629b149f53829423f8f5531ea21249408e8e2f8671ec104"
checksum = "61285f6515fa018fb2d1e46eb21223fff441ee8db5d0f1435e8ab4f5cdb80931"
dependencies = [
"backtrace",
"bytes",
"libc",
"mio",
"num_cpus",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"socket2",
"tokio-macros",
"windows-sys 0.48.0",

View file

@ -8,3 +8,14 @@ members = [
"parser",
"storage_engine"
]
[workspace.dependencies]
anyhow = "1.0.79"
async-trait = "0.1.77"
bimap = "0.6.3"
bincode = "2.0.0-rc.3"
clap = "4.4.18"
rand = "0.8.5"
serde = "1.0.196"
thiserror = "1.0.56"
tokio = "1.36.0"

View file

@ -15,28 +15,29 @@
## Running the server
```bash
cargo run -p server -- [OPTIONS] --file <FILE>
cargo run -p server -- [OPTIONS] --folder <FOLDER>
```
```
Options:
-a, --address <ADDRESS> IP address for the server to listen on [default: 127.0.0.1]
-p, --port <PORT> Port for the server to listen on [default: 5432]
-f, --file <FILE> Path to the data file
-f, --folder <FOLDER> Path to the folder for database data
-t, --throttle <DELAY> Delay between rows in milliseconds
-h, --help Print help
```
This will start the server listening on `<ADDRESS>:<PORT>` and load the state from `<FILE>`.
If the `<FILE>` does not exist, it will be created.
This will start the server listening on `<ADDRESS>:<PORT>` and load the state from `<FOLDER>`.
If the `<FOLDER>` does not exist, it will be created.
### Demo Database
A database with demo data is available in `demo.json`. To run the server with this database, use:
```bash
cargo run -p server -- --file demo.json
```
Commands that set up a database with demo data are available in `demo-1.sql`, `demo-2.sql`, and `demo-3.sql`.
This database contains two tables:
- Table `users` with columns `id`, `name`, `surname`, `email`
- Table `cars` with columns `id`, `vid`, `brand`, `model`, `year`
These files showcase the following things:
- `demo-1.sql`: small tables that handle Unicode and make use of the Optional type
- `demo-2.sql`: a bigger (1000 rows) table with realistic data
- `demo-3.sql`: a big (10,000 rows) table with simple data (was easier to generate)
See comments in these files for details.
## Running the client
```bash
@ -56,7 +57,7 @@ SQL queries can be entered line by line. The client will print the result of eac
To exit the REPL client, enter `exit` or `quit`.
# Features
- SQL must be on single line, in **UPPERCASE** and end with `;`, as it should be
- SQL must be on single line, in **UPPERCASE**, as it should be. The `;` at EOL is optional.
- Supported operations: `CREATE TABLE`, `CREATE INDEX`, `SELECT`, `INSERT`, `DELETE`
- Supported data types: `UUID`, `STRING`, `INT`, `NUMBER`
- Supported subset of PostgreSQL protocol, without authentication and simple query flow
@ -129,6 +130,7 @@ DELETE FROM users WHERE name = "Christina";
- `STRING` - string enclosed in double quotes, e.g. `"Hello World"`
- `INT` - integer, e.g. `12345`
- `NUMBER` - floating point number, e.g. `123.45`
- `Option(Something)` - optional type, e.g. `Some("james.stuart@gmail.com")` or `None`
## Testing with `psql`
Thanks to the subset of PostgreSQL protocol implemented in `proto`, the server can be tested with `psql`,

View file

@ -6,9 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tokio = { version = "1.35.1", features = ["full"] }
anyhow = "1.0.76"
anyhow = { workspace = true }
clap = { workspace = true, features = ["derive"] }
tokio = { workspace = true, features = ["io-util", "macros", "net", "rt-multi-thread"] }
proto = { path = "../proto" }
minisql = { path = "../minisql" }
parser = { path = "../parser" }
clap = { version = "4.4.18", features = ["derive"] }

10010
demo-3.sql Normal file

File diff suppressed because it is too large Load diff

View file

@ -7,13 +7,14 @@ rust-version = "1.74"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
anyhow = "1.0.79"
async-trait = "0.1.77"
bimap = { version = "0.6.3", features = ["serde"] }
bincode = "2.0.0-rc.3"
serde = { version = "1.0.196", features = ["derive", "rc"] }
tokio = { version = "1.34.0", features = ["full"] }
thiserror = "1.0.50"
anyhow = { workspace = true }
async-trait = { workspace = true }
bimap = { workspace = true, features = ["serde"] }
bincode = { workspace = true }
serde = { workspace = true, features = ["derive", "rc"] }
serde_json = "1.0.113"
thiserror = { workspace = true }
tokio = { workspace = true, features = ["macros", "sync"] }
proto = { path = "../proto" }
storage_engine = { path = "../storage_engine" }
serde_json = "1.0.113"

View file

@ -141,7 +141,6 @@ impl State {
}
async fn attach_table(&mut self, table: Table) {
// TODO: You need to update the global DB SCHEMA!
let new_table_position: TablePosition = self.tables.len();
self.table_name_position_mapping
.insert(table.schema().table_name().clone(), new_table_position);

View file

@ -2,8 +2,6 @@ use crate::error::TypeConversionError;
use proto::message::primitive::pgoid::PgOid;
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
// TODO: Private???
// use bincode::{Encode, Encoder, EncodeError, Decode, Decoder, DecodeError};
use bincode::{Decode, Encode};
// ==============Types================
@ -92,7 +90,6 @@ impl PartialOrd for Value {
}
}
// TODO: Make column know about indexable types
impl Ord for Value {
fn cmp(&self, other: &Self) -> Ordering {
match (self, other) {
@ -120,18 +117,6 @@ impl Ord for Value {
}
}
// impl Encode for Value {
// fn encode<E: Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError> {
// todo!()
// }
// }
// impl Decode for Value {
// fn decode<D: Decoder>(decoder: &mut D) -> Result<Self, DecodeError> {
// todo!()
// }
// }
impl DbType {
fn new_n_option(n: usize, inside: DbType) -> DbType {
if n == 0 {

View file

@ -6,8 +6,9 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
nom-peg = "0.1.1"
bimap = { workspace = true }
nom = "7.1.3"
nom-peg = "0.1.1"
thiserror = { workspace = true }
minisql = { path = "../minisql" }
bimap = "0.6.3"
thiserror = "1"

View file

@ -4,10 +4,10 @@ version = "0.1.0"
edition = "2021"
[dependencies]
bincode = "2.0.0-rc.3"
tokio = { version = "1.34.0", features = ["io-util", "macros", "test-util"] }
async-trait = "0.1.74"
thiserror = "1.0.50"
rand_seeder = "0.2.3"
async-trait = { workspace = true }
bincode = { workspace = true }
rand = { workspace = true }
rand_pcg = "0.3.1"
rand = "0.8.5"
rand_seeder = "0.2.3"
thiserror = { workspace = true }
tokio = { workspace = true, features = ["io-util", "macros"] }

View file

@ -6,12 +6,12 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
tokio = { version = "1.35.1", features = ["full"] }
anyhow = "1.0.76"
clap = { version = "4.4.18", features = ["derive"] }
async-trait = "0.1.74"
rand = "0.8.5"
serde_json = "1.0.112"
anyhow = { workspace = true }
async-trait = { workspace = true }
clap = { workspace = true, features = ["derive"] }
rand = { workspace = true }
tokio = { workspace = true, features = ["io-util", "macros", "net", "rt-multi-thread", "time"] }
minisql = { path = "../minisql" }
parser = { path = "../parser" }
proto = { path = "../proto" }
parser = { path = "../parser" }

View file

@ -85,7 +85,7 @@ async fn handle_stream(
let mut wrapped_writer = ServerProtoWrapper::new(writer, config.get_throttle());
let result = match request {
Ok(req) => {
handle_connection(&mut reader, &mut wrapped_writer, req, state, token, config).await
handle_connection(&mut reader, &mut wrapped_writer, req, state, token).await
}
Err(ServerHandshakeError::IsCancelRequest(cancel)) => {
handle_cancellation(cancel.pid, cancel.secret, &tokens).await
@ -141,7 +141,6 @@ async fn handle_connection<R, W>(
request: HandshakeRequest,
state: SharedDbState,
token: ResetCancelToken,
config: Arc<Configuration>,
) -> anyhow::Result<()>
where
R: FrontendProtoReader + Send,
@ -157,7 +156,7 @@ where
break;
}
FrontendMessage::Query(data) => {
let result = handle_query(writer, &state, data.query.into(), &token, &config).await;
let result = handle_query(writer, &state, data.query.into(), &token).await;
match result {
Ok(_) => {}
Err(e) => writer.write_error_message(&e.to_string()).await?,
@ -176,7 +175,6 @@ async fn handle_query<W>(
state: &SharedDbState,
query: String,
token: &ResetCancelToken,
config: &Arc<Configuration>,
) -> anyhow::Result<()>
where
W: BackendProtoWriter + ProtoFlush + Send,

View file

@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"
[dependencies]
bincode = "2.0.0-rc.3"
tokio = { version = "1.34.0", features = ["full"] }
async-trait = "0.1.74"
thiserror = "1.0.50"
async-trait = { workspace = true }
bincode = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["fs", "io-util", "macros", "rt-multi-thread"] }

View file

@ -15,7 +15,6 @@ pub type Result<T> = std::result::Result<T, Error>;
pub type Column = u64;
pub type FilePosition = u64;
// TODO: Consider adding another type parameter for indexable values
#[derive(Debug)]
pub struct Store<T> {
pub header: StoreHeader,