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

TransactionalIndexedCollection support for UniqueIndex is broken #302

Open
abhishek opened this issue Sep 3, 2022 · 0 comments
Open

TransactionalIndexedCollection support for UniqueIndex is broken #302

abhishek opened this issue Sep 3, 2022 · 0 comments

Comments

@abhishek
Copy link

abhishek commented Sep 3, 2022

TransactionalIndexedCollection<Car> cache = new TransactionalIndexedCollection<>(Car.class);
cache.addIndex(UniqueIndex.onAttribute(Car.CAR_ID));
cache.add(new Car(1, "Ferrari"));

cache.update(Collections.singletonList(new Car(1, "Ferrari")), Collections.singletonList(new Car(1, "Mercedes")));

I expected this to succeed since I am basically trying to update CAR_ID = 1 with new data.

However I get - UniqueConstraintViolatedException

com.googlecode.cqengine.index.unique.UniqueIndex$UniqueConstraintViolatedException: The application has attempted to add a duplicate object to the UniqueIndex on attribute 'carId', potentially causing inconsistencies between indexes. UniqueIndex should not be used with attributes which do not uniquely identify objects. Problematic attribute value: '1', problematic duplicate object: Car[carId=1, name='Mercedes']

Looking at

if (objectsToAddIterator.hasNext()) {
// Configure new reading threads to exclude the objects we will add,
// and then wait for threads reading previous versions to finish...
incrementVersion(objectsToAdd);
// Now add the given objects...
modified = doAddAll(objectsToAdd, queryOptions);
}
if (objectsToRemoveIterator.hasNext()) {
// Configure (or reconfigure) new reading threads to (instead) exclude the objects we will remove,
// and then wait for threads reading previous versions to finish...
incrementVersion(objectsToRemove);
// Now remove the given objects...
modified = doRemoveAll(objectsToRemove, queryOptions) || modified;
}

If we move DELETE before ADD, unique index would work.

I don't fully understand exclusion logic and I can see some interaction due to remove before add for new readers.

If, that's the case. Then updating the documentation/code to block UniqueIndex and TransactionalIndexedCollection being used together.

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

No branches or pull requests

1 participant