Skip to content

Commit e5ebcac

Browse files
craig[bot]jbowensyuzefovichdodeca12
committed
153738: storage: raise MemTableStopWritesThreshold when memory permits r=sumeerbhola a=jbowens When there's sufficient memory available, raise the MemTableStopWritesThreshold up to as high as 16. We've observed instances of memtable write stalls in practice, especially in the presence of high latencies in cloud networked block devices. If the higher levels are not writing to the storage engine too fast, but flushes are unable to keep up because of disk slowness, we'd rather accumulate additional memtables that forcibly stall writes. Epic: none Fixes: cockroachdb#153673. Release note: None 154002: execbuilder: only run geospatial in local config r=yuzefovich a=yuzefovich We generally run execbuilder tests in local or 5node configs since the tests are about planning and tracing of expected KV requests, so there is no benefit to running the tests with more diverse configs. Due to some historical reasons, `geospatial` test file has been running in almost all configs, but I don't see a reason why that should be the case. This commit updates the test to run only in `local` config. Epic: None Release note: None 154038: workflows: run `update_releases` on `release-25.4` r=dodeca12 a=dodeca12 Epic: None Release note: None Co-authored-by: Jackson Owens <[email protected]> Co-authored-by: Yahor Yuzefovich <[email protected]> Co-authored-by: Swapneeth Gorantla <[email protected]>
4 parents 4fe5b55 + 6703963 + b600ee3 + 3ebedae commit e5ebcac

File tree

28 files changed

+157
-1057
lines changed

28 files changed

+157
-1057
lines changed

.github/workflows/update_releases.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
- "release-24.3"
3333
- "release-25.2"
3434
- "release-25.3"
35+
- "release-25.4"
3536
name: Update pkg/testutils/release/cockroach_releases.yaml on ${{ matrix.branch }}
3637
runs-on: ubuntu-latest
3738
steps:

