Skip to content

Commit

Permalink
Move shale into firewood as a module (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkuris authored Nov 1, 2023
1 parent 3718962 commit e65d24a
Show file tree
Hide file tree
Showing 23 changed files with 43 additions and 67 deletions.
4 changes: 2 additions & 2 deletions .github/check-license-headers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"RELEASE.md",
"rpc/**",
"README*",
"*/README*",
"**/README*",
"Cargo.toml",
"*/Cargo.toml",
"libaio/**",
Expand All @@ -27,7 +27,7 @@
"RELEASE.md",
"rpc/**",
"README*",
"*/README*",
"**/README*",
"Cargo.toml",
"*/Cargo.toml",
"libaio/**",
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ members = [
"growth-ring",
"libaio",
"rpc",
"shale",
]
resolver = "2"

Expand Down
1 change: 0 additions & 1 deletion firewood/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ bytemuck = { version = "1.13.1", features = ["derive"] }
enum-as-inner = "0.6.0"
growth-ring = { version = "0.0.4", path = "../growth-ring" }
libaio = {version = "0.0.4", path = "../libaio" }
shale = { version = "0.0.4", path = "../shale" }
futures = "0.3.24"
hex = "0.4.3"
lru = "0.12.0"
Expand Down
12 changes: 6 additions & 6 deletions firewood/benches/hashops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ use criterion::{criterion_group, criterion_main, profiler::Profiler, BatchSize,
use firewood::{
db::{BatchOp, DbConfig},
merkle::{Merkle, TrieHash, TRIE_HASH_LEN},
shale::{
cached::PlainMem,
compact::{CompactHeader, CompactSpace},
disk_address::DiskAddress,
CachedStore, ObjCache, Storable, StoredView,
},
storage::WalConfig,
v2::api::{Db, Proposal},
};
use pprof::ProfilerGuard;
use rand::{distributions::Alphanumeric, rngs::StdRng, Rng, SeedableRng};
use shale::{
cached::PlainMem,
compact::{CompactHeader, CompactSpace},
disk_address::DiskAddress,
CachedStore, ObjCache, Storable, StoredView,
};
use std::{fs::File, iter::repeat_with, ops::Deref, os::raw::c_int, path::Path, sync::Arc};

const ZERO_HASH: TrieHash = TrieHash([0u8; TRIE_HASH_LEN]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
use criterion::{
black_box, criterion_group, criterion_main, profiler::Profiler, Bencher, Criterion,
};
use pprof::ProfilerGuard;
use rand::Rng;
use shale::{
use firewood::shale::{
cached::{DynamicMem, PlainMem},
compact::{CompactHeader, CompactSpaceHeader},
disk_address::DiskAddress,
CachedStore, Obj, StoredView,
};
use pprof::ProfilerGuard;
use rand::Rng;
use std::{fs::File, os::raw::c_int, path::Path};

const BENCH_MEM_SIZE: usize = 2_000_000;
Expand Down
11 changes: 6 additions & 5 deletions firewood/src/db.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// Copyright (C) 2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE.md for licensing terms.

use crate::shale::{
self,
compact::{CompactSpace, CompactSpaceHeader},
disk_address::DiskAddress,
CachedStore, Obj, ShaleError, ShaleStore, SpaceId, Storable, StoredView,
};
pub use crate::{
config::{DbConfig, DbRevConfig},
storage::{buffer::DiskBufferConfig, WalConfig},
Expand All @@ -21,11 +27,6 @@ use async_trait::async_trait;
use bytemuck::{cast_slice, AnyBitPattern};
use metered::metered;
use parking_lot::{Mutex, RwLock};
use shale::{
compact::{CompactSpace, CompactSpaceHeader},
disk_address::DiskAddress,
CachedStore, Obj, ShaleError, ShaleStore, SpaceId, Storable, StoredView,
};
use std::{
collections::VecDeque,
error::Error,
Expand Down
2 changes: 1 addition & 1 deletion firewood/src/db/proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use super::{
DbHeader, DbInner, DbRev, DbRevInner, SharedStore, Store, Universe, MERKLE_META_SPACE,
MERKLE_PAYLOAD_SPACE, ROOT_HASH_SPACE,
};
use crate::shale::CachedStore;
use crate::{
merkle::{TrieHash, TRIE_HASH_LEN},
storage::{buffer::BufferWrite, AshRecord, StoreRevMut},
v2::api::{self, KeyType, ValueType},
};
use async_trait::async_trait;
use parking_lot::{Mutex, RwLock};
use shale::CachedStore;
use std::{io::ErrorKind, sync::Arc};
use tokio::task::block_in_place;

Expand Down
2 changes: 2 additions & 0 deletions firewood/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,7 @@ pub mod storage;

pub mod config;
pub mod nibbles;
// TODO: shale should not be pub, but there are integration test dependencies :(
pub mod shale;

pub mod v2;
2 changes: 1 addition & 1 deletion firewood/src/merkle.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (C) 2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE.md for licensing terms.

use crate::shale::{self, disk_address::DiskAddress, ObjWriteError, ShaleError, ShaleStore};
use crate::{nibbles::Nibbles, v2::api::Proof};
use sha3::Digest;
use shale::{self, disk_address::DiskAddress, ObjWriteError, ShaleError, ShaleStore};
use std::{
cmp::Ordering,
collections::HashMap,
Expand Down
4 changes: 2 additions & 2 deletions firewood/src/merkle/node.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (C) 2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE.md for licensing terms.

use crate::shale::{disk_address::DiskAddress, CachedStore, ShaleError, ShaleStore, Storable};
use bincode::{Error, Options};
use enum_as_inner::EnumAsInner;
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use sha3::{Digest, Keccak256};
use shale::{disk_address::DiskAddress, CachedStore, ShaleError, ShaleStore, Storable};
use std::{
fmt::{self, Debug},
io::{Cursor, Read, Write},
Expand Down Expand Up @@ -850,7 +850,7 @@ pub(super) mod tests {
use std::array::from_fn;

use super::*;
use shale::cached::PlainMem;
use crate::shale::cached::PlainMem;
use test_case::test_case;

pub fn leaf(path: Vec<u8>, data: Vec<u8>) -> Node {
Expand Down
2 changes: 1 addition & 1 deletion firewood/src/merkle/trie_hash.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (C) 2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE.md for licensing terms.

use shale::{CachedStore, ShaleError, Storable};
use crate::shale::{CachedStore, ShaleError, Storable};
use std::{
fmt::{self, Debug},
io::Write,
Expand Down
8 changes: 4 additions & 4 deletions firewood/src/merkle_util.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Copyright (C) 2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE.md for licensing terms.

use crate::shale::{
self, cached::DynamicMem, compact::CompactSpace, disk_address::DiskAddress, CachedStore,
ShaleStore, StoredView,
};
use crate::{
merkle::{Merkle, Node, Ref, RefMut, TrieHash},
proof::ProofError,
v2::api::Proof,
};
use shale::{
cached::DynamicMem, compact::CompactSpace, disk_address::DiskAddress, CachedStore, ShaleStore,
StoredView,
};
use std::{num::NonZeroUsize, sync::Arc};
use thiserror::Error;

Expand Down
4 changes: 1 addition & 3 deletions firewood/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
use std::cmp::Ordering;
use std::ops::Deref;

use crate::shale::{disk_address::DiskAddress, ShaleError, ShaleStore};
use nix::errno::Errno;
use sha3::Digest;
use shale::disk_address::DiskAddress;
use shale::ShaleError;
use shale::ShaleStore;
use thiserror::Error;

use crate::nibbles::Nibbles;
Expand Down
3 changes: 3 additions & 0 deletions firewood/src/shale/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# shale

This directory was forked from [`shale`](https://github.com/Determinant/shale) at commit [`caa6d75`](https://github.com/Determinant/shale/commit/caa6d7543d253e2172c51a65d226d65d232a9b9a), under MIT license.
4 changes: 2 additions & 2 deletions shale/src/cached.rs → firewood/src/shale/cached.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (C) 2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE.md for licensing terms.

use crate::{CachedStore, CachedView, SendSyncDerefMut, SpaceId};
use crate::shale::{CachedStore, CachedView, SendSyncDerefMut, SpaceId};
use std::{
borrow::BorrowMut,
fmt::Debug,
Expand All @@ -10,7 +10,7 @@ use std::{
};

/// Purely volatile, vector-based implementation for [CachedStore]. This is good for testing or trying
/// out stuff (persistent data structures) built on [ShaleStore](crate::ShaleStore) in memory, without having to write
/// out stuff (persistent data structures) built on [ShaleStore](super::ShaleStore) in memory, without having to write
/// your own [CachedStore] implementation.
#[derive(Debug)]
pub struct PlainMem {
Expand Down
6 changes: 3 additions & 3 deletions shale/src/compact.rs → firewood/src/shale/compact.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (C) 2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE.md for licensing terms.

use crate::ObjCache;
use crate::shale::ObjCache;

use super::disk_address::DiskAddress;
use super::{CachedStore, Obj, ObjRef, ShaleError, ShaleStore, Storable, StoredView};
Expand Down Expand Up @@ -589,7 +589,7 @@ impl<T: Storable + 'static, M: CachedStore + Send + Sync> ShaleStore<T> for Comp
mod tests {
use sha3::Digest;

use crate::{cached::DynamicMem, ObjCache};
use crate::shale::{self, cached::DynamicMem, ObjCache};

use super::*;

Expand Down Expand Up @@ -648,7 +648,7 @@ mod tests {
let compact_header = DiskAddress::from(0x1);
dm.write(
compact_header.unwrap().get(),
&crate::to_dehydrated(&CompactSpaceHeader::new(
&shale::to_dehydrated(&CompactSpaceHeader::new(
reserved.0.unwrap(),
reserved.0.unwrap(),
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::ops::{Deref, DerefMut};

use bytemuck::NoUninit;

use crate::{CachedStore, ShaleError, Storable};
use crate::shale::{CachedStore, ShaleError, Storable};

/// The virtual disk address of an object
#[repr(C)]
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions firewood/src/storage/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::sync::Arc;
use std::{cell::RefCell, collections::HashMap};

use super::{AshRecord, FilePool, Page, StoreDelta, StoreError, WalConfig, PAGE_SIZE_NBIT};
use crate::shale::SpaceId;
use crate::storage::DeltaPage;
use aiofut::{AioBuilder, AioError, AioManager};
use futures::future::join_all;
Expand All @@ -19,7 +20,6 @@ use growthring::{
walerror::WalError,
WalFileImpl, WalStoreImpl,
};
use shale::SpaceId;
use tokio::{
sync::{
mpsc,
Expand Down Expand Up @@ -621,14 +621,14 @@ mod tests {
use tokio::task::block_in_place;

use super::*;
use crate::shale::CachedStore;
use crate::{
file,
storage::{
Ash, CachedSpace, DeltaPage, MemStoreR, StoreConfig, StoreRevMut, StoreRevMutDelta,
StoreRevShared, ZeroStore,
},
};
use shale::CachedStore;

const STATE_SPACE: SpaceId = 0x0;
const HASH_SIZE: usize = 32;
Expand Down
2 changes: 1 addition & 1 deletion firewood/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
// TODO: try to get rid of the use `RefCell` in this file
use self::buffer::DiskBufferRequester;
use crate::file::File;
use crate::shale::{self, CachedStore, CachedView, SendSyncDerefMut, SpaceId};
use nix::fcntl::{flock, FlockArg};
use parking_lot::RwLock;
use serde::{Deserialize, Serialize};
use shale::{CachedStore, CachedView, SendSyncDerefMut, SpaceId};
use std::{
collections::HashMap,
fmt::{self, Debug},
Expand Down
3 changes: 2 additions & 1 deletion firewood/tests/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ use firewood::{
merkle::Node,
merkle_util::{new_merkle, DataStoreError, MerkleSetup},
proof::ProofError,
// TODO: we should not be using shale from an integration test
shale::{cached::DynamicMem, compact::CompactSpace},
v2::api::Proof,
};
use rand::Rng;
use shale::{cached::DynamicMem, compact::CompactSpace};
use std::collections::HashMap;

type Store = CompactSpace<Node, DynamicMem>;
Expand Down
24 changes: 0 additions & 24 deletions shale/Cargo.toml

This file was deleted.

3 changes: 0 additions & 3 deletions shale/README.md

This file was deleted.

0 comments on commit e65d24a

Please sign in to comment.