Repository: dolthub/dolt
File: go/libraries/doltcore/sqle/auto_gc.go (Go)

Code before:
	// pending request for GC or a GC is currently running. Once
	// |done| is closed, we can check for auto GC conditions on
	// the database to see if we should request a new GC.
	done chan *gcWorkReport
	// It simplifies the logic and efficiency of the
	// implementation a bit to have an already allocated channel
	// we can try to send when we request a GC. If will become our
	// new |done| channel once we send it successfully.
	next chan *gcWorkReport
	// lastSz is set the first time we observe StoreSizes after a
	// GC or after the server comes up. It is used in some simple
	// growth heuristics to figure out if we want to run a GC. We
	// set it back to |nil| when we successfully submit a request
	// to GC, so that we observe and store the new size after the
	// GC is finished.
	lastSz *doltdb.StoreSizes
	// This records stats about the last run of Auto GC. It starts
	// |nil| and will only be populated after a successful run.
	lastGcWorkReport *gcWorkReport

	db *doltdb.DoltDB

	// Closed when the thread should shutdown because the database
	// is being removed.
	stopCh chan struct{}
	// Closed as the background processing thread shutsdown. The
	// dattabase hook selects on this to avoid deadlocking if it
	// is trying to send to the worker thread after it has been
	// shutdown.
	stoppedCh chan struct{}
	// An optimistic send on this channel notifies the background
	// thread that the sizes may have changed and it can check for
	// the GC condition.
	tickCh chan struct{}
	wg     sync.WaitGroup
}

// During engine initialization, called on the original set of
// databases to configure them for auto-GC.
func (c *AutoGCController) ApplyCommitHooks(ctx context.Context, mrEnv *env.MultiRepoEnv, dbs ...dsess.SqlDatabase) error {
	for _, db := range dbs {
		denv := mrEnv.GetEnv(db.Name())
		if denv == nil {
			continue
		}
		ddb := denv.DoltDB(ctx)
		ddb.PrependCommitHooks(ctx, c.newCommitHook(db.Name(), ddb))
	}
	return nil
}


Review comment (suggestion):
```suggestion
	// Closed as the background processing thread shuts down. The
```

Code after:
	// pending request for GC or a GC is currently running. Once
	// |done| is closed, we can check for auto GC conditions on
	// the database to see if we should request a new GC.
	done chan *gcWorkReport
	// It simplifies the logic and efficiency of the
	// implementation a bit to have an already allocated channel
	// we can try to send when we request a GC. If will become our
	// new |done| channel once we send it successfully.
	next chan *gcWorkReport
	// lastSz is set the first time we observe StoreSizes after a
	// GC or after the server comes up. It is used in some simple
	// growth heuristics to figure out if we want to run a GC. We
	// set it back to |nil| when we successfully submit a request
	// to GC, so that we observe and store the new size after the
	// GC is finished.
	lastSz *doltdb.StoreSizes
	// This records stats about the last run of Auto GC. It starts
	// |nil| and will only be populated after a successful run.
	lastGcWorkReport *gcWorkReport

	db *doltdb.DoltDB

	// Closed when the thread should shutdown because the database
	// is being removed.
	stopCh chan struct{}
	// Closed as the background processing thread shuts down. The
	// database hook selects on this to avoid deadlocking if it
	// is trying to send to the worker thread after it has been
	// shutdown.
	stoppedCh chan struct{}
	// An optimistic send on this channel notifies the background
	// thread that the sizes may have changed and it can check for
	// the GC condition.
	tickCh chan struct{}
	wg     sync.WaitGroup
}

// During engine initialization, called on the original set of
// databases to configure them for auto-GC.
func (c *AutoGCController) ApplyCommitHooks(ctx context.Context, mrEnv *env.MultiRepoEnv, dbs ...dsess.SqlDatabase) error {
	for _, db := range dbs {
		denv := mrEnv.GetEnv(db.Name())
		if denv == nil {
			continue
		}
		ddb := denv.DoltDB(ctx)
		ddb.PrependCommitHooks(ctx, c.newCommitHook(db.Name(), ddb))
	}
	return nil
}