From fb76a24ac0984653275fbe9a3d7afb7f3476d844 Mon Sep 17 00:00:00 2001 From: Bilal Akhtar Date: Tue, 18 Jul 2023 13:23:24 -0400 Subject: [PATCH] db: Add BackingType, Locator to SSTableInfo The SSTables() method returns sstable info from a Pebble db instance. This change adds an additional field denoting the type of storage backing a given sstable in addition to all other sstable properties; i.e. whether an sstable is local, shared (non-foreign), shared+foreign, or external. It also adds a field denoting the shared.Locator, if one was specified. --- db.go | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) 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