mirror of
https://github.com/Icinga/icingadb.git
synced 2026-06-08 16:34:29 -04:00
commit
40cef17db1
1 changed files with 0 additions and 74 deletions
|
|
@ -2,19 +2,15 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/icinga/icingadb/internal/command"
|
||||
"github.com/icinga/icingadb/pkg/contracts"
|
||||
"github.com/icinga/icingadb/pkg/flatten"
|
||||
"github.com/icinga/icingadb/pkg/icingadb"
|
||||
"github.com/icinga/icingadb/pkg/icingadb/history"
|
||||
v1 "github.com/icinga/icingadb/pkg/icingadb/v1"
|
||||
"github.com/icinga/icingadb/pkg/icingaredis"
|
||||
"github.com/icinga/icingadb/pkg/utils"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/sync/errgroup"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
@ -55,70 +51,6 @@ func main() {
|
|||
go func() {
|
||||
g, synctx := errgroup.WithContext(hactx)
|
||||
|
||||
g.Go(func() error {
|
||||
return nil
|
||||
// TODO(el). This code is a draft for trying to synchronize customvar_flat from the customvar
|
||||
// delta, which actually doesn't really make sense, since both synchronizations must always be
|
||||
// completed without errors. The synchronization of customar and customvar_flat should only
|
||||
// fetch the desired entities once and multiplex them to the synchronization of customvar and
|
||||
// customvar_flat.
|
||||
delta := s.GetDelta(synctx, v1.NewCustomvar)
|
||||
if err := delta.Wait(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
entities := delta.Create.Entities(synctx)
|
||||
flat := make(chan contracts.Entity, 0)
|
||||
|
||||
cvg, _ := errgroup.WithContext(synctx)
|
||||
|
||||
g.Go(func() error {
|
||||
defer close(flat)
|
||||
|
||||
for i := 0; i < 1<<runtime.NumCPU()*2; i++ {
|
||||
cvg.Go(func() error {
|
||||
for entity := range entities {
|
||||
var value interface{}
|
||||
customvar := entity.(*v1.Customvar)
|
||||
if err := json.Unmarshal([]byte(customvar.Value), &value); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
flattened := flatten.Flatten(value, customvar.Name)
|
||||
|
||||
for flatname, flatvalue := range flattened {
|
||||
flatvalue := fmt.Sprintf("%v", flatvalue)
|
||||
flat <- &v1.CustomvarFlat{
|
||||
CustomvarMeta: v1.CustomvarMeta{
|
||||
EntityWithoutChecksum: v1.EntityWithoutChecksum{
|
||||
IdMeta: v1.IdMeta{
|
||||
// TODO(el): Schema comment is wrong.
|
||||
// Without customvar.Id we would produce duplicate keys here.
|
||||
Id: utils.Checksum(customvar.EnvironmentId.String() + customvar.Id.String() + flatname + flatvalue),
|
||||
},
|
||||
},
|
||||
EnvironmentMeta: v1.EnvironmentMeta{
|
||||
EnvironmentId: customvar.EnvironmentId,
|
||||
},
|
||||
CustomvarId: customvar.Id,
|
||||
},
|
||||
Flatname: flatname,
|
||||
FlatnameChecksum: utils.Checksum(flatname),
|
||||
Flatvalue: flatvalue,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
return cvg.Wait()
|
||||
})
|
||||
|
||||
return db.Create(synctx, flat)
|
||||
})
|
||||
|
||||
for _, factoryFunc := range []contracts.EntityFactoryFunc{
|
||||
v1.NewActionUrl,
|
||||
v1.NewCheckcommand,
|
||||
|
|
@ -177,12 +109,6 @@ func main() {
|
|||
return v
|
||||
}
|
||||
|
||||
// vs
|
||||
// g.Go(func(factoryFunc contracts.EntityFactoryFunc) func() error {
|
||||
// return func() error {
|
||||
// return s.Sync(synctx, factoryFunc)
|
||||
// }
|
||||
// }(factoryFunc))
|
||||
g.Go(func() error {
|
||||
return s.Sync(synctx, ff)
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue