Skip to content

Commit

Permalink
db: add format major version for range keys
Browse files Browse the repository at this point in the history
Introduce a new format major version for range keys, with associated
table format `Pebble,v2`. When the DB is opened at this version, it is
free to make use of range key features.

Related to cockroachdb#1339.
  • Loading branch information
nicktrav committed Feb 4, 2022
1 parent 19e11cf commit 9efd3a7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
9 changes: 8 additions & 1 deletion format_major_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ const (
// FormatBlockPropertyCollector is a format major version that introduces
// BlockPropertyCollectors.
FormatBlockPropertyCollector
// FormatRangeKeys is a format major version that introduces range keys.
FormatRangeKeys
// FormatNewest always contains the most recent format major version.
// NB: When adding new versions, the MaxTableFormat method should also be
// updated to return the maximum allowable version for the new
// FormatMajorVersion.
FormatNewest FormatMajorVersion = FormatBlockPropertyCollector
FormatNewest FormatMajorVersion = FormatRangeKeys
)

// MaxTableFormat returns the maximum sstable.TableFormat that can be used at
Expand All @@ -86,6 +88,8 @@ func (v FormatMajorVersion) MaxTableFormat() sstable.TableFormat {
return sstable.TableFormatRocksDBv2
case FormatBlockPropertyCollector:
return sstable.TableFormatPebblev1
case FormatRangeKeys:
return sstable.TableFormatPebblev2
default:
panic(fmt.Sprintf("pebble: unsupported format major version: %s", v))
}
Expand Down Expand Up @@ -167,6 +171,9 @@ var formatMajorVersionMigrations = map[FormatMajorVersion]func(*DB) error{
FormatBlockPropertyCollector: func(d *DB) error {
return d.finalizeFormatVersUpgrade(FormatBlockPropertyCollector)
},
FormatRangeKeys: func(d *DB) error {
return d.finalizeFormatVersUpgrade(FormatRangeKeys)
},
}

const formatVersionMarkerName = `format-version`
Expand Down
3 changes: 3 additions & 0 deletions format_major_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ func TestRatchetFormat(t *testing.T) {
require.Equal(t, FormatSetWithDelete, d.FormatMajorVersion())
require.NoError(t, d.RatchetFormatMajorVersion(FormatBlockPropertyCollector))
require.Equal(t, FormatBlockPropertyCollector, d.FormatMajorVersion())
require.NoError(t, d.RatchetFormatMajorVersion(FormatRangeKeys))
require.Equal(t, FormatRangeKeys, d.FormatMajorVersion())
require.NoError(t, d.Close())

// If we Open the database again, leaving the default format, the
Expand Down Expand Up @@ -189,6 +191,7 @@ func TestFormatMajorVersions_TableFormat(t *testing.T) {
FormatVersioned: sstable.TableFormatRocksDBv2,
FormatSetWithDelete: sstable.TableFormatRocksDBv2,
FormatBlockPropertyCollector: sstable.TableFormatPebblev1,
FormatRangeKeys: sstable.TableFormatPebblev2,
}

// Valid versions.
Expand Down
2 changes: 1 addition & 1 deletion open_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func TestNewDBFilenames(t *testing.T) {
"LOCK",
"MANIFEST-000001",
"OPTIONS-000003",
"marker.format-version.000004.005",
"marker.format-version.000005.006",
"marker.manifest.000001.MANIFEST-000001",
},
}
Expand Down
13 changes: 8 additions & 5 deletions testdata/checkpoint
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ sync: db
create: db/marker.format-version.000004.005
close: db/marker.format-version.000004.005
sync: db
create: db/marker.format-version.000005.006
close: db/marker.format-version.000005.006
sync: db
sync: db/MANIFEST-000001
create: db/000002.log
sync: db
Expand Down Expand Up @@ -96,9 +99,9 @@ close:
open-dir: checkpoints/checkpoint1
link: db/OPTIONS-000003 -> checkpoints/checkpoint1/OPTIONS-000003
open-dir: checkpoints/checkpoint1
create: checkpoints/checkpoint1/marker.format-version.000001.005
sync: checkpoints/checkpoint1/marker.format-version.000001.005
close: checkpoints/checkpoint1/marker.format-version.000001.005
create: checkpoints/checkpoint1/marker.format-version.000001.006
sync: checkpoints/checkpoint1/marker.format-version.000001.006
close: checkpoints/checkpoint1/marker.format-version.000001.006
sync: checkpoints/checkpoint1
close: checkpoints/checkpoint1
create: checkpoints/checkpoint1/MANIFEST-000001
Expand Down Expand Up @@ -153,7 +156,7 @@ CURRENT
LOCK
MANIFEST-000001
OPTIONS-000003
marker.format-version.000004.005
marker.format-version.000005.006
marker.manifest.000001.MANIFEST-000001

list checkpoints/checkpoint1
Expand All @@ -163,7 +166,7 @@ list checkpoints/checkpoint1
000007.sst
MANIFEST-000001
OPTIONS-000003
marker.format-version.000001.005
marker.format-version.000001.006
marker.manifest.000001.MANIFEST-000001

open checkpoints/checkpoint1 readonly
Expand Down
10 changes: 7 additions & 3 deletions testdata/event_listener
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ create: db/marker.format-version.000004.005
close: db/marker.format-version.000004.005
sync: db
upgraded to format version: 005
create: db/marker.format-version.000005.006
close: db/marker.format-version.000005.006
sync: db
upgraded to format version: 006
create: db/MANIFEST-000003
close: db/MANIFEST-000001
sync: db/MANIFEST-000003
Expand Down Expand Up @@ -205,9 +209,9 @@ close:
open-dir: checkpoint
link: db/OPTIONS-000004 -> checkpoint/OPTIONS-000004
open-dir: checkpoint
create: checkpoint/marker.format-version.000001.005
sync: checkpoint/marker.format-version.000001.005
close: checkpoint/marker.format-version.000001.005
create: checkpoint/marker.format-version.000001.006
sync: checkpoint/marker.format-version.000001.006
close: checkpoint/marker.format-version.000001.006
sync: checkpoint
close: checkpoint
create: checkpoint/MANIFEST-000017
Expand Down

0 comments on commit 9efd3a7

Please sign in to comment.