Skip to content

Commit

Permalink
sqlstats: rename sizeUnsafe -> sizeUnsafeLocked
Browse files Browse the repository at this point in the history
This function accesses data behind a mutex without acquring it.
Ensure that this is clearly communicated so this fn is not
misused.

Epic: none

Release note: None
  • Loading branch information
xinhaoz committed Apr 10, 2024
1 parent 4683d65 commit f6332e8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pkg/sql/sqlstats/ssmemstorage/ss_mem_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ type stmtStats struct {
}
}

func (s *stmtStats) sizeUnsafe() int64 {
func (s *stmtStats) sizeUnsafeLocked() int64 {
const stmtStatsShallowSize = int64(unsafe.Sizeof(stmtStats{}))
databaseNameSize := int64(len(s.mu.database))

Expand Down Expand Up @@ -832,7 +832,7 @@ func (s *Container) Add(ctx context.Context, other *Container) (err error) {
// If we created a new entry for the fingerprint, we check if we have
// exceeded our memory budget.
if created {
estimatedAllocBytes := stats.sizeUnsafe() + k.size() + 8 /* stmtKey hash */
estimatedAllocBytes := stats.sizeUnsafeLocked() + k.size() + 8 /* stmtKey hash */
// We still want to continue this loop to merge stats that are already
// present in our map that do not require allocation.
if latestErr := func() error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/sqlstats/ssmemstorage/ss_mem_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (s *Container) RecordStatement(

if created {
// stats size + stmtKey size + hash of the statementKey
estimatedMemoryAllocBytes := stats.sizeUnsafe() + statementKey.size() + 8
estimatedMemoryAllocBytes := stats.sizeUnsafeLocked() + statementKey.size() + 8

// We also account for the memory used for s.sampledPlanMetadataCache.
// timestamp size + key size + hash.
Expand Down

0 comments on commit f6332e8

Please sign in to comment.