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

config/storage: cache zone config values to avoid repetitive deserialization #30143

Merged
merged 1 commit into from
Sep 19, 2018

Conversation

spencerkimball
Copy link
Member

This change allows a SystemConfig to cache object ID -> ZoneConfig
lookups to avoid repetitively deserializing table descriptors and zone
configs for every replica in the system. Replicas themselves now also
cache zone config entries to avoid maintaining per-replica min/max bytes
and for making future use of additional zone config parameters simpler
(e.g. zone config GC policies, number of replicas, etc.).

Fixes #21702

@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Member

@nvanbenschoten nvanbenschoten left a comment

Choose a reason for hiding this comment

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

Mechanically this :lgtm: However, I'm not familiar enough with zone configs and especially subzones and placeholder zones to be able to comment about them.

Reviewed 61 of 67 files at r1, 6 of 6 files at r2.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale)


pkg/storage/replica_proposal.go, line 537 at r2 (raw file):

	if needsSplitBySize {
		log.Infof(context.TODO(), "zone for %s: %+v", r, r.GetZoneConfig())

Did you mean to remove this?

Copy link
Member Author

@spencerkimball spencerkimball 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: :shipit: complete! 1 of 0 LGTMs obtained


pkg/storage/replica_proposal.go, line 537 at r2 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

Did you mean to remove this?

Done.

@spencerkimball
Copy link
Member Author

Added @benesch to review.

@spencerkimball spencerkimball force-pushed the cache-zone-configs branch 2 times, most recently from 1255303 to e02bbc7 Compare September 18, 2018 14:21
Copy link
Contributor

@benesch benesch left a comment

Choose a reason for hiding this comment

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

Whew, that looked like it was painful. Thanks for finally fixing this! And sorry I didn't get to this yesterday; I got stuck tracking down fallout from the go1.11 bump.

The only thing I'd like to get resolved before merging is my confusion about the cache return parameter from sql.ZoneConfigHook. Feel free to ignore everything else.

Reviewed 67 of 67 files at r1, 2 of 6 files at r2, 24 of 24 files at r3.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale)


pkg/config/system.go, line 201 at r1 (raw file):

// GetZoneConfigForKey looks up the zone config for the object (table
// or database, specified by key.id) and optional partition (specified
// by key.suffix). It is the caller's responsibility to ensure that

Is this true? Seems like key is still just a roachpb.RKey. I think maybe this comment should have gone on getZoneConfigForKey?


pkg/config/system.go, line 244 at r1 (raw file):

		} else if zone != nil {
			entry = zoneEntry{zone: zone, placeholder: placeholder}
			if cache {

What's this cache param about? It seems to always be equivalent to err != nil.


pkg/sql/show_zone_config.go, line 109 at r1 (raw file):

			zone = &subzone.Config
		}
	}

I think I'd have preferred to keep this complexity in GetZoneConfigInTxn, since this chunk of logic is duplicated in setZoneConfig and showZoneConfig, and verifyZoneConfigs. Feel free to leave to a follow up, since I think Ridwan's going to be doing cleanup in the area anyway.


pkg/storage/replica.go, line 6735 at r1 (raw file):

	kvs := br.Responses[0].GetInner().(*roachpb.ScanResponse).Rows
	sysCfg := config.NewSystemConfig()
	sysCfg.Values = kvs

Food for thought: perhaps NewSystemConfig should take the values as an argument.


pkg/storage/store_rebalancer.go, line 391 at r1 (raw file):

		desc, zone := replWithStats.repl.DescAndZone()
		if zone == nil {

Could this really be nil? It seems like repl.mu.zone is always set to a non-nil zone config.

…ization

This change allows a `SystemConfig` to cache object ID -> `ZoneConfig`
lookups to avoid repetitively deserializing table descriptors and zone
configs for every replica in the system. Replicas themselves now also
cache zone config entries to avoid maintaining per-replica min/max bytes
and for making future use of additional zone config parameters simpler
(e.g. zone config GC policies, number of replicas, etc.).

Fixes cockroachdb#21702
Copy link
Member Author

@spencerkimball spencerkimball 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: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale)


