Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
al8n committed Sep 27, 2024
1 parent 5e2cbe2 commit c996446
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 3 deletions.
27 changes: 27 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
codecov:
require_ci_to_pass: false

ignore:
- "**/integration/"
- "**/examples/"
- "**/benches/"
- "src/error.rs"

coverage:
status:
project: # Overall project status
default:
target: auto
if_not_found: success
only_pulls: false
patch: # Status for the patch in pull requests
default:
target: auto
if_not_found: success
only_pulls: true
changes: false # Whether to comment on the coverage changes in pull requests

comment:
layout: "header, diff, files, footer"
behavior: default
require_changes: false
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ English | [简体中文][zh-cn-url]

## Introduction

This crate is designed for databases based on the WiscKey architecture, which separates the storage of keys from values. Consequently, this crate focuses exclusively on managing values. Users are responsible for storing the value pointers returned by the `write*` APIs.
This crate is designed for databases based on the WiscKey architecture, which separates the storage of keys from values. Consequently, this crate focuses exclusively on managing values. Users are responsible for storing the `ValuePointer`s returned by the `write*` APIs.

### Features

Expand Down Expand Up @@ -52,6 +52,10 @@ This crate offers a robust solution for managing value storage in WiscKey-based
valog = { version = "0.1", default-features = false, features = ["alloc"] }
```

## Example

Please see [examples](./examples/).

#### License

`valog` is under the terms of both the MIT license and the
Expand Down
92 changes: 92 additions & 0 deletions examples/concurrent_rw.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
use std::sync::{Arc, Mutex};
use valog::{
sync::ValueLog, Builder, LogReader, LogReaderExt, LogWriter, LogWriterExt, VacantBuffer,
ValueBuilder,
};
use wg::WaitGroup;

fn main() {
const N: u32 = 500;

let (tx, rx) = crossbeam_channel::bounded(N as usize);
let data = Arc::new(Mutex::new(Vec::new()));
let wg = WaitGroup::new();

let dir = ::tempfile::tempdir().unwrap();
let p = dir.path().join("example.vlog");

let l = unsafe {
Builder::new()
.with_capacity(1024 * 1024)
.with_create_new(true)
.with_read(true)
.with_write(true)
.map_mut::<ValueLog, _>(&p, 0)
.unwrap()
};

// concurrent write
(0..N).for_each(|i| {
let l = l.clone();
let tx = tx.clone();
let wg = wg.add(1);
std::thread::spawn(move || {
let val = i.to_string();
let vp = match i % 6 {
0 => l.insert(val.as_bytes()).unwrap(),
1 => l.insert_generic::<String>(&val).unwrap(),
2 => l
.insert_with(ValueBuilder::new(
val.len() as u32,
|buf: &mut VacantBuffer<'_>| buf.put_slice(val.as_bytes()),
))
.unwrap(),
3 => l.insert_tombstone(val.as_bytes()).unwrap(),
4 => l.insert_generic_tombstone::<String>(&val).unwrap(),
5 => l
.insert_tombstone_with(ValueBuilder::new(
val.len() as u32,
|buf: &mut VacantBuffer<'_>| buf.put_slice(val.as_bytes()),
))
.unwrap(),
_ => unreachable!(),
};

tx.send(vp).unwrap();
wg.done();
});
});

// concurrent read
(0..N).for_each(|i| {
let l = l.clone();
let rx = rx.clone();
let data = data.clone();

let wg = wg.add(1);
std::thread::spawn(move || {
for vp in rx {
let val = if i % 2 == 0 {
let bytes = l.read(vp.offset(), vp.size()).unwrap();
let val: u32 = std::str::from_utf8(bytes).unwrap().parse().unwrap();
val
} else {
let bytes = unsafe { l.read_generic::<String>(vp.offset(), vp.size()).unwrap() };
let val: u32 = bytes.parse().unwrap();
val
};

data.lock().unwrap().push(val);
}

wg.done();
});
});

drop(tx);
wg.wait();

let mut data = data.lock().unwrap();
data.sort_unstable();
assert_eq!(data.as_slice(), &(0..N).collect::<Vec<_>>());
}
1 change: 0 additions & 1 deletion examples/foo.rs

This file was deleted.

1 change: 0 additions & 1 deletion tests/foo.rs

This file was deleted.

0 comments on commit c996446

Please sign in to comment.