Skip to content

kvserver: add load vec#91593

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
kvoli:22117.rstats
Jan 3, 2023
Merged

kvserver: add load vec#91593
craig[bot] merged 1 commit intocockroachdb:masterfrom
kvoli:22117.rstats

Conversation

@kvoli
Copy link
Copy Markdown
Contributor

@kvoli kvoli commented Nov 9, 2022

Previously, disparate types were used when comparing StoreCapacity,
XThreshold and RangeUsageInfo. This patch introduces a uniform
intermediate type Load, which is used to perform arithmetic and
comparison between types representing load.

The purpose of this change is to decouple changes to inputs, enable
modifying existing dimensions and adding new ones with less code
modification.

The only load dimension added in this patch is Queries, which is then
used in place of QueriesPerSecond within the rebalancing logic.

Additionally, RangeUsageInfo is uniformly passed around in place of
any specific calls to the underlying tracking datastructure
ReplicaStats.

Part of #91152

Release note: None

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@kvoli kvoli force-pushed the 22117.rstats branch 6 times, most recently from 1d0b59a to aaacd6f Compare November 9, 2022 14:59
@kvoli kvoli changed the title kvserver: add load dimensions kvserver: add load vec Nov 29, 2022
@kvoli kvoli force-pushed the 22117.rstats branch 6 times, most recently from 6d14e3f to cfb4c5f Compare December 8, 2022 10:02
@kvoli kvoli marked this pull request as ready for review December 8, 2022 19:12
@kvoli kvoli requested a review from a team as a code owner December 8, 2022 19:12
@kvoli kvoli force-pushed the 22117.rstats branch 4 times, most recently from 471b49c to 5e8ec4c Compare December 19, 2022 19:28
@kvoli kvoli self-assigned this Dec 19, 2022
@kvoli kvoli requested review from AlexTalks, andrewbaptist and nvb and removed request for AlexTalks December 19, 2022 21:20
@kvoli kvoli force-pushed the 22117.rstats branch 3 times, most recently from e880e2b to 6b4edb0 Compare December 27, 2022 22:40
Copy link
Copy Markdown

@andrewbaptist andrewbaptist left a comment

Choose a reason for hiding this comment

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

This mostly looks great. Most of the comments are pretty minor, but I'm a little confused about some of the "multi-dimension" code that exists.

Reviewed 37 of 37 files at r1, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @kvoli and @nvanbenschoten)


pkg/kv/kvserver/replica_rankings.go line 103 at r1 (raw file):

//
// TODO(kvoli): When adding another load dimension to be balanced upon, it will
// be necessary to clairfy the semantics of this API. This is especially true

nit: clairfy -> clarify


pkg/kv/kvserver/replica_rankings.go line 105 at r1 (raw file):

