simonbowen

simonbowen

Ordering issue with erlang queue and an ETS table

I have a system which I need to feed data into and maintain. Currently I have a GenServer that communicates with an ETS table and inserts items into the table. As part of this I have a FIFO erlang queue, when an item is added to the ETS table I am pushing it to the queue to be consumed from elsewhere.

For some reason the ordering of the items in the ETS and Queue are different and I cannot work out why. This is the code I am using to push the item into the ETS table and Queue.

with :ok <- Queue.add(job), true <- :ets.insert(table, {id, job}) do
    PubSub.broadcast!(BrokerEx.PubSub, @topic, {:added, job})
end

When I dump the contents of the table and the queue they are not the same. The Queue in this context is a simple GenServer that manipulates Erlangs built in queue module.

Where am I going wrong?

Marked As Solved

simonbowen

simonbowen

I’ve worked it out. Using table = :ets.new("table", [:set, :protected]) creates an ETS table with the type of set and there is no guarantee of the order with this table type.

To be honest I think I need to use a RDBMS at this point anyway since I need to have some persistence for this data anyway.

Also Liked

dimitarvp

dimitarvp

Yep, was about to say “why not use a database”? You can also use timeseries if needed – not so hard to install the timescale Postgres extension. Or you can just queue things up in Redis and have background workers pull them away from there and store them in a regular DB.

Where Next?

Popular in Questions Top

lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
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
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
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
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
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
Codball
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New

Other popular topics Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
sergio
I couldn’t find any guides that worked well with Phoenix 1.6.0 and esbuild. I hope this helps people test the waters and eases you into t...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New

We're in Beta

About us Mission Statement