Skip to content

Commit

Permalink
domain: fix data race in the MockInfoCacheAndLoadInfoSchema (#39802)
Browse files Browse the repository at this point in the history
close #39801
  • Loading branch information
hawkingrei authored Dec 12, 2022
1 parent ee5d8cc commit c13dfe3
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ddl/concurrentddltest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_test")

go_test(
name = "concurrentddltest_test",
timeout = "long",
timeout = "moderate",
srcs = [
"main_test.go",
"switch_test.go",
Expand Down
2 changes: 1 addition & 1 deletion domain/test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

// MockInfoCacheAndLoadInfoSchema only used in unit tests.
func (do *Domain) MockInfoCacheAndLoadInfoSchema(is infoschema.InfoSchema) {
do.infoCache = infoschema.NewCache(16)
do.infoCache.Reset(16)
do.infoCache.Insert(is, 0)
}

Expand Down
2 changes: 1 addition & 1 deletion executor/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ go_library(

go_test(
name = "executor_test",
timeout = "long",
timeout = "moderate",
srcs = [
"adapter_test.go",
"admin_test.go",
Expand Down
2 changes: 1 addition & 1 deletion executor/seqtest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_test")

go_test(
name = "seqtest_test",
timeout = "moderate",
timeout = "short",
srcs = [
"main_test.go",
"prepared_test.go",
Expand Down
11 changes: 9 additions & 2 deletions infoschema/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,15 @@ type InfoCache struct {
}

// NewCache creates a new InfoCache.
func NewCache(capcity int) *InfoCache {
return &InfoCache{cache: make([]InfoSchema, 0, capcity)}
func NewCache(capacity int) *InfoCache {
return &InfoCache{cache: make([]InfoSchema, 0, capacity)}
}

// Reset resets the cache.
func (h *InfoCache) Reset(capacity int) {
h.mu.Lock()
defer h.mu.Unlock()
h.cache = make([]InfoSchema, 0, capacity)
}

// GetLatest gets the newest information schema.
Expand Down

0 comments on commit c13dfe3

Please sign in to comment.