Skip to content

Commit

Permalink
objstorage: rename 'shared' to 'remote'
Browse files Browse the repository at this point in the history
Shared objects refer to objects that have been created by a Pebble
instance and are owned by the Pebble instances in a cluster. Remote
objects can be shared objects or external objects (such as those
attached by online restore).

In this commit we rename uses of "shared" to "remote" in objstorage
provider code that applies to all types of remote objects. We now
conceptually have a remote subsystem which itself contains a shared
subsystem.
  • Loading branch information
RaduBerinde committed Jul 24, 2023
1 parent 4afa98e commit 7ef7553
Show file tree
Hide file tree
Showing 19 changed files with 426 additions and 400 deletions.
2 changes: 1 addition & 1 deletion db.go
Original file line number Diff line number Diff line change
Expand Up @@ -2561,7 +2561,7 @@ func firstError(err0, err1 error) error {
}

// SetCreatorID sets the CreatorID which is needed in order to use shared objects.
// Shared object usage is disabled until this method is called the first time.
// Remote object usage is disabled until this method is called the first time.
// Once set, the Creator ID is persisted and cannot change.
//
// Does nothing if SharedStorage was not set in the options when the DB was
Expand Down
4 changes: 2 additions & 2 deletions ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ func ingestTargetLevel(
// local sstables. This is the step where overlap with memtables is
// determined. If there is overlap, we remember the most recent memtable
// that overlaps.
// 6. Update the sequence number in the ingested local sstables. (Shared
// 6. Update the sequence number in the ingested local sstables. (Remote
// sstables get fixed sequence numbers that were determined at load time.)
// 7. Wait for the most recent memtable that overlaps to flush (if any).
// 8. Add the ingested sstables to the version (DB.ingestApply).
Expand Down Expand Up @@ -1295,7 +1295,7 @@ func (d *DB) ingest(
}
}

