Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: prepare segcache storage crate for release #91

Merged
merged 18 commits into from
Dec 19, 2023
Merged
35 changes: 17 additions & 18 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 @@ -50,6 +50,7 @@ bytes = "1.3.0"
clap = "4.1.4"
clocksource = "0.6.0"
crossbeam-channel = "0.5.6"
datatier = { path = "./src/storage/datatier", version = "0.1.0"}
foreign-types-shared = "0.3.1"
httparse = "1.8.0"
libc = "0.2.139"
Expand Down
4 changes: 2 additions & 2 deletions src/entrystore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repository = { workspace = true }
license = { workspace = true }

[features]
debug = ["seg/debug"]
debug = ["pelikan-storage-seg/debug"]

[dependencies]
common = { path = "../common" }
Expand All @@ -19,4 +19,4 @@ protocol-common = { path = "../protocol/common" }
protocol-memcache = { path = "../protocol/memcache" }
protocol-ping = { path = "../protocol/ping" }
protocol-resp = { path = "../protocol/resp" }
seg = { path = "../storage/seg" }
pelikan-storage-seg = { path = "../storage/seg" }
brayniac marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 6 additions & 6 deletions src/entrystore/src/seg/memcache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ impl Storage for Seg {
let o = item.optional().unwrap_or(&[0, 0, 0, 0]);
let flags = u32::from_be_bytes([o[0], o[1], o[2], o[3]]);
match item.value() {
seg::Value::Bytes(b) => {
pelikan_storage_seg::Value::Bytes(b) => {
values.push(Value::new(item.key(), flags, None, b));
}
seg::Value::U64(v) => {
pelikan_storage_seg::Value::U64(v) => {
values.push(Value::new(
item.key(),
flags,
Expand All @@ -66,10 +66,10 @@ impl Storage for Seg {
let o = item.optional().unwrap_or(&[0, 0, 0, 0]);
let flags = u32::from_be_bytes([o[0], o[1], o[2], o[3]]);
match item.value() {
seg::Value::Bytes(b) => {
pelikan_storage_seg::Value::Bytes(b) => {
values.push(Value::new(item.key(), flags, Some(item.cas().into()), b));
}
seg::Value::U64(v) => {
pelikan_storage_seg::Value::U64(v) => {
values.push(Value::new(
item.key(),
flags,
Expand Down Expand Up @@ -263,7 +263,7 @@ impl Storage for Seg {
fn incr(&mut self, incr: &Incr) -> Response {
match self.data.wrapping_add(incr.key(), incr.value()) {
Ok(item) => match item.value() {
seg::Value::U64(v) => Response::numeric(v, incr.noreply()),
pelikan_storage_seg::Value::U64(v) => Response::numeric(v, incr.noreply()),
_ => Response::server_error(""),
},
Err(SegError::NotFound) => Response::not_found(incr.noreply()),
Expand All @@ -275,7 +275,7 @@ impl Storage for Seg {
fn decr(&mut self, decr: &Decr) -> Response {
match self.data.saturating_sub(decr.key(), decr.value()) {
Ok(item) => match item.value() {
seg::Value::U64(v) => Response::numeric(v, decr.noreply()),
pelikan_storage_seg::Value::U64(v) => Response::numeric(v, decr.noreply()),
_ => Response::server_error(""),
},
Err(SegError::NotFound) => Response::not_found(decr.noreply()),
Expand Down
6 changes: 3 additions & 3 deletions src/entrystore/src/seg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ use crate::EntryStore;

use config::seg::Eviction;
use config::SegConfig;
use seg::{Policy, SegError};
use pelikan_storage_seg::{Policy, SegError};

mod memcache;
mod resp;

/// A wrapper around [`seg::Seg`] which implements `EntryStore` and storage
/// protocol traits.
pub struct Seg {
data: ::seg::Seg,
data: pelikan_storage_seg::Seg,
}

impl Seg {
Expand All @@ -43,7 +43,7 @@ impl Seg {
};

// build the datastructure from the config
let data = ::seg::Seg::builder()
let data = pelikan_storage_seg::Seg::builder()
.hash_power(config.hash_power())
.overflow_factor(config.overflow_factor())
.heap_size(config.heap_size())
Expand Down
8 changes: 5 additions & 3 deletions src/entrystore/src/seg/resp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//! storage commands.

use super::*;
use protocol_common::*;

use protocol_common::*;
use protocol_resp::*;

use std::time::Duration;
Expand All @@ -26,8 +26,10 @@ impl Storage for Seg {
fn get(&mut self, get: &Get) -> Response {
if let Some(item) = self.data.get(get.key()) {
match item.value() {
seg::Value::Bytes(b) => Response::bulk_string(b),
seg::Value::U64(v) => Response::bulk_string(format!("{v}").as_bytes()),
pelikan_storage_seg::Value::Bytes(b) => Response::bulk_string(b),
pelikan_storage_seg::Value::U64(v) => {
Response::bulk_string(format!("{v}").as_bytes())
}
}
} else {
Response::null()
Expand Down
18 changes: 10 additions & 8 deletions src/storage/seg/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "seg"
description = "segment-structured in-memory storage with eager expiration"
name = "pelikan-storage-seg"
version = "0.1.0"
description = "Pelikan segment-structured storage"
authors = ["Brian Martin <brian@pelikan.io>"]

version = { workspace = true }
edition = { workspace = true }
homepage = { workspace = true }
repository = { workspace = true }
Expand All @@ -19,22 +19,24 @@ harness = false
# enables setting/checking magic strings
magic = []

# enables metrics
metrics = ["metriken"]

# metafeatures
debug = ["magic"]

# default set of enabled features
default = []
default = ["metrics"]

[dependencies]
ahash = { workspace = true }
clocksource = { workspace = true }
datatier = { path = "../datatier" }
metriken = { workspace = true }
datatier = { workspace = true }
log = { workspace = true }
metriken = { workspace = true, optional = true }
rand = { workspace = true , features = ["small_rng", "getrandom"] }
rand_chacha = { workspace = true }
rand_xoshiro = { workspace = true }
ringlog = { workspace = true }
storage-types = { path = "../types" }
thiserror = { workspace = true }

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion src/storage/seg/benches/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
// http://www.apache.org/licenses/LICENSE-2.0

use criterion::{criterion_group, criterion_main, Criterion, Throughput};
use pelikan_storage_seg::*;
use rand::RngCore;
use rand::SeedableRng;
use seg::*;

use std::time::Duration;

Expand Down
2 changes: 1 addition & 1 deletion src/storage/seg/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cargo-fuzz = true
[dependencies]
libfuzzer-sys = "0.4"

[dependencies.seg]
[dependencies.pelikan-storage-seg]
path = ".."

# Prevent this from interfering with workspaces
Expand Down
2 changes: 1 addition & 1 deletion src/storage/seg/fuzz/fuzz_targets/seg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use libfuzzer_sys::fuzz_target;

use core::time::Duration;

use seg::*;
use pelikan_storage_seg::*;

const DEBUG_PRINTS: bool = false;

Expand Down
12 changes: 6 additions & 6 deletions src/storage/seg/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl Builder {
/// `2^(N + 3)` bytes.
///
/// ```
/// use seg::Seg;
/// use pelikan_storage_seg::Seg;
///
/// // create a cache with a small hashtable that has room for ~114k items
/// // without using any overflow buckets.
Expand All @@ -53,7 +53,7 @@ impl Builder {
/// will result in a hash table that is 100% larger.
///
/// ```
/// use seg::Seg;
/// use pelikan_storage_seg::Seg;
///
/// // create a cache with a hashtable with room for ~228k items, which is
/// // about the same as using a hash power of 18, but is more tolerant of
Expand All @@ -79,7 +79,7 @@ impl Builder {
/// This includes, key, value, and per-item overheads.
///
/// ```
/// use seg::Seg;
/// use pelikan_storage_seg::Seg;
///
/// const MB: usize = 1024 * 1024;
///
Expand All @@ -102,7 +102,7 @@ impl Builder {
/// same total size.
///
/// ```
/// use seg::Seg;
/// use pelikan_storage_seg::Seg;
///
/// const MB: i32 = 1024 * 1024;
///
Expand All @@ -121,7 +121,7 @@ impl Builder {
/// for more details about each strategy.
///
/// ```
/// use seg::{Policy, Seg};
/// use pelikan_storage_seg::{Policy, Seg};
///
/// // create a cache using random segment eviction
/// let cache = Seg::builder().eviction(Policy::Random).build();
Expand All @@ -148,7 +148,7 @@ impl Builder {
/// Consumes the builder and returns a fully-allocated `Seg` instance.
///
/// ```
/// use seg::{Policy, Seg};
/// use pelikan_storage_seg::{Policy, Seg};
///
/// const MB: usize = 1024 * 1024;
///
Expand Down
Loading