diff --git a/internal/api/syncapi/syncapi_test.go b/internal/api/syncapi/syncapi_test.go index 8bd8d2e1..32f7a493 100644 --- a/internal/api/syncapi/syncapi_test.go +++ b/internal/api/syncapi/syncapi_test.go @@ -26,6 +26,7 @@ import ( "github.com/garethgeorge/backrest/internal/testutil" "github.com/google/go-cmp/cmp" "github.com/ncruces/go-sqlite3/vfs/memdb" + "go.uber.org/zap" "golang.org/x/net/http2" "golang.org/x/net/http2/h2c" "google.golang.org/protobuf/encoding/protojson" @@ -172,6 +173,7 @@ func TestSyncConfigChange(t *testing.T) { peerHostConfig := &v1.Config{ Version: migrations.CurrentVersion, + Modno: 0, Instance: defaultHostID, Repos: []*v1.Repo{ { @@ -247,13 +249,16 @@ func TestSyncConfigChange(t *testing.T) { }, }) hostConfigChanged := proto.Clone(peerHostConfig).(*v1.Config) - hostConfigChanged.Repos[0].Env = []string{"SOME_ENV=VALUE"} + hostConfigChanged.Repos[1].Env = []string{"SOME_ENV=VALUE"} + hostConfigChanged.Modno += 1 + zap.S().Infof("updating host config to: %s", protojson.Format(hostConfigChanged)) peerHost.configMgr.Update(hostConfigChanged) tryConnect(t, ctx, peerClient, peerClientConfig.Multihost.KnownHosts[0]) tryExpectConfigFromHost(t, ctx, peerClient, peerClientConfig.Multihost.KnownHosts[0], &v1sync.RemoteConfig{ Version: migrations.CurrentVersion, + Modno: 1, Repos: []*v1.Repo{ { Id: defaultRepoID, diff --git a/internal/api/syncapi/syncmanager.go b/internal/api/syncapi/syncmanager.go index c373596a..a6b6f411 100644 --- a/internal/api/syncapi/syncmanager.go +++ b/internal/api/syncapi/syncmanager.go @@ -85,16 +85,20 @@ func (m *SyncManager) RunSync(ctx context.Context) { configWatchCh := m.configMgr.OnChange.Subscribe() defer m.configMgr.OnChange.Unsubscribe(configWatchCh) + defer func() { + zap.L().Info("syncmanager exited") + }() runSyncWithNewConfig := func() { m.mu.Lock() defer m.mu.Unlock() - // TODO: rather than cancel the top level context, something clever e.g. diffing the set of peers could be done here. if cancelLastSync != nil { cancelLastSync() zap.L().Info("syncmanager applying new config, waiting for existing sync goroutines to exit") syncWg.Wait() + } else { + zap.L().Info("syncmanager applying new config, starting sync goroutines") } syncCtx, cancel := context.WithCancel(ctx) cancelLastSync = cancel @@ -129,7 +133,7 @@ func (m *SyncManager) RunSync(ctx context.Context) { return } - zap.S().Infof("syncmanager applying new config, starting sync with identity %v, spawning goroutines for %d known peers", + zap.S().Infof("sync using identity %v, spawning goroutines for %d known peers", config.Multihost.GetIdentity().GetKeyid(), len(config.Multihost.GetKnownHosts())) for _, knownHostPeer := range config.Multihost.KnownHosts { if knownHostPeer.InstanceId == "" {