LCOV - code coverage report
Current view: top level - pebble/objstorage/objstorageprovider - remote_obj_name.go (source / functions) Hit Total Coverage
Test: 2024-05-11 08:15Z f75ed446 - tests + meta.lcov Lines: 41 46 89.1 %
Date: 2024-05-11 08:16:20 Functions: 0 0 -

          Line data    Source code
       1             : // Copyright 2023 The LevelDB-Go and Pebble Authors. All rights reserved. Use
       2             : // of this source code is governed by a BSD-style license that can be found in
       3             : // the LICENSE file.
       4             : 
       5             : package objstorageprovider
       6             : 
       7             : import (
       8             :         "fmt"
       9             : 
      10             :         "github.com/cockroachdb/pebble/internal/base"
      11             :         "github.com/cockroachdb/pebble/objstorage"
      12             : )
      13             : 
      14             : // remoteObjectName returns the name of an object on remote storage.
      15             : //
      16             : // For sstables, the format is: <hash>-<creator-id>-<file-num>.sst
      17             : // For example: 1a3f-2-000001.sst
      18           2 : func remoteObjectName(meta objstorage.ObjectMetadata) string {
      19           2 :         if meta.Remote.CustomObjectName != "" {
      20           2 :                 return meta.Remote.CustomObjectName
      21           2 :         }
      22           2 :         switch meta.FileType {
      23           2 :         case base.FileTypeTable:
      24           2 :                 return fmt.Sprintf(
      25           2 :                         "%04x-%d-%06d.sst",
      26           2 :                         objHash(meta), meta.Remote.CreatorID, meta.Remote.CreatorFileNum,
      27           2 :                 )
      28             :         }
      29           0 :         panic("unknown FileType")
      30             : }
      31             : 
      32             : // sharedObjectRefName returns the name of the object's ref marker associated
      33             : // with a given referencing provider. This name is the object's name concatenated with
      34             : // ".ref.<ref-creator-id>.<local-file-num>".
      35             : //
      36             : // For example: 1a3f-2-000001.sst.ref.5.000008
      37             : func sharedObjectRefName(
      38             :         meta objstorage.ObjectMetadata, refCreatorID objstorage.CreatorID, refFileNum base.DiskFileNum,
      39           2 : ) string {
      40           2 :         if meta.Remote.CleanupMethod != objstorage.SharedRefTracking {
      41           0 :                 panic("ref object used when ref tracking disabled")
      42             :         }
      43           2 :         if meta.Remote.CustomObjectName != "" {
      44           1 :                 return fmt.Sprintf(
      45           1 :                         "%s.ref.%d.%06d", meta.Remote.CustomObjectName, refCreatorID, refFileNum,
      46           1 :                 )
      47           1 :         }
      48           2 :         switch meta.FileType {
      49           2 :         case base.FileTypeTable:
      50           2 :                 return fmt.Sprintf(
      51           2 :                         "%04x-%d-%06d.sst.ref.%d.%06d",
      52           2 :                         objHash(meta), meta.Remote.CreatorID, meta.Remote.CreatorFileNum, refCreatorID, refFileNum,
      53           2 :                 )
      54             :         }
      55           0 :         panic("unknown FileType")
      56             : }
      57             : 
      58           2 : func sharedObjectRefPrefix(meta objstorage.ObjectMetadata) string {
      59           2 :         if meta.Remote.CustomObjectName != "" {
      60           1 :                 return meta.Remote.CustomObjectName + ".ref."
      61           1 :         }
      62           2 :         switch meta.FileType {
      63           2 :         case base.FileTypeTable:
      64           2 :                 return fmt.Sprintf(
      65           2 :                         "%04x-%d-%06d.sst.ref.",
      66           2 :                         objHash(meta), meta.Remote.CreatorID, meta.Remote.CreatorFileNum,
      67           2 :                 )
      68             :         }
      69           0 :         panic("unknown FileType")
      70             : }
      71             : 
      72             : // sharedObjectRefName returns the name of the object's ref marker associated
      73             : // with this provider. This name is the object's name concatenated with
      74             : // ".ref.<creator-id>.<local-file-num>".
      75             : //
      76             : // For example: 1a3f-2-000001.sst.ref.5.000008
      77           2 : func (p *provider) sharedObjectRefName(meta objstorage.ObjectMetadata) string {
      78           2 :         if meta.Remote.CleanupMethod != objstorage.SharedRefTracking {
      79           0 :                 panic("ref object used when ref tracking disabled")
      80             :         }
      81           2 :         return sharedObjectRefName(meta, p.remote.shared.creatorID, meta.DiskFileNum)
      82             : }
      83             : 
      84             : // objHash returns a 16-bit hash value derived from the creator ID and creator
      85             : // file num. We prepend this value to object names to ensure balanced
      86             : // partitioning with AWS (and likely other blob storage providers).
      87           2 : func objHash(meta objstorage.ObjectMetadata) uint16 {
      88           2 :         const prime1 = 7459
      89           2 :         const prime2 = 17539
      90           2 :         return uint16(uint64(meta.Remote.CreatorID)*prime1 + uint64(meta.Remote.CreatorFileNum)*prime2)
      91           2 : }

Generated by: LCOV version 1.14