Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

objstorageprovider: small readahead improvements #3607

Merged
merged 1 commit into from May 13, 2024

Conversation

sumeerbhola
Copy link
Collaborator

  • The limit was not being updated in certain cases, which delayed when readahead would occur. This is fixed, and new test case exercises this.
  • The code in recordCacheHit is almost identical to the one in maybeReadahead and the main comprehension challenge of the code is the various predicates (and their code comments with examples), which are repeated (without the examples). These are now merged into a single helper method.
  • A small side-effect of the previous change is that numReads is incremented on a cache hit when we are already above the threshold. This has no actual effect on when readahead will happen. And arguably, this new behavior is more principled.
  • One of the test cases had a missing - and was not being exercised, and resulting in an incorrect error in a later test case. This is fixed.
  • There is additional invariant documentation.

- The limit was not being updated in certain cases, which delayed
  when readahead would occur. This is fixed, and new test case
  exercises this.
- The code in recordCacheHit is almost identical to the one in
  maybeReadahead and the main comprehension challenge of the code
  is the various predicates (and their code comments with examples),
  which are repeated (without the examples). These are now merged
  into a single helper method.
- A small side-effect of the previous change is that numReads is
  incremented on a cache hit when we are already above the threshold.
  This has no actual effect on when readahead will happen. And
  arguably, this new behavior is more principled.
- One of the test cases had a missing - and was not being exercised,
  and resulting in an incorrect error in a later test case. This is
  fixed.
- There is additional invariant documentation.
@sumeerbhola sumeerbhola requested a review from a team as a code owner May 10, 2024 15:30
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 3 files reviewed, 1 unresolved discussion (waiting on @sumeerbhola)


objstorage/objstorageprovider/readahead.go line 96 at r1 (raw file):

			//
			rs.numReads++
			if readahead {

Could we extract these two blocks from this function? This would make the semantics of the function cleaner - it just figures out if the reads matches a readahead pattern and updates the state accordingly. Each caller then does its own thing.

Copy link
Collaborator Author

@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.

TFTR!

Reviewable status: 0 of 3 files reviewed, 1 unresolved discussion (waiting on @RaduBerinde)


objstorage/objstorageprovider/readahead.go line 96 at r1 (raw file):

Previously, RaduBerinde wrote…

Could we extract these two blocks from this function? This would make the semantics of the function cleaner - it just figures out if the reads matches a readahead pattern and updates the state accordingly. Each caller then does its own thing.

I am wary of that since there are other paths in this function that modify limit, prevSize, and size. It is confusing that in some cases this function will modify those fields and in other cases the caller has to modify them. And the complexity in this function is from the various nested conditions that result in this action -- the caller would need to do the same or we would need to return some bool. These choices seem harder to grok.

Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: 0 of 3 files reviewed, all discussions resolved


objstorage/objstorageprovider/readahead.go line 96 at r1 (raw file):

Previously, sumeerbhola wrote…

I am wary of that since there are other paths in this function that modify limit, prevSize, and size. It is confusing that in some cases this function will modify those fields and in other cases the caller has to modify them. And the complexity in this function is from the various nested conditions that result in this action -- the caller would need to do the same or we would need to return some bool. These choices seem harder to grok.

👍

@sumeerbhola sumeerbhola merged commit c969241 into cockroachdb:master May 13, 2024
11 checks passed
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.

None yet

3 participants