Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

atomic counters #6

Open
gedw99 opened this issue Jun 13, 2022 · 5 comments
Open

atomic counters #6

gedw99 opened this issue Jun 13, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@gedw99
Copy link

gedw99 commented Jun 13, 2022

Rita looks really nice.

As per nats-io/nats-server#2656 It looks like Rita might be a good way to calculate atomic counters and other such things. In the issue the hack is to send +1 and -1 and then recalc and store the KV value.

@bruth
Copy link
Owner

bruth commented Jun 16, 2022

I guess the proposal is effectively asking for the server to serialize incr/decr commands from concurrent actors. I have a hard time thinking about write-only counters. Meaning if you need to read the value and decide how much to incr/decr, then you would want the kv.Update command as Derek suggested (a compare-and-swap). A more robust option would be a CRDT that could properly merge concurrent operations.

That said, if eventual consistency of the counter is sufficient, then one option would be to have a model of state that have a live subscription to receives incr/decr operations and the value is derived. It doesn't solve the atomic problem, but agree that a live model of state could be useful. I had written up an API design for this a while ago, I will dig it up and post.

@bruth bruth added the enhancement New feature or request label Jun 16, 2022
@gedw99
Copy link
Author

gedw99 commented Jun 20, 2022

CRDT is definitely another way !

This nats project models the data in a CRDT style: https://github.com/simpleiot/simpleiot/search?q=crdt

It does not have as far as i can see a way to reconcile the state using CRDT yet from what i can see.

But its interesting to see. they also use an embedded database btw called genji, which is backed by the cockroachdb pebble, which i am sure you know. https://github.com/genjidb/genji/blob/main/go.mod#L8

Its interesting to compare rita and siot. Sito uses a generalized type structure called points. https://github.com/simpleiot/simpleiot/blob/master/docs/adr/1-consider-changing-point-data-type.md
I like how it goes through the considerations of how and why ...

@gedw99
Copy link
Author

gedw99 commented Jun 20, 2022

@bruth " I had written up an API design for this a while ago, I will dig it up and post."
If you find it would be cool to read 👍

@bruth
Copy link
Owner

bruth commented Jan 9, 2023

@gedw99 There has been some internal discussion about a stream type/operation that enables an atomic counter. It is currently a stretch goal for the next minor release (2.10.0), but may land in the coming months.

@gedw99
Copy link
Author

gedw99 commented Jan 30, 2023

hey @bruth thanks for letting me know about this !

If there are any issues on the nats repo please do add here :)

Also i am working on time smearing for nats. It basically keeps the time on all nodes the same and accounts for leap years.
It's sort of related to the whole eventual consistency aspects we are discussing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants