Skip to content

Conversation

@pav-kv
Copy link
Collaborator

@pav-kv pav-kv commented Nov 20, 2025

This commit clarifies in Engine.NewReader that consistent iterators are not that as of the NewReader() call time.

This is already mentioned in the Reader interface comment, but it is easy to miss in the details. Worth calling it out in the NewReader comment directly because this is the user's entry point into "reading" and it proved easy to assume that this is where consistency happens.

Epic: none
Release note: none

This commit clarifies in Engine.NewReader that consistent iterators are
not that as of the NewReader() call time.

This is already mentioned in the Reader interface comment, but it is
easy to miss in the details. Worth calling it out in the NewReader
comment directly because this is the user's entry point into "reading"
and it proved easy to assume that this is where consistency happens.

Epic: none
Release note: none
@pav-kv pav-kv requested a review from sumeerbhola November 20, 2025 23:10
@pav-kv pav-kv requested a review from a team as a code owner November 20, 2025 23:10
@blathers-crl
Copy link

blathers-crl bot commented Nov 20, 2025

It looks like your PR touches production code but doesn't add or edit any test code. Did you consider adding tests to your PR?

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

//
// NB: consistent iterators are not as of when NewReader is called. They are
// as of the time when the first iterator is created (often, this is when the
// first read happens if iterators are not used directly), or earlier if
Copy link
Collaborator Author

@pav-kv pav-kv Nov 20, 2025

Choose a reason for hiding this comment

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

Looking for suggestion on how to word this. Iterators are always used, but I mean to say that they are often hidden behind things (e.g. MVCCGet), so it can be the "first read/access" from the storage package user's perspective.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can leave it as the simple "when the first iterator is created, or earlier is Reader.PinEngineStateForIterators ...".
Code readers are expected to know that passing a Reader to some function could cause it to create an iterator.

// NB: consistent iterators are not as of when NewReader is called. They are
// as of the time when the first iterator is created (often, this is when the
// first read happens if iterators are not used directly), or earlier if
// Reader.PinEngineStateForIterators is called.
NewReader(durability DurabilityRequirement) Reader
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Any other places to call this out? NewReadOnly below seems like one.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We have many methods that give us a Reader: NewBatch, NewReader, NewReadOnly, NewUnindexedBatch.
We can either repeat the earlier comment with each. Or move that comment to the Reader declaration and point to it from all the methods. I have a preference for the latter.

Copy link
Collaborator

@sumeerbhola sumeerbhola left a comment

Choose a reason for hiding this comment

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

@sumeerbhola reviewed all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @pav-kv)

//
// NB: consistent iterators are not as of when NewReader is called. They are
// as of the time when the first iterator is created (often, this is when the
// first read happens if iterators are not used directly), or earlier if
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can leave it as the simple "when the first iterator is created, or earlier is Reader.PinEngineStateForIterators ...".
Code readers are expected to know that passing a Reader to some function could cause it to create an iterator.

// NB: consistent iterators are not as of when NewReader is called. They are
// as of the time when the first iterator is created (often, this is when the
// first read happens if iterators are not used directly), or earlier if
// Reader.PinEngineStateForIterators is called.
NewReader(durability DurabilityRequirement) Reader
Copy link
Collaborator

Choose a reason for hiding this comment

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

We have many methods that give us a Reader: NewBatch, NewReader, NewReadOnly, NewUnindexedBatch.
We can either repeat the earlier comment with each. Or move that comment to the Reader declaration and point to it from all the methods. I have a preference for the latter.

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.

3 participants