How do I integrate Amnesia in a elixir program

Hi Guys,

I want tot learn Amnesia and I want to use this package in a simple elixir program.

Can anyone give me an example program to study how to use/integrate Amnesia
in a elixir program.

Many thanks in advance,

Thiel

You might want to get some experience with mnesia first:

http://erlang.org/doc/man/mnesia.html

https://elixirschool.com/en/lessons/specifics/mnesia/

Then read the source code of amnesia and its docs:

https://hexdocs.pm/amnesia/api-reference.html

1 Like

Way to push into Erlang land! This is still considered a land to scary to many. Mnesia rocks even though it does not handle split brain scenarios the best.

Apparently WhatsApp still uses it.

I salute you!

Take a look at the piranha project on my github it uses amnesia in database.ex

Happy exploring!

Bibek

1 Like

That’s a kind way to put it. There is unsplit for it though.

Get outta here. Cool!

Hi mr. bibekp,

Many thanks for your advice!

It seems I have a problem with integrating Amnesia in an Elixir program.

I created a simple (!) program and added in mix.exs :

defp deps do
[{:amnesia, github: “meh/amnesia”, tag: :master}]
end

After compiling I received the message: “unchecked dependencies…” and I run mix deps.get

However mix deps.get responded with: “… Could not resolve github.com”

Can you explain what went wrong?

Many thanks in advance,

Thiel

Try it via the hex package way and see if that works.

Hi bibekp,

Many thanks for your suggestion. I did it via the hex package and it works.

Now I can continue with playing and learning to use Amnesia in my elixir program.

By the way, making “errors” is a very efficient way of learning!

Many thanks,

Thiel

About the Split Brain scenario: Wasn’t Mnesia’s approach to say “What should happen in that case is application-specific, so you should write it yourself”, or am I mistaken?

:slight_smile:

1 Like

Wasn’t Mnesia’s approach to say “What should happen in that case is application-specific, so you should write it yourself”

But it didn’t offer any sensible tools for that, which I think a modern database should do.

1 Like

Yes, that’s the one. A statement in the same realm as: “I’ve found a truly magnificent proof of this theorem but it is too big to fit the margin”

Yes, mnesia was written before CAP theorem and also with different use case. If I remember correctly the “network” between nodes where physical cables so netsplits were unlikely to happen.

It does have something built-in to deal with this though. You can set the majority flag on a table which means that a majority of the nodes must be available for you to be able to write to the database. This makes it easier to reconcile, but it also choses consistency over availability (which might not be what you want).

I also don’t think unsplit solves all the cases. I haven’t looked into it in a while but when I did some testing with it, if both nodes had modifications done they were hard to heal (I might be very wrong here though so don’t take my word for it and look it up!)

I like mnesia a lot and think it is a pretty cool database. Now that different back-ends has popped up (leveldb, rocksdb) I might spend some time to see if is worth the trade-offs for truly persistent data.

3 Likes

I take my hat off to you: What a marvellous comparison! :clap: :tophat:

1 Like

Hi mr. bibekp,

Many thanks for your advice!

  It seems I have a problem with integrating Amnesia in an Elixir

program.

I created a simple (!) program and added in mix.exs :

> defp deps do
> [{:amnesia, github: "meh/amnesia", tag: :master}]

> end
After compiling I received the message: "unchecked dependencies....." and I run mix deps.get
However mix deps.get responded with: "... Could not resolve github.com"
Can you explain what went wrong?
Many thanks in advance,
Thiel