Need help understanding the Erlang file server

I’m having a hard time understanding the file server concept in Erlang. From the docs I came up with some assumptions, but I’m not sure they actually hold.

So I assume that this only makes a difference if you’re running multiple nodes, right? Does the file server work on all nodes simultaneously? I.e. if I call the Elixir function File.exists?/2 and I don’t pass the :raw option, is it going to return true if the file exists on the file system of any one node? Also if I call, does it open the file on any node if it exists, even if it does not exist on the node where the call is made?

There’s no difference. :file is for handling concurrent file access within a single beam instance (besides :raw). So multiple processes on the same instance trying to work with files. It’s doing nothing for distributed nodes afaik.

Each node has it’s own independant file server.

iex(bar@Lillith)1> Node.connect(:"foo@Lillith")
iex(bar@Lillith)2> Node.list
iex(bar@Lillith)3> Node.self()
iex(bar@Lillith)4> Process.whereis(:file_server_2)
iex(bar@Lillith)5>"foo@Lillith", Process, :whereis, [:file_server_2])

Thanks for your answer. In that case I don’t get the :raw option. What is the difference if I use it or not?

You have the same problem you have with multiple nodes with multiple processes. Without :raw all file operations go through the file server, which can coordinate concurrent access by multiple processes. With :raw only a single process can access the file at a time, as otherwise concurrent access (especially for writes) can corrupt the file.

1 Like

Oh I think I know now. It’s just that with :raw you can’t use a remote file server but it’s faster. If you wan’t to open files remotely as described in this post, you can’t pass :raw.