Comments (5)
couldn't you just do a read of the tournament state, check whether the operation would succeed
Yes, in general, this is possible; however, not all types fit this restriction. In particular, if you are working with a type that is defined in another crate, you might not have the ability to check the fallibility of an operation through a shared reference.
I rewatched the impl
video on this and understand the design considerations behind the refresh
better now and how they are at odds with what I'm specifically wanting. Ulimately, I'm wanting a cross between a left-right
and a watch channel. This might be an idea for a seperate crate.
from left-right.
Can you give a motivating use-case for when operations might fail? I'm not opposed to this, but I want to make sure we land this complexity only if we think the solution actually addresses a real use-case.
Also, I think the fallibility needs to be exposed to writers in publish
(i.e., try_publish
), since append
only appends to the log and does not (and cannot) apply the operation at all. At that point, I wonder whether the error is even still useful, because it might happen to some operation that's in the middle of the operational log. Which then leaves us in a weird middle-state.
More in the weeds: I don't think we need try_drop_*
, since drop shouldn't be fallible.
from left-right.
Sure, I can provide my use case. I also say the conversation you had on stream around this ticket, so I'll also expand on some things that you mentioned there.
I have a service that allows multiple users to send and receive updates to the same data structure. In my particular use case, these are tournaments (but you could replace "tournament" with "text document" and everything will still hold). Using websockets, a user sends an update message, the server processes it, and, on success, the same message is forwarded to all of the users so they can apply it to their local states. The received message can fail for a number of reasons (the user was out of sync, the server receives an improper or malicious message, etc).
Each multi-user session is managed by a tokio task. To reduce the DB-bound latency, this task maintains an in-memory copy of the tournament. This ensures that the session can always process incoming messages without any waiting on the DB. We persist the tournaments to the DB via a separate task that is responsible for persisting all tournaments. After every successful update from a user, we send a message to the persistence task to indicate that tournament has been updated and needs to be saved.
Ideally, the persistence task holds left-right
reader handles to every tournament and will read from them only when it receives a message that a tournament has updated (this message is just the id of the tournament). Instead, there is a system of inter-task communication for retrieving clones of the tournament. Using left-right
would both simplify the persistence problem and reduce the number of copies of the tournament that need to be made.
While watching your stream, you cleared up a misconception that I had. I was under the impression that when a writer appended to the operation log, it also applied the operation to the copy that it should have exclusive access to. This is somewhat important to this particular system because having immediate access to the success or failure of an operation is important as it dictates what the session task will do next. A similar effect could still be achieved by flushing after every update and receiving errors at that point; however, I don't think that is true in general.
from left-right.
Ah, interesting, thanks for the context! I may be missing something obvious, but couldn't you just do a read of the tournament state, check whether the operation would succeed, and the only do the (infallible) write operation if that is indeed the case. Then there'd be no need for fallible writes to be a thing.
The reason why writes are enqueued and applied only on a refresh
, rather than applied directly, is that it allows left-right
to return "early" from refresh
so that the time spent waiting for readers to depart one "side" is time when the writing thread also gets to execute. It's a little hard to explain without a diagram, but it allows left-right
to spend less time blocking the current thread overall.
from left-right.
That sounds about right 👍 I'll close this as wontfix, but please do post back if you end up building such a thing to aid in discovery!
from left-right.
Related Issues (20)
- Support for no_std? HOT 5
- i saw the presentation, will it take a lot of CPU like spinlock while write is waiting? HOT 1
- Why you dont use Crossbeam Epoch?? i have question about this please help HOT 1
- Memory bloat when using with async runtime HOT 2
- Possible to shallowcopy a HashMap HOT 1
- #[derive(ShallowCopy)] has prohibitive "T: ShallowCopy" bound HOT 4
- Thread Safety Error on ReadHandler HOT 3
- Why not make `map_ref` of `ReadGuard` public? HOT 1
- Recreating WriteHandle after its dropped HOT 2
- RFC: Hash and Eq requirement for values HOT 4
- Replace Clone bound with Freeze HOT 4
- Possible UB from Box<T> aliasing HOT 7
- data races due to incorrect `Send + Sync` bounds HOT 3
- Relaxation of epoch invariant HOT 2
- rollback HOT 5
- Switch oplog to VecDeque HOT 1
- A potential alternative to epochs, if it works HOT 1
- can DropBehavior have an associated constant instead of a function HOT 11
- Is there a way to get the backing data structure out? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from left-right.