-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Previously, it was impossible to correlate an individual execution of a transaction (identified via transaction ID) to this historical execution statistics (identified via transaction fingerprint ID). This commit introduces Transaction ID Cache (TxnIDCache), a FIFO cache that stores the mapping from transaction ID to transaction fingerprint ID. This buffer records the mapping at the end of the transaction execution. The oldest entry in the buffer will be evicted through FIFO policy. The default size of this Transaction ID Cache is capped at 64 MB and it is configurable via the sql.contention.txn_id_cache.max_size cluster setting. Release note (sql change): Transaction ID to Transaction Fingerprint ID mapping is now stored in the new Transaction ID Cache, a FIFO unordered in-memory buffer. The size of the buffer is 64 MB by default and configurable via sql.contention.txn_id_cache.max_size cluster setting. Consequentially, two additioanl metrics are introduced: * sql.contention.txn_id_cache.size: tracks the current memory usage of transaction ID Cache * sql.contention.txn_id_cache.discarded_count: number of resolved transaction IDs that are dropped due to memory constraints.
- Loading branch information
Showing
21 changed files
with
1,051 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") | ||
|
||
go_library( | ||
name = "txnidcache", | ||
srcs = [ | ||
"cluster_settings.go", | ||
"metrics.go", | ||
"provider.go", | ||
"sharded_store.go", | ||
"txn_id_cache.go", | ||
"txn_id_cache_shard.go", | ||
"txn_id_cache_write_buffer.go", | ||
"writer_pool.go", | ||
], | ||
importpath = "github.com/cockroachdb/cockroach/pkg/sql/contention/txnidcache", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//pkg/roachpb:with-mocks", | ||
"//pkg/settings", | ||
"//pkg/settings/cluster", | ||
"//pkg/util/cache", | ||
"//pkg/util/encoding", | ||
"//pkg/util/metric", | ||
"//pkg/util/stop", | ||
"//pkg/util/syncutil", | ||
"//pkg/util/uuid", | ||
], | ||
) | ||
|
||
go_test( | ||
name = "txnidcache_test", | ||
srcs = [ | ||
"main_test.go", | ||
"txn_id_cache_test.go", | ||
], | ||
deps = [ | ||
":txnidcache", | ||
"//pkg/kv", | ||
"//pkg/roachpb:with-mocks", | ||
"//pkg/security", | ||
"//pkg/security/securitytest", | ||
"//pkg/server", | ||
"//pkg/sql", | ||
"//pkg/sql/sessiondata", | ||
"//pkg/sql/tests", | ||
"//pkg/testutils", | ||
"//pkg/testutils/serverutils", | ||
"//pkg/testutils/sqlutils", | ||
"//pkg/testutils/testcluster", | ||
"//pkg/util/leaktest", | ||
"//pkg/util/log", | ||
"//pkg/util/uuid", | ||
"@com_github_cockroachdb_errors//:errors", | ||
"@com_github_stretchr_testify//require", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package txnidcache | ||
|
||
import "github.com/cockroachdb/cockroach/pkg/settings" | ||
|
||
// MaxSize limits the maximum byte size can be used by the TxnIDCache. | ||
var MaxSize = settings.RegisterByteSizeSetting( | ||
`sql.contention.txn_id_cache.max_size`, | ||
"the maximum byte size TxnID cache will use", | ||
64*1024*1024, // 64 MB | ||
).WithPublic() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package txnidcache_test | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/security" | ||
"github.com/cockroachdb/cockroach/pkg/security/securitytest" | ||
"github.com/cockroachdb/cockroach/pkg/server" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/testcluster" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
security.SetAssetLoader(securitytest.EmbeddedAssets) | ||
serverutils.InitTestServerFactory(server.TestServerFactory) | ||
serverutils.InitTestClusterFactory(testcluster.TestClusterFactory) | ||
os.Exit(m.Run()) | ||
} |
Oops, something went wrong.