[HSearch 5] Indexing entities with a shared id across tenants results in removal from those tenants
Description
Activity
Yoann Rodière January 23, 2023 at 1:17 PM
For the record, the problem is not that the executors don’t handle tenants, but that we have some optimization logic that picks one executor or another depending on requirements (multitenancy or not, …), and in some cases that logic picks the wrong one (which doesn’t handle tenants, even though others do).
Ok, so actually @SmorgasbordQ was right. The problem is just that ByTermUpdateWorkExecutor
, DeleteExtWorkExecutor
, UpdateExtWorkExecutor
are buggy and don’t handle tenant IDs, at least not in all cases.
Yoann Rodière January 23, 2023 at 12:52 PM
@SmorgasbordQ Thanks a lot for your report and reproducer.
This is quite embarrassing, and my only relief is that we reworked that part in Hibernate Search 6 which means this will only affect Hibernate Search 5.11 and maybe 5.10 (I didn’t check yet), but not later versions.
For the record, the problem is not that the executors don’t handle tenants, but that we have some optimization logic that picks one executor or another depending on requirements (multitenancy or not, …), and in some cases that logic picks the wrong one (which doesn’t handle tenants, even though others do).
I will work on a fix.
SmorgasbordQ January 22, 2023 at 4:46 PM
I think I found the issue(s): ByTermUpdateWorkExecutor, DeleteExtWorkExecutor, UpdateExtWorkExecutor do not factor in a tenantId as needed.
I added a tenantId option to NumericFieldUtils.createExactMatchQuery (to conditionally build a BooleanQuery) for numericIds, otherwise when updateDocument was called, I checked the tenantId to see if a call to Utility.deleteWorkByQuery+addDocument was needed (otherwise use updateDocument with idTerm)
I’m not sure what the preferred coding practices / test cases / pull-requests are - if you’d like me to do anything more to help let me know… but otherwise I imagine this info would be enough
https://github.com/Smorgasbordq/spring-boot-hibernate-search
I’ve encountered an issue where, whenever an Indexed entity has an update to its Field (or if the hibernate enhance plugin has
enableDirtyTracking=true
) then other Tenants lose their index on that entity.The above repo (very loosely based on the web env I work in) should demonstrate it: once it’s running, you can access http://localhost:9000/plant/update?tc=tenant_1 and see the updated list of plants returned by Hibernate Search. If you access http://localhost:9000/plant/search?tc=tenant_2&text=fir&fields=name you’ll see no results are returned (unless you update that tenant, or trigger a reindex)