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

Using RKV inside struct implementation #205

Open
janus opened this issue Sep 20, 2020 · 4 comments
Open

Using RKV inside struct implementation #205

janus opened this issue Sep 20, 2020 · 4 comments

Comments

@janus
Copy link

janus commented Sep 20, 2020

The below code fails once it calls commit function. What is it that I am not doing well here. Looks like I am omitting something important

pub struct Datastore {
    pub store: SingleStore<SafeModeDatabase>,
    pub env: Rkv<SafeModeEnvironment>,
}

impl Datastore {
    pub fn new(file_name: &str, db_name: &str) -> Datastore {
        let root = Builder::new().prefix(file_name).tempdir().unwrap();
        fs::create_dir_all(root.path()).unwrap();
        let path = root.path();
        let env = Rkv::new::<SafeMode>(path).expect("new succeeded");
        let store = env
            .open_single(db_name, StoreOptions::create())
            .expect("opened");

        //let store = env.open_single(db_name, StoreOptions::create()).unwrap();

        Datastore {
            store,
            env: env,
        }

        // unimplemented!();
    }

    pub fn insert(&mut self, x: &TxOutpoint, address: &str) {
        let mut writer = self.env.write().unwrap();

        let tx = bincode::serialize(&x).unwrap();
        self.store
            .put(&mut writer, &tx, &Value::Str(address))
            .unwrap();
        writer.commit().unwrap();
    }

The call that leads to this issue:

    let mut datastore = Datastore::new("foo", "deal");
    let dd: [u8; 32] = [
        90, 34, 12, 44, 1, 3, 4, 1, 4, 5, 12, 90, 2, 9, 3, 0, 0, 0, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3,
        1, 2, 3, 1,
    ];
    let ddx = TxOutpoint {
        txid: dd,
        index: 90,
    };
    datastore.insert(&ddx, "offor");

The error message:
thread 'main' panicked at 'calledResult::unwrap()on anErrvalue: IoError(Os { code: 2, kind: NotFound, message: "No such file or directory" })', src/block/db/kv.rs:56:25 note: run withRUST_BACKTRACE=1environment variable to display a backtrace
The commit function is at line 56

@linabutler
Copy link
Member

Hi there! Could you please post the error you're seeing?

@janus
Copy link
Author

janus commented Sep 21, 2020

@linacambridge I have added error message.

@janus
Copy link
Author

janus commented Oct 23, 2020

No help yet. I need support.

@victorporof
Copy link
Contributor

The error is "No such file or directory", which means that the destination directory does not exist when calling commit. Can you confirm that the directory exists on disk before you call the commit function? Are you using rkv from multiple threads?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants