Skip to content

Commit

Permalink
db: Add BackingType, Locator to SSTableInfo
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
itsbilal committed Jul 19, 2023
1 parent d9bbb98 commit fb76a24
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fb76a24

Please sign in to comment.