Exemple #1
0
        int hot_optimize(const Slice &left, const Slice &right, OptimizeCallback callback, uint64_t *loops_run = NULL) const {
            DBT ldbt = left.dbt();
            DBT rdbt = right.dbt();

            class WrappedOptimizeCallback {
                OptimizeCallback &_oc;
                size_t _loops;

            public:
                WrappedOptimizeCallback(OptimizeCallback &oc)
                    : _oc(oc),
                      _loops(0)
                {}

                static int call(void *extra, float progress) {
                    WrappedOptimizeCallback *e = static_cast<WrappedOptimizeCallback *>(extra);
                    return e->_oc(progress, ++e->_loops);
                }
            } woc(callback);

            uint64_t dummy;
            return _db->hot_optimize(_db, &ldbt, &rdbt,
                                     &WrappedOptimizeCallback::call, &woc,
                                     loops_run == NULL ? &dummy : loops_run);
        }
Exemple #2
0
        DB open(const DBEnv &env, const DBTxn &txn, const char *fname, const char *dbname, DBTYPE dbtype, uint32_t flags, int mode) const {
            ::DB *db;
            int r = db_create(&db, env.env(), 0);
            handle_ft_retval(r);

            if (_readpagesize) {
                r = db->set_readpagesize(db, _readpagesize);
                handle_ft_retval(r);
            }

            if (_compression_method >= 0) {
                r = db->set_compression_method(db, TOKU_COMPRESSION_METHOD(_compression_method));
                handle_ft_retval(r);
            }

            if (_fanout) {
                r = db->set_fanout(db, _fanout);
                handle_ft_retval(r);
            }

            if (_memcmp_magic) {
                r = db->set_memcmp_magic(db, _memcmp_magic);
                handle_ft_retval(r);
            }

            if (_pagesize) {
                r = db->set_pagesize(db, _pagesize);
                handle_ft_retval(r);
            }

            const DBTxn *txnp = &txn;
            DBTxn writeTxn;
            if (txn.is_read_only()) {
                writeTxn = DBTxn(env, DB_SERIALIZABLE);
                txnp = &writeTxn;
            }

            r = db->open(db, txnp->txn(), fname, dbname, dbtype, flags, mode);
            handle_ft_retval(r);

            if (!_descriptor.empty()) {
                DBT desc = _descriptor.dbt();
                r = db->change_descriptor(db, txnp->txn(), &desc, DB_UPDATE_CMP_DESCRIPTOR);
                handle_ft_retval(r);
            }

            if (txn.is_read_only()) {
                writeTxn.commit();
            }

            return DB(db, true);
        }
Exemple #3
0
        int getf_set(const DBTxn &txn, const Slice &key, int flags, Callback cb) const {
            class WrappedCallback {
                Callback &_cb;
            public:
                WrappedCallback(Callback &cb_)
                    : _cb(cb_)
                {}

                static int call(const DBT *key_, const DBT *val_, void *extra) {
                    WrappedCallback *wc = static_cast<WrappedCallback *>(extra);
                    return wc->call(key_, val_);
                }

                int call(const DBT *key_, const DBT *val_) {
                    return _cb(Slice(*key_), Slice(*val_));
                }
            } wc(cb);

            DBT kdbt = key.dbt();
            return _db->getf_set(_db, txn.txn(), flags, &kdbt, &WrappedCallback::call, &wc);
        }
Exemple #4
0
 int put(const DBTxn &txn, const Slice &key, const Slice &val, int flags=0) const {
     DBT kdbt = key.dbt();
     DBT vdbt = val.dbt();
     return put(txn, &kdbt, &vdbt, flags);
 }
Exemple #5
0
 int del(const DBTxn &txn, const Slice &key, int flags=0) const {
     DBT kdbt = key.dbt();
     return _db->del(_db, txn.txn(), &kdbt, flags);
 }
Exemple #6
0
 int update(const DBTxn &txn, const Slice &key, const Slice &extra, int flags=0) const {
     DBT kdbt = key.dbt();
     DBT edbt = extra.dbt();
     return update(txn, &kdbt, &edbt, flags);
 }