Skip to content

MINOR: Unmap index on close follow-up#5778

Closed
ijuma wants to merge 1 commit intoapache:trunkfrom
ijuma:unmap-index-on-close-follow-up
Closed

MINOR: Unmap index on close follow-up#5778
ijuma wants to merge 1 commit intoapache:trunkfrom
ijuma:unmap-index-on-close-follow-up

Conversation

@ijuma
Copy link
Copy Markdown
Member

@ijuma ijuma commented Oct 11, 2018

Update comment, isMemoryMappedBufferClosed variable and
handle close followed by delete.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@ijuma ijuma requested a review from lindong28 October 11, 2018 00:48
@ijuma
Copy link
Copy Markdown
Member Author

ijuma commented Oct 11, 2018

I noticed after merging the unmap on close change that maybe more needs to be done @lindong28.

Update comment, isMemoryMappedBufferClosed variable and
handle `close` followed by `delete`.
@ijuma ijuma force-pushed the unmap-index-on-close-follow-up branch from af42b12 to 23e97f0 Compare October 11, 2018 04:58
@ijuma
Copy link
Copy Markdown
Member Author

ijuma commented Oct 11, 2018

retest this please

@ijuma
Copy link
Copy Markdown
Member Author

ijuma commented Oct 20, 2018

@lindong28 does this seem OK to you? The previous change was incomplete so I think we need this in 2.1 to avoid issues.

@lindong28
Copy link
Copy Markdown
Member

@ijuma Sure, I will review it today.

@lindong28 lindong28 self-assigned this Oct 20, 2018
// (the clean shutdown file is written after the logs are all closed).
producerStateManager.takeSnapshot()
logSegments.foreach(_.close())
isMemoryMappedBufferClosed = true
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we also set isMemoryMappedBufferClosed to true in close(), the first sentence in its comment, The memory mapped buffer for index files of this log will be closed with either delete() or closeHandlers(), is no longer accurate.

Can we update its comment to e.g. After memory mapped buffer is closed, all disk IO operation other than delete() on this log should throw KafkaStorageException.

maybeHandleIOException(s"Error while deleting log for $topicPartition in dir ${dir.getParent}") {
lock synchronized {
checkIfMemoryMappedBufferClosed()
removeLogMetrics()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if it would be more intuitive not to set isMemoryMappedBufferClosed = true in delete().

The reason is that, if we don't call checkIfMemoryMappedBufferClosed() in delete(), it suggests that delete() can be done anytime after close() is called, which is actually the case in logManager.replaceCurrentWithFutureLog() which calls addLogToBeDeleted(sourceLog) after sourceLog.close(). Then the intuition is that, if delete() can be done without considering the state (i.e. isMemoryMappedBufferClosed) of log, it probably should not change the state of log as well.

Another intuition is that, it seems weird if delete() sets isMemoryMappedBufferClosed to true and yet delete() can be called again without triggering KafkaStorageException.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good question. It's a little unclear what's the best path as we don't generally require close to be called before delete for the various log/index classes. As a result, we have one case where we don't call Log.close at all (the LogManager.asyncDelete path) and rely on the Log.delete method to release resources. If we don't set isMemoryMappedBufferClosed in the delete method, then it would stay false for this path.

As it happens, the fact that we don't close the file handles before we rename the directory in LogManager.asyncDelete is one reason why things break on Windows.

Copy link
Copy Markdown
Member

@lindong28 lindong28 Oct 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the design for the Log.java API, it seems intuitive to only allow delete() after close() or closeHandlers() is invoked. delete() will only delete files on disk without reading or writing anything and thus it does not require any handler to be open for this log.

And it seems reasonable to enforce the rule that we always close a log before deleting it in e.g. LogManager.asyncDelete(). And delete() can throw IllegalStateException if isMemoryMappedBufferClosed is false.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this needs a bit more discussion. I propose we revert the change in 2.1 to close the index during Log.close so that the behaviour remains the same as in 2.0. In trunk, we can make the changes after we agree to them. How does that sound?

Copy link
Copy Markdown
Member

@lindong28 lindong28 Oct 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Sounds good. Thanks for the patch! The previous PR has been reverted in 2.1 branch.

lindong28 added a commit that referenced this pull request Oct 21, 2018
@lindong28 lindong28 removed their assignment Dec 7, 2018
@github-actions
Copy link
Copy Markdown

This PR is being marked as stale since it has not had any activity in 90 days. If you
would like to keep this PR alive, please leave a comment asking for a review. If the PR has
merge conflicts, update it with the latest from the base branch.

If you are having difficulty finding a reviewer, please reach out on the [mailing list](https://kafka.apache.org/contact).

If this PR is no longer valid or desired, please feel free to close it. If no activity occurs in the next 30 days, it will be automatically closed.

@github-actions github-actions Bot added the stale Stale PRs label Nov 21, 2024
@github-actions
Copy link
Copy Markdown

This PR has been closed since it has not had any activity in 120 days. If you feel like this
was a mistake, or you would like to continue working on it, please feel free to re-open the
PR and ask for a review.

@github-actions github-actions Bot added the closed-stale PRs that were closed due to inactivity label Dec 22, 2024
@github-actions github-actions Bot closed this Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

closed-stale PRs that were closed due to inactivity stale Stale PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants