Exemplo n.º 1
0
 NuDBBackend (int keyBytes, Section const& keyValues,
     Scheduler& scheduler, beast::Journal journal)
     : journal_ (journal)
     , keyBytes_ (keyBytes)
     , name_ (get<std::string>(keyValues, "path"))
     , deletePath_(false)
     , scheduler_ (scheduler)
 {
     if (name_.empty())
         Throw<std::runtime_error> (
             "nodestore: Missing path in NuDB backend");
     auto const folder = boost::filesystem::path (name_);
     boost::filesystem::create_directories (folder);
     auto const dp = (folder / "nudb.dat").string();
     auto const kp = (folder / "nudb.key").string ();
     auto const lp = (folder / "nudb.log").string ();
     using beast::nudb::make_salt;
     api::create (dp, kp, lp,
         currentType, make_salt(), keyBytes,
             beast::nudb::block_size(kp),
         0.50);
     try
     {
         if (! db_.open (dp, kp, lp, arena_alloc_size))
             Throw<std::runtime_error> ("nodestore: open failed");
         if (db_.appnum() != currentType)
             Throw<std::runtime_error> ("nodestore: unknown appnum");
     }
     catch (std::exception const& e)
     {
         // log and terminate?
         std::cerr << e.what();
         std::terminate();
     }
 }
Exemplo n.º 2
0
 void
 verify() override
 {
     auto const dp = db_.dat_path();
     auto const kp = db_.key_path();
     auto const lp = db_.log_path();
     db_.close();
     api::verify (dp, kp);
     db_.open (dp, kp, lp,
         arena_alloc_size);
 }
Exemplo n.º 3
0
 void
 for_each (std::function <void(std::shared_ptr<NodeObject>)> f) override
 {
     auto const dp = db_.dat_path();
     auto const kp = db_.key_path();
     auto const lp = db_.log_path();
     //auto const appnum = db_.appnum();
     db_.close();
     api::visit (dp,
         [&](
             void const* key, std::size_t key_bytes,
             void const* data, std::size_t size)
         {
             DecodedBlob decoded (key, data, size);
             if (! decoded.wasOk ())
                 return false;
             f (decoded.createObject());
             return true;
         });
     db_.open (dp, kp, lp,
         arena_alloc_size);
 }