Skip to content

Conversation

pstratem
Copy link
Contributor

Previously an ERROR was logged every time an index was initialized. Now we only record an error on actual error.

Previously an ERROR was logged every time an index was initialized.
Now we only record an error on actual error.
@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 17, 2023

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
Concept ACK mzumsande

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #24230 (indexes: Stop using node internal types and locking cs_main, improve sync logic by ryanofsky)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@maflcko maflcko changed the title Fix BaseIndex::Commit false error. log: Fix BaseIndex::Commit false error Jan 17, 2023
@pstratem
Copy link
Contributor Author

@MarcoFalke this does also change the behavior slightly

@maflcko maflcko changed the title log: Fix BaseIndex::Commit false error Fix BaseIndex::Commit false error Jan 17, 2023
@maflcko
Copy link
Member

maflcko commented Jan 17, 2023

In Rewind? I guess it might be good to list all behaviour changes in the commit or pull description to give reviewers a more accessible entry point. Also, for new code, we use {} in multi-line if.

@pstratem
Copy link
Contributor Author

@MarcoFalke anything that checks the return value will see a different result on the first call.

I'm not sure that matters but it is different.

@pstratem
Copy link
Contributor Author

@MarcoFalke each of the if statements is a single line single expression block

@pstratem
Copy link
Contributor Author

yes the only thing checking the result from Commit is Rewind, the behavior isn't changed here since Rewind won't be called before m_best_block_index has been set (it asserts that the best block index is the current tip)

@mzumsande
Copy link
Contributor

Concept ACK

@fanquake fanquake requested a review from ryanofsky February 27, 2023 15:02
@ryanofsky
Copy link
Contributor

I agree 1c67b49 would fix the problem, but I think it suppresses errors too broadly. The Commit() function is called many places, so changing it to silently skip the CustomCommit() call and return true when it doesn't do anything could make it harder debug other problems in the future, or even know about them.

I think it would be better to apply a more targeted fix of just not calling Commit() when there is nothing to commit in the sync thread:

--- a/src/index/base.cpp
+++ b/src/index/base.cpp
@@ -189,9 +189,9 @@ void BaseIndex::ThreadSync()
                           GetName(), pindex->nHeight);
                 last_log_time = current_time;
             }
 
-            if (last_locator_write_time + SYNC_LOCATOR_WRITE_INTERVAL < current_time) {
+            if (pindex->pprev && last_locator_write_time + SYNC_LOCATOR_WRITE_INTERVAL < current_time) {
                 SetBestBlockIndex(pindex->pprev);
                 last_locator_write_time = current_time;
                 // No need to handle errors in Commit. See rationale above.
                 Commit();

Note on history of this bug: The m_best_block_index == nullptr check in the Commit() function was first added in 0243907 from #24117 to avoid writing the index locator and try to prevent data corruption. It was later extended in 7878f97 from #25494 to avoid writing custom index data as well as the index locator, and to print an error message. That change unfortunately caused the issue here by spuriously printing the error message on startup when a new index was enabled. @mzumsande actually pointed out the spurious error message at the time in a review comment #25494 (comment), but I didn't realize how commonly the error would happen, and we didn't do anything about it then.

@achow101
Copy link
Member

Are you still working on this?

@fanquake
Copy link
Member

@mzumsande Maybe you'll want to pick this up?

@fanquake fanquake closed this Sep 26, 2023
@mzumsande
Copy link
Contributor

I think this worth fixing and could pick it up (might take a week or two), but @ryanofsky since you suggested a specific fix above do you want to PR it?

achow101 added a commit that referenced this pull request Mar 20, 2024
f65b0f6 index: Move last_locator_write_time and logging to end of threadsync loop (Fabian Jahr)

Pull request description:

  In the index sync thread, when initializing an index for the first time, stop callng BaseIndex::Commit when m_best_block_index is null, to avoid a spurious "failed to commit" error from that function. This error started happening in commit 7878f97 from #25494 and was reported by pstratem in #26903 with an alternate fix.

ACKs for top commit:
  achow101:
    ACK f65b0f6
  ryanofsky:
    Code review ACK f65b0f6. Just moved log "Syncing" log line since last commit to avoid having to call now() twice.
  furszy:
    ACK f65b0f6
  TheCharlatan:
    ACK f65b0f6

Tree-SHA512: afa8f05786318d36346d167ff53ea0b3bc8abdb0ad04465d199dc3eb91e9f837369e24fcb7e24b5757b02d698ec504e61da6ac365eaf006c874fc07a424a7e20
@bitcoin bitcoin locked and limited conversation to collaborators Sep 26, 2024
@fanquake
Copy link
Member

Removed "Up for Grabs", as this looks like it was fixed in #29671.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants