diff --git a/cluster/events.go b/cluster/events.go index e42b42d..1c83178 100644 --- a/cluster/events.go +++ b/cluster/events.go @@ -28,9 +28,10 @@ type ActivateConfig struct { } type UpsertConfig struct { - Config entity.Config - Create bool - Unsafe bool + Config entity.Config + VersionId string + Create bool + Unsafe bool } type DeleteConfigs struct { diff --git a/controller/config.go b/controller/config.go index 2743d4b..cd60355 100644 --- a/controller/config.go +++ b/controller/config.go @@ -64,8 +64,9 @@ func (c *config) CreateUpdateConfig(config domain.CreateUpdateConfigRequest) (*d config.CreatedAt = now config.UpdatedAt = now upsertConfig := cluster.UpsertConfig{ - Config: config.Config, - Unsafe: config.Unsafe, + Config: config.Config, + Unsafe: config.Unsafe, + VersionId: state.GenerateId(), } if config.Id == "" { upsertConfig.Config.Id = state.GenerateId() diff --git a/service/config.go b/service/config.go index 6c01797..bd1283a 100644 --- a/service/config.go +++ b/service/config.go @@ -147,7 +147,7 @@ func (cs configService) HandleUpsertConfigCommand(upsertConfig cluster.UpsertCon config.Version = oldCfg.Version + 1 state.WritableConfigs().UpdateById(config) - _ = ConfigHistory.SaveConfigVersion(oldCfg, state) + versionConfig = ConfigHistory.SaveConfigVersion(upsertConfig.VersionId, oldCfg, state) } if holder.ClusterClient.IsLeader() { diff --git a/service/version.go b/service/version.go index 02cda0a..eb4236e 100644 --- a/service/version.go +++ b/service/version.go @@ -42,14 +42,15 @@ func (configHistoryService) HandleGetAllVersionConfigCommand(cfg cluster.Identit return cluster.NewResponse(resp) } -func (s configHistoryService) SaveConfigVersion(oldConfig entity.Config, writableState state.WritableState) entity.VersionConfig { +func (s configHistoryService) SaveConfigVersion(id string, oldConfig entity.Config, + state state.WritableState) entity.VersionConfig { cfg := entity.VersionConfig{ - Id: state.GenerateId(), //todo all node generate own id + Id: id, ConfigVersion: oldConfig.Version, ConfigId: oldConfig.Id, Data: oldConfig.Data, } - removedVersionId := writableState.WriteableVersionConfigStore().Update(cfg) + removedVersionId := state.WriteableVersionConfigStore().Update(cfg) if holder.ClusterClient.IsLeader() { s.updateDB(cfg, removedVersionId) } diff --git a/subs/client.go b/subs/client.go index e2fdb74..4345fb5 100644 --- a/subs/client.go +++ b/subs/client.go @@ -109,9 +109,10 @@ func (h *SocketEventHandler) handleConfigSchema(conn etp.Conn, data []byte) []by UpdatedAt: now, } upsertConfig := cluster.UpsertConfig{ - Config: config, - Create: true, - Unsafe: true, + Config: config, + Create: true, + Unsafe: true, + VersionId: state.GenerateId(), } command := cluster.PrepareUpsertConfigCommand(upsertConfig)