Skip to content

Commit

Permalink
kvserver: write new GCHint fields under cluster setting
Browse files Browse the repository at this point in the history
Since it is late to enable this behaviour in 23.1 (risk of backwards
incompatibility), hide it behind a default-off cluster setting. In 23.2,
it will be enabled by default, and the cluster setting will be
deprecated.

The new GCHint behaviour is likely backwards compatible, but we are
hiding it behind a setting for extra safety.

The safest moment to enable this cluster setting is when there is some
confidence that the cluster binaries will not rollback to previous patch
versions of 23.1. The risk exists only in mixed-version state in which
some 23.1 binaries don't know the new GCHint fields, and some do.

Epic: none
Release note (ops change): introduce a default-off cluster setting
`kv.gc.sticky_hint.enabled` which helps expediting garbage collection
after range deletions, such as when a SQL table or index is dropped.
  • Loading branch information
pav-kv committed Oct 24, 2023
1 parent 38630c5 commit aab9af1
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions pkg/kv/kvserver/batcheval/cmd_delete_range.go
Expand Up @@ -21,12 +21,22 @@ import (
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/lockspanset"
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/spanset"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/settings"
"github.com/cockroachdb/cockroach/pkg/storage"
"github.com/cockroachdb/cockroach/pkg/storage/enginepb"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
"github.com/cockroachdb/errors"
)

// enableStickyGCHint controls whether the sticky GCHint is enabled.
var enableStickyGCHint = settings.RegisterBoolSetting(
settings.SystemOnly,
"kv.gc.sticky_hint.enabled",
"enable writing sticky GC hints which expedite garbage collection after schema changes"+
" (ignored and assumed 'true' in 23.2)",
false,
)

func init() {
RegisterReadWriteCommand(kvpb.DeleteRange, declareKeysDeleteRange, DeleteRange)
}
Expand Down Expand Up @@ -135,8 +145,11 @@ func DeleteRange(
return err
}

// Add the timestamp to GCHint to guarantee that GC eventually clears it.
updated := hint.ScheduleGCFor(h.Timestamp)
updated := false
if enableStickyGCHint.Get(&cArgs.EvalCtx.ClusterSettings().SV) {
// Add the timestamp to GCHint to guarantee that GC eventually clears it.
updated = hint.ScheduleGCFor(h.Timestamp)
}
// If the range tombstone covers the whole Range key span, update the
// corresponding timestamp in GCHint to enable ClearRange optimization.
if args.Key.Equal(desc.StartKey.AsRawKey()) && args.EndKey.Equal(desc.EndKey.AsRawKey()) {
Expand Down

0 comments on commit aab9af1

Please sign in to comment.