Menu
  • HOME
  • TAGS

Riak sibling creation in erlang

Tag: erlang,riak,siblings

Suppose two processes execute the same write command at the same time to RIAK with same bucket and same key (might be addressing two different RIAK nodes) with allow_mult true and the key is definitely new in the bucket: {ok, WrittenObject} = riakc_pb_socket:put(Pid, Obj, [return_body])

Can it happen that both processes get WrittenObject back where riakc_obj:value_count(WrittenObject) is greater than 1, or definitely one process will have it as 1 and the other gets the value of 2?

Best How To :

Depending on what is already stored at the key, and what vclock is included with each put request, the value count may be 1,2 or 3. Assuming no partition event (i.e. non-failure case), each put will be coordinated by one of the primary vnodes in the key's preflist, and if the vclock contained in the object being stored does not dominate the one already present, both values will be stored. Even if both requests are made nearly simultaneously, which is processed first, and which if not both see a sibling will be a race.

Edit: If the allow_mult property on the bucket is set to false, Riak will select a single value to return based on the X-Riak-Last-Modified and X-Riak-Deleted entries in metadata. This means that the value you put may not be the value returned.

Only if allow_mult is true will you see more than one value returned.

How to delete the whole directory which is not empty?

erlang

You can delete a directory via console command using os:cmd, though it's a rough approach. For unix-like OS it will be: os:cmd("rm -Rf " ++ DirPath). If you want to delete a non-empty directory using appropriate erlang functions you have to do it recursively. The following example from here shows...

erlang message passing architecture

process,erlang,messaging

Message receiving is an atomic operation. If you are interested how it is done, read the source code of VM. If I simplify it, the sending process is doing those steps: Allocate a target memory space in the sending process (it's called environment). Copy the message to that memory space...

Does Erlang has Map?

erlang

Yes, since the release version R17 - somewhere early 2014 - Erlang supports maps. You can read all about it at http://learnyousomeerlang.com/maps. You should go for the latest release, being 17.5.

Fast mutable objects in Erlang

erlang

You should have a look at the ETS-module (Erlang Term Storage). It is an in-memory key-value-store and, as the name suggests, it can store erlang-terms in hashmap/tree-structures. I recommend reading this article, it has nice examples and is written for beginners. With ETS, you can have 4 types of storage:...

Modelling a leaderboard/ranking list in Riak

solr,ranking,riak,leaderboard

Riak search (Solr) may seem a natural choice for at least some of your use cases. It supports sorting (by highest score) and pagination. However, according to Basho, Riak search should not be used when deep pagination is needed. It also does not scale well beyond 8-10 nodes. Also from...

Pid as erlang maps key?

erlang

Support for arbitrary keys in map patterns is already available in "Erlang 18 (release candidate 2)". $ erl Erlang/OTP 18 [RELEASE CANDIDATE 2] [erts-7.0] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] Eshell V7.0 (abort with ^G) 1> Pid = self(). <0.33.0> 2> #{Pid => 1}. #{<0.33.0> => 1} ...

Erlang based chat (load balancing and notifications distribution)

erlang

1) Yep - this is a good scheme. An improvement you can make is to increment the load of a remote node every time you balance load to another node. This is like keeping an estimate for remote node load and stops you from sending all load to one node...

Erlang: Returning a function from a function

erlang

Ah, here we go: -module(test). -export([run/0]). test() -> io:format("toasters", []). bagel() -> fun test/0. % <- This is what I needed to change. run() -> (bagel())(). I was looking here for an answer, and they didn't explicitly state it, but the example near the top gave me the hint just...

What is the difference between .app and .app.src files in Erlang?

erlang

The .app file (in ebin/) is the file necessary by the Erlang VM to load OTP applications. It must contain fields such as the dependencies of the application, the modules it contains, the version, and so on. Particularly, the list of modules for the application is tedious to maintain, but...

Adding to an existing value in Erlang

erlang,record,erl

Take a look at this code: -module(test). -export([add/1]). -record(adder, {value=6}). add(X) -> #adder{value = X + #adder.value}. If you compile this in your shell, any call to "add(3)" will result in "{adder,5}" and not in "{adder, 9}". Take a look: Eshell V6.4 (abort with ^G) 1> c(test). {ok,test} 2> test:add(3)....

