Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

objstorage: rename Shared to Remote in the objstorage provider API #2754

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cleaner.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ func (cm *cleanupManager) needsPacing(fileType base.FileType, fileNum base.DiskF
// delete anything, so we don't need to pace.
return false
}
// Don't throttle deletion of shared objects.
return !meta.IsShared()
// Don't throttle deletion of remote objects.
return !meta.IsRemote()
}

// maybePace sleeps before deleting an object if appropriate. It is always
Expand Down
24 changes: 13 additions & 11 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -2005,15 +2005,17 @@ func (d *DB) SSTables(opts ...SSTablesOption) ([][]SSTableInfo, error) {
if err != nil {
return nil, err
}
if objMeta.IsShared() {
if d.objProvider.IsForeign(objMeta) {
destTables[j].BackingType = BackingTypeSharedForeign
} else if objMeta.Shared.CleanupMethod == objstorage.SharedNoCleanup {
destTables[j].BackingType = BackingTypeExternal
if objMeta.IsRemote() {
if objMeta.IsShared() {
if d.objProvider.IsForeign(objMeta) {
destTables[j].BackingType = BackingTypeSharedForeign
} else {
destTables[j].BackingType = BackingTypeShared
}
} else {
destTables[j].BackingType = BackingTypeShared
destTables[j].BackingType = BackingTypeExternal
}
destTables[j].Locator = objMeta.Shared.Locator
destTables[j].Locator = objMeta.Remote.Locator
} else {
destTables[j].BackingType = BackingTypeLocal
}
Expand Down Expand Up @@ -2102,9 +2104,9 @@ func (d *DB) EstimateDiskUsageByBackingType(
if err != nil {
return 0, 0, 0, err
}
if meta.IsShared() {
if meta.IsRemote() {
remoteSize += file.Size
if meta.Shared.CleanupMethod == objstorage.SharedNoCleanup {
if meta.Remote.CleanupMethod == objstorage.SharedNoCleanup {
externalSize += file.Size
}
}
Expand Down Expand Up @@ -2137,9 +2139,9 @@ func (d *DB) EstimateDiskUsageByBackingType(
if err != nil {
return 0, 0, 0, err
}
if meta.IsShared() {
if meta.IsRemote() {
remoteSize += size
if meta.Shared.CleanupMethod == objstorage.SharedNoCleanup {
if meta.Remote.CleanupMethod == objstorage.SharedNoCleanup {
externalSize += size
}
}
Expand Down
8 changes: 4 additions & 4 deletions ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,19 +449,19 @@ func ingestLink(
})
}
}
sharedObjs := make([]objstorage.SharedObjectToAttach, 0, len(shared))
sharedObjs := make([]objstorage.RemoteObjectToAttach, 0, len(shared))
for i := range shared {
backing, err := shared[i].Backing.Get()
if err != nil {
return err
}
sharedObjs = append(sharedObjs, objstorage.SharedObjectToAttach{
sharedObjs = append(sharedObjs, objstorage.RemoteObjectToAttach{
FileNum: lr.sharedMeta[i].FileBacking.DiskFileNum,
FileType: fileTypeTable,
Backing: backing,
})
}
sharedObjMetas, err := objProvider.AttachSharedObjects(sharedObjs)
sharedObjMetas, err := objProvider.AttachRemoteObjects(sharedObjs)
if err != nil {
return err
}
Expand All @@ -473,7 +473,7 @@ func ingestLink(
// open the db again after a crash/restart (see checkConsistency in open.go),
// plus it more accurately allows us to prioritize compactions of files
// that were originally created by us.
if !objProvider.IsForeign(sharedObjMetas[i]) {
if sharedObjMetas[i].IsShared() && !objProvider.IsForeign(sharedObjMetas[i]) {
size, err := objProvider.Size(sharedObjMetas[i])
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion ingest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ func TestSimpleIngestShared(t *testing.T) {
}

m := metaMap[base.FileNum(2).DiskFileNum()]
handle, err := provider2.SharedObjectBacking(&m)
handle, err := provider2.RemoteObjectBacking(&m)
require.NoError(t, err)
size, err := provider2.Size(m)
require.NoError(t, err)
Expand Down
77 changes: 45 additions & 32 deletions objstorage/objstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ type ObjectMetadata struct {
DiskFileNum base.DiskFileNum
FileType base.FileType

// The fields below are only set if the object is on shared storage.
Shared struct {
// The fields below are only set if the object is on remote storage.
Remote struct {
// CreatorID identifies the DB instance that originally created the object.
//
// Only used when CustomObjectName is not set.
Expand All @@ -113,31 +113,44 @@ type ObjectMetadata struct {
}
}

// IsShared returns true if the object is on shared storage.
// IsRemote returns true if the object is on remote storage.
func (meta *ObjectMetadata) IsRemote() bool {
return meta.IsShared() || meta.IsExternal()
}

// IsExternal returns true if the object is on remote storage but is not owned
// by any Pebble instances in the cluster.
func (meta *ObjectMetadata) IsExternal() bool {
return meta.Remote.CustomObjectName != ""
}

// IsShared returns true if the object is on remote storage and is owned by a
// Pebble instance in the cluster (potentially shared between multiple
// instances).
func (meta *ObjectMetadata) IsShared() bool {
return meta.Shared.CreatorID.IsSet() || meta.Shared.CustomObjectName != ""
return meta.Remote.CreatorID.IsSet()
}

// AssertValid checks that the metadata is sane.
func (meta *ObjectMetadata) AssertValid() {
if !meta.IsShared() {
// Verify all Shared fields are empty.
if meta.Shared != (ObjectMetadata{}).Shared {
panic(errors.AssertionFailedf("meta.Shared not empty: %#v", meta.Shared))
if !meta.IsRemote() {
// Verify all Remote fields are empty.
if meta.Remote != (ObjectMetadata{}).Remote {
panic(errors.AssertionFailedf("meta.Remote not empty: %#v", meta.Remote))
}
} else {
if meta.Shared.CustomObjectName != "" {
if meta.Shared.CreatorID == 0 {
if meta.Remote.CustomObjectName != "" {
if meta.Remote.CreatorID == 0 {
panic(errors.AssertionFailedf("CreatorID not set"))
}
if meta.Shared.CreatorFileNum == base.FileNum(0).DiskFileNum() {
if meta.Remote.CreatorFileNum == base.FileNum(0).DiskFileNum() {
panic(errors.AssertionFailedf("CreatorFileNum not set"))
}
}
if meta.Shared.CleanupMethod != SharedNoCleanup && meta.Shared.CleanupMethod != SharedRefTracking {
panic(errors.AssertionFailedf("invalid CleanupMethod %d", meta.Shared.CleanupMethod))
if meta.Remote.CleanupMethod != SharedNoCleanup && meta.Remote.CleanupMethod != SharedRefTracking {
panic(errors.AssertionFailedf("invalid CleanupMethod %d", meta.Remote.CleanupMethod))
}
if meta.Shared.Storage == nil {
if meta.Remote.Storage == nil {
panic(errors.AssertionFailedf("Storage not set"))
}
}
Expand All @@ -161,7 +174,7 @@ const (
// keep track of references via reference marker objects.
SharedRefTracking SharedCleanupMethod = iota

// SharedNoCleanup is used for shared objects that are managed externally; the
// SharedNoCleanup is used for remote objects that are managed externally; the
// objstorage provider never deletes such objects.
SharedNoCleanup
)
Expand Down Expand Up @@ -249,7 +262,7 @@ type Provider interface {
List() []ObjectMetadata

// SetCreatorID sets the CreatorID which is needed in order to use shared
// objects. Shared object usage is disabled until this method is called the
// objects. Remote object usage is disabled until this method is called the
// first time. Once set, the Creator ID is persisted and cannot change.
//
// Cannot be called if shared storage is not configured for the provider.
Expand All @@ -260,16 +273,16 @@ type Provider interface {
// exist in this provider.
IsForeign(meta ObjectMetadata) bool

// SharedObjectBacking encodes the shared object metadata for the given object.
SharedObjectBacking(meta *ObjectMetadata) (SharedObjectBackingHandle, error)
// RemoteObjectBacking encodes the remote object metadata for the given object.
RemoteObjectBacking(meta *ObjectMetadata) (RemoteObjectBackingHandle, error)

// CreateSharedObjectBacking creates a backing for an existing object with a
// CreateExternalObjectBacking creates a backing for an existing object with a
// custom object name. The object is considered to be managed outside of
// Pebble and will never be removed by Pebble.
CreateSharedObjectBacking(locator shared.Locator, objName string) (SharedObjectBacking, error)
CreateExternalObjectBacking(locator shared.Locator, objName string) (RemoteObjectBacking, error)

// AttachSharedObjects registers existing shared objects with this provider.
AttachSharedObjects(objs []SharedObjectToAttach) ([]ObjectMetadata, error)
// AttachRemoteObjects registers existing remote objects with this provider.
AttachRemoteObjects(objs []RemoteObjectToAttach) ([]ObjectMetadata, error)

Close() error

Expand All @@ -278,31 +291,31 @@ type Provider interface {
IsNotExistError(err error) bool
}

// SharedObjectBacking encodes the metadata necessary to incorporate a shared
// RemoteObjectBacking encodes the metadata necessary to incorporate a shared
// object into a different Pebble instance. The encoding is specific to a given
// Provider implementation.
type SharedObjectBacking []byte
type RemoteObjectBacking []byte

// SharedObjectBackingHandle is a container for a SharedObjectBacking which
// RemoteObjectBackingHandle is a container for a RemoteObjectBacking which
// ensures that the backing stays valid. A backing can otherwise become invalid
// if this provider unrefs the shared object. The SharedObjectBackingHandle
// if this provider unrefs the shared object. The RemoteObjectBackingHandle
// delays any unref until Close.
type SharedObjectBackingHandle interface {
type RemoteObjectBackingHandle interface {
// Get returns the backing. The backing is only guaranteed to be valid until
// Close is called (or until the Provider is closed). If Close was already
// called, returns an error.
Get() (SharedObjectBacking, error)
Get() (RemoteObjectBacking, error)
Close()
}

// SharedObjectToAttach contains the arguments needed to attach an existing shared object.
type SharedObjectToAttach struct {
// RemoteObjectToAttach contains the arguments needed to attach an existing remote object.
type RemoteObjectToAttach struct {
// FileNum is the file number that will be used to refer to this object (in
// the context of this instance).
FileNum base.DiskFileNum
FileType base.FileType
// Backing contains the metadata for the shared object backing (normally
// Backing contains the metadata for the remote object backing (normally
// generated from a different instance, but using the same Provider
// implementation).
Backing SharedObjectBacking
Backing RemoteObjectBacking
}
24 changes: 12 additions & 12 deletions objstorage/objstorageprovider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func (p *provider) OpenForReading(
}

var r objstorage.Readable
if !meta.IsShared() {
if !meta.IsRemote() {
r, err = p.vfsOpenForReading(ctx, fileType, fileNum, opts)
} else {
r, err = p.sharedOpenForReading(ctx, meta, opts)
Expand Down Expand Up @@ -271,7 +271,7 @@ func (p *provider) Remove(fileType base.FileType, fileNum base.DiskFileNum) erro
return err
}

if !meta.IsShared() {
if !meta.IsRemote() {
err = p.vfsRemove(fileType, fileNum)
} else {
// TODO(radu): implement shared object removal (i.e. deref).
Expand All @@ -293,8 +293,8 @@ func (p *provider) Remove(fileType base.FileType, fileNum base.DiskFileNum) erro
}

func (p *provider) isNotExistError(meta objstorage.ObjectMetadata, err error) bool {
if meta.Shared.Storage != nil {
return meta.Shared.Storage.IsNotExistError(err)
if meta.Remote.Storage != nil {
return meta.Remote.Storage.IsNotExistError(err)
}
return oserror.IsNotExist(err)
}
Expand Down Expand Up @@ -411,15 +411,15 @@ func (p *provider) Lookup(

// Path is part of the objstorage.Provider interface.
func (p *provider) Path(meta objstorage.ObjectMetadata) string {
if !meta.IsShared() {
if !meta.IsRemote() {
return p.vfsPath(meta.FileType, meta.DiskFileNum)
}
return p.sharedPath(meta)
}

// Size returns the size of the object.
func (p *provider) Size(meta objstorage.ObjectMetadata) (int64, error) {
if !meta.IsShared() {
if !meta.IsRemote() {
return p.vfsSize(meta.FileType, meta.DiskFileNum)
}
return p.sharedSize(meta)
Expand All @@ -446,14 +446,14 @@ func (p *provider) addMetadata(meta objstorage.ObjectMetadata) {
p.mu.Lock()
defer p.mu.Unlock()
p.mu.knownObjects[meta.DiskFileNum] = meta
if meta.IsShared() {
if meta.IsRemote() {
p.mu.shared.catalogBatch.AddObject(sharedobjcat.SharedObjectMetadata{
FileNum: meta.DiskFileNum,
FileType: meta.FileType,
CreatorID: meta.Shared.CreatorID,
CreatorFileNum: meta.Shared.CreatorFileNum,
Locator: meta.Shared.Locator,
CleanupMethod: meta.Shared.CleanupMethod,
CreatorID: meta.Remote.CreatorID,
CreatorFileNum: meta.Remote.CreatorFileNum,
Locator: meta.Remote.Locator,
CleanupMethod: meta.Remote.CleanupMethod,
})
} else {
p.mu.localObjectsChanged = true
Expand All @@ -469,7 +469,7 @@ func (p *provider) removeMetadata(fileNum base.DiskFileNum) {
return
}
delete(p.mu.knownObjects, fileNum)
if meta.IsShared() {
if meta.IsRemote() {
p.mu.shared.catalogBatch.DeleteObject(fileNum)
} else {
p.mu.localObjectsChanged = true
Expand Down
Loading
Loading