divijvaidya commented on PR #17425: URL: https://github.com/apache/kafka/pull/17425#issuecomment-2481156602
You have understood my intention. The `maybeFlush()` proposal will work as well for the current problem. But I would like to extend that a bit further and try to eliminate this class of bug altogether. This can be done if we introduce a lifecycle state within the index. After lifecycle transitions to "closing" or "closed", no other thread should be able to mutate the index. Consider the following: Indices are already `Closeable`. When `close` is called, we should set a "isClosing" boolean on the index. When `flush()` is called, if the `isClosing` boolean is set, we will do nothing. As an example, `AbstractIndex.flush()` ``` def flush(): Unit = { inLock(lock) { mmap.force() } } ``` Will change into: ``` def flush(): Unit = { if (isClosing) return; inLock(lock) { if (isClosing) return; mmap.force() } } ``` We need to apply this lifecycle state to other methods such as `trimToValidSize` as well i.e. once an index is closed, it shouldn't be possible to call any of it's public APIs. Thoughts? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org