pkg/BUILD.bazel

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -538,14 +538,6 @@ ALL_TESTS = [
538538
"//pkg/sql/opt/cycle:cycle_test",
539539
"//pkg/sql/opt/distribution:distribution_test",
540540
"//pkg/sql/opt/exec/execbuilder/tests/5node:5node_test",
541-
"//pkg/sql/opt/exec/execbuilder/tests/fakedist-disk:fakedist-disk_test",
542-
"//pkg/sql/opt/exec/execbuilder/tests/fakedist-vec-off:fakedist-vec-off_test",
543-
"//pkg/sql/opt/exec/execbuilder/tests/fakedist:fakedist_test",
544-
"//pkg/sql/opt/exec/execbuilder/tests/local-legacy-schema-changer:local-legacy-schema-changer_test",
545-
"//pkg/sql/opt/exec/execbuilder/tests/local-mixed-25.2:local-mixed-25_2_test",
546-
"//pkg/sql/opt/exec/execbuilder/tests/local-mixed-25.3:local-mixed-25_3_test",
547-
"//pkg/sql/opt/exec/execbuilder/tests/local-prepared:local-prepared_test",
548-
"//pkg/sql/opt/exec/execbuilder/tests/local-vec-off:local-vec-off_test",
549541
"//pkg/sql/opt/exec/execbuilder/tests/local:local_test",
550542
"//pkg/sql/opt/exec/execbuilder:execbuilder_test",
551543
"//pkg/sql/opt/exec/explain:explain_test",
@@ -2120,14 +2112,6 @@ GO_TARGETS = [
21202112
"//pkg/sql/opt/distribution:distribution",
21212113
"//pkg/sql/opt/distribution:distribution_test",
21222114
"//pkg/sql/opt/exec/execbuilder/tests/5node:5node_test",
2123-
"//pkg/sql/opt/exec/execbuilder/tests/fakedist-disk:fakedist-disk_test",
2124-
"//pkg/sql/opt/exec/execbuilder/tests/fakedist-vec-off:fakedist-vec-off_test",
2125-
"//pkg/sql/opt/exec/execbuilder/tests/fakedist:fakedist_test",
2126-
"//pkg/sql/opt/exec/execbuilder/tests/local-legacy-schema-changer:local-legacy-schema-changer_test",
2127-
"//pkg/sql/opt/exec/execbuilder/tests/local-mixed-25.2:local-mixed-25_2_test",
2128-
"//pkg/sql/opt/exec/execbuilder/tests/local-mixed-25.3:local-mixed-25_3_test",
2129-
"//pkg/sql/opt/exec/execbuilder/tests/local-prepared:local-prepared_test",
2130-
"//pkg/sql/opt/exec/execbuilder/tests/local-vec-off:local-vec-off_test",
21312115
"//pkg/sql/opt/exec/execbuilder/tests/local:local_test",
21322116
"//pkg/sql/opt/exec/execbuilder:execbuilder",
21332117
"//pkg/sql/opt/exec/execbuilder:execbuilder_test",

pkg/ccl/logictestccl/tests/local-read-committed/generated_test.go

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/ccl/logictestccl/tests/local-repeatable-read/BUILD.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ go_test(
88
"//c-deps:libgeos", # keep
99
"//pkg/ccl/logictestccl:testdata", # keep
1010
"//pkg/sql/logictest:testdata", # keep
11-
"//pkg/sql/opt/exec/execbuilder:testdata", # keep
1211
],
1312
exec_properties = {"test.Pool": "large"},
1413
shard_count = 48,
@@ -20,7 +19,6 @@ go_test(
2019
"//pkg/security/securityassets",
2120
"//pkg/security/securitytest",
2221
"//pkg/server",
23-
"//pkg/sql",
2422
"//pkg/sql/logictest",
2523
"//pkg/testutils/serverutils",
2624
"//pkg/testutils/skip",

pkg/ccl/logictestccl/tests/local-repeatable-read/generated_test.go

Lines changed: 0 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/server/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,13 +613,15 @@ go_test(
613613
"//pkg/util/tracing",
614614
"//pkg/util/tracing/tracingpb",
615615
"//pkg/util/uuid",
616+
"@com_github_cockroachdb_crlib//crstrings",
616617
"@com_github_cockroachdb_datadriven//:datadriven",
617618
"@com_github_cockroachdb_errors//:errors",
618619
"@com_github_cockroachdb_logtags//:logtags",
619620
"@com_github_cockroachdb_pebble//:pebble",
620621
"@com_github_cockroachdb_pebble//vfs",
621622
"@com_github_cockroachdb_redact//:redact",
622623
"@com_github_dustin_go_humanize//:go-humanize",
624+
"@com_github_ghemawat_stream//:stream",
623625
"@com_github_gogo_protobuf//jsonpb",
624626
"@com_github_gogo_protobuf//proto",
625627
"@com_github_gorilla_mux//:mux",

pkg/server/config.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,9 +739,26 @@ func (cfg *Config) CreateEngines(ctx context.Context) (Engines, error) {
739739
if err != nil {
740740
return Engines{}, err
741741
}
742-
743742
log.Event(ctx, "initializing engines")
744743

744+
// The (pebble.Options).MemTableStopWritesThreshold configures the number of
745+
// memtables that may be queued before Pebble induces a write stall.
746+
// Queueing memtables consume memory from the block cache, evicting resident
747+
// blocks. If flushes are not keeping up and the count of queued memtables
748+
// grows too large, read performance will degrade severely:
749+
//
750+
// - Every read needs to seek in every queued memtable.
751+
// - Memtables take memory from the block cache, meaning that block
752+
// cache effectiveness decreases the more memtables that are queued.
753+
//
754+
// We constrain the count of queued memtables to be between 4 and 16. Within
755+
// those bounds, we'll grow it to use up to half of the block cache. If
756+
// there are multiple stores, we need to divide that half by the count of
757+
// stores.
758+
stopWritesThreshold := int(cfg.CacheSize/2/storage.DefaultMemtableSize) / len(cfg.Stores.Specs)
759+
stopWritesThreshold = max(stopWritesThreshold, 4)
760+
stopWritesThreshold = min(stopWritesThreshold, 16)
761+
745762
var fileCache *pebble.FileCache
746763
// TODO(radu): use the fileCache for in-memory stores as well.
747764
if physicalStores > 0 {
@@ -779,6 +796,7 @@ func (cfg *Config) CreateEngines(ctx context.Context) (Engines, error) {
779796
storage.Attributes(roachpb.Attributes{Attrs: spec.Attributes}),
780797
storage.If(storeKnobs.SmallEngineBlocks, storage.BlockSize(1)),
781798
storage.BlockConcurrencyLimitDivisor(len(cfg.Stores.Specs)),
799+
storage.MemTableStopWritesThreshold(stopWritesThreshold),
782800
}
783801
if len(storeKnobs.EngineKnobs) > 0 {
784802
storageConfigOpts = append(storageConfigOpts, storeKnobs.EngineKnobs...)

pkg/server/config_test.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
package server
77

88
import (
9+
"bytes"
910
"context"
11+
"fmt"
12+
"io"
1013
"net"
1114
"os"
1215
"reflect"
16+
"strings"
1317
"sync/atomic"
1418
"testing"
1519
"time"
@@ -27,7 +31,10 @@ import (
2731
"github.com/cockroachdb/cockroach/pkg/util/log"
2832
"github.com/cockroachdb/cockroach/pkg/util/netutil"
2933
"github.com/cockroachdb/cockroach/pkg/util/netutil/addr"
34+
"github.com/cockroachdb/crlib/crstrings"
35+
"github.com/cockroachdb/datadriven"
3036
"github.com/cockroachdb/pebble/vfs"
37+
"github.com/ghemawat/stream"
3138
"github.com/kr/pretty"
3239
"github.com/stretchr/testify/assert"
3340
"github.com/stretchr/testify/require"
@@ -368,3 +375,76 @@ func TestIdProviderServerIdentityString(t *testing.T) {
368375
})
369376
}
370377
}
378+
379+
func TestCreateEngines(t *testing.T) {
380+
defer leaktest.AfterTest(t)()
381+
defer log.Scope(t).Close(t)
382+
383+
specs := map[string]base.StoreSpec{}
384+
385+
datadriven.RunTest(t, "testdata/create_engines", func(t *testing.T, d *datadriven.TestData) string {
386+
switch d.Cmd {
387+
case "store-spec":
388+
var name string
389+
d.ScanArgs(t, "name", &name)
390+
spec := base.StoreSpec{}
391+
spec.Path = name
392+
for _, line := range crstrings.Lines(d.Input) {
393+
parts := strings.SplitN(line, "=", 2)
394+
switch parts[0] {
395+
case "in-memory":
396+
spec.InMemory = true
397+
case "attrs":
398+
spec.Attributes = strings.Split(parts[1], ":")
399+
default:
400+
return fmt.Sprintf("unknown field: %q", parts[0])
401+
}
402+
}
403+
specs[name] = spec
404+
return ""
405+
case "create-engines":
406+
var cfg Config
407+
cfg.Settings = cluster.MakeTestingClusterSettings()
408+
409+
var pattern string
410+
d.ScanArgs(t, "pattern", &pattern)
411+
var specNames []string
412+
d.ScanArgs(t, "specs", &specNames)
413+
for _, specName := range specNames {
414+
spec, ok := specs[specName]
415+
if !ok {
416+
return fmt.Sprintf("unknown store: %q", specName)
417+
}
418+
cfg.Stores.Specs = append(cfg.Stores.Specs, spec)
419+
}
420+
d.MaybeScanArgs(t, "CacheSize", &cfg.CacheSize)
421+
422+
engines, err := cfg.CreateEngines(context.Background())
423+
if err != nil {
424+
return fmt.Sprintf("failed to create engines: %v", err)
425+
}
426+
defer engines.Close()
427+
428+
var buf bytes.Buffer
429+
for _, e := range engines {
430+
buf.WriteString(strings.TrimSpace(e.GetPebbleOptions().String()))
431+
buf.WriteString("\n")
432+
}
433+
return grepStr(&buf, pattern)
434+
default:
435+
return fmt.Sprintf("unknown command: %q", d.Cmd)
436+
}
437+
})
438+
}
439+
440+
func grepStr(r io.Reader, pattern string) string {
441+
var buf bytes.Buffer
442+
if err := stream.Run(stream.Sequence(
443+
stream.ReadLines(r),
444+
stream.Grep(pattern),
445+
stream.WriteLines(&buf),
446+
)); err != nil {
447+
return err.Error()
448+
}
449+
return buf.String()
450+
}

pkg/server/testdata/create_engines

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
store-spec name=a
2+
in-memory
3+
----
4+
5+
store-spec name=b
6+
in-memory
7+
----
8+
9+
# 64 MiB cache; should result in 4 memtable stop writes threshold.
10+
11+
create-engines specs=(a,b) pattern=mem_table_stop_writes_threshold CacheSize=67108864
12+
----
13+
mem_table_stop_writes_threshold=4
14+
mem_table_stop_writes_threshold=4
15+
16+
create-engines specs=(a) pattern=mem_table_stop_writes_threshold CacheSize=67108864
17+
----
18+
mem_table_stop_writes_threshold=4
19+
20+
# 1 GiB cache; should result in 8 memtable stop writes threshold with a single
21+
# store (with 64 MiB memtables).
22+
23+
create-engines specs=(b) pattern=mem_table_stop_writes_threshold CacheSize=1073741824
24+
----
25+
mem_table_stop_writes_threshold=8
26+
27+
# But if we add another store, the memtable stop writes threshold should be
28+
# halved back to the minimum of 4.
29+
30+
create-engines specs=(a, b) pattern=mem_table_stop_writes_threshold CacheSize=1073741824
31+
----
32+
mem_table_stop_writes_threshold=4
33+
mem_table_stop_writes_threshold=4
34+
35+
# 64 GiB cache; should result in 16 memtable stop writes threshold.
36+
37+
create-engines specs=(a,b) pattern=mem_table_stop_writes_threshold CacheSize=68719476736
38+
----
39+
mem_table_stop_writes_threshold=16
40+
mem_table_stop_writes_threshold=16

pkg/sql/opt/exec/execbuilder/testdata/geospatial

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
# This logic test fails in the 3node-tenant configuration because the keys are
2-
# prefixed with the tenant ID if run by a tenant:
3-
# https://github.com/cockroachdb/cockroach/issues/49582
4-
# LogicTest: !3node-tenant-default-configs
1+
# LogicTest: local
52

63
statement ok
74
CREATE TABLE b(

0 commit comments

Comments
 (0)