jsm

jsm

Pow's mnesia cache with dynamic nodes (containers in Kubernetes)

Thanks for the awesome work on your library, @danschultzer :slight_smile: I’m planning to use Pow in my next project, which will rely on distributed nodes which will dynamically scale up and down. They will discover one another using libcluster’s DNS-based discovery mechanism.

It is not immediately clear to me if this will work properly with Pow’s mnesia caching mechanism. In the docs (https://hexdocs.pm/pow/Pow.Store.Backend.MnesiaCache.html) it seems to me that the output of Node.list is passed to the mnesia cache worker as an initial parameter. It is possible, however, that this list is not fully populated yet (mnesia cache will effectively race libcluster) or that the list changes at some later point in time, when nodes are added or removed.

So the question is, will the MnesiaCache (or the cluster heal Unsplit worker) deal with such situations by itself? If not, do you have any advice for dealing with it? Or would you recommend using the Redis cache in this case?

Marked As Solved

danschultzer

danschultzer

Pow Core Team

@sensiblearts has been working on a guide for libcluster setup (that will be put up on powauth.com). Here’s a way to handle it: https://github.com/pow-auth/pow_site/issues/10#issuecomment-533845299

I’ve tested it locally with a k8s cluster, and it worked perfectly scaling up and down. If you push this to production environment I would be really happy to hear some feedback, since I don’t have a production setup using libcluster.

Also, you are more than welcome to join in helping to write the guide, adding examples, caveats, etc :smile:

Also Liked

jsm

jsm

Thanks, that is interesting! Especially the bit in the guide that says:

As long as at least one node in the :extra_db_nodes list is connected to the cluster, the MnesiaCache instances for all other nodes will automatically be connected and replicated. This makes it very easy to join clusters, since you won’t have to update the config on the old nodes at all. And as long as the old nodes connect to at least one node that’s in the cluster when restarting, it’ll automatically connect to the new node as well, even without updating the :extra_db_nodes setting.

I’m not completely clear if the potential for a race condition does not exist anymore though. Suppose I have two containers, my_app@x.x.x.1 and my_app@x.x.x.2. Let’s say node 1 is brought up first. It polls the DNS service and receives a list of peers with only itself in it at that moment. It starts MnesiaCache with :extra_db_nodes receiving only itself. Node 2 is brought up later, receives both itself and node 1 from the DNS request and passes this along to MnesiaCache.

For node 1, does this fulfill the stated requirement “at least one node in the :extra_db_nodes list is connected to the cluster”? Or will node1 have it’s own separate mnesia cache because it only found itself initially?

I intend to provide any feedback / guide / PR that I have to offer :slight_smile:

danschultzer

danschultzer

Pow Core Team

The replication starts as soon as another node connects, so node 1 will automatically be in the cluster when node 2 connects to it.

jsm

jsm

Awesome, thanks for your help!

Where Next?

Popular in Questions Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
logicmason
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
hpopp
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
New

Other popular topics Top

dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement