My use case is to get the latest value for any key in a Kafka topic. For this, I am currently using GlobalStateStore.
The problem is that, if I have different application.id for each instance, a different state dir is being created.
What I would want is to reuse the existing state store dir across all instances to avoid duplicating the data. This is because, all of my application instances run on the same machine, so there is no point of having different state directories.
I have done the following:
Use the same application.id and created 2 stream instances, The 2 instances pointing to the same state.dir but the state store instances are different (java objects are different) statestore1 and statestore2
and then as a test I have done the following:
while(true)
{
new Thread(()-> stateStore1.get(key)).start();
new Thread(()-> stateStore2.get(key)).start();
}
and then I started producing values in the topic...
I have observed that all the state store instances (statestore1 and statestore2) are updating the same state store (i.e. same state.dir) (since that is the code)
I did not encounter any problems in the tests doing that. But.. I suppose that a write lock should be acquired before writing the data to the state.dir. Now, if for some reason, statestore1 did not release the lock, then statestore2 will be going on waiting?
Is my above approach safe or are there any other ways?
Update:
The use-case is that there is some common data which I would want to share across different processes (different JVM instances). Since the data is common there is no need to have a global store for each process (since it would be redundant).
All processes should have the ability to read and write to that store because each process is independent of each other. So if one process goes down, the other can do its work (store the latest value in the global store and get it when needed).