Skip to content

Yield every 1000 iterations when fetching sharding keys and funcs#500

Closed
ita-sammann wants to merge 1 commit into
tarantool:masterfrom
ita-sammann:fetch-sharding-keys-with-yield
Closed

Yield every 1000 iterations when fetching sharding keys and funcs#500
ita-sammann wants to merge 1 commit into
tarantool:masterfrom
ita-sammann:fetch-sharding-keys-with-yield

Conversation

@ita-sammann

Copy link
Copy Markdown
Contributor

Yield every 1000 iterations when fetching sharding keys and functions so the server stays responsive when there are millions of records.

@ita-sammann ita-sammann requested review from Satbek, a1div0 and vakhov June 25, 2026 17:21

@vakhov vakhov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR! I left a few comments below.

adding explicit yields changes the consistency semantics of this function: concurrent DDL updates may now interleave with the scan, so metadata_map can contain entries from different schema states, including a sharding key and function fetched at different moments. is this eventual consistency guaranteed to be handled by the hash/reload mechanism? could we add a regression test for the cold-cache case to verify that another fiber gets scheduled during a large metadata scan?

space_name)
end

if i % 1000 == 0 then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could we extract 1000 into a named constant to avoid duplicating the magic number?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good idea, thanks! Extracted

end

if i % 1000 == 0 then
fiber.yield()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

on a cold cache, get_sharding_(func|key)_hash() calls init_cache(), which scans the whole DDL space without yielding. So the first fetch may still block. should we add yielding inside init_cache() instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added yield there, thanks for noticing!

@ita-sammann ita-sammann force-pushed the fetch-sharding-keys-with-yield branch from 86a61f7 to 4fe10ac Compare June 26, 2026 20:24
@ita-sammann

Copy link
Copy Markdown
Contributor Author

adding explicit yields changes the consistency semantics of this function

@vakhov, actually I don't like the idea of this yields at all. If there is a sane amount of sharding keys there are no problems.
Maybe we should just add migration helpers (tarantool/migrations#88) and update the documentation to highlight that user should drop the corresponding sharding key when dropping the space. And just close this PR.

@ita-sammann ita-sammann closed this Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants