Parent

Namespace

Included Modules

Class/Module Index

TDB

<code>

tdb = TDB.new("/path/to/file", flags => IO::RDWR|IO::CREAT)
tdb.store("HELLO", "world")
tdb.fetch("HELLO")  -> "world"
tdb.delete("HELLO") -> "world"

</code>

Public Class Methods

new("/path/to/file") → TDB view method source
new("/path/to/file", :hash_size => 666) → TDB
new("/path/to/file", :hash => :murmur2) → TDB
new("/path/to/file", :open_flags => IO::RDONLY) → TDB
new("/path/to/file", :tdb_flags => TDB::NOSYNC) → TDB

: Initializes a TDB context. It takes several options.

:hash_size - the number of buckets, this is the most important tuning parameter when creating large databases. This parameter only affects the creation of new databases.

:open_flags - a bit mask of IO flags passed directly to open(2), File.open-compatible flags are accepted.

:hash - any of the hashes described in Hash_Functions. This must remain the same for all clients.

:tdb_flags - a bitmask of any combination of TDB::CLEAR_IF_FIRST, TDB::INTERNAL, TDB::NOLOCK, TDB::NOMMAP, TDB::CONVERT, TDB::BIGENDIAN, TDB::NOSYNC, TDB::SEQNUM, TDB::VOLATILE, TDB::ALLOW_NESTING, TDB::DISALLOW_NESTING, TDB::INCOMPATIBLE_HASH

:mode - octal mode mask passed to open(2)

static VALUE init(int argc, VALUE *argv, VALUE self)
{
        struct tdb_context *tdb = db(self, 0);
        VALUE path, opts;
        struct open_args o;

        if (tdb)
                rb_raise(rb_eRuntimeError, "TDB already initialized");
        rb_scan_args(argc, argv, "11", &path, &opts);
        set_args(self, &o, opts);

        if (NIL_P(path))
                o.tdb_flags |= TDB_INTERNAL;
        else
                o.name = StringValuePtr(path);

        tdb = (struct tdb_context *)my_tbr(nogvl_open, &o);
        if (!tdb) {
                switch (errno) {
                case ENOMEM:
                case EMFILE:
                case ENFILE:
                        rb_gc();
                        tdb = (struct tdb_context *)my_tbr(nogvl_open, &o);
                }
                if (!tdb)
                        rb_sys_fail("tdb_open_ex");
        }
        DATA_PTR(self) = tdb;

        return self;
}

Public Instance Methods

static VALUE aref(VALUE self, VALUE key)
{
        return fetch(1, &key, self);
}
[]=(p1, p2) view method source
static VALUE store(VALUE self, VALUE key, VALUE val)
{
        return rbtdb_store(self, key, val, 0, 0);
}

clears out the database

