Skip to content

Commit

Permalink
Merge pull request #161 from naomijub/issue-159
Browse files Browse the repository at this point in the history
Issue 159
  • Loading branch information
naomijub authored Apr 23, 2021
2 parents 7562e0e + 943307d commit d8b7d9f
Show file tree
Hide file tree
Showing 14 changed files with 63 additions and 30 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ zstd = "0.6.0+zstd.1.4.8"
bcrypt = "0.8"
actix-web-httpauth = "0.5.0"
serde_json = { version = "1.0", optional = true }
bincode = "1.3"

[dev-dependencies]
bytes = "1.0.1"
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,17 @@ PORT=1438
> 2,3 GHz Intel Core i9 8-Core 32 GB 2667 MHz DDR4
- `create_entity` time: [4.7008 ms 4.7367 ms 4.7725 ms]
- `insert_entity` time: [9.5938 ms 9.8263 ms 10.057 ms]
- `update_set_entity` time: [11.899 ms 11.984 ms 12.083 ms]
- `update_content_entity` time: [12.048 ms 12.328 ms 12.719 ms]
- `insert_entity` time: [12.647 ms 12.977 ms 13.308 ms]
- `update_set_entity` time: [14.896 ms 15.087 ms 15.309 ms]
- `update_content_entity` time: [14.871 ms 15.070 ms 15.307 ms]
- `delete_entity` time: [5.3966 ms 5.4423 ms 5.4908 ms] - Filtered 400s
- `evict_entity_id` time: [15.534 ms 15.623 ms 15.721 ms] - Filtered 400s
- `evict_entity` time: [12.318 ms 12.416 ms 12.540 ms] - Filtered 400s
- `select_all` 20 entities time: [5.8810 ms 5.9318 ms 5.9889 ms]
- `select_all` 10 entities time: [5.4012 ms 5.4432 ms 5.4860 ms]
- `select_all` 1 entity time: [4.8442 ms 4.8786 ms 4.9140 ms]
- `history_10_registries_for_entity` time: [5.7265 ms 5.7868 ms 5.8673 ms]
- `history_20_registries_for_entity` time: [6.1166 ms 6.1943 ms 6.2987 ms]
- `select_all` 20 entities time: [6.3402 ms 6.4743 ms 6.6356 ms]
- `select_all` 10 entities time: [5.8318 ms 5.9682 ms 6.1340 ms]
- `select_all` 1 entity time: [5.1030 ms 5.1379 ms 5.1738 ms]
- `history_10_registries_for_entity` time: [5.4936 ms 5.5328 ms 5.5725 ms]
- `history_20_registries_for_entity` time: [6.0676 ms 6.1049 ms 6.1429 ms]

### WQL
> 2,3 GHz Intel Core i9 8-Core 32 GB 2667 MHz DDR4
Expand Down
2 changes: 1 addition & 1 deletion data/local_data.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"encrypt_ent": {},"encrypt_ent2": {},"hello": {"50e68bc1-0c3b-4ffc-93be-46e57f59b415": ((file_name: "2021_02_10.log",offset: 447,bytes_length: 153,), {},),},"oh_yeah": {"27367bd0-1966-4005-a8b5-5e323e1c3524": ((file_name: "2021_02_10.log",offset: 180,bytes_length: 247,), {}),},}
{"encrypt_ent": {},"encrypt_ent2": {},"hello": {"50e68bc1-0c3b-4ffc-93be-46e57f59b415": ((file_name: "2021_02_10.log",offset: 447,bytes_length: 153,),[0, 0, 0, 0, 0, 0, 0, 0,],),},"oh_yeah": {"27367bd0-1966-4005-a8b5-5e323e1c3524": ((file_name: "2021_02_10.log",offset: 180,bytes_length: 247,), [0, 0, 0, 0, 0, 0, 0, 0,],),},}
10 changes: 10 additions & 0 deletions woori-db/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions woori-db/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ glob = "0.3.0"
zstd = "0.6.0+zstd.1.4.8"
bcrypt = "0.8"
actix-web-httpauth = "0.5.0"
bincode = "1.3"

