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 1 : func remoteObjectName(meta objstorage.ObjectMetadata) string { 19 1 : if meta.Remote.CustomObjectName != "" { 20 0 : return meta.Remote.CustomObjectName 21 0 : } 22 1 : switch meta.FileType { 23 1 : case base.FileTypeTable: 24 1 : return fmt.Sprintf( 25 1 : "%04x-%d-%06d.sst", 26 1 : objHash(meta), meta.Remote.CreatorID, meta.Remote.CreatorFileNum, 27 1 : ) 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 1 : ) string { 40 1 : if meta.Remote.CleanupMethod != objstorage.SharedRefTracking { 41 0 : panic("ref object used when ref tracking disabled") 42 : } 43 1 : if meta.Remote.CustomObjectName != "" { 44 0 : return fmt.Sprintf( 45 0 : "%s.ref.%d.%06d", meta.Remote.CustomObjectName, refCreatorID, refFileNum, 46 0 : ) 47 0 : } 48 1 : switch meta.FileType { 49 1 : case base.FileTypeTable: 50 1 : return fmt.Sprintf( 51 1 : "%04x-%d-%06d.sst.ref.%d.%06d", 52 1 : objHash(meta), meta.Remote.CreatorID, meta.Remote.CreatorFileNum, refCreatorID, refFileNum, 53 1 : ) 54 : } 55 0 : panic("unknown FileType") 56 : } 57 : 58 1 : func sharedObjectRefPrefix(meta objstorage.ObjectMetadata) string { 59 1 : if meta.Remote.CustomObjectName != "" { 60 0 : return meta.Remote.CustomObjectName + ".ref." 61 0 : } 62 1 : switch meta.FileType { 63 1 : case base.FileTypeTable: 64 1 : return fmt.Sprintf( 65 1 : "%04x-%d-%06d.sst.ref.", 66 1 : objHash(meta), meta.Remote.CreatorID, meta.Remote.CreatorFileNum, 67 1 : ) 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 1 : func (p *provider) sharedObjectRefName(meta objstorage.ObjectMetadata) string { 78 1 : if meta.Remote.CleanupMethod != objstorage.SharedRefTracking { 79 0 : panic("ref object used when ref tracking disabled") 80 : } 81 1 : 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 1 : func objHash(meta objstorage.ObjectMetadata) uint16 { 88 1 : const prime1 = 7459 89 1 : const prime2 = 17539 90 1 : return uint16(uint64(meta.Remote.CreatorID)*prime1 + uint64(meta.Remote.CreatorFileNum)*prime2) 91 1 : }