moremore0812 / cqengine

Automatically exported from code.google.com/p/cqengine
0 stars 0 forks source link

Support application threads racing to add/remove same object #9

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
A data race between multiple application threads racing each other to add and 
remove the *same* object simultaneously, can leave indexes in an inconsistent 
state.

See discussion in forum: 
https://groups.google.com/forum/?fromgroups=#!topic/cqengine-discuss/7sxA-MDr7yk

The following sequence of method calls is unsafe:

 // setup
collection.addIndex( ... ) 
collection.addIndex( ... ) 
collection.addIndex( ... ) 

// .... calls
collection.add(instance); // thread 1
collection.remove(instance) // thread 2

By default CQEngine supports application threads adding/removing different 
objects concurrently, but a race in the application to add/remove the same 
object concurrently, can leave the object added to some indexes but removed 
from others.

This issue is to add locking support inside CQEngine, to force attempts by the 
application threads to add/remove the same object simultaneously to be 
performed sequentially.

Concurrent modification for different objects, should not incur locking. Reads 
should remain lock-free.

Original issue reported on code.google.com by ni...@npgall.com on 23 Dec 2012 at 11:18

GoogleCodeExporter commented 9 years ago
Checked in initial support to trunk. Functionality is implemented but *the API 
is not final* yet:

http://code.google.com/p/cqengine/source/browse/cqengine/trunk/src/main/java/com
/googlecode/cqengine/collection/impl/IndexedCollectionStripedImpl.java

Usage (note: API might change!): 
IndexedCollection<O> collection = CQEngine.newInstanceStriped(512);

...this would return an implementation which supports concurrent 
adding/removing of the same object.

Original comment by ni...@npgall.com on 23 Dec 2012 at 11:51

GoogleCodeExporter commented 9 years ago
This feature will be included in the next release, along with the recent 
support for JOINS. ETA: next few weeks. API is likely to be renamed from this 
example slightly.

Original comment by ni...@npgall.com on 27 Jan 2013 at 10:21

GoogleCodeExporter commented 9 years ago
Done. Available in CQEngine 1.1.0, released.

Implemented as 
http://cqengine.googlecode.com/svn/cqengine/javadoc/apidocs/com/googlecode/cqeng
ine/collection/impl/ObjectLockingIndexedCollection.html

Static factory methods added to CQEngine convenience class, to create 
object-locking instances of IndexedCollection.

Original comment by ni...@npgall.com on 16 Aug 2013 at 10:30