Skip to content

Commit 97bcce6

Browse files
committed
db: move replayIngestedFlushable into recovery.go
1 parent 0188943 commit 97bcce6

File tree

2 files changed

+78
-79
lines changed

2 files changed

+78
-79
lines changed

open.go

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@ package pebble
66

77
import (
88
"bytes"
9-
"context"
10-
"encoding/binary"
119
"fmt"
1210
"io"
1311
"math"
1412
"os"
15-
"slices"
1613
"sync"
1714
"sync/atomic"
1815

@@ -23,7 +20,6 @@ import (
2320
"github.com/cockroachdb/pebble/internal/cache"
2421
"github.com/cockroachdb/pebble/internal/inflight"
2522
"github.com/cockroachdb/pebble/internal/invariants"
26-
"github.com/cockroachdb/pebble/internal/keyspan"
2723
"github.com/cockroachdb/pebble/internal/manifest"
2824
"github.com/cockroachdb/pebble/internal/manual"
2925
"github.com/cockroachdb/pebble/objstorage"
@@ -675,81 +671,6 @@ func GetVersion(dir string, fs vfs.FS) (string, error) {
675671
return version, nil
676672
}
677673

678-
func (d *DB) replayIngestedFlushable(
679-
b *Batch, logNum base.DiskFileNum,
680-
) (entry *flushableEntry, err error) {
681-
br := b.Reader()
682-
seqNum := b.SeqNum()
683-
684-
fileNums := make([]base.DiskFileNum, 0, b.Count())
685-
var exciseSpan KeyRange
686-
addFileNum := func(encodedFileNum []byte) {
687-
fileNum, n := binary.Uvarint(encodedFileNum)
688-
if n <= 0 {
689-
panic("pebble: ingest sstable file num is invalid")
690-
}
691-
fileNums = append(fileNums, base.DiskFileNum(fileNum))
692-
}
693-
694-
for i := 0; i < int(b.Count()); i++ {
695-
kind, key, val, ok, err := br.Next()
696-
if err != nil {
697-
return nil, err
698-
}
699-
if kind != InternalKeyKindIngestSST && kind != InternalKeyKindExcise {
700-
panic("pebble: invalid batch key kind")
701-
}
702-
if !ok {
703-
panic("pebble: invalid batch count")
704-
}
705-
if kind == base.InternalKeyKindExcise {
706-
if exciseSpan.Valid() {
707-
panic("pebble: multiple excise spans in a single batch")
708-
}
709-
exciseSpan.Start = slices.Clone(key)
710-
exciseSpan.End = slices.Clone(val)
711-
continue
712-
}
713-
addFileNum(key)
714-
}
715-
716-
if _, _, _, ok, err := br.Next(); err != nil {
717-
return nil, err
718-
} else if ok {
719-
panic("pebble: invalid number of entries in batch")
720-
}
721-
722-
meta := make([]*manifest.TableMetadata, len(fileNums))
723-
var lastRangeKey keyspan.Span
724-
for i, n := range fileNums {
725-
readable, err := d.objProvider.OpenForReading(context.TODO(), base.FileTypeTable, n,
726-
objstorage.OpenOptions{MustExist: true})
727-
if err != nil {
728-
return nil, errors.Wrap(err, "pebble: error when opening flushable ingest files")
729-
}
730-
// NB: ingestLoad1 will close readable.
731-
meta[i], lastRangeKey, _, err = ingestLoad1(context.TODO(), d.opts, d.FormatMajorVersion(),
732-
readable, d.cacheHandle, base.PhysicalTableFileNum(n), disableRangeKeyChecks())
733-
if err != nil {
734-
return nil, errors.Wrap(err, "pebble: error when loading flushable ingest files")
735-
}
736-
}
737-
if lastRangeKey.Valid() && d.opts.Comparer.Split.HasSuffix(lastRangeKey.End) {
738-
return nil, errors.AssertionFailedf("pebble: last ingest sstable has suffixed range key end %s",
739-
d.opts.Comparer.FormatKey(lastRangeKey.End))
740-
}
741-
742-
numFiles := len(meta)
743-
if exciseSpan.Valid() {
744-
numFiles++
745-
}
746-
if uint32(numFiles) != b.Count() {
747-
panic("pebble: couldn't load all files in WAL entry")
748-
}
749-
750-
return d.newIngestedFlushableEntry(meta, seqNum, logNum, exciseSpan)
751-
}
752-
753674
func readOptionsFile(opts *Options, path string) (string, error) {
754675
f, err := opts.FS.Open(path)
755676
if err != nil {

recovery.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package pebble
66

77
import (
88
"bytes"
9+
"context"
10+
"encoding/binary"
911
"io"
1012
"slices"
1113

@@ -14,6 +16,7 @@ import (
1416
"github.com/cockroachdb/pebble/internal/arenaskl"
1517
"github.com/cockroachdb/pebble/internal/base"
1618
"github.com/cockroachdb/pebble/internal/invariants"
19+
"github.com/cockroachdb/pebble/internal/keyspan"
1720
"github.com/cockroachdb/pebble/internal/manifest"
1821
"github.com/cockroachdb/pebble/objstorage"
1922
"github.com/cockroachdb/pebble/objstorage/objstorageprovider"
@@ -593,3 +596,78 @@ func (d *DB) replayWAL(
593596
// mem is nil here, if !ReadOnly.
594597
return flushableIngests, maxSeqNum, err
595598
}
599+
600+
func (d *DB) replayIngestedFlushable(
601+
b *Batch, logNum base.DiskFileNum,
602+
) (entry *flushableEntry, err error) {
603+
br := b.Reader()
604+
seqNum := b.SeqNum()
605+
606+
fileNums := make([]base.DiskFileNum, 0, b.Count())
607+
var exciseSpan KeyRange
608+
addFileNum := func(encodedFileNum []byte) {
609+
fileNum, n := binary.Uvarint(encodedFileNum)
610+
if n <= 0 {
611+
panic("pebble: ingest sstable file num is invalid")
612+
}
613+
fileNums = append(fileNums, base.DiskFileNum(fileNum))
614+
}
615+
616+
for i := 0; i < int(b.Count()); i++ {
617+
kind, key, val, ok, err := br.Next()
618+
if err != nil {
619+
return nil, err
620+
}
621+
if kind != InternalKeyKindIngestSST && kind != InternalKeyKindExcise {
622+
panic("pebble: invalid batch key kind")
623+
}
624+
if !ok {
625+
panic("pebble: invalid batch count")
626+
}
627+
if kind == base.InternalKeyKindExcise {
628+
if exciseSpan.Valid() {
629+
panic("pebble: multiple excise spans in a single batch")
630+
}
631+
exciseSpan.Start = slices.Clone(key)
632+
exciseSpan.End = slices.Clone(val)
633+
continue
634+
}
635+
addFileNum(key)
636+
}
637+
638+
if _, _, _, ok, err := br.Next(); err != nil {
639+
return nil, err
640+
} else if ok {
641+
panic("pebble: invalid number of entries in batch")
642+
}
643+
644+
meta := make([]*manifest.TableMetadata, len(fileNums))
645+
var lastRangeKey keyspan.Span
646+
for i, n := range fileNums {
647+
readable, err := d.objProvider.OpenForReading(context.TODO(), base.FileTypeTable, n,
648+
objstorage.OpenOptions{MustExist: true})
649+
if err != nil {
650+
return nil, errors.Wrap(err, "pebble: error when opening flushable ingest files")
651+
}
652+
// NB: ingestLoad1 will close readable.
653+
meta[i], lastRangeKey, _, err = ingestLoad1(context.TODO(), d.opts, d.FormatMajorVersion(),
654+
readable, d.cacheHandle, base.PhysicalTableFileNum(n), disableRangeKeyChecks())
655+
if err != nil {
656+
return nil, errors.Wrap(err, "pebble: error when loading flushable ingest files")
657+
}
658+
}
659+
if lastRangeKey.Valid() && d.opts.Comparer.Split.HasSuffix(lastRangeKey.End) {
660+
return nil, errors.AssertionFailedf("pebble: last ingest sstable has suffixed range key end %s",
661+
d.opts.Comparer.FormatKey(lastRangeKey.End))
662+
}
663+
664+
numFiles := len(meta)
665+
if exciseSpan.Valid() {
666+
numFiles++
667+
}
668+
if uint32(numFiles) != b.Count() {
669+
panic("pebble: couldn't load all files in WAL entry")
670+
}
671+
672+
return d.newIngestedFlushableEntry(meta, seqNum, logNum, exciseSpan)
673+
}

0 commit comments

Comments
 (0)