I'm new to Elixir and working on a distributed system. This system shares several global tables. Writes to this tables are frequent, so they should be pretty fast. Now, I sometimes have to process one whole table and generate some JSON from it, but I need to process the records in this table in the order they were inserted into the database. (I do not need any hard guarantees. Infrequent errors, like two swapped records or even single dropped ones are tolerable.)
Unfortunately, mnesia afaik doesn't have anything like SQL's auto_increment
, and now I struggle to implement this functionality myself.
Solution I can think of:
Store a unix timestamp (or some other kind of timestamp) as a key for the records. But it feels wrong for me that the correctness of the program depends on something like time. Situation where the time on two machines gets out of sync would be horrible to debug. And retrieval of time is afaik slow (read it somewhere, please correct me if I'm wrong)Unix timestamps's unit is a second, which is far too big.- Store a global counter as they key for the records. Might be even slower then the timestamp, and I'm unsure if messing around with mnesia counters is a good idea as they are not suited for distributed systems (again, please correct me if I'm wrong)
- Find a magic way how to maintain the order the records were inserted in. This is my favourite ;)