I've doing some experiment to solve the issue with implementing custom DirectoryProvider, so the indexes is stored on different path based on the tenant ID. Example:
Base Index Path: /lucene/indexes Tenant ID 1: user_abc Indexes Path for Tenant 1: /lucene/indexes/user_abc/com.test.User
Tenant ID 2: user_def Indexes Path for Tenant 2: /lucene/indexes/user_def/com.test.User
With this approach, I can get a clear picture which index data belongs to which tenant.
In the test, the getDirectory() method will return dynamic directory based on the active tenantId. Currently my application using LocalThread to retrieve the tenantId (need some hacks, because sometime the DirectoryProvider.getDirectory() is called on different thread). With this experiment, i've been able to get the correct query result for each tenant. This is looks more like a "hack" than a solution It should be handled better within the framework internally.
Is it possible each IndexManager have multiple DirectoryProviders for each tenantId?
I think this "multi-tenancy" feature should be different than "custom sharding" feature. Each tenant should be able to have each own sets of shardIdentifier. And the purge or re-index operation should affect only the targeted tenant data.
|