// be necessary to clairfy the semantics of this API. This is especially true
// since the UI is coupled to this function.
func (rr *ReplicaRankings) NewAccumulator(dimension load.Dimension) *RRAccumulator {

I'm confused why this is a method on ReplicaRankings instead of just a function. You don't use the rr in here at all. It looks like it was this way before, but makes it a little more confusing to read.


pkg/kv/kvserver/replica_rankings.go line 223 at r1 (raw file):

// TopQPS returns the highest QPS CandidateReplicas that are tracked.
func (rr *ReplicaRankingMap) TopQPS(tenantID roachpb.TenantID) []CandidateReplica {

Rename to TopLoad?


pkg/kv/kvserver/replica_rankings.go line 244 at r1 (raw file):

func (a RRAccumulatorByTenant) AddReplica(repl CandidateReplica) {
	// Do not consider ranges as hot when they are accessed once or less times.
	if repl.RangeUsageInfo().QueriesPerSecond <= 1 {

I probably just need a walk through with you on this. But I assumed that the function here would be "generic" over the replica. Here it is still assuming QPS.


pkg/kv/kvserver/replicate_queue.go line 2167 at r1 (raw file):

// NB: This is currently just the replicas usage, it assumes that the range's
// usage information matches. Which is dubious in some cases but often
// reasoanble when we only consider the leaseholder.

nit: reasoanble -> reasonable


pkg/kv/kvserver/store.go line 3411 at r1 (raw file):

// out of date.
func (s *Store) HottestReplicas() []HotReplicaInfo {
	topQPS := s.replRankings.TopLoad()

nit: rename variable.


pkg/kv/kvserver/store_rebalancer.go line 714 at r1 (raw file):

		desc, conf := candidateReplica.DescAndSpanConfig()
		log.KvDistribution.VEventf(ctx, 3, "considering lease transfer for r%d with %s load",

Consider printing the dimension being used here so that the "units" make sense. Otherwise, this might be hard to debug if the configuration isn't known. (add on other events as well).


pkg/kv/kvserver/store_rebalancer.go line 824 at r1 (raw file):

		if candidateReplica == nil {
			panic("programming error: nil candidate replica found")

This is unnecessary to have this check at all anymore. It will panic anyway on the line below.


pkg/kv/kvserver/allocator/base.go line 176 at r1 (raw file):

	// LoadDimensions declares the load dimensions to use when the Goal is
	// LoadConvergence.
	LoadDimensions []load.Dimension

I'm a little confused why this is an array (rather than just a single Dimension). I'm not clear that this is needed here at all since it can be pulled from configuration when needed (should discuss at walkthrough).


pkg/kv/kvserver/allocator/allocatorimpl/allocator.go line 1923 at r1 (raw file):

				LoadThreshold:                LoadThresholds(&a.st.SV, opts.LoadDimensions...),
				MinLoadThreshold:             LoadMinThresholds(opts.LoadDimensions...),
				MinRequiredRebalanceLoadDiff: LoadRebalanceRequiredMinDiff(&a.st.SV, opts.LoadDimensions...),

It seems like this would be much better if it was a ratio rather than an absolute difference.


pkg/kv/kvserver/allocator/allocatorimpl/allocator_scorer.go line 417 at r1 (raw file):

	// MinRequiredRebalanceLoadDiff declares the minimum load difference
	// between stores required before recommending an action to rebalance.
	MinRequiredRebalanceLoadDiff load.Load

As noted elsewhere, can this be changed to be a ratio rather than an absolute difference?


pkg/kv/kvserver/allocator/allocatorimpl/allocator_scorer.go line 438 at r1 (raw file):

	// rebalance or transfer. These shoulld more generally use two different
	// methods when estimating an impact.
	RebalanceImpact load.Load

This seems very difficult to calculate correctly. Also, I'm a little confused if you are computing the "cost" of follower replicas. If not, then it may skew the results badly. Let's discuss during the walkthrough.


pkg/kv/kvserver/allocator/allocatorimpl/allocator_scorer.go line 496 at r1 (raw file):

		log.KvDistribution.VEventf(
			ctx, 4,
			"should rebalance replica with %0.2f qps from s%d (qps=%0.2f) to s%d (qps=%0.2f)",

Fix the comment to not say qps


pkg/kv/kvserver/allocator/allocatorimpl/allocator_scorer.go line 1205 at r1 (raw file):

			len(options.LoadDims)))
	}
	dimension := options.LoadDims[0]

Should LoadDims just be a singleton rather than an array?


pkg/kv/kvserver/allocator/load/dimension.go line 22 at r1 (raw file):

const (
	nDimensions = 1

nit: This is better done with
`nDimensions int = int(Queries) + 1 put at the end of the const block above. This makes it less likely to be missed when new dimensions are added.


pkg/kv/kvserver/allocator/load/load.go line 36 at r1 (raw file):

	Min(other Load) Load
	// Mul multiplies the calling Load with other and returns the result.
	Mul(other Load) Load

Mul seems strange. Its not clear what the units would be on this anymore... For instance if it was Q/S before it would now be Q^2/S^2. This would be clearer if it was Mul(threshold float).


pkg/kv/kvserver/asim/storerebalancer/replica_rankings.go line 21 at r1 (raw file):

func hottestRanges(state state.State, storeID state.StoreID) []kvserver.CandidateReplica {
	replRankings := kvserver.NewReplicaRankings()
	accumulator := replRankings.NewAccumulator(load.Queries)

Shouldn't the dimension be passed in here and used instead?


pkg/kv/kvserver/replicastats/replica_stats.go line 397 at r1 (raw file):

func (rs *ReplicaStats) SnapshotRatedSummary() *RatedSummary {
	qps, duration := rs.AverageRatePerSecond()
	localityCounts, _ := rs.PerLocalityDecayingRate()

I don't understand the significance of this change. Minor nit is that we should change the signature of PerLocalityDecayingRate to not return the duration anymore as this is the only production use of it.


pkg/kv/kvserver/replica_rankings_test.go line 83 at r1 (raw file):

		replsCopy := rr.TopLoad()
		if !reflect.DeepEqual(repls, replsCopy) {
			t.Errorf("got different replicas on second call to topQPS; first call: %v, second call: %v", repls, replsCopy)

nit: topQPS -> TopLoad

Copy link
Copy Markdown
Contributor Author

@kvoli kvoli left a comment

Choose a reason for hiding this comment

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

Thanks for taking a look! Lets discuss the multiple dimension part - it is done with an intent to use more than one dimension of load at a time in the near future.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @andrewbaptist and @nvanbenschoten)


pkg/kv/kvserver/replica_rankings.go line 103 at r1 (raw file):

Previously, andrewbaptist (Andrew Baptist) wrote…

nit: clairfy -> clarify

updated.


pkg/kv/kvserver/replica_rankings.go line 105 at r1 (raw file):

Previously, andrewbaptist (Andrew Baptist) wrote…

I'm confused why this is a method on ReplicaRankings instead of just a function. You don't use the rr in here at all. It looks like it was this way before, but makes it a little more confusing to read.

I agree, it has been that way since inception (a11ff0f). Updated to be separate. My only thought was that possibly it was used for namespacing in lieu of a separate package.


pkg/kv/kvserver/replica_rankings.go line 223 at r1 (raw file):

Previously, andrewbaptist (Andrew Baptist) wrote…

Rename to TopLoad?

The tenant tracking is different in that it is only used in the UI (and was recently added). I opted not to touch it here since it only has purpose in supporting UI unified architecture changes. I've added a TODO above the ReplicaRankingsMap to come back and update after clarifying what "should" happen between UI and what is used in rebalancing - initially I thought it was obvious to force every ranking to be on the current rebalancing load dimension, however it's not necessarily in the tenants control (system setting) etc.


pkg/kv/kvserver/replica_rankings.go line 244 at r1 (raw file):

Previously, andrewbaptist (Andrew Baptist) wrote…

I probably just need a walk through with you on this. But I assumed that the function here would be "generic" over the replica. Here it is still assuming QPS.

See above comment - can discuss.


pkg/kv/kvserver/replicate_queue.go line 2167 at r1 (raw file):

Previously, andrewbaptist (Andrew Baptist) wrote…

nit: reasoanble -> reasonable

Updated.


pkg/kv/kvserver/store.go line 3411 at r1 (raw file):

Previously, andrewbaptist (Andrew Baptist) wrote…

nit: rename variable.

Done


pkg/kv/kvserver/store_rebalancer.go line 714 at r1 (raw file):

Previously, andrewbaptist (Andrew Baptist) wrote…

Consider printing the dimension being used here so that the "units" make sense. Otherwise, this might be hard to debug if the configuration isn't known. (add on other events as well).

It does make me reconsider including every dimension by default or not filtering earlier, so that what is displayed when calling string is just the filtered dimensions. I considered it but decided against it to avoid the added fields.

Lets discuss this. Printing the dimension seems good if keeping this approach.


pkg/kv/kvserver/store_rebalancer.go line 824 at r1 (raw file):

Previously, andrewbaptist (Andrew Baptist) wrote…

This is unnecessary to have this check at all anymore. It will panic anyway on the line below.

do


pkg/kv/kvserver/allocator/base.go line 176 at r1 (raw file):

Previously, andrewbaptist (Andrew Baptist) wrote…

I'm a little confused why this is an array (rather than just a single Dimension). I'm not clear that this is needed here at all since it can be pulled from configuration when needed (should discuss at walkthrough).

I opted (perhaps prematurely) to setup for multiple dimension in the load vector to be used. Lets discuss.


pkg/kv/kvserver/allocator/allocatorimpl/allocator.go line 1923 at r1 (raw file):

Previously, andrewbaptist (Andrew Baptist) wrote…

It seems like this would be much better if it was a ratio rather than an absolute difference.

There have to be some absolute numbers somewhere in the system at this stage. This just wraps what already existed with QPS, which is 2x the min threshold difference https://github.com/kvoli/cockroach/blob/6b4edb0f76dc368fb1d25c74c5ed35aba5575f75/pkg/kv/kvserver/allocator/base.go#L38-L38. The reason that it exists as 2x the min threshold difference is essentially to stop thrashing. The reason the min threshold difference exists is explained here

https://github.com/kvoli/cockroach/blob/6b4edb0f76dc368fb1d25c74c5ed35aba5575f75/pkg/kv/kvserver/allocator/base.go#L36-L37

It would be nice to rid ourselves of magic numbers but it makes sense at least when considering QPS for there to be a minimum to create friction. A better alternative is to estimate the cost vs benefit and use that ratio to ensure adequate smoothing/rebalance friction in the system.


pkg/kv/kvserver/allocator/allocatorimpl/allocator_scorer.go line 417 at r1 (raw file):

Previously, andrewbaptist (Andrew Baptist) wrote…

As noted elsewhere, can this be changed to be a ratio rather than an absolute difference?

See above comment.


pkg/kv/kvserver/allocator/allocatorimpl/allocator_scorer.go line 438 at r1 (raw file):

Previously, andrewbaptist (Andrew Baptist) wrote…

This seems very difficult to calculate correctly. Also, I'm a little confused if you are computing the "cost" of follower replicas. If not, then it may skew the results badly. Let's discuss during the walkthrough.

Lets discuss - I'm not changing anything here with this patch, just wrapping and keeping the status quo.

See #75630 for details.

The prototyping I have done on top of this commit with CPU rebalancing does more accurately calculate the impact.


pkg/kv/kvserver/allocator/allocatorimpl/allocator_scorer.go line 496 at r1 (raw file):

Previously, andrewbaptist (Andrew Baptist) wrote…

Fix the comment to not say qps

Fixed.


pkg/kv/kvserver/allocator/allocatorimpl/allocator_scorer.go line 1205 at r1 (raw file):

Previously, andrewbaptist (Andrew Baptist) wrote…

Should LoadDims just be a singleton rather than an array?

It could be - as mentioned above I was optimistic on making things multiple signal friendly from the beginning.


pkg/kv/kvserver/allocator/load/dimension.go line 22 at r1 (raw file):

Previously, andrewbaptist (Andrew Baptist) wrote…

nit: This is better done with
`nDimensions int = int(Queries) + 1 put at the end of the const block above. This makes it less likely to be missed when new dimensions are added.

Good idea, updated.


pkg/kv/kvserver/allocator/load/load.go line 36 at r1 (raw file):

Previously, andrewbaptist (Andrew Baptist) wrote…

Mul seems strange. Its not clear what the units would be on this anymore... For instance if it was Q/S before it would now be Q^2/S^2. This would be clearer if it was Mul(threshold float).

Updated to be clearer naming: https://en.wikipedia.org/wiki/Hadamard_product_(matrices)


pkg/kv/kvserver/asim/storerebalancer/replica_rankings.go line 21 at r1 (raw file):

Previously, andrewbaptist (Andrew Baptist) wrote…

Shouldn't the dimension be passed in here and used instead?

It should - I partially ignored the asim part here but better to go all the way. Updated.


pkg/kv/kvserver/replicastats/replica_stats.go line 397 at r1 (raw file):

Previously, andrewbaptist (Andrew Baptist) wrote…

I don't understand the significance of this change. Minor nit is that we should change the signature of PerLocalityDecayingRate to not return the duration anymore as this is the only production use of it.

Using the duration of windows used rather than the last time the replica stats was reset. In most cases these are the same, in tests they are sometimes not. This rectifies this so that the patch can wholesale adopt the RatedSummary into RangeUsageInfo.


pkg/kv/kvserver/replica_rankings_test.go line 83 at r1 (raw file):

Previously, andrewbaptist (Andrew Baptist) wrote…

nit: topQPS -> TopLoad

do

Copy link
Copy Markdown

@andrewbaptist andrewbaptist left a comment

Choose a reason for hiding this comment

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

:lgtm: - there were a couple minor comments that you hadn't fully addressed, but after that I'm happy with the changes.

Reviewed 6 of 20 files at r2, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @nvanbenschoten)

Copy link
Copy Markdown
Contributor

@nvb nvb left a comment

Choose a reason for hiding this comment

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

Reviewed 10 of 37 files at r1, 6 of 20 files at r2, 2 of 4 files at r3, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @andrewbaptist and @kvoli)


pkg/kv/kvserver/allocator/load/dimension.go line 22 at r1 (raw file):

Previously, kvoli (Austen) wrote…

Good idea, updated.

I think it's even more idiomatic to rely on the auto-incrementing iota, so that there's no chance of the value being missed when new dimensions are added. This will inherit the Dimension type though. If that's an issue, you could:

Queries Dimension = iota

nDimensionsTyped
nDimensions = int(nDimensionsTyped)

pkg/kv/kvserver/allocator/load/dimension.go line 31 at r3 (raw file):

	String() string
	// Format returns a formatted string for a value.
	Format(float64)

It doesn't currently return anything. So Format(float64) string and then maybe also a type assertion that Dimension implements DimensionMeta. Is this interface used though? Will it be?


pkg/kv/kvserver/allocator/load/load.go line 20 at r3 (raw file):

	Dim(dim Dimension) float64
	// Greater returns true if for every dim given the calling load is greater
	// than the other element-wise, false otherwise.

Consider being explicit about unspecified dimensions being ignored.


pkg/kv/kvserver/allocator/load/load.go line 36 at r3 (raw file):

	Min(other Load) Load
	// ElementWiseProduct multiplies the calling Load with other and returns
	// the result. The multiplication is done entry-wise:

nit: you use "element-wise" instead of "entry-wise" everywhere else, so might as well use that here.


pkg/kv/kvserver/allocator/load/vector.go line 25 at r3 (raw file):

func (s Vector) Dim(dim Dimension) float64 {
	if int(dim) > len(s) || dim < 0 {
		panic("Unkown load dimension tried to be accessed")

nit: this includes less information (no index) than if you just let s[dim] panic.


pkg/kv/kvserver/allocator/load/vector.go line 34 at r3 (raw file):

func (s Vector) Greater(other Load, dims ...Dimension) bool {
	for _, dim := range dims {
		if s.Dim(dim) <= other.Dim(dim) {

It's interesting that Greater and Less could be defined above the interface as free functions that apply to any Load implementations, instead of being pushed into it. To some extent, that's true of most of these methods. The Load interface could be as simple as:

type Load interface {
	// Dim returns the value of the Dimension given.
	Dim(dim Dimension) float64
	// String returns a string representation of Load.
	String() string
}

It raises the question of what the interface is providing. Do we plan to add other implementations of it? Perhaps on a data structure that sits in gossip? If not, do we need the interface? At a minimum, it forces the Vector array onto the heap, which is mildly unfortunate.


pkg/kv/kvserver/allocator/load/vector.go line 91 at r3 (raw file):

// String returns a string representation of Load.
func (s Vector) String() string {
	var buf bytes.Buffer

nit: strings.Builder avoids a heap alloc.


pkg/kv/kvserver/allocator/load/vector.go line 97 at r3 (raw file):

		dim := Dimension(i)
		fmt.Fprintf(&buf, "%s=%s", dim.String(), dim.Format(val))
		if i < n-1 {

nit: you can avoid n by placing this first in the loop under the condition if i > 0 {.


pkg/kv/kvserver/asim/config/settings.go line 33 at r3 (raw file):

	defaultLBRebalanceQPSThreshold = 0.1
	defaultLBMinRequiredQPSDiff    = 200
	defaultLBRebalancingDimension  = 0 // QPS

Can we use the type directly? Or does that create an import cycle?

Copy link
Copy Markdown
Contributor

@nvb nvb left a comment

Choose a reason for hiding this comment

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

Reviewed 9 of 37 files at r1, 10 of 20 files at r2, 2 of 4 files at r3.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @andrewbaptist and @kvoli)


pkg/kv/kvserver/replica_rankings.go line 233 at r3 (raw file):

NB:

Did you mean to add more here?


pkg/kv/kvserver/asim/config/settings.go line 33 at r3 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

Can we use the type directly? Or does that create an import cycle?

EDIT: never mind. The type you'd want to import is kvserver.LBRebalancingDimension, not load.Dimension, so it would create a cycle.

Previously, disparate types were used when comparing `StoreCapacity`,
`XThreshold` and `RangeUsageInfo`. This patch introduces a uniform
intermediate type `Load`, which is used to perform arithmetic and
comparison between types representing load.

The purpose of this change is to decouple changes to inputs, enable
modifying existing dimensions and adding new ones with less code
modification.

The only load dimension added in this patch is `Queries`, which is then
used in place of `QueriesPerSecond` within the rebalancing logic.

Additionally, `RangeUsageInfo` is uniformly passed around in place of
any specific calls to the underlying tracking datastructure
`ReplicaStats`.

Part of cockroachdb#91152

Release note: None
Copy link
Copy Markdown
Contributor Author

@kvoli kvoli 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) (waiting on @andrewbaptist and @nvanbenschoten)


pkg/kv/kvserver/replica_rankings.go line 233 at r3 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

NB:

Did you mean to add more here?

I did not - removed.


pkg/kv/kvserver/store_rebalancer.go line 824 at r1 (raw file):

Previously, kvoli (Austen) wrote…

do

done*


pkg/kv/kvserver/allocator/load/dimension.go line 22 at r1 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

I think it's even more idiomatic to rely on the auto-incrementing iota, so that there's no chance of the value being missed when new dimensions are added. This will inherit the Dimension type though. If that's an issue, you could:

Queries Dimension = iota

nDimensionsTyped
nDimensions = int(nDimensionsTyped)

Nice - updated.


pkg/kv/kvserver/allocator/load/dimension.go line 31 at r3 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

It doesn't currently return anything. So Format(float64) string and then maybe also a type assertion that Dimension implements DimensionMeta. Is this interface used though? Will it be?

Removed the iface - it was redundant here.


pkg/kv/kvserver/allocator/load/load.go line 20 at r3 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

Consider being explicit about unspecified dimensions being ignored.

Updated.


pkg/kv/kvserver/allocator/load/load.go line 36 at r3 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

nit: you use "element-wise" instead of "entry-wise" everywhere else, so might as well use that here.

updated.


pkg/kv/kvserver/allocator/load/vector.go line 25 at r3 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

nit: this includes less information (no index) than if you just let s[dim] panic.

Added index along with description.


pkg/kv/kvserver/allocator/load/vector.go line 34 at r3 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

It's interesting that Greater and Less could be defined above the interface as free functions that apply to any Load implementations, instead of being pushed into it. To some extent, that's true of most of these methods. The Load interface could be as simple as:

type Load interface {
	// Dim returns the value of the Dimension given.
	Dim(dim Dimension) float64
	// String returns a string representation of Load.
	String() string
}

It raises the question of what the interface is providing. Do we plan to add other implementations of it? Perhaps on a data structure that sits in gossip? If not, do we need the interface? At a minimum, it forces the Vector array onto the heap, which is mildly unfortunate.

A fair point. I was leaning towards ranges/replicas having an implementation as well as a container over the top of StoreDescriptor in the store pool. However since this patch doesn't add this you're right it is needless complexity.

Updated to your suggestion.


pkg/kv/kvserver/allocator/load/vector.go line 91 at r3 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

nit: strings.Builder avoids a heap alloc.

Updated.


pkg/kv/kvserver/allocator/load/vector.go line 97 at r3 (raw file):

Previously, nvanbenschoten (Nathan VanBenschoten) wrote…

nit: you can avoid n by placing this first in the loop under the condition if i > 0 {.

Updated.


pkg/kv/kvserver/replica_rankings_test.go line 83 at r1 (raw file):

Previously, kvoli (Austen) wrote…

do

done*

Copy link
Copy Markdown
Contributor

@nvb nvb left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 8 of 8 files at r4, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @andrewbaptist)

@kvoli
Copy link
Copy Markdown
Contributor Author

kvoli commented Jan 3, 2023

bors r=nvanbenschoten,andrewbaptist

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Jan 3, 2023

Build succeeded:

@craig craig bot merged commit f259e66 into cockroachdb:master Jan 3, 2023
kvoli added a commit to kvoli/cockroach that referenced this pull request Jan 4, 2023
From cockroachdb#91593 it was possible for a new lease target to have its store
descriptor dereferenced despite not existing in a list of candidate
stores earlier.

This patch resolves the dereference.

fixes: cockroachdb#94688

Release note: None
craig bot pushed a commit that referenced this pull request Jan 4, 2023
86891: bazci: enable --flaky_test_attempts=3 for Unit tests on release branches r=rickystewart,healthy-pod,renatolabs a=srosenberg

When a test fails, --flaky_test_attempts=3 will cause up to two retry
attempts by executing the corresponding test binary (shard).
If a test passes on either attempt, it is reported 'FLAKY' in the
test result summary. In addition, each attempt yields an (XML) log
under 'test_attempts' subdirectory. The attempts are now copied
into the artifactsDir.

Note, while the test result summary may say the test is 'FLAKY', it's
reported as 'PASS' as per main test.xml. Thus, a 'FLAKY' test will
not fail the CI; i.e., a test succeeding after up to two
retries is assumed to have _passed_ whereas three consecutive
failures result in a failed test. Consequently, CI now has a higher
probability of passing than before this change. However, the two additional
attempts per test binary (shard) could slow down the build. Hence, initially
the plan is to enable only on release branches and not staging (i.e., bors).

This change supports [1]. In a follow-up PR, a test reporter could be
augmented to parse attempt logs thereby obtaining a set of FLAKY tests
which should be skipped on subsequent builds.

[1] #81293

Release justification: CI improvement
Release note: None
Epic: None

92955: opt: inline UDFs as subqueries r=mgartner a=mgartner

UDFs are now inlined as subqueries by a normalization rule when possible, speeding up their evaluation.

Epic: CRDB-20370

Release note (performance improvement): Some types of user-defined functions are now inlined in query plans as relation expressions, which speeds up their evaluation. UDFs must be non-volatile and have a single statement in the function body to be inlined.

94660: colserde: perform memory accounting for scratch slices in the converter r=yuzefovich a=yuzefovich

This commit introduces the memory accounting for values and offsets
scratch slices that are being reused across `BatchToArrow` calls since
recently. This required a lot of plumbing to propagate the memory
account from all places. The converter is careful to only grow and
shrink the account by its own usage, so the same memory account can be
reused across multiple converters (as long as there is no concurrency
going on, and we only can have concurrency for hash router outputs, so
there we give each output a separate account).

An additional minor change is that now in `diskQueue.Enqueue` we
properly `Close` the `FileSerializer` before `nil`-ing it out. This
isn't a problem per se since it is the caller's responsibility to close
the account used by the serializer, but it's nice to properly release
the accounted for bytes.

Epic: None

Release note: None

94702: workload: fix non-determinism in TPC-H data generation r=rytaft a=rytaft

This commit fixes the non-determinism in the TPC-H data generation by using a local slice for the random permutation of indexes into `randPartNames`. It also fixes the permutation algorithm to use a modified Fisher–Yates shuffle.

Fixes #93958

Release note: None

94713: sql: add user-facing error for invalid job type in job_payload_type builtin r=jayshrivastava a=jayshrivastava

### sql: add user-facing error for invalid job type in job_payload_type builtin

Previously, the `job_payload_type` builtin would return an internal error
if the payload could be unmarshalled, but the type could not be determined.
This changes ensures the builtin returns an appropriate user-facing error
in this case.

Epic: none
Fixes: #94680

Release note: None

94723: kvserver: check lease rebalance target exists in cached storelist r=erikgrinaker a=kvoli

From #91593 it was possible for a new lease target to have its store descriptor dereferenced despite not existing in a list of candidate stores earlier.

This patch resolves the dereference.

fixes: #94688

Release note: None

Co-authored-by: Stan Rosenberg <stan@cockroachlabs.com>
Co-authored-by: Marcus Gartner <marcus@cockroachlabs.com>
Co-authored-by: Yahor Yuzefovich <yahor@cockroachlabs.com>
Co-authored-by: Rebecca Taft <becca@cockroachlabs.com>
Co-authored-by: Jayant Shrivastava <jayants@cockroachlabs.com>
Co-authored-by: Austen McClernon <austen@cockroachlabs.com>
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.

4 participants