test: bugfix, synchronize indexes synchronously #28026

pull furszy wants to merge 1 commits into bitcoin:master from furszy:2023_fix_index_timeout changing 8 files +17 −54
  1. furszy commented at 11:18 pm on July 3, 2023: member

    Fixing the current CI failures.

    The tests objective is to exercise the chain synchronization code, verifying that the indexes are able to catch up with the chain-tip. Therefore, there is no need to run the process on a worker thread.

    Note: After #27607, the BaseIndex::Start method will be almost empty. Only containing the ThreadSync call, allowing us to extract the thread ownership from the index class and place it into an external structure (probably, the thread pool introduced in #26966).

  2. test: bugfix, synchronize indexes synchronously
    The tests objective is to exercise the chain synchronization
    code, verifying that the indexes are able to catch up with the
    chain-tip. Therefore, there is no need to run the process on
    a worker thread.
    f01cb3a8dc
  3. DrahtBot commented at 11:18 pm on July 3, 2023: contributor

    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
    ACK MarcoFalke, TheCharlatan

    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:

    • #28036 (test: Restore unlimited timeout in IndexWaitSynced by MarcoFalke)
    • #27607 (index: make startup more efficient by furszy)

    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.

  4. DrahtBot added the label Tests on Jul 3, 2023
  5. maflcko commented at 6:16 am on July 4, 2023: member
    lgtm ACK f01cb3a8dcc12954d5b6e075ebeb94c00fd37779
  6. fanquake requested review from ryanofsky on Jul 4, 2023
  7. fanquake requested review from mzumsande on Jul 4, 2023
  8. TheCharlatan approved
  9. TheCharlatan commented at 11:32 am on July 5, 2023: contributor
    ACK f01cb3a8dcc12954d5b6e075ebeb94c00fd37779
  10. maflcko commented at 11:35 am on July 5, 2023: member
    (An alternative, functionally equivalent to this, might be to just make the timeout infinite, see #27988 (comment), but I think this is fine as well.)
  11. mzumsande commented at 3:59 pm on July 5, 2023: contributor

    (An alternative, functionally equivalent to this, might be to just make the timeout infinite, see #27988 (comment), but I think this is fine as well.)

    I think I’d prefer that option because then we wouldn’t need to add a test-only arg to BaseIndex::Start, plus having the same thread structure as in production seems more natural and more robust with respect to possible future changes of the init sequence and unit tests.

  12. furszy commented at 9:34 pm on July 5, 2023: member

    (An alternative, functionally equivalent to this, might be to just make the timeout infinite, see #27988 (comment), but I think this is fine as well.)

    I think I’d prefer that option because then we wouldn’t need to add a test-only arg to BaseIndex::Start, plus having the same thread structure as in production seems more natural and more robust with respect to possible future changes of the init sequence and unit tests.

    I agree that the current index initialization structure isn’t ideal as it tightly couples the init sequence with the background sync thread creation.

    We have #27607 addressing it, which decouples the init procedure from the BaseIndex::Start method. Leaving only the background sync thread creation there and nothing else.

    Having that solved, and regarding the topic of matching production thread structure: I don’t see why unit tests in general should replicate the complete production behavior or precisely match the thread model used in production. Furthermore, none of these tests really concern themselves with concurrency; they simply start the index sync thread and wait for it to finish before proceeding, effectively running the task synchronously.

    I mean, I’m also ok if we simply rise the timeout but, at the same time, I don’t think that the background threads creation adds any meaningful test coverage here.


    On a slightly unrelated note and going a bit further over the topic, I think that the app’s threading decisions should not be part of the index class. In other words, threads should not be owned and managed by each index object. It is not a responsibility that indexes should have. Instead, indexes should sync purely based on external events.

    And actually, by separating the threading concerns from the index class, we can optimize a high amount of redundant work currently performed by indexes. For instance, there is no need to traverse the entire chain and read every single block from disk in each of the index threads. We could have just one thread dedicated to reading blocks from disk, while an event dispatcher class notifies all existing indexes. Or.. even better, there could be multiple threads, reading different ranges of blocks at the same time, and dispatching events asynchronously to the indexes (this idea is related to #26966, and it’s something I intend to pursue after #24230).

  13. maflcko commented at 7:15 am on July 6, 2023: member

    I mean, I’m also ok if we simply rise the timeout but, at the same time, I don’t think that the background threads creation adds any meaningful test coverage here.

    Right, it doesn’t add any meaningful coverage. Though, I think the main point is that we should try to avoid adding test-only code to “real” code where possible. I am fine with anything, though.

    (Only modifying the test code would also avoid the conflicting with the other pull?)

  14. maflcko commented at 12:23 pm on July 6, 2023: member
    Went ahead and created the alternative: #28036, if reviewers want it. Happy to close it, if this is merged in the meantime.
  15. ajtowns commented at 2:56 pm on July 6, 2023: contributor

    I think I’d prefer that option because then we wouldn’t need to add a test-only arg to BaseIndex::Start, plus having the same thread structure as in production seems more natural and more robust with respect to possible future changes of the init sequence and unit tests.

    I think I (weakly) agree with this – having the code be non-threaded in tests but threading in the real use seems like an annoying difference.

  16. maflcko commented at 7:56 am on July 7, 2023: member

    Does your feedback from #28036 (comment) also apply here? I think you’ll also have to check for it being synced?

    0Assert(index.GetSummary().synced);
    
  17. DrahtBot added the label Needs rebase on Jul 7, 2023
  18. DrahtBot commented at 10:34 am on July 7, 2023: contributor

    🐙 This pull request conflicts with the target branch and needs rebase.

  19. furszy commented at 1:11 pm on July 7, 2023: member

    Does your feedback from #28036 (comment) also apply here? I think you’ll also have to check for it being synced?

    0Assert(index.GetSummary().synced);
    

    Yeah @MarcoFalke. Same applies here. I didn’t push it just because of #28036. Thought that we were going to tackle it there.

  20. maflcko commented at 1:23 pm on July 7, 2023: member
    Looks like #28036 got merged in the meantime, so I’ll add the Assert(!ShutdownRequested()) as follow-up on Monday unless someone beats me to it.
  21. furszy commented at 1:25 pm on July 7, 2023: member

    Looks like #28036 got merged in the meantime, so I’ll add the Assert(!ShutdownRequested()) as follow-up on Monday unless someone beats me to it.

    Yeah, not sure why it got merged it. Already pushed #28044 fixing it.

  22. maflcko commented at 1:29 pm on July 7, 2023: member
    Thanks, I think this one can be closed for now?
  23. furszy closed this on Jul 7, 2023

  24. fanquake commented at 1:30 pm on July 7, 2023: member

    Already pushed #28044 fixing it.

    Why not just push it here, and re-use this PR (dropping any now-redundant changes) . Otherwise, why is this still open.

    Yeah, not sure why it got merged it.

    It got merged to fix the persistent (potentially confusing) CI issues. What you want to fix isn’t currently an active issue.

  25. furszy commented at 1:49 pm on July 7, 2023: member

    Why not just push it here, and re-use this PR (dropping any now-redundant changes) . Otherwise, why is this still open.

    Closed the PR a minute before your comment.

    It got merged to fix the persistent (potentially confusing) CI issues. What you want to fix isn’t currently an active issue.

    Well, the previous CI failure was due a pretty clear timeout error. Now there is a possibility of tests hanging forever with no clear reason. So, this last one is practically more confusing than the first one.

    Isn’t a big deal anyway but would had being nicer if you would have waited a bit for Marco’s feedback there. The timeout was open for few days, it could had continued open for few more hours.

  26. bitcoin locked this on Jul 6, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-09-28 22:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me