[dev-dependencies]
bytes = "1.0.1"
2 changes: 1 addition & 1 deletion woori-db/data/local_data.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"encrypt_ent": {},"encrypt_ent2": {},"hello": {"50e68bc1-0c3b-4ffc-93be-46e57f59b415": ((file_name: "2021_02_10.log",offset: 447,bytes_length: 153,), {},),},"oh_yeah": {"27367bd0-1966-4005-a8b5-5e323e1c3524": ((file_name: "2021_02_10.log",offset: 180,bytes_length: 247,), {}),},}
{"encrypt_ent": {},"encrypt_ent2": {},"hello": {"50e68bc1-0c3b-4ffc-93be-46e57f59b415": ((file_name: "2021_02_10.log",offset: 447,bytes_length: 153,), [0, 0, 0, 0, 0, 0, 0, 0,],),},"oh_yeah": {"27367bd0-1966-4005-a8b5-5e323e1c3524": ((file_name: "2021_02_10.log",offset: 180,bytes_length: 247,), [0, 0, 0, 0, 0, 0, 0, 0,],),},}
3 changes: 1 addition & 2 deletions woori-db/src/actors/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ fn get_previous_registry(fractions: &[&str]) -> Result<Option<DataRegister>, Err
.to_owned();
let state = &state[..(state.len() - 1)];

let resp: Result<(DataRegister, HashMap<String, Types>), Error> = match ron::de::from_str(state)
{
let resp: Result<(DataRegister, Vec<u8>), Error> = match ron::de::from_str(state) {
Ok(x) => Ok(x),
Err(_) => Err(Error::FailedToParseRegistry),
};
Expand Down
3 changes: 2 additions & 1 deletion woori-db/src/controllers/clauses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,12 @@ fn or_clauses(
}

async fn generate_state(
registries: &BTreeMap<Uuid, (DataRegister, HashMap<String, Types>)>,
registries: &BTreeMap<Uuid, (DataRegister, Vec<u8>)>,
args_to_select: ToSelect,
) -> Result<BTreeMap<Uuid, HashMap<String, Types>>, Error> {
let mut states: BTreeMap<Uuid, HashMap<String, Types>> = BTreeMap::new();
for (uuid, (_, state)) in registries {
let state: HashMap<String, Types> = bincode::deserialize(&state).unwrap();
let state = state
.into_par_iter()
.filter(|(_, v)| !v.is_hash())
Expand Down
10 changes: 6 additions & 4 deletions woori-db/src/controllers/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ pub async fn select_all_with_id(
registry
};

let state = registry.1;
let state: HashMap<String, Types> = bincode::deserialize(&registry.1).unwrap();
let filterd_state = filter_keys_and_hash(state, None);
Ok(filterd_state.into())
}
Expand Down Expand Up @@ -327,7 +327,7 @@ pub async fn select_all_with_ids(
.filter(|(_id, reg)| reg.is_some())
})
.map(|(uuid, reg)| (uuid, reg.map(ToOwned::to_owned)))
.collect::<Vec<(Uuid, Option<(DataRegister, HashMap<String, Types>)>)>>()
.collect::<Vec<(Uuid, Option<(DataRegister, Vec<u8>)>)>>()
} else {
return Err(Error::EntityNotCreated(entity));
};
Expand All @@ -337,6 +337,7 @@ pub async fn select_all_with_ids(
let mut states: BTreeMap<Uuid, Option<HashMap<String, Types>>> = BTreeMap::new();
for (uuid, registry) in registries.into_iter().skip(offset).take(limit) {
if let Some((_, state)) = registry {
let state: HashMap<String, Types> = bincode::deserialize(&state).unwrap();
let filtered = filter_keys_and_hash(state, None);
states.insert(uuid, Some(filtered));
} else {
Expand Down Expand Up @@ -377,7 +378,7 @@ pub async fn select_keys_with_id(
registry
};

let state = registry.1;
let state: HashMap<String, Types> = bincode::deserialize(&registry.1).unwrap();
let filtered = filter_keys_and_hash(state, Some(keys));
Ok(filtered.into())
}
Expand Down Expand Up @@ -411,7 +412,7 @@ pub async fn select_keys_with_ids(
.filter(|(_id, reg)| reg.is_some())
})
.map(|(uuid, reg)| (uuid, reg.map(ToOwned::to_owned)))
.collect::<Vec<(Uuid, Option<(DataRegister, HashMap<String, Types>)>)>>()
.collect::<Vec<(Uuid, Option<(DataRegister, Vec<u8>)>)>>()
} else {
return Err(Error::EntityNotCreated(entity));
};
Expand All @@ -421,6 +422,7 @@ pub async fn select_keys_with_ids(
let mut states: BTreeMap<Uuid, Option<HashMap<String, Types>>> = BTreeMap::new();
for (uuid, registry) in registries.into_iter().skip(offset).take(limit) {
if let Some((_, state)) = registry {
let state: HashMap<String, Types> = bincode::deserialize(&state).unwrap();
let filtered = filter_keys_and_hash(state, Some(keys.clone()));
states.insert(uuid, Some(filtered));
} else {
Expand Down
27 changes: 18 additions & 9 deletions woori-db/src/controllers/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ pub async fn insert_controller(
return Err(Error::LockData);
};
if let Some(map) = local_data.get_mut(&args.entity) {
map.insert(content_value.1, (local_data_register, encrypted_content));
let encoded: Vec<u8> = bincode::serialize(&encrypted_content).unwrap();
map.insert(content_value.1, (local_data_register, encoded));
}
local_data.clone()
};
Expand Down Expand Up @@ -420,7 +421,8 @@ pub async fn update_set_controller(
previous_entry.clone()
};

let mut previous_state = previous_entry.1.clone();
let mut previous_state: HashMap<String, Types> =
bincode::deserialize(&previous_entry.1.clone()).unwrap();
let encrypted_content_clone = encrypted_content.clone();
encrypted_content.into_iter().for_each(|(k, v)| {
let local_state = previous_state.entry(k).or_insert_with(|| v.clone());
Expand Down Expand Up @@ -461,7 +463,8 @@ pub async fn update_set_controller(
};
if let Some(map) = local_data.get_mut(&args.entity) {
if let Some(reg) = map.get_mut(&args.id) {
*reg = (local_data_register, encrypted_content_clone);
let encoded: Vec<u8> = bincode::serialize(&encrypted_content_clone).unwrap();
*reg = (local_data_register, encoded);
}
}
local_data.clone()
Expand Down Expand Up @@ -541,7 +544,8 @@ pub async fn update_content_controller(
previous_entry.clone()
};

let mut previous_state = previous_entry.1.clone();
let mut previous_state: HashMap<String, Types> =
bincode::deserialize(&previous_entry.1.clone()).unwrap();

content
.into_iter()
Expand Down Expand Up @@ -578,7 +582,8 @@ pub async fn update_content_controller(
};
if let Some(map) = local_data.get_mut(&args.entity) {
if let Some(reg) = map.get_mut(&args.id) {
*reg = (local_data_register, previous_state);
let encoded: Vec<u8> = bincode::serialize(&previous_state).unwrap();
*reg = (local_data_register, encoded);
}
}
local_data.clone()
Expand Down Expand Up @@ -679,7 +684,8 @@ pub async fn delete_controller(
};
if let Some(map) = local_data.get_mut(&entity) {
if let Some(reg) = map.get_mut(&uuid) {
*reg = (local_data_register, state_to_be.0);
let encoded: Vec<u8> = bincode::serialize(&state_to_be.0).unwrap();
*reg = (local_data_register, encoded);
}
}
local_data.clone()
Expand Down Expand Up @@ -723,12 +729,14 @@ pub async fn match_update_set_controller(
previous_entry.clone()
};

let mut previous_state = previous_entry.1.clone();
let previous_entry: HashMap<String, Types> =
bincode::deserialize(&previous_entry.1.clone()).unwrap();
let mut previous_state = previous_entry.clone();

actor
.send(MatchUpdate {
conditions: args.conditions,
previous_state: previous_entry.1.clone(),
previous_state: previous_entry.clone(),
})
.await??;

Expand Down Expand Up @@ -793,7 +801,8 @@ pub async fn match_update_set_controller(
};
if let Some(map) = local_data.get_mut(&args.entity) {
if let Some(reg) = map.get_mut(&args.id) {
*reg = (local_data_register, encrypted_content);
let encoded: Vec<u8> = bincode::serialize(&encrypted_content).unwrap();
*reg = (local_data_register, encoded);
}
}
local_data.clone()
Expand Down
3 changes: 2 additions & 1 deletion woori-db/src/core/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ pub(crate) fn filter_keys_and_hash(
}

pub fn registries_to_states(
registries: BTreeMap<Uuid, (DataRegister, HashMap<String, Types>)>,
registries: BTreeMap<Uuid, (DataRegister, Vec<u8>)>,
keys: Option<HashSet<String>>,
offset: usize,
limit: usize,
) -> BTreeMap<Uuid, HashMap<String, Types>> {
let mut states: BTreeMap<Uuid, HashMap<String, Types>> = BTreeMap::new();
for (uuid, (_, state)) in registries.into_iter().skip(offset).take(limit) {
let state: HashMap<String, Types> = bincode::deserialize(&state).unwrap();
let filtered = filter_keys_and_hash(state, keys.clone());
states.insert(uuid, filtered);
}
Expand Down
2 changes: 1 addition & 1 deletion woori-db/src/io/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ mod test {
assert!(local_data.is_ok());
assert_eq!(
format!("{:?}", local_data),
"Ok({\"encrypt_ent\": {}, \"encrypt_ent2\": {}, \"hello\": {50e68bc1-0c3b-4ffc-93be-46e57f59b415: (DataRegister { file_name: \"2021_02_10.log\", offset: 447, bytes_length: 153 }, {})}, \"oh_yeah\": {27367bd0-1966-4005-a8b5-5e323e1c3524: (DataRegister { file_name: \"2021_02_10.log\", offset: 180, bytes_length: 247 }, {})}})"
"Ok({\"encrypt_ent\": {}, \"encrypt_ent2\": {}, \"hello\": {50e68bc1-0c3b-4ffc-93be-46e57f59b415: (DataRegister { file_name: \"2021_02_10.log\", offset: 447, bytes_length: 153 }, [0, 0, 0, 0, 0, 0, 0, 0])}, \"oh_yeah\": {27367bd0-1966-4005-a8b5-5e323e1c3524: (DataRegister { file_name: \"2021_02_10.log\", offset: 180, bytes_length: 247 }, [0, 0, 0, 0, 0, 0, 0, 0])}})"
);
}

Expand Down
3 changes: 1 addition & 2 deletions woori-db/src/repository/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ use std::collections::{BTreeMap, HashMap, HashSet};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use wql::Types;

use crate::{auth::schemas::Role, model::DataRegister};

pub type StateInfo = (DataRegister, HashMap<String, Types>);
pub type StateInfo = (DataRegister, Vec<u8>);
pub type LocalContext = BTreeMap<String, BTreeMap<Uuid, StateInfo>>;
pub type UniquenessContext = BTreeMap<String, HashMap<String, HashSet<String>>>;
pub type EncryptContext = BTreeMap<String, HashSet<String>>;
Expand Down

0 comments on commit d8b7d9f

Please sign in to comment.