static VALUE clear(VALUE self)
{
        struct tdb_context *tdb = db(self, 1);
        if ((int)my_tbr((rb_blocking_function_t *)tdb_wipe_all, tdb))
                my_raise(tdb);
        return self;
}
static VALUE tdbclose(VALUE self)
{
        struct tdb_context *tdb = db(self, 1);

        DATA_PTR(self) = NULL;

        if ((int)my_tbr(nogvl_close, tdb) == -1)
                rb_sys_fail("tdb_close");

        return Qnil;
}
static VALUE closed(VALUE self)
{
        struct tdb_context *tdb = db(self, 0);

        return tdb ? Qfalse : Qtrue;
}
delete(*args) view method source
static VALUE delete(int argc, VALUE *argv, VALUE self)
{
        VALUE rc = fetch(argc, argv, self);

        if (! NIL_P(rc))
                if (nuke(self, argv[0]) == Qfalse)
                        return Qnil;
        return rc;
}
static VALUE each(VALUE self)
{
        struct traverse_args t;

        t.tdb = db(self, 1);
        t.state = 0;

        my_tbr(nogvl_traverse, &t);
        if (t.state)
                rb_jump_tag(t.state);
        return self;
}
fetch(p1, p2 = v2) view method source
static VALUE fetch(int argc, VALUE *argv, VALUE self)
{
        struct fetch_parse_args f;
        VALUE key;

        rb_scan_args(argc, argv, "11", &key, &f.value);
        if (NIL_P(f.value)) {
                f.value = rb_str_new(0, 0);
        } else {
                StringValue(f.value);
                rb_str_set_len(f.value, 0);
        }

        f.tdb = db(self, 1);
        TO_TDB_DATA(f.as.key, key);

        return my_tbr(nogvl_parse_record, &f);
}
has_key?(p1) view method source
static VALUE has_key(VALUE self, VALUE key)
{
        struct exists_args e;

        e.tdb = db(self, 1);
        TO_TDB_DATA(e.key, key);

        return my_tbr(nogvl_exists, &e);
}
include?(p1) view method source
static VALUE has_key(VALUE self, VALUE key)
{
        struct exists_args e;

        e.tdb = db(self, 1);
        TO_TDB_DATA(e.key, key);

        return my_tbr(nogvl_exists, &e);
}
insert(p1, p2) view method source
static VALUE insert(VALUE self, VALUE key, VALUE val)
{
        return rbtdb_store(self, key, val, TDB_INSERT, 1);
}
insert!(p1, p2) view method source
static VALUE insert_bang(VALUE self, VALUE key, VALUE val)
{
        return rbtdb_store(self, key, val, TDB_INSERT, 0);
}
static VALUE has_key(VALUE self, VALUE key)
{
        struct exists_args e;

        e.tdb = db(self, 1);
        TO_TDB_DATA(e.key, key);

        return my_tbr(nogvl_exists, &e);
}
static VALUE lockall(VALUE self)
{
        struct tdb_context *tdb = db(self, 1);
        if ((int)my_tbr((rb_blocking_function_t *)tdb_lockall, tdb))
                my_raise(tdb);

        return Qtrue;
}
lockall_mark() view method source
static VALUE lockall_mark(VALUE self)
{
        struct tdb_context *tdb = db(self, 1);
        if ((int)my_tbr((rb_blocking_function_t *)tdb_lockall_mark, tdb))
                my_raise(tdb);
        return Qtrue;
}
lockall_read() view method source
static VALUE lockall_read(VALUE self)
{
        struct tdb_context *tdb = db(self, 1);
        if ((int)my_tbr((rb_blocking_function_t *)tdb_lockall_read, tdb))
                my_raise(tdb);
        return Qtrue;
}
lockall_unmark() view method source
static VALUE lockall_unmark(VALUE self)
{
        struct tdb_context *tdb = db(self, 1);
        if ((int)my_tbr((rb_blocking_function_t *)tdb_lockall_unmark, tdb))
                my_raise(tdb);
        return Qtrue;
}
member?(p1) view method source
static VALUE has_key(VALUE self, VALUE key)
{
        struct exists_args e;

        e.tdb = db(self, 1);
        TO_TDB_DATA(e.key, key);

        return my_tbr(nogvl_exists, &e);
}
modify(p1, p2) view method source
static VALUE modify(VALUE self, VALUE key, VALUE val)
{
        return rbtdb_store(self, key, val, TDB_MODIFY, 1);
}
modify!(p1, p2) view method source
static VALUE modify_bang(VALUE self, VALUE key, VALUE val)
{
        return rbtdb_store(self, key, val, TDB_MODIFY, 0);
}
static VALUE nuke(VALUE self, VALUE key)
{
        struct delete_args d;

        d.tdb = db(self, 1);
        TO_TDB_DATA(d.key, key);

        return my_tbr(nogvl_delete, &d);
}

repacks a database to reduce fragmentation, available with tdb 1.2.x+

static VALUE repack(VALUE self)
{
        struct tdb_context *tdb = db(self, 1);
        if ((int)my_tbr((rb_blocking_function_t *)tdb_repack, tdb))
                my_raise(tdb);
        return self;
}
store(p1, p2) view method source
static VALUE store(VALUE self, VALUE key, VALUE val)
{
        return rbtdb_store(self, key, val, 0, 0);
}
threadsafe!() view method source

makes the current TDB object thread-safe (DANGEROUS) Do not use this method yet, it has problems

threadsafe?() view method source

will return true when TDB::MT is included in TDB or the TDB object is extended by TDB

trylockall() view method source
static VALUE trylockall(VALUE self)
{
        struct tdb_context *tdb = db(self, 1);
        void *fn = tdb_lockall_nonblock;

        if ((int)my_tbr((rb_blocking_function_t *)fn, tdb)) {
                if (tdb_error(tdb) == TDB_ERR_LOCK)
                        return Qfalse;
                my_raise(tdb);
        }
        return Qtrue;
}
trylockall_read() view method source
static VALUE trylockall_read(VALUE self)
{
        struct tdb_context *tdb = db(self, 1);
        void *fn = tdb_lockall_read_nonblock;
        if ((int)my_tbr((rb_blocking_function_t *)fn, tdb)) {
                if (tdb_error(tdb) == TDB_ERR_LOCK)
                        return Qfalse;
                my_raise(tdb);
        }
        return Qtrue;
}
unlockall() view method source
static VALUE unlockall(VALUE self)
{
        struct tdb_context *tdb = db(self, 1);
        if ((int)my_tbr((rb_blocking_function_t *)tdb_unlockall, tdb))
                my_raise(tdb);
        return Qtrue;
}
unlockall_read() view method source
static VALUE unlockall_read(VALUE self)
{
        struct tdb_context *tdb = db(self, 1);
        if ((int)my_tbr((rb_blocking_function_t *)tdb_unlockall_read, tdb))
                my_raise(tdb);
        return Qtrue;
}

Originally generated with the Darkfish Rdoc Generator 2, modified by wrongdoc.