Comments (6)
Have you read this documentation? https://github.com/npgall/cqengine/blob/master/documentation/TransactionIsolation.md
from cqengine.
Yes.
Let's say I wanted to store a single integer as an atomic counter.
The initial value is 4, and a couple threads are concurrently incrementing it.
{4}
t1: update(4, 5) -> {5}
t1: update(5, 6) -> {6}
t2: update(4, 5) -> {5, 6} (BAD STATE)
from cqengine.
I see.
Maybe it's not clear from the documentation, but atomic object replacement here means if an object is contained in the collection, it can be swapped for another object, such that reading threads will either see the old object, or the new object, but not both, and not neither. The atomic aspect is from the perspective of the reading threads, not the writing threads.
There is no CAS operation. Basically, the behavior is intentionally similar to transaction isolation in databases. In databases, if you have a transaction comprised of a DELETE statement followed by an INSERT statement, and the DELETE statement does not match any rows, then it does not abort the transaction, and INSERT will still be performed.
Maybe it would be possible to extend TransactionalIndexedCollection with support for CAS operations. Can you give me a good use case for it? Implementing an atomic counter isn't really compelling enough as we already have AtomicInteger for that. But I guess above is just an example and you have another use case?
Incidentally, note that TransactionalIndexedCollection will actually serialize all of your calls to the update() method above. Currently the MVCC mechanism prevents concurrent writes. So technically if you wanted to achieve CAS semantics, you could synchronize all of your writes externally outside of CQEngine, and before you call update(), your could check if the first object is contained :)
from cqengine.
Well, an atomic counter isn't compelling in and of itself (although, it's a pretty basic atomic operation). But rather, we may want to atomically update some fields of a larger object. For example, a BankAccount
object might have many fields. One really important field to update atomically is balance
. And it doesn't have to be numeric. There might be an array field emails
and we want to make sure that concurrent appends don't end with a race.
More generally, it's useful for DB operations to grab a write lock, read some data, write some data based off of the reads, and then release the lock.
from cqengine.
Okay I can see how it might be useful.
I think I will add support for it, by allowing the client to supply a query option to the update methods such as: queryOptions(enableFlags(TransactionalIndexedCollection.STRICT_REPLACEMENT))
If this is supplied, then the update method will validate that the objects to be replaced actually are stored in the collection. If any are not, it will not modify the collection and the update method will return false.
from cqengine.
Done. This is implemented and will be included in the next release. Thanks for the suggestion!
from cqengine.
Related Issues (20)
- FilteringIterator returns hasNext as true after the collection is consumed HOT 1
- Update data automatically HOT 1
- Pagination Over data HOT 4
- Perfomance index HOT 3
- Consider exposing utility static method taking collections
- Reenable cached hashCode
- Support for java.util.Optional
- [Question] How does CQEngine pick the appropriate index to query?
- most longest prefix value exist in the column value but it doesn't intersect with other columns values in the query that we need part of query retrieval HOT 7
- Support STRICT_REPLACEMENT in ObjectLockingIndexedCollection/ConcurrentIndexedCollection
- TransactionalIndexedCollection support for UniqueIndex is broken
- Support for attribute accessors for Java record type HOT 1
- Kryo generates InaccessibleObjectException - Make Dependencies "Java 17 compatible"
- Bug in AttributeOrdersComparator HOT 5
- Offheap cache visibility HOT 1
- Support for ANTLR 4.10.1 HOT 12
- Does it support SQL statistics queries HOT 3
- Thread blocked when using Materialized View Sort For the Longest Prefix for CSV that contain more than 11 K rows HOT 3
- Error while parsing SQL NOT LIKE query HOT 1
- Error while parsing SQL LIKE '%%%' query
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 cqengine.