Skip to content

Commit 038fa15

Browse files
authored
Added mrecordlog_cli. (#64)
* Added mrecordlog_cli. * blop
1 parent 3e5f648 commit 038fa15

File tree

7 files changed

+112
-14
lines changed

7 files changed

+112
-14
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
workspace = { members = ["mrecordlog_cli"] }
12
[package]
23
name = "mrecordlog"
34
version = "0.4.0"

Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# --- Builder
2+
3+
FROM rust:bullseye AS bin-builder
4+
5+
COPY . /mrecordlog
6+
7+
WORKDIR /mrecordlog/mrecordlog_cli
8+
9+
RUN --mount=type=cache,target=/usr/local/cargo/registry \
10+
--mount=type=cache,target=/mrecordlog/target \
11+
cargo build --release --bin mrecordlog && \
12+
ls /mrecordlog/target/release && \
13+
mkdir -p /quickwit/bin && \
14+
mv /mrecordlog/target/release/mrecordlog /quickwit/bin/mrecordlog
15+
16+
# --- ACTUAL image.
17+
18+
FROM debian:bullseye-slim AS quickwit
19+
20+
LABEL org.opencontainers.image.title="Quickwit MRecordlog utils CLI"
21+
LABEL maintainer="Quickwit, Inc. <hello@quickwit.io>"
22+
LABEL org.opencontainers.image.vendor="Quickwit, Inc."
23+
LABEL org.opencontainers.image.licenses="AGPL-3.0"
24+
25+
WORKDIR /quickwit
26+
27+
COPY --from=bin-builder /quickwit/bin/mrecordlog /usr/local/bin/mrecordlog
28+
29+
ENTRYPOINT ["mrecordlog"]

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ fmt:
88
fix: fmt
99
@echo "Running cargo clippy --fix"
1010
cargo clippy --fix --all-features --allow-dirty --allow-staged
11+
12+
push:
13+
docker buildx build --platform linux/amd64 -t quickwit/mrecordlog:0.1 . --push
14+

mrecordlog_cli/Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "mrecordlog_cli"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
mrecordlog = { path = "../" }
10+
anyhow = "*"
11+
structopt = "0.3"
12+
13+
[[bin]]
14+
name = "mrecordlog"
15+
path = "src/main.rs"

mrecordlog_cli/src/main.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
use std::path::{Path, PathBuf};
2+
3+
use mrecordlog::MultiRecordLog;
4+
use structopt::StructOpt;
5+
6+
#[derive(Debug, StructOpt)]
7+
enum Command {
8+
Summary {
9+
#[structopt(short = "f", default_value = "./wal")]
10+
wal_path: PathBuf,
11+
},
12+
Read {
13+
#[structopt(short = "f", default_value = "./wal")]
14+
wal_path: PathBuf,
15+
queue_name: String,
16+
},
17+
}
18+
19+
fn run_summary(path: &Path) -> anyhow::Result<()> {
20+
let multi_record_log = MultiRecordLog::open(path)?;
21+
let summary = multi_record_log.summary();
22+
for (queue, summary) in summary.queues {
23+
println!("{}", queue);
24+
println!("{summary:?}");
25+
}
26+
Ok(())
27+
}
28+
29+
fn run_read_queue(path: &Path, queue_name: &str) -> anyhow::Result<()> {
30+
let multi_record_log = MultiRecordLog::open(path)?;
31+
for record in multi_record_log.range(queue_name, ..)? {
32+
let Ok(payload_str) = std::str::from_utf8(&record.payload) else {
33+
eprintln!("Payload is not utf8: {:?}", record.payload);
34+
continue;
35+
};
36+
println!("{payload_str}");
37+
}
38+
Ok(())
39+
}
40+
41+
fn main() -> anyhow::Result<()> {
42+
let command = Command::from_args();
43+
match command {
44+
Command::Summary { wal_path } => {
45+
run_summary(&wal_path)?;
46+
}
47+
Command::Read {
48+
queue_name,
49+
wal_path,
50+
} => {
51+
run_read_queue(&wal_path, &queue_name)?;
52+
}
53+
}
54+
Ok(())
55+
}

src/error.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ impl From<MissingQueue> for AppendError {
7676
#[derive(Debug)]
7777
pub struct MissingQueue(pub String);
7878

79+
impl std::fmt::Display for MissingQueue {
80+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
81+
write!(f, "Missing queue: {}", self.0)
82+
}
83+
}
84+
85+
impl std::error::Error for MissingQueue {}
86+
7987
#[derive(Error, Debug)]
8088
pub enum ReadRecordError {
8189
#[error("Io error: {0}")]

src/main.rs

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)