/
README
119 lines (90 loc) · 3.87 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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