Skip to content

Commit

Permalink
Merge pull request #313 from mimiro-io/fix/statistics
Browse files Browse the repository at this point in the history
move stats and gc to internal jobs
  • Loading branch information
rompetroll authored Aug 13, 2024
2 parents be310fa + adea7c1 commit f8cd287
Show file tree
Hide file tree
Showing 9 changed files with 511 additions and 321 deletions.
9 changes: 9 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/mimiro-io/datahub/internal/jobs"
"github.com/mimiro-io/datahub/internal/security"
"github.com/mimiro-io/datahub/internal/server"
"github.com/mimiro-io/datahub/internal/service/scheduler"
"github.com/mimiro-io/datahub/internal/web"
"go.uber.org/zap"
"os"
Expand All @@ -49,11 +50,13 @@ type DatahubInstance struct {
securityServiceCore *security.ServiceCore
gc *server.GarbageCollector
backup *server.BackupManager
updater *scheduler.Scheduler
}

func (dhi *DatahubInstance) Start() error {
dhi.logger.Info("Starting data hub instance")

dhi.updater.Start()
// start web server
go func() {
err := dhi.webService.Start(context.Background())
Expand Down Expand Up @@ -87,6 +90,7 @@ func (dhi *DatahubInstance) Stop(ctx context.Context) error {
dhi.logger.Info("Data hub stopping")
dhi.webService.Stop(ctx)
dhi.gc.Stop(ctx)
dhi.updater.Stop(ctx)
dhi.scheduler.Stop(ctx)
dhi.store.Close()

Expand Down Expand Up @@ -139,6 +143,11 @@ func NewDatahubInstance(config *conf.Config) (*DatahubInstance, error) {
}

dhi.gc = server.NewGarbageCollector(dhi.store, dhi.config)
dhi.updater = scheduler.NewScheduler(
dhi.logger,
dhi.gc,
server.NewBadgerAccess(dhi.store, dhi.dsManager),
)
// dhi.gc.Start(context.Background())

// web service config from dhi (ideally we pass through the dhi here or interface)
Expand Down
5 changes: 3 additions & 2 deletions internal/server/garbagecollector.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ func NewGarbageCollector(store *Store, env *conf.Config) *GarbageCollector {
env: env,
}

gc.Start(context.Background())
// this is now orchestrated from service/scheduler/scheduler.go
//gc.Start(context.Background())

return gc
}
Expand Down Expand Up @@ -85,7 +86,7 @@ again:
if garbageCollector.isCancelled() {
return errors.New("gc cancelled")
}
err := garbageCollector.store.database.RunValueLogGC(0.5)
err := garbageCollector.store.database.RunValueLogGC(0.3) // 30% of the value log can be discarded
if err == nil {
goto again
}
Expand Down
Loading

0 comments on commit f8cd287

Please sign in to comment.