First things first, this is the code for the problem I had, if you have the time and interest, keep reading to understand what happened =)
That's it, the code is not the best but solves my problem.
Explanation:
The function validate_license is receiving a list [License|Host] with the License and the Host where it needs to compare the licenses.
It was necessary to make an rpc:call instead of mapreduce to be sure the function was going to run on the specified host(node).
I need to send a Node, Module, Function, and the Args to rpc:call.
I had to use string:join because the Host was a list and string:concat to concatenate the 'riak@' with the Host that was passed so I could get something like this: riak@127.0.0.1.
list_to_atom because rpc:call expects an atom as the node, you can't pass a string, to finish, walk(module), check_license(function) and [0,0, [License]](check_license parameters).
With that code I'm able to run a specific function on a specific node.
Details, details
The scenario: I have two nodes running with a library we have at work.
The problem: We had to run a function that generates a serial number based on the machine id and when the function was called Riak was the responsible to decide on which node to run it and with that we had a problem. How could we make sure that our function that checks the serial number would check for the serial number in the correct node? We couldn't.
We have a bucket where we store the encrypted license. The function validate_license had to check if the encrypted license sent to it by another application was the same on the bucket. So my application send the license to the node A but some times Riak would send that request to the node B and the function would return an error.
We have a bucket where we store the encrypted license. The function validate_license had to check if the encrypted license sent to it by another application was the same on the bucket. So my application send the license to the node A but some times Riak would send that request to the node B and the function would return an error.
The solution: It was necessary to guarantee that the function was going to be executed in the correct node so it could check the licenses correctly.
That's all.
I'd really appreciate any feedback on that since my experience with Riak and Erlang are 0.1%.
Today, be nice with someone you're not fond of, this will make your day better.
Power to you!
That's all.
I'd really appreciate any feedback on that since my experience with Riak and Erlang are 0.1%.
Today, be nice with someone you're not fond of, this will make your day better.
Power to you!