generated from al8n/template-rs
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
124 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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<_>>()); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.