diff --git a/db.go b/db.go index 63a403538d..4b4a6aa3c4 100644 --- a/db.go +++ b/db.go @@ -23,6 +23,7 @@ import ( "github.com/cockroachdb/pebble/internal/manifest" "github.com/cockroachdb/pebble/internal/manual" "github.com/cockroachdb/pebble/objstorage" + "github.com/cockroachdb/pebble/objstorage/shared" "github.com/cockroachdb/pebble/rangekey" "github.com/cockroachdb/pebble/record" "github.com/cockroachdb/pebble/sstable" @@ -1904,7 +1905,30 @@ func WithApproximateSpanBytes() SSTablesOption { } } -// SSTableInfo export manifest.TableInfo with sstable.Properties +// BackingType denotes the type of storage backing a given sstable. +type BackingType int + +const ( + // BackingTypeLocal denotes an sstable stored on local disk according to the + // objprovider. This file is completely owned by us. + BackingTypeLocal BackingType = iota + // BackingTypeShared denotes an sstable stored on shared storage, created + // by this Pebble instance and possibly shared by other Pebble instances. + // These types of files have lifecycle managed by Pebble. + BackingTypeShared + // BackingTypeSharedForeign denotes an sstable stored on shared storage, + // created by a Pebble instance other than this one. These types of files have + // lifecycle managed by Pebble. + BackingTypeSharedForeign + // BackingTypeExternal denotes an sstable stored on external storage, + // not owned by any Pebble instance and with no refcounting/cleanup methods + // or lifecycle management. An example of an external file is a file restored + // from a backup. + BackingTypeExternal +) + +// SSTableInfo export manifest.TableInfo with sstable.Properties alongside +// other file backing info. type SSTableInfo struct { manifest.TableInfo // Virtual indicates whether the sstable is virtual. @@ -1913,6 +1937,11 @@ type SSTableInfo struct { // backs the sstable associated with this SSTableInfo. If Virtual is false, // then BackingSSTNum == FileNum. BackingSSTNum base.FileNum + // BackingType is the type of storage backing this sstable. + BackingType BackingType + // Locator is the shared.Locator backing this sstable, if one was specified + // during ingest. + Locator shared.Locator // Properties is the sstable properties of this table. If Virtual is true, // then the Properties are associated with the backing sst. @@ -1972,6 +2001,22 @@ func (d *DB) SSTables(opts ...SSTablesOption) ([][]SSTableInfo, error) { } destTables[j].Virtual = m.Virtual destTables[j].BackingSSTNum = m.FileBacking.DiskFileNum.FileNum() + objMeta, err := d.objProvider.Lookup(fileTypeTable, m.FileBacking.DiskFileNum) + 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 + } else { + destTables[j].BackingType = BackingTypeShared + } + destTables[j].Locator = objMeta.Shared.Locator + } else { + destTables[j].BackingType = BackingTypeLocal + } if opt.withApproximateSpanBytes { var spanBytes uint64