pkg/config/system.go, line 201 at r1 (raw file):

Previously, benesch (Nikhil Benesch) wrote…

Is this true? Seems like key is still just a roachpb.RKey. I think maybe this comment should have gone on getZoneConfigForKey?

You're right. Fixed.


pkg/config/system.go, line 244 at r1 (raw file):

Previously, benesch (Nikhil Benesch) wrote…

What's this cache param about? It seems to always be equivalent to err != nil.

The cache param is returned by the zone config hook. It specifies whether the hook allows its results to be cached by the SystemConfig. This is always true in production, but not true in some test cases where there's a testing hook set.


pkg/sql/show_zone_config.go, line 109 at r1 (raw file):

Previously, benesch (Nikhil Benesch) wrote…

I think I'd have preferred to keep this complexity in GetZoneConfigInTxn, since this chunk of logic is duplicated in setZoneConfig and showZoneConfig, and verifyZoneConfigs. Feel free to leave to a follow up, since I think Ridwan's going to be doing cleanup in the area anyway.

No, that's a solid idea. I wasn't sure about the various ways that GetZoneConfigInTxn was used when I started this. I'll move this code back into that method and return the subzone from there instead.


pkg/storage/replica.go, line 6735 at r1 (raw file):

Previously, benesch (Nikhil Benesch) wrote…

Food for thought: perhaps NewSystemConfig should take the values as an argument.

In this case we don't want to use NewSystemConfig because we want the underlying protobuf, not the caching parent struct


pkg/storage/store_rebalancer.go, line 391 at r1 (raw file):

Previously, benesch (Nikhil Benesch) wrote…

Could this really be nil? It seems like repl.mu.zone is always set to a non-nil zone config.

It is in some test conditions and it's a pain to work around it from the test itself. (e.g. storage.TestChooseLeaseToTransfer)

Copy link
Contributor

@benesch benesch left a comment

Choose a reason for hiding this comment

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

:lgtm_strong:

Reviewed 13 of 13 files at r4.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (and 1 stale)


pkg/config/system.go, line 244 at r1 (raw file):

Previously, spencerkimball (Spencer Kimball) wrote…

The cache param is returned by the zone config hook. It specifies whether the hook allows its results to be cached by the SystemConfig. This is always true in production, but not true in some test cases where there's a testing hook set.

Ah! Thanks, missed that.

Now that zone configs are accessible from SQL we can probably get rid of that testing hook with some elbow grease. (Definitely not suggested that you do that.)


pkg/storage/replica.go, line 6735 at r1 (raw file):

Previously, spencerkimball (Spencer Kimball) wrote…

In this case we don't want to use NewSystemConfig because we want the underlying protobuf, not the caching parent struct

Ack. That comment was on an earlier revision of your PR. Design as-is LGTM.


pkg/storage/store_rebalancer.go, line 391 at r1 (raw file):

Previously, spencerkimball (Spencer Kimball) wrote…

It is in some test conditions and it's a pain to work around it from the test itself. (e.g. storage.TestChooseLeaseToTransfer)

Seems like you did, though? 🙌

@spencerkimball
Copy link
Member Author

bors r+

craig bot pushed a commit that referenced this pull request Sep 19, 2018
30143: config/storage: cache zone config values to avoid repetitive deserialization r=spencerkimball a=spencerkimball

This change allows a `SystemConfig` to cache object ID -> `ZoneConfig`
lookups to avoid repetitively deserializing table descriptors and zone
configs for every replica in the system. Replicas themselves now also
cache zone config entries to avoid maintaining per-replica min/max bytes
and for making future use of additional zone config parameters simpler
(e.g. zone config GC policies, number of replicas, etc.).

Fixes #21702

Co-authored-by: Spencer Kimball <spencer.kimball@gmail.com>
@craig
Copy link
Contributor

craig bot commented Sep 19, 2018

Build succeeded

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

4 participants