From 702fdfe93beff46a0c44e1fbd09b7d9b0af1f5f4 Mon Sep 17 00:00:00 2001 From: Noah Hilverling Date: Tue, 16 Jul 2019 15:08:59 +0200 Subject: [PATCH] Allow objects without checksum --- configobject/configobject.go | 1 + configobject/configsync/configsync.go | 49 +++++++++++++++------------ configobject/objecttypes/host/host.go | 1 + 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/configobject/configobject.go b/configobject/configobject.go index dd740280..cd69dd71 100644 --- a/configobject/configobject.go +++ b/configobject/configobject.go @@ -7,6 +7,7 @@ import ( type ObjectInformation struct { ObjectType string RedisKey string + HasChecksum bool Factory connection.RowFactory BulkInsertStmt *connection.BulkInsertStmt BulkDeleteStmt *connection.BulkDeleteStmt diff --git a/configobject/configsync/configsync.go b/configobject/configsync/configsync.go index d8071a38..595db640 100644 --- a/configobject/configsync/configsync.go +++ b/configobject/configsync/configsync.go @@ -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) } diff --git a/configobject/objecttypes/host/host.go b/configobject/objecttypes/host/host.go index 328ded8f..e4901738 100644 --- a/configobject/objecttypes/host/host.go +++ b/configobject/objecttypes/host/host.go @@ -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),