Exemplo n.º 1
0
    void
    storeBatch (Batch const& batch)
    {
        rocksdb::WriteBatch wb;

        EncodedBlob encoded;

        for (auto const& e : batch)
        {
            encoded.prepare (e);

            wb.Put (
                rocksdb::Slice (reinterpret_cast <char const*> (
                    encoded.getKey ()), m_keyBytes),
                rocksdb::Slice (reinterpret_cast <char const*> (
                    encoded.getData ()), encoded.getSize ()));
        }

        rocksdb::WriteOptions const options;

        auto ret = m_db->Write (options, &wb);

        if (!ret.ok ())
            throw std::runtime_error ("storeBatch failed: " + ret.ToString());
    }
Exemplo n.º 2
0
 void
 do_insert (std::shared_ptr <NodeObject> const& no)
 {
     EncodedBlob e;
     e.prepare (no);
     db_.insert (e.getKey(),
         e.getData(), e.getSize());
 }
Exemplo n.º 3
0
    void storeBatch (Batch const& batch)
    {
        leveldb::WriteBatch wb;

        EncodedBlob encoded;

        BOOST_FOREACH (NodeObject::ref object, batch)
        {
            encoded.prepare (object);

            wb.Put (
                leveldb::Slice (reinterpret_cast <char const*> (
                    encoded.getKey ()), m_keyBytes),
                leveldb::Slice (reinterpret_cast <char const*> (
                    encoded.getData ()), encoded.getSize ()));
        }
Exemplo n.º 4
0
    // Checks encoding/decoding blobs
    void testBlobs (int64 const seedValue)
    {
        beginTestCase ("encoding");

        Batch batch;
        createPredictableBatch (batch, 0, numObjectsToTest, seedValue);

        EncodedBlob encoded;
        for (int i = 0; i < batch.size (); ++i)
        {
            encoded.prepare (batch [i]);

            DecodedBlob decoded (encoded.getKey (), encoded.getData (), encoded.getSize ());

            expect (decoded.wasOk (), "Should be ok");

            if (decoded.wasOk ())
            {
                NodeObject::Ptr const object (decoded.createObject ());

                expect (batch [i]->isCloneOf (object), "Should be clones");
            }
        }
    }