Skip to content

Commit 31c66db

Browse files
committed
wip
1 parent 89ea47d commit 31c66db

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

compaction.go

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ const (
462462
compactionKindRead
463463
compactionKindRewrite
464464
compactionKindIngestedFlushable
465+
compactionKindBufferedFlush
465466
)
466467

467468
func (k compactionKind) String() string {
@@ -1874,6 +1875,7 @@ func (d *DB) flush1() (bytesFlushed uint64, err error) {
18741875
var n, inputs int
18751876
var inputBytes uint64
18761877
var ingest bool
1878+
var bufferedFlush = true // TODO(aaditya): loop this into a config setting
18771879
for ; n < len(d.mu.mem.queue)-1; n++ {
18781880
if f, ok := d.mu.mem.queue[n].flushable.(*ingestedFlushable); ok {
18791881
if n == 0 {
@@ -1932,6 +1934,10 @@ func (d *DB) flush1() (bytesFlushed uint64, err error) {
19321934
if err != nil {
19331935
return 0, err
19341936
}
1937+
1938+
if bufferedFlush && !ingest {
1939+
c.kind = compactionKindBufferedFlush
1940+
}
19351941
d.addInProgressCompaction(c)
19361942

19371943
jobID := d.mu.nextJobID
@@ -1946,7 +1952,16 @@ func (d *DB) flush1() (bytesFlushed uint64, err error) {
19461952

19471953
// Compactions always write directly to the database's object provider.
19481954
// Flushes may write to an in-memory object provider first.
1949-
var objCreator objectCreator = d.objProvider
1955+
var objCreator objectCreator
1956+
if c.kind == compactionKindBufferedFlush {
1957+
bufferedSSTs := &bufferedSSTables{}
1958+
// TODO(aaditya): pick a better size
1959+
bufferedSSTs.init(10)
1960+
objCreator = bufferedSSTs
1961+
} else {
1962+
objCreator = d.objProvider
1963+
}
1964+
19501965
var ve *manifest.VersionEdit
19511966
var pendingOutputs []physicalMeta
19521967
var stats compactStats
@@ -1963,6 +1978,27 @@ func (d *DB) flush1() (bytesFlushed uint64, err error) {
19631978
// TODO(aadityas,jackson): If the buffered output sstables are too small,
19641979
// avoid linking them into the version and just update the flushable queue
19651980
// appropriately.
1981+
if c.kind == compactionKindBufferedFlush {
1982+
var metas []*fileMetadata
1983+
var fileNums []base.DiskFileNum
1984+
for _, file := range ve.NewFiles {
1985+
metas = append(metas, file.Meta)
1986+
fileNums = append(fileNums, file.BackingFileNum)
1987+
}
1988+
1989+
bufferedSST := objCreator.(*bufferedSSTables)
1990+
if bufferedSST.size < d.opts.MemTableSize /* TODO(aaditya): does this make sense? */ {
1991+
var f flushable
1992+
f, err = newFlushableBufferedSSTables(d.opts.Comparer, metas, sstable.ReaderOptions{}, bufferedSST)
1993+
fe := d.newFlushableEntry(f, fileNums[0], 0 /* TODO(aaditya): figure out what to put here */)
1994+
remaining := d.mu.mem.queue[n : len(d.mu.mem.queue)-2]
1995+
mutable := d.mu.mem.queue[len(d.mu.mem.queue)-1]
1996+
d.mu.mem.queue = append(remaining, fe, mutable)
1997+
return 0, err
1998+
}
1999+
2000+
// else convert to objProvider and write to disk
2001+
}
19662002

19672003
// Acquire logLock. This will be released either on an error, by way of
19682004
// logUnlock, or through a call to logAndApply if there is no error.

flushable.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,8 @@ type bufferedSSTables struct {
554554
currFileNum base.DiskFileNum
555555
// finished holds the set of previously written and finished sstables.
556556
finished []bufferedSSTable
557+
// cumulative size of the finished buffers
558+
size uint64
557559
// objectIsOpen is true if the bufferedSSTables is currently being used as a
558560
// Writable.
559561
objectIsOpen bool
@@ -619,10 +621,9 @@ func (b *bufferedSSTables) Sync() error {
619621
// written by the flush.
620622
var _ objstorage.Writable = (*bufferedSSTables)(nil)
621623

622-
// Finish implements objstorage.Writable.
624+
// Write implements objstorage.Writable.
623625
func (o *bufferedSSTables) Write(p []byte) error {
624626
_, err := o.curr.Write(p)
625-
o.curr.Reset()
626627
return err
627628
}
628629

@@ -635,6 +636,7 @@ func (o *bufferedSSTables) Finish() error {
635636
fileNum: o.currFileNum,
636637
buf: slices.Clone(o.curr.Bytes()),
637638
})
639+
o.size += uint64(o.curr.Len())
638640
o.curr.Reset()
639641
o.objectIsOpen = false
640642
return nil

table_cache.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,7 @@ type loadInfo struct {
11801180
}
11811181

11821182
func (v *tableCacheValue) load(loadInfo loadInfo, c *tableCacheShard, dbOpts *tableCacheOpts) {
1183+
// TODO(aaditya): Example of creating iter for SST
11831184
// Try opening the file first.
11841185
var f objstorage.Readable
11851186
var err error

0 commit comments

Comments
 (0)