Mnesia pagination with fragmented table

pagination,erlang,mnesia

The problem is that you expect mnesia:select/4, which is documented as: select(Tab, MatchSpec, NObjects, Lock) -> transaction abort | {[Object],Cont} | '$end_of_table' to get you the NObjects limit, being NObjects in your example 10,000. But the same documentation also says: For efficiency the NObjects is a recommendation only and the...

Erlang spawning large amounts of C processes

c,multithreading,lua,erlang,ffi

If you can make the Lua code — or more accurately, its underlying native code — cooperate with the Erlang VM, you have a few choices. Consider one of the most important functions of the Erlang VM: managing the execution of a (potentially large number of) Erlang's lightweight processes across...

Getting SSL related error against my request to Ejabberd

android,sockets,ssl,erlang,ejabberd

Here is how you can go about it. I work on the sandbox environment and after a bit of patching, i could make it work. Follow the patching done here: http://erlang.org/pipermail/erlang-questions/2015-June/084868.html You would be required to make changes in ssl_cipher.erl and ssl_handshake.erl files. These 2 files are a part of...

Manipulating XML element to get value from Sub-element in Erlang

xml,erlang,ejabberd

You can use function xml:get_path_s, asking it to descend into the element called received to get the attribute called id: > xml:get_path_s(Packet, [{elem, "received"}, {attr, "id"}]). "018A12FB-0718-4304-87FD-430C59EDB4F9" ...

passing arrays to a function in erlang

arrays,function,erlang,arguments