// NB: Shared-sstable-only ingestions do not assign a sequence number to
// NB: Remote-sstable-only ingestions do not assign a sequence number to
// any sstables.
globalSeqNum := uint64(0)
if len(loadResult.localMeta) > 0 {
Expand Down
12 changes: 6 additions & 6 deletions ingest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1030,11 +1030,11 @@ func TestSimpleIngestShared(t *testing.T) {
NoSyncOnClose: opts2.NoSyncOnClose,
BytesPerSync: opts2.BytesPerSync,
}
providerSettings.Shared.StorageFactory = remote.MakeSimpleFactory(map[remote.Locator]remote.Storage{
providerSettings.Remote.StorageFactory = remote.MakeSimpleFactory(map[remote.Locator]remote.Storage{
"": remote.NewInMem(),
})
providerSettings.Shared.CreateOnShared = true
providerSettings.Shared.CreateOnSharedLocator = ""
providerSettings.Remote.CreateOnShared = true
providerSettings.Remote.CreateOnSharedLocator = ""

provider2, err := objstorageprovider.Open(providerSettings)
require.NoError(t, err)
Expand All @@ -1059,9 +1059,9 @@ func TestSimpleIngestShared(t *testing.T) {
L0CompactionThreshold: 100,
L0StopWritesThreshold: 100,
}
opts.Experimental.RemoteStorage = providerSettings.Shared.StorageFactory
opts.Experimental.CreateOnShared = providerSettings.Shared.CreateOnShared
opts.Experimental.CreateOnSharedLocator = providerSettings.Shared.CreateOnSharedLocator
opts.Experimental.RemoteStorage = providerSettings.Remote.StorageFactory
opts.Experimental.CreateOnShared = providerSettings.Remote.CreateOnShared
opts.Experimental.CreateOnSharedLocator = providerSettings.Remote.CreateOnSharedLocator

var err error
d, err = Open("", opts)
Expand Down
46 changes: 23 additions & 23 deletions objstorage/objstorageprovider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ type provider struct {

tracer *objiotracing.Tracer

shared sharedSubsystem
remote remoteSubsystem

mu struct {
sync.RWMutex

shared struct {
// catalogBatch accumulates shared object creations and deletions until
remote struct {
// catalogBatch accumulates remote object creations and deletions until
// Sync is called.
catalogBatch remoteobjcat.Batch

storageObjects map[remote.Locator]remote.Storage
}

// localObjectsChanged is set if non-shared objects were created or deleted
// localObjectsChanged is set if non-remote objects were created or deleted
// but Sync was not yet called.
localObjectsChanged bool

Expand Down Expand Up @@ -91,19 +91,19 @@ type Settings struct {
// out a large chunk of dirty filesystem buffers.
BytesPerSync int

// Fields here are set only if the provider is to support shared objects
// Fields here are set only if the provider is to support remote objects
// (experimental).
Shared struct {
Remote struct {
StorageFactory remote.StorageFactory

// If CreateOnShared is true, sstables are created on shared storage using
// If CreateOnShared is true, sstables are created on remote storage using
// the CreateOnSharedLocator (when the PreferSharedStorage create option is
// true).
CreateOnShared bool
CreateOnSharedLocator remote.Locator

// CacheSizeBytes is the size of the on-disk block cache for objects
// on shared storage. If it is 0, no cache is used.
// on remote storage. If it is 0, no cache is used.
CacheSizeBytes int64

// CacheBlockSize is the block size of the cache; if 0, the default of 32KB is used.
Expand All @@ -128,7 +128,7 @@ type Settings struct {
}
}

// DefaultSettings initializes default settings (with no shared storage),
// DefaultSettings initializes default settings (with no remote storage),
// suitable for tests and tools.
func DefaultSettings(fs vfs.FS, dirName string) Settings {
return Settings{
Expand Down Expand Up @@ -174,8 +174,8 @@ func open(settings Settings) (p *provider, _ error) {
return nil, err
}

// Initialize shared subsystem (if configured) and add shared objects.
if err := p.sharedInit(); err != nil {
// Initialize remote subsystem (if configured) and add remote objects.
if err := p.remoteInit(); err != nil {
return nil, err
}

Expand Down Expand Up @@ -217,7 +217,7 @@ func (p *provider) OpenForReading(
if !meta.IsRemote() {
r, err = p.vfsOpenForReading(ctx, fileType, fileNum, opts)
} else {
r, err = p.sharedOpenForReading(ctx, meta, opts)
r, err = p.remoteOpenForReading(ctx, meta, opts)
if err != nil && p.isNotExistError(meta, err) {
// Wrap the error so that IsNotExistError functions properly.
err = errors.Mark(err, os.ErrNotExist)
Expand All @@ -242,8 +242,8 @@ func (p *provider) Create(
fileNum base.DiskFileNum,
opts objstorage.CreateOptions,
) (w objstorage.Writable, meta objstorage.ObjectMetadata, err error) {
if opts.PreferSharedStorage && p.st.Shared.CreateOnShared {
w, meta, err = p.sharedCreate(ctx, fileType, fileNum, p.st.Shared.CreateOnSharedLocator, opts)
if opts.PreferSharedStorage && p.st.Remote.CreateOnShared {
w, meta, err = p.sharedCreate(ctx, fileType, fileNum, p.st.Remote.CreateOnSharedLocator, opts)
} else {
w, meta, err = p.vfsCreate(ctx, fileType, fileNum)
}
Expand All @@ -260,8 +260,8 @@ func (p *provider) Create(

// Remove removes an object.
//
// Note that if the object is shared, the object is only (conceptually) removed
// from this provider. If other providers have references on the shared object,
// Note that if the object is remote, the object is only (conceptually) removed
// from this provider. If other providers have references on the remote object,
// it will not be removed.
//
// The object is not guaranteed to be durably removed until Sync is called.
Expand All @@ -274,7 +274,7 @@ func (p *provider) Remove(fileType base.FileType, fileNum base.DiskFileNum) erro
if !meta.IsRemote() {
err = p.vfsRemove(fileType, fileNum)
} else {
// TODO(radu): implement shared object removal (i.e. deref).
// TODO(radu): implement remote object removal (i.e. deref).
err = p.sharedUnref(meta)
if err != nil && p.isNotExistError(meta, err) {
// Wrap the error so that IsNotExistError functions properly.
Expand Down Expand Up @@ -331,7 +331,7 @@ func (p *provider) LinkOrCopyFromLocal(
dstFileNum base.DiskFileNum,
opts objstorage.CreateOptions,
) (objstorage.ObjectMetadata, error) {
shared := opts.PreferSharedStorage && p.st.Shared.CreateOnShared
shared := opts.PreferSharedStorage && p.st.Remote.CreateOnShared
if !shared && srcFS == p.st.FS {
// Wrap the normal filesystem with one which wraps newly created files with
// vfs.NewSyncingFile.
Expand Down Expand Up @@ -414,15 +414,15 @@ func (p *provider) Path(meta objstorage.ObjectMetadata) string {
if !meta.IsRemote() {
return p.vfsPath(meta.FileType, meta.DiskFileNum)
}
return p.sharedPath(meta)
return p.remotePath(meta)
}

// Size returns the size of the object.
func (p *provider) Size(meta objstorage.ObjectMetadata) (int64, error) {
if !meta.IsRemote() {
return p.vfsSize(meta.FileType, meta.DiskFileNum)
}
return p.sharedSize(meta)
return p.remoteSize(meta)
}

// List is part of the objstorage.Provider interface.
Expand All @@ -447,7 +447,7 @@ func (p *provider) addMetadata(meta objstorage.ObjectMetadata) {
defer p.mu.Unlock()
p.mu.knownObjects[meta.DiskFileNum] = meta
if meta.IsRemote() {
p.mu.shared.catalogBatch.AddObject(remoteobjcat.RemoteObjectMetadata{
p.mu.remote.catalogBatch.AddObject(remoteobjcat.RemoteObjectMetadata{
FileNum: meta.DiskFileNum,
FileType: meta.FileType,
CreatorID: meta.Remote.CreatorID,
Expand All @@ -470,13 +470,13 @@ func (p *provider) removeMetadata(fileNum base.DiskFileNum) {
}
delete(p.mu.knownObjects, fileNum)
if meta.IsRemote() {
p.mu.shared.catalogBatch.DeleteObject(fileNum)
p.mu.remote.catalogBatch.DeleteObject(fileNum)
} else {
p.mu.localObjectsChanged = true
}
}

// protectObject prevents the unreferencing of a shared object until
// protectObject prevents the unreferencing of a remote object until
// unprotectObject is called.
func (p *provider) protectObject(fileNum base.DiskFileNum) {
p.mu.Lock()
Expand Down
40 changes: 20 additions & 20 deletions objstorage/objstorageprovider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestProvider(t *testing.T) {
log.Infof("<local fs> "+fmt, args...)
})
sharedStore := remote.WithLogging(remote.NewInMem(), func(fmt string, args ...interface{}) {
log.Infof("<shared> "+fmt, args...)
log.Infof("<remote> "+fmt, args...)
})
sharedFactory := remote.MakeSimpleFactory(map[remote.Locator]remote.Storage{
"": sharedStore,
Expand Down Expand Up @@ -58,13 +58,13 @@ func TestProvider(t *testing.T) {
case "open":
var fsDir string
var creatorID objstorage.CreatorID
scanArgs("<fs-dir> <shared-creator-id>", &fsDir, &creatorID)
scanArgs("<fs-dir> <remote-creator-id>", &fsDir, &creatorID)

st := DefaultSettings(fs, fsDir)
if creatorID != 0 {
st.Shared.StorageFactory = sharedFactory
st.Shared.CreateOnShared = true
st.Shared.CreateOnSharedLocator = ""
st.Remote.StorageFactory = sharedFactory
st.Remote.CreateOnShared = true
st.Remote.CreateOnSharedLocator = ""
}
require.NoError(t, fs.MkdirAll(fsDir, 0755))
p, err := Open(st)
Expand All @@ -75,7 +75,7 @@ func TestProvider(t *testing.T) {
// Checking refs on open affects the test output. We don't want tests to
// only pass when the `invariants` tag is used, so unconditionally
// enable ref checking on open.
p.(*provider).shared.checkRefsOnOpen = true
p.(*provider).remote.shared.checkRefsOnOpen = true
providers[fsDir] = p
curProvider = p

Expand Down Expand Up @@ -283,17 +283,17 @@ func TestSharedMultipleLocators(t *testing.T) {
sharedFactory := remote.MakeSimpleFactory(stores)

st1 := DefaultSettings(vfs.NewMem(), "")
st1.Shared.StorageFactory = sharedFactory
st1.Shared.CreateOnShared = true
st1.Shared.CreateOnSharedLocator = "foo"
st1.Remote.StorageFactory = sharedFactory
st1.Remote.CreateOnShared = true
st1.Remote.CreateOnSharedLocator = "foo"
p1, err := Open(st1)
require.NoError(t, err)
require.NoError(t, p1.SetCreatorID(1))

st2 := DefaultSettings(vfs.NewMem(), "")
st2.Shared.StorageFactory = sharedFactory
st2.Shared.CreateOnShared = true
st2.Shared.CreateOnSharedLocator = "bar"
st2.Remote.StorageFactory = sharedFactory
st2.Remote.CreateOnShared = true
st2.Remote.CreateOnSharedLocator = "bar"
p2, err := Open(st2)
require.NoError(t, err)
require.NoError(t, p2.SetCreatorID(2))
Expand Down Expand Up @@ -369,7 +369,7 @@ func TestSharedMultipleLocators(t *testing.T) {

// Try to attach an object to a provider that doesn't recognize the locator.
st3 := DefaultSettings(vfs.NewMem(), "")
st3.Shared.StorageFactory = remote.MakeSimpleFactory(nil)
st3.Remote.StorageFactory = remote.MakeSimpleFactory(nil)
p3, err := Open(st3)
require.NoError(t, err)
require.NoError(t, p3.SetCreatorID(3))
Expand All @@ -390,7 +390,7 @@ func TestAttachCustomObject(t *testing.T) {
})

st1 := DefaultSettings(vfs.NewMem(), "")
st1.Shared.StorageFactory = sharedFactory
st1.Remote.StorageFactory = sharedFactory
p1, err := Open(st1)
require.NoError(t, err)
defer p1.Close()
Expand Down Expand Up @@ -434,7 +434,7 @@ func TestAttachCustomObject(t *testing.T) {
require.NoError(t, err)

st2 := DefaultSettings(vfs.NewMem(), "")
st2.Shared.StorageFactory = sharedFactory
st2.Remote.StorageFactory = sharedFactory
p2, err := Open(st2)
require.NoError(t, err)
defer p2.Close()
Expand All @@ -461,11 +461,11 @@ func TestNotExistError(t *testing.T) {
fs := vfs.NewMem()
st := DefaultSettings(fs, "")
sharedStorage := remote.NewInMem()
st.Shared.StorageFactory = remote.MakeSimpleFactory(map[remote.Locator]remote.Storage{
st.Remote.StorageFactory = remote.MakeSimpleFactory(map[remote.Locator]remote.Storage{
"": sharedStorage,
})
st.Shared.CreateOnShared = true
st.Shared.CreateOnSharedLocator = ""
st.Remote.CreateOnShared = true
st.Remote.CreateOnSharedLocator = ""
provider, err := Open(st)
require.NoError(t, err)
require.NoError(t, provider.SetCreatorID(1))
Expand All @@ -474,7 +474,7 @@ func TestNotExistError(t *testing.T) {
fileNum := base.FileNum(1 + i).DiskFileNum()
name := "local"
if shared {
name = "shared"
name = "remote"
}
t.Run(name, func(t *testing.T) {
// Removing or opening an object that the provider doesn't know anything
Expand All @@ -497,7 +497,7 @@ func TestNotExistError(t *testing.T) {
} else {
meta, err := provider.Lookup(base.FileTypeTable, fileNum)
require.NoError(t, err)
require.NoError(t, sharedStorage.Delete(sharedObjectName(meta)))
require.NoError(t, sharedStorage.Delete(remoteObjectName(meta)))
}

_, err = provider.OpenForReading(context.Background(), base.FileTypeTable, fileNum, objstorage.OpenOptions{})
Expand Down
Loading

0 comments on commit 7ef7553

Please sign in to comment.