From c0eeea88b09618f101c616923efc386b76457b52 Mon Sep 17 00:00:00 2001 From: Brendan Dougherty Date: Thu, 15 Jun 2023 17:09:28 -0400 Subject: [PATCH] Merge pull request #102 from Shopify/generate-cachedsize-for-placement-vindex Generate CachedSize function for Placement vindex (cherry picked from commit 986ffc65eb603ea4bafd539f740628c1c47e793c) (cherry picked from commit 1fe7126a122320a1a76f4d83e6624fc064d24fa6) (cherry picked from commit 62a60b22f515d61d7f7d90fff87b4505e8d4f081) (cherry picked from commit f258063b0038c0ea7e88e9c051d55737017db7a3) (cherry picked from commit 448060c4a65618f2238d63c694c35534869bf070) --- go/vt/vtgate/vindexes/cached_size.go | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/go/vt/vtgate/vindexes/cached_size.go b/go/vt/vtgate/vindexes/cached_size.go index a97411a6ac8..2051876895d 100644 --- a/go/vt/vtgate/vindexes/cached_size.go +++ b/go/vt/vtgate/vindexes/cached_size.go @@ -416,6 +416,42 @@ func (cached *NumericStaticMap) CachedSize(alloc bool) int64 { } return size } + +//go:nocheckptr +func (cached *Placement) CachedSize(alloc bool) int64 { + if cached == nil { + return int64(0) + } + size := int64(0) + if alloc { + size += int64(80) + } + // field name string + size += hack.RuntimeAllocSize(int64(len(cached.name))) + // field placementMap vitess.io/vitess/go/vt/vtgate/vindexes.PlacementMap + if cached.placementMap != nil { + size += int64(48) + hmap := reflect.ValueOf(cached.placementMap) + numBuckets := int(math.Pow(2, float64((*(*uint8)(unsafe.Pointer(hmap.Pointer() + uintptr(9))))))) + numOldBuckets := (*(*uint16)(unsafe.Pointer(hmap.Pointer() + uintptr(10)))) + size += hack.RuntimeAllocSize(int64(numOldBuckets * 208)) + if len(cached.placementMap) > 0 || numBuckets > 1 { + size += hack.RuntimeAllocSize(int64(numBuckets * 208)) + } + for k := range cached.placementMap { + size += hack.RuntimeAllocSize(int64(len(k))) + } + } + // field subVindex vitess.io/vitess/go/vt/vtgate/vindexes.Vindex + if cc, ok := cached.subVindex.(cachedObject); ok { + size += cc.CachedSize(true) + } + // field subVindexType string + size += hack.RuntimeAllocSize(int64(len(cached.subVindexType))) + // field subVindexName string + size += hack.RuntimeAllocSize(int64(len(cached.subVindexName))) + return size +} func (cached *RegionExperimental) CachedSize(alloc bool) int64 { if cached == nil { return int64(0)