Home > cdberl

cdberl

Cdberl is a project mainly written in Erlang, it's free.

Transactions with CouchDB via mnesia and http

Erlang API for CouchDB and at the same time transactions on top of CouchDB by using mnesia. More or less, cdberl adds CouchDB as a backend to mnesia with it's benefits: scalable, reliable, large storage and so on.

Of course the cdberl library can be used directly with CouchDB for simple access and by inserting records right into CouchDB.

Look at this library as a proof-of-concept.

Background

- needed new backend for current DBMS. (dets has it's limitations like a 
    2GB limit per table)
- needed ACID transactions and locking.
- chosing mnesia with mnesiaex would lead to a transparent layer and the 
    current implementation wouldn't need so much refactoring

Dependencies:

    Erlang/OTP R12B-5
    CouchDB 0.90 and newer
    Mnesiaex  http://code.google.com/p/mnesiaex/

Installation
  • Install Mnesiaex - there are an excellent tutorial on it's site
  • Install CouchDB
  • Install cdberl: Put the cdberl lib in a path accessible by erlang either with: erl -pa <path-to-cdberl/ebin> or just put cdberl in erlang/lib/. Compile with: erlc -o ebin src/*.erl

Check out the wiki for more information: http://wiki.github.com/RCardell/cdberl

Example

Erlang (BEAM) emulator version 5.6.5 [source] [64-bit] [smp:4] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.6.5 (abort with ^G)

(rc@sillhaj)1> cdberl:start(). ok

(rc@sillhaj)2> mnesia:start(). ok

(rc@sillhaj)3> mnesia:change_table_copy_type (schema, node (), disc_copies). {atomic,ok}

%% create a table (rc@sillhaj)4>mnesia:create_table(testtable,[{ type, { external, ordered_set, cdb_tab } }, { external_copies, [ node () ]}]). {atomic,ok}

%% read and write a record (rc@sillhaj)5>mnesia:dirty_write({testtable, foo, {an_atom, 1234, "string", {tuple}}}), mnesia:dirty_read(testtable, foo). [{testtable, foo, {an_atom, 1234, "string", {tuple}}}]

%% a simple write test, only for fun (rc@sillhaj)6>f (), Start = now (), [ mnesia:dirty_write ({ testtab, N, N }) || N <- lists:seq (1, 10000) ], End = now (), timer:now_diff (End, Start). 38335037

%% a simple read test, only for fun (rc@sillhaj)7>f (), Start = now (), [ mnesia:dirty_read(testtable, N) || N <- lists:seq (1, 10000) ] ,End = now (), timer:now_diff (End, Start). 11970713

%% writing and reading some Erlang terms: (rc@sillhaj)8> Record = {testtable, term_test, [an_atom, "a_list", {a_tuple}, 1234567890, ["a_complex",{[42],{[42]}},-1234567890]]}. ok (rc@sillhaj)9>mnesia:dirty_write(Record). ok (rc@sillhaj)10>[Record] =:= mnesia:dirty_read(testtable, term_test). true

(rc@sillhaj)15> mnesia:info(). ---> Processes holding locks <--- ---> Processes waiting for locks <--- ---> Participant transactions <--- ---> Coordinator transactions <--- ---> Uncertain transactions <--- ---> Active tables <--- testtable : with 10002 records occupying 5553469 words of mem schema : with 3 records occupying 651 words of mem ===> System info in version "4.4.7.6", debug level = none <=== opt_disc. Directory "/home/cardell/development/git/cdberl/Mnesia.nonode@nohost" is used. use fallback at restart = false running db nodes = [nonode@nohost] stopped db nodes = [] master node tables = [] remote = [] ram_copies = [] disc_copies = [schema] disc_only_copies = [] external_copies = [testtable] [{nonode@nohost,disc_copies}] = [schema] [{nonode@nohost,{external_copies,cdb_tab}}] = [testtable] 4 transactions committed, 0 aborted, 0 restarted, 1 logged to disc 0 held locks, 0 in queue; 0 local transactions, 0 remote 0 transactions waits for other nodes: [] ok

^C BREAK: (a)bort (c)ontinue (p)roc info (i)nfo (l)oaded (v)ersion (k)ill (D)b-tables (d)istribution a


There are some screenshots in the download section and some examples in src/examples.erl

Previous:CRM-ROR851A