{"action":"created","issue":{"url":"https://api.github.com/repos/apavlo/h-store/issues/175","labels_url":"https://api.github.com/repos/apavlo/h-store/issues/175/labels{/name}","comments_url":"https://api.github.com/repos/apavlo/h-store/issues/175/comments","events_url":"https://api.github.com/repos/apavlo/h-store/issues/175/events","html_url":"https://github.com/apavlo/h-store/issues/175","id":42103858,"number":175,"title":"Adding utility threads for anti-cache eviction ","user":{"login":"apavlo","id":718045,"avatar_url":"https://avatars.githubusercontent.com/u/718045?v=3","gravatar_id":"","url":"https://api.github.com/users/apavlo","html_url":"https://github.com/apavlo","followers_url":"https://api.github.com/users/apavlo/followers","following_url":"https://api.github.com/users/apavlo/following{/other_user}","gists_url":"https://api.github.com/users/apavlo/gists{/gist_id}","starred_url":"https://api.github.com/users/apavlo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apavlo/subscriptions","organizations_url":"https://api.github.com/users/apavlo/orgs","repos_url":"https://api.github.com/users/apavlo/repos","events_url":"https://api.github.com/users/apavlo/events{/privacy}","received_events_url":"https://api.github.com/users/apavlo/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/apavlo/h-store/labels/Anti-Cache","name":"Anti-Cache","color":"516F69"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":13,"created_at":"2014-09-06T00:39:59Z","updated_at":"2015-01-28T02:32:39Z","closed_at":null,"body":"The following is a rough outline for how to add support for an additional thread to operate \"down\" in the EE while the main PartitionExecutor thread processes transactions. This is not possible in the current architecture because there is a single shared buffer that we use to pass data + error codes between the Java layer and the C++ layer (through JNI). The mapping between the Java and C++ layers is as follows:\r\n\r\n* **Exception Buffer:** `ExecutionEngineJNI.exceptionBuffer` -> `VoltDBEngine::m_reusedResultBuffer``\r\n* **VoltTable Result Buffer:** `ExecutionEngineJNI.deserializer` (this is a wrapper for the ByteBuffer) -> `VoltDBEnginer::m_reusedResultBuffer`\r\n\r\nNote that the memory is allocated in Java and then we pass down the pointers to the C++ layer.\r\n\r\nTo give an example why this is a problem now with the existing AntiCacheManager implementation, I will now discuss a race condition that can occur. The Java AntiCacheManager has its own thread that it uses to unevict data at a partition. If this uneviction process encounters an error, then it will write a `SerializedException` into that partition's shared buffer. If the PartitionExecutor is processing a txn at the same time it may trip its own exception and want to write into that same buffer. If the other thread is trying to deserialize the exception, then the contents will get collobered. This is a race condition that we have definitely seen crop up before.\r\n\r\n1. What needs to happen is that we need to make a separate buffer for data and exceptions for utility operations. This will allow us to evict and unevict data in a separate thread without worrying about overwriting the main buffers. Add this new utility buffer to `ExecutionEngineJNI` and update the parameters to `ExecutionEngine.nativeSetBuffers()` to pass down this new buffer pointer. You can see how we did the same thing with `ExecutionEngineJNI.ariesLogBuffer`. You will need to update `VoltDBEngine::setBuffers()` accordingly.\r\n\r\n2. Modify `VoltDBEngine::antiCacheReadBlocks()` to use this new utility buffer when there is an exception. You can see the **FIXME** in the code that makes reference to this problem. You will also need to modify `ExecutionEngineJNI.antiCacheReadBlocks()` to look for errors in the new utility buffers.\r\n\r\n3. The final step is to now add an additional utility thread for evicting data without needing to block transactions. This is more complicated because we need to collect blocks of cold tuples to evict but also make sure that those tuples are being used by an active txn. We may want to add a new global flag in the EE that tells us that the eviction thread is doing something and keep track of the read-write sets of any txn that executes during this brief window. When we're ready to do the eviction, we then set a lock to prevent txns from executing, remove any tuples from the block we're about to evict that are also in the active txn's `ReadWriteSet`, and then write out the block. I'm not sure how we just want to do this just yet because I don't want to have to check for a lock every time we normally execute txns. We can talk about this problem when you get to this point."},"comment":{"url":"https://api.github.com/repos/apavlo/h-store/issues/comments/71770854","html_url":"https://github.com/apavlo/h-store/issues/175#issuecomment-71770854","issue_url":"https://api.github.com/repos/apavlo/h-store/issues/175","id":71770854,"user":{"login":"zheguang","id":2547821,"avatar_url":"https://avatars.githubusercontent.com/u/2547821?v=3","gravatar_id":"","url":"https://api.github.com/users/zheguang","html_url":"https://github.com/zheguang","followers_url":"https://api.github.com/users/zheguang/followers","following_url":"https://api.github.com/users/zheguang/following{/other_user}","gists_url":"https://api.github.com/users/zheguang/gists{/gist_id}","starred_url":"https://api.github.com/users/zheguang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zheguang/subscriptions","organizations_url":"https://api.github.com/users/zheguang/orgs","repos_url":"https://api.github.com/users/zheguang/repos","events_url":"https://api.github.com/users/zheguang/events{/privacy}","received_events_url":"https://api.github.com/users/zheguang/received_events","type":"User","site_admin":false},"created_at":"2015-01-28T02:32:39Z","updated_at":"2015-01-28T02:32:39Z","body":"Would you guys be available to take a look at my initial patch for the second bullet point?  I wrote a long commit message to convey the overall design. This however is based on my current understanding of the frontend, so please do point out what looks wrong to you.\r\n\r\nhttps://github.com/zheguang/h-store/commit/5537d01102b9b77dd2c5860805c63dfb8c64361b\r\n\r\nMany thanks!"}}