tikv / agatedb

A persistent key-value storage in rust.
Apache License 2.0
835 stars 77 forks source link

一个我搞不定的错误 No such file or directory (os error 2) #179

Closed gcxfd closed 2 years ago

gcxfd commented 2 years ago

代码见我的fork的cli分支 https://github.com/rmw-lib/agatedb/tree/cli/examples

我的想法是给 agatedb 写一个命令行工具,也可以当做学习agatedb的demo代码

代码是在 https://github.com/tikv/agatedb/pull/178 (simple agatedb get put) 基础上继续开发的

但是目前卡在了这个错误上 No such file or directory (os error 2),因为这个错误没代码行提示,我也搞不清楚为啥出错

截图如下

image

另外,每次运行 /tmp/adb 下面都会多一个 .mem文件,感觉这也不太正常

gcxfd commented 2 years ago

加了 RUST_BACKTRACE , 看起来是open的时候就报错了,但是还是没法定位哪儿导致的错误

RUST_BACKTRACE=1 cargo +nightly run -- /tmp/adb put 1 2
   Compiling agatedb v0.1.0 (/Users/z/rmw/rmw_feed/rust/lib/agatedb)
   Compiling adb v0.1.0 (/Users/z/rmw/rmw_feed/rust/lib/agatedb/examples/adb)
    Finished dev [unoptimized + debuginfo] target(s) in 3.18s
     Running `/Users/z/rmw/rmw_feed/rust/lib/agatedb/target/debug/adb /tmp/adb put 1 2`
[src/db.rs:223] &path = "/tmp/adb/00001.mem"
[src/db.rs:223] &path = "/tmp/adb/00002.mem"
Error: IO error: No such file or directory (os error 2)

Caused by:
    No such file or directory (os error 2)

Stack backtrace:
   0: std::backtrace_rs::backtrace::libunwind::trace
             at /rustc/27eb6d7018e397cf98d51c205e3576951d766323/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   1: std::backtrace_rs::backtrace::trace_unsynchronized
             at /rustc/27eb6d7018e397cf98d51c205e3576951d766323/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2: std::backtrace::Backtrace::create
             at /rustc/27eb6d7018e397cf98d51c205e3576951d766323/library/std/src/backtrace.rs:328:13
   3: std::backtrace::Backtrace::capture
             at /rustc/27eb6d7018e397cf98d51c205e3576951d766323/library/std/src/backtrace.rs:296:9
   4: anyhow::error::<impl core::convert::From<E> for anyhow::Error>::from
             at /Users/z/.cargo/registry/src/rsproxy.cn-8f6827c7555bfaf8/anyhow-1.0.58/src/error.rs:533:25
   5: <core::result::Result<T,F> as core::ops::try_trait::FromResidual<core::result::Result<core::convert::Infallible,E>>>::from_residual
             at /rustc/27eb6d7018e397cf98d51c205e3576951d766323/library/core/src/result.rs:2125:27
   6: adb::main
             at ./main.rs:46:9
   7: core::ops::function::FnOnce::call_once
             at /rustc/27eb6d7018e397cf98d51c205e3576951d766323/library/core/src/ops/function.rs:248:5
   8: std::sys_common::backtrace::__rust_begin_short_backtrace
             at /rustc/27eb6d7018e397cf98d51c205e3576951d766323/library/std/src/sys_common/backtrace.rs:122:18
   9: std::rt::lang_start::{{closure}}
             at /rustc/27eb6d7018e397cf98d51c205e3576951d766323/library/std/src/rt.rs:145:18
  10: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once
             at /rustc/27eb6d7018e397cf98d51c205e3576951d766323/library/core/src/ops/function.rs:280:13
  11: std::panicking::try::do_call
             at /rustc/27eb6d7018e397cf98d51c205e3576951d766323/library/std/src/panicking.rs:492:40
  12: std::panicking::try
             at /rustc/27eb6d7018e397cf98d51c205e3576951d766323/library/std/src/panicking.rs:456:19
  13: std::panic::catch_unwind
             at /rustc/27eb6d7018e397cf98d51c205e3576951d766323/library/std/src/panic.rs:137:14
  14: std::rt::lang_start_internal::{{closure}}
             at /rustc/27eb6d7018e397cf98d51c205e3576951d766323/library/std/src/rt.rs:128:48
  15: std::panicking::try::do_call
             at /rustc/27eb6d7018e397cf98d51c205e3576951d766323/library/std/src/panicking.rs:492:40
  16: std::panicking::try
             at /rustc/27eb6d7018e397cf98d51c205e3576951d766323/library/std/src/panicking.rs:456:19
  17: std::panic::catch_unwind
             at /rustc/27eb6d7018e397cf98d51c205e3576951d766323/library/std/src/panic.rs:137:14
  18: std::rt::lang_start_internal
             at /rustc/27eb6d7018e397cf98d51c205e3576951d766323/library/std/src/rt.rs:128:20
  19: std::rt::lang_start
             at /rustc/27eb6d7018e397cf98d51c205e3576951d766323/library/std/src/rt.rs:144:17
  20: _main
GanZiheng commented 2 years ago
  1. 第一个问题应该来源于没有设置 AgateOptions 中的 value_dir
  2. 第二个情况是符合预期的,每次都会新增一个 mem 文件作为 memtable,其他的都是 immutable memtable。
gcxfd commented 2 years ago

可以了,多谢。 就是感觉每次新增一个 mem 文件作为 memtable,如果做桌面端应用,长期下来会导致文件很多,最好能有一个后台进程compact下

BusyJay commented 2 years ago

For new questions, perhaps it's better send it to Discussions.