go: sqle/auto_gc: Some PR feedback.

This commit is contained in:
Aaron Son
2025-02-24 14:43:09 -08:00
parent 7f1e9dd3dd
commit 160b434dbd
2 changed files with 20 additions and 10 deletions

View File

@@ -1952,15 +1952,21 @@ func (ddb *DoltDB) StoreSizes(ctx context.Context) (StoreSizes, error) {
cs := datas.ChunkStoreFromDatabase(ddb.db)
if generationalNBS, ok := cs.(*nbs.GenerationalNBS); ok {
newgen := generationalNBS.NewGen()
newgenSz, err := newgen.(chunks.TableFileStore).Size(ctx)
newGenTFS, newGenTFSOk := newgen.(chunks.TableFileStore)
totalTFS, totalTFSOk := cs.(chunks.TableFileStore)
newGenNBS, newGenNBSOk := newgen.(*nbs.NomsBlockStore)
if !(newGenTFSOk && totalTFSOk && newGenNBSOk) {
return StoreSizes{}, fmt.Errorf("unexpected newgen or chunk store type for *nbs.GenerationalNBS instance; cannot take store sizes: cs: %T, newgen: %T", cs, newgen)
}
newgenSz, err := newGenTFS.Size(ctx)
if err != nil {
return StoreSizes{}, err
}
totalSz, err := cs.(chunks.TableFileStore).Size(ctx)
totalSz, err := totalTFS.Size(ctx)
if err != nil {
return StoreSizes{}, err
}
journal := newgen.(*nbs.NomsBlockStore).ChunkJournal()
journal := newGenNBS.ChunkJournal()
if journal != nil {
return StoreSizes{
JournalBytes: uint64(journal.Size()),
@@ -1974,7 +1980,11 @@ func (ddb *DoltDB) StoreSizes(ctx context.Context) (StoreSizes, error) {
}, nil
}
} else {
totalSz, err := cs.(chunks.TableFileStore).Size(ctx)
totalTFS, totalTFSOk := cs.(chunks.TableFileStore)
if !totalTFSOk {
return StoreSizes{}, fmt.Errorf("unexpected chunk store type for non-*nbs.GenerationalNBS ddb.db instance; cannot take store sizes: cs: %T", cs)
}
totalSz, err := totalTFS.Size(ctx)
if err != nil {
return StoreSizes{}, err
}

View File

@@ -288,6 +288,10 @@ func (h *autoGCCommitHook) ExecuteForWorkingSets() bool {
return true
}
const checkInterval = 1 * time.Second
const size_128mb = (1 << 27)
const defaultCheckSizeThreshold = size_128mb
func (h *autoGCCommitHook) checkForGC(ctx context.Context) error {
select {
case <-h.done:
@@ -299,12 +303,10 @@ func (h *autoGCCommitHook) checkForGC(ctx context.Context) error {
if h.lastSz == nil {
h.lastSz = &sz
}
const size_128mb = (1 << 27)
const size_256mb = (1 << 28)
if sz.JournalBytes > size_128mb {
if sz.JournalBytes > defaultCheckSizeThreshold {
// Our first heuristic is simply if journal is greater than a fixed size...
return h.requestGC(ctx)
} else if sz.TotalBytes > h.lastSz.TotalBytes && sz.TotalBytes-h.lastSz.TotalBytes > size_256mb {
} else if sz.TotalBytes > h.lastSz.TotalBytes && sz.TotalBytes-h.lastSz.TotalBytes > defaultCheckSizeThreshold {
// Or if the store has grown by a fixed size since our last GC / we started watching it...
return h.requestGC(ctx)
}
@@ -314,8 +316,6 @@ func (h *autoGCCommitHook) checkForGC(ctx context.Context) error {
return nil
}
const checkInterval = 100 * time.Millisecond
func (h *autoGCCommitHook) thread(ctx context.Context) {
defer h.wg.Done()
timer := time.NewTimer(checkInterval)