Allow objects without checksum

This commit is contained in:
Noah Hilverling 2019-07-16 15:08:59 +02:00
parent 1cf47757ab
commit 702fdfe93b
3 changed files with 30 additions and 21 deletions

View file

@ -7,6 +7,7 @@ import (
type ObjectInformation struct {
ObjectType string
RedisKey string
HasChecksum bool
Factory connection.RowFactory
BulkInsertStmt *connection.BulkInsertStmt
BulkDeleteStmt *connection.BulkDeleteStmt

View file

@ -149,25 +149,27 @@ func Operator(super *supervisor.Supervisor, chHA chan int, objectInformation *co
}
}()
go func() {
benchmarc := utils.NewBenchmark()
wgUpdate.Add(len(update))
if (objectInformation.HasChecksum) {
go func() {
benchmarc := utils.NewBenchmark()
wgUpdate.Add(len(update))
// Provide the UpdateCompWorker with IDs to compare
chUpdateComp <- update
// Provide the UpdateCompWorker with IDs to compare
chUpdateComp <- update
// Wait for all IDs to be update in MySQL
kill := waitOrKill(wgUpdate, done)
benchmarc.Stop()
if !kill {
log.WithFields(log.Fields{
"type": objectInformation.ObjectType,
"count": atomic.LoadUint32(updateCounter),
"benchmark": benchmarc.String(),
"action": "update",
}).Infof("Updated %v %ss in %v", atomic.LoadUint32(updateCounter), objectInformation.ObjectType, benchmarc.String())
}
}()
// Wait for all IDs to be update in MySQL
kill := waitOrKill(wgUpdate, done)
benchmarc.Stop()
if !kill {
log.WithFields(log.Fields{
"type": objectInformation.ObjectType,
"count": atomic.LoadUint32(updateCounter),
"benchmark": benchmarc.String(),
"action": "update",
}).Infof("Updated %v %ss in %v", atomic.LoadUint32(updateCounter), objectInformation.ObjectType, benchmarc.String())
}
}()
}
}
}
@ -191,7 +193,7 @@ func GetDelta(super *supervisor.Supervisor, objectInformation *configobject.Obje
go func() {
defer wg.Done()
var err error
res, err := super.Rdbw.HKeys(fmt.Sprintf("icinga:checksum:%s", objectInformation.RedisKey)).Result()
res, err := super.Rdbw.HKeys(fmt.Sprintf("icinga:config:%s", objectInformation.RedisKey)).Result()
if err != nil {
super.ChErr <- err
return
@ -226,16 +228,21 @@ func InsertPrepWorker(super *supervisor.Supervisor, objectInformation *configobj
ChBack: chInsertBack,
}
for i, key := range chunk.Keys {
if chunk.Configs[i] == nil || chunk.Checksums[i] == nil {
if chunk.Configs[i] == nil {
continue
}
pkg := jsondecoder.JsonDecodePackage{
Id: key,
ChecksumsRaw: chunk.Checksums[i].(string),
ConfigRaw: chunk.Configs[i].(string),
ConfigRaw: chunk.Configs[i].(string),
Factory: objectInformation.Factory,
ObjectType: objectInformation.ObjectType,
}
if chunk.Checksums[i] != nil {
pkg.ChecksumsRaw = chunk.Checksums[i].(string)
}
pkgs.Packages = append(pkgs.Packages, pkg)
}

View file

@ -173,6 +173,7 @@ func init() {
ObjectType: "host",
RedisKey: "host",
Factory: NewHost,
HasChecksum: true,
BulkInsertStmt: connection.NewBulkInsertStmt("host", Fields),
BulkDeleteStmt: connection.NewBulkDeleteStmt("host"),
BulkUpdateStmt: connection.NewBulkUpdateStmt("host", Fields),