Like Hynek Vychodil says in his answer, there is no built-in array type in Erlang. Arrays do exist, in a sense, as you can get something that behaves like an (immutable) array using the array module. In Erlang, an expression that begins with an opening bracket, such as [1, 2,...

Riak CS LDAP authentication

authentication,ldap,riak,riak-cs

I don't know what the doc supposed but, as far as I know, keystone authentication feature may be used. Riak CS (should) support keystone authentication [1] and keystone auth can be configured to use LDAP [2] [3]. [1] http://docs.basho.com/riakcs/latest/cookbooks/Using-Riak-CS-With-Keystone/ [2] http://docs.basho.com/riakcs/latest/cookbooks/Keystone-Conf-Sample/ [3] http://docs.openstack.org/developer/keystone/configuration.html P.S. Keystone cooperation is not widely used,...

Does the pattern [_|_] in Erlang mean anything specific?

erlang

The pattern [p1 | p2] matches a non-empty list, whose head matches the pattern p1 and whose tail matches the pattern p2. So since the pattern _ matches anything, [_ | _] matches any non-empty list. _ by itself on the other hand matches anything, including the empty list....

How does Riak nodes distribute data

database,amazon-web-services,riak

This is how Riak works. The whole idea of a scalable database is distributing the load between its nodes. Riak achieves this by hashing a key and directing the reads/writes to a node responsible for that key. As of disaster recovery, Riak can store a number of replicas for each...

Erlang syntax error unclear

function,variables,if-statement,functional-programming,erlang

Because expressions should be separated by ,, not ;: Val=cal(Arg1), if ... ; is the separator for if/case/receive and function clauses....

Where does Elixir/erlang fit into the microservices approach? [closed]

architecture,erlang,docker,elixir,microservices

This is a very open question but I will try to illustrate why Elixir/Erlang may be the best platform out there for developing distributed systems (regardless if you are working with microservices). First, let's start with some background. The Erlang VM and its standard library were designed upfront for building...

erlang processes and message passing architecture

concurrency,process,erlang,messages

Erlang processes are cheap. You're free (and encouraged) to use more than however many cores you have. There might be an upper limit to what is practical for your problem (loading 1TB of data in one process per line is asking a bit for much, depending on line size)....

How to make a gen_server reply with a message?

erlang

The whole point of gen_server:call/2,3 is to wrap into a function call the passing of a message into a gen_server process and the reception of its reply. If you want to deal only with messages, don't use gen_server:call/2,3 but rather have the caller invoke gen_server:cast/2 and include the caller pid...

gen_server handle_info/2 clarification

syntax,erlang,gen-server

All function parameter definitions are patterns, and #state{lsock = LSock} = State is one pattern that binds State to the whole term passed as a function call argument, and at the same time asserts that it is a record state and binds State#state.lsock to LSock. In your shell examples, A...

how to handle low_entropy exception of crypto:strong_rand_bytes(N)?

openssl,erlang

how to handle low_entropy exception of crypto:strong_rand_bytes(N)? Handle it by not getting into the bad state in the first place. You avoid it by seeding the generator. You should explicitly seed the generator on startup. This avoids some of the problems with calling RAND_poll. For some of the problems,...

How to rewrite Erlang combinations algorithm in Elixir?

functional-programming,erlang,elixir

You need to wrap the for expression in parentheses like the Erlang code. def combination(n, [x|xs]) do (for y <- combination(n - 1, xs), do: [x|y]) ++ combination(n, xs) end Demo: iex(1)> defmodule Foo do ...(1)> def combination(0, _), do: [[]] ...(1)> def combination(_, []), do: [] ...(1)> def combination(n,...

Is ++ operator more expensive than | operator in Erlang?

erlang

You might want to read about this issue in the Erlang efficiency guide, since there it says that building the list via | and then reversing the result is more efficient than using the appending ++ operator. If you want to know the performance difference, use timer:tc: 1> timer:tc(fun() ->...

First word of binary string erlang

functional-programming,erlang,pattern-matching

Although Attic's approach is correct, there is a straightforward solution (including trimming of leading spaces): first_word_bin(Bin) -> first_word_bin(ltrim(Bin), <<>>). first_word_bin(<<>>, Acc) -> Acc; first_word_bin(<<$\s, _/binary>>, Acc) -> Acc; first_word_bin(<<X, Bin/binary>>, Acc) -> first_word_bin(Bin, <<Acc/binary, X>>). ltrim(<<$\s, Bin/binary>>) -> ltrim(Bin); ltrim(Bin) -> Bin. ...

Wait for Node.connect before using :global.whereis_name

erlang,elixir

You could do a :global.sync() before :global.whereis_name(id)

Elixir exrm release crashes on eredis start_link

erlang,elixir,exrm

You need to add :eredis to your app_list function, so that it is packaged with the release, that goes for the rest of your dependencies as well.

Modifying an Erlang Record [duplicate]

erlang,record,erl

There are various ways to do this. Think about where you want to store the value: Erlang doesn't have "static variables" like C, so the function itself cannot remember the value. You could pass the current record as an argument to add_new_num, and get the updated record from its return...

How to list all the bucket types in riak?

erlang,riak

excerpt from http://docs.basho.com/riak/latest/dev/advanced/bucket-types/#Managing-Bucket-Types-Through-the-Command-Line: Bucket types are created, updated, activated, and more through the riak-admin bucket-type interface. Below is a full list of available sub-commands: Command Action Form create create or modify a bucket type create <type> <json> before activation activate activate a bucket type activate <type> list list all currently...

Fetching and updating data in mnesia

erlang,mnesia

As far as I know, you cannot build a guard with a call to get the substring from a string, so instead of using a Erlang Match Specification you would have to iterate over all the records and filter the ones that you need. -module(tuples). -compile(export_all). -record(group, {group_id, group_name, group_type,...

Riak mapReduce fails with > 15 records

mapreduce,erlang,riak

The problem is with the reduce phase. The map phase is spread around the cluster and executed by many vnodes that forward the map phase result to the node that will be running the reduce. Since these are not expect to arrive simultaneously, the reduce phase function may be run...

How to invoke Erlang function with variable?

erlang

I know abs is an atom, not a function. [...] Why does it work when the module name is used? The documentation explains that (slightly reorganized): ExprM:ExprF(Expr1,...,ExprN) each of ExprM and ExprF must be an atom or an expression that evaluates to an atom. The function is said to...

Can I change allow_mult to false on map bucket/bucket type in riak?

riak,bucket

Why do you want to turn allow_mult to false ? I think it's needed for the map data type to work properly. Values stored in it will properly automatically converge by themselves, so you'll never see siblings from the client point of view, but I suspect CRDTs need allow_mult to...

erlang os:cmd() command with UTF8 binary

unicode,encoding,erlang,utf

Its because Erlang reads your source files like latin1 by default, but on newer versions of erlang you can set your files to use unicode. %% coding: utf-8 -module(test). -compile(export_all). test() -> COMMAND = "touch ჟანიweł", os:cmd(COMMAND). and then compiling and executing the module works fine rorra-air:~ > erl Erlang/OTP...

Erlang pass-by-reference nuances

erlang,pass-by-reference

a list is a recursive construction of the form L=[Head|Tail] where Head is any valid erlang term and Tail should be a list (if it is something else L is called an improper list, out of the scope of this discussion). Saying that L is passed as a reference means...

Why doesn't spawn link cause the calling process to die?

erlang,erlang-shell

The reason for this is that you set a trap_exit flag to true which means this process will get {'EXIT', FromPid, Reason} message instead of being killed. Just remove process_flag(trap_exit, true) or in case of receiving this type of message, kill it. You can read about it here....

How to read and write id3v1 and id3v2 tags in Elixir

erlang,mp4,elixir,id3

You can always use erlang NIFs (http://erlang.org/doc/tutorial/nif.html) to wrap an external library

Erlang result in accumulator

erlang

There are many problems in the code you propose. First, there is only one case in the if statement so if A+B+C is different from N it will crash (try with main(20)). in the find_triple function you assign 4 time the variable Acc, remember than variable are not mutable in...

Erlang driver erl_errno issue

erlang,erlang-driver

This seems like a bug either in the documentation or the code. If the code that invokes the driver start function finds that the function returns ERL_DRV_ERROR_ERRNO, it takes the error number from errno, not erl_errno (this is true as of otp master commit dc35ae6c, anyway, which is roughly Erlang...

Jabber user going offline: Why the two different scenarios?

android,erlang,xmpp,ejabberd,user-presence

Scenario 1: When I swipe-right the app (kill the app), the user goes offline on the server immediately. Its status is changed to offline at that very instant. In above case your Android xmpp client is sending presence as unavailable before closing your Android application, maybe your Android XMPP...

Value from binding in LFE interpreter using Erlang

erlang,lisp,lfe

I won't attempt to answer completely your broader question about the "best practices" of adding scripting. It seems to me that choosing between "hook-based" solution (in which you define hook implementations by name convention and they are automatically recognized) and "explicit api" solution (in which you use functions predefinied in...

Getting a sibling process in Elixir

erlang,elixir,otp

The simplest way would probably be for child1 and child2 to be registered under local aliases. You can do that while starting your GenServer by passing the name option: defmodule Child1 do use GenServer def start_link do GenServer.start_link(__MODULE__, [], name: __MODULE__) end end In this case a process backed by...

Multiple specifications for same function in Erlang header file

erlang

Found the answer here: http://erlang.org/doc/reference_manual/typespec.html I had to use the ';' change this: -spec update(pid(), tuple(tuple(), integer(), atom()), tuple(atom(), atom())) -> tuple(tuple(), integer(), atom()). -spec update(pid(), tuple(tuple(), atom(), atom()), tuple(integer(), atom())) -> tuple(tuple(), atom(), atom()). -spec update(pid(), tuple(tuple(), atom(), atom()), tuple(atom())) -> tuple(tuple(), atom(), atom()). into this: -spec update(pid(), tuple(tuple(),...

ctrl+G in erl doesn't work

unicode,encoding,utf-8,erlang,docker

Fixed the problem, needed export TERM=linux.

boot2docker resulting in “Cannot connect to the Docker daemon. Is 'docker -d' running on this host?”

docker,riak,boot2docker

Run the full docker version command, and you should see something like this: $ docker version Client version: 1.6.2 Client API version: 1.18 Go version (client): go1.4.2 Git commit (client): 7c8fca2 OS/Arch (client): darwin/amd64 Server version: 1.6.2 Server API version: 1.18 Go version (server): go1.4.2 Git commit (server): 7c8fca2 OS/Arch...

Type errors in dialyzer in function with specified type

erlang,dialyzer

The problem is that url() is specified as a binary() but you pass in [byte()] (strings) in there. You need to change the type specification of url() to something like iodata() instead, or to restrict your input by converting it to a binary first.