fdb-rs / fdb

FoundationDB client API for Tokio
https://fdb-rs.github.io/
Apache License 2.0
44 stars 2 forks source link

Can't open database #26

Closed fredrik-jansson-se closed 2 years ago

fredrik-jansson-se commented 2 years ago

Hey,

first, thanks for making this available!

I'm having some issues getting started, my code looks like this:

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    pretty_env_logger::init();
    let c_path = std::path::Path::new("/etc/foundationdb/fdb.cluster");
    let db = fdb::open_database(c_path)?;
    Ok(())
}

But if I try to run it, I get this error:

Error: FdbError { error_code: 2008 }

Can't figure out what I'm doing wrong, so any help appreciated.

Cargo.toml

[package]
name = "fdb-test"
version = "0.1.0"
edition = "2021"

[dependencies]
anyhow = "1.0.57"
fdb = { version = "0.3.1", features = ["fdb-7_1"] }
pretty_env_logger = "0.4.0"
tokio = { version = "1.18.2", features = ["full"] }

status

fdbcli --exec status
Using cluster file `/etc/foundationdb/fdb.cluster'.

Configuration:
  Redundancy mode        - single
  Storage engine         - memory-2
  Coordinators           - 1
  Usable Regions         - 1

Cluster:
  FoundationDB processes - 1
  Zones                  - 1
  Machines               - 1
  Memory availability    - 8.0 GB per process on machine with least available
  Fault Tolerance        - 0 machines
  Server time            - 05/10/22 18:48:22

Data:
  Replication health     - Healthy
  Moving data            - 0.000 GB
  Sum of key-value sizes - 0 MB
  Disk space used        - 105 MB

Operating space:
  Storage server         - 1.0 GB free on most full server
  Log server             - 547.0 GB free on most full server

Workload:
  Read rate              - 17 Hz
  Write rate             - 0 Hz
  Transactions started   - 5 Hz
  Transactions committed - 0 Hz
  Conflict rate          - 0 Hz

Backup and DR:
  Running backups        - 0
  Running DRs            - 0

Client time: 05/10/22 18:48:22

version

fdbserver -v
FoundationDB 7.1 (v7.1.4)
source version cb750b1859ab68993ee2c2991c9e85fc125eca2b
protocol fdb00b071010000
fredrik-jansson-se commented 2 years ago

Feeling stupid, but I had missed:

    unsafe {
        fdb::select_api_version(fdb::FDB_API_VERSION as _);
        fdb::start_network();
    }

Can I suggest adding that to the documentation?

fredrik-jansson-se commented 2 years ago

Added PR for minimal example in the docs: https://github.com/fdb-rs/fdb/pull/27

rajivr commented 2 years ago

Thanks @fredrik-jansson-se for the suggestion. I've implemented a minimal example in #28 and also credited you as the co-author of the commit.

The main difference between your suggestion and the merged PR is that I've avoided using the #[tokio::main] macro.

While there is nothing wrong in your code, when developing FoundationDB client application, its important for beginners to be aware of the presence of the network thread. FoundationDB does not have a stable client/server wire protocol like other databases do. Instead the stable API happens at the C API level.

The client thread does a lot of things for us under the hood and is an important aspect of FoundationDB. I've deliberately separated out the management of the client thread in the documentation so that by the time users gain familiarity with the rest of the API, I would have subtly nudged them into understand the importance of the client thread as well.

Thanks again for the PR.

fredrik-jansson-se commented 2 years ago

Hey, all good, thank you!!