From 31a4a6f5b8cfbebc7bc84a381d4991073c65ffe6 Mon Sep 17 00:00:00 2001 From: DeniskaRediska Date: Tue, 9 Jun 2020 13:55:39 +0300 Subject: [PATCH] ref --- cluster/const.go | 5 ----- cluster/const_string.go | 17 ++++++++--------- controller/config.go | 8 +++----- service/config.go | 9 +-------- service/version.go | 10 +++------- store/apply.go | 10 ---------- store/store.go | 1 - 7 files changed, 15 insertions(+), 45 deletions(-) diff --git a/cluster/const.go b/cluster/const.go index 72c8c10..9d1c6cc 100644 --- a/cluster/const.go +++ b/cluster/const.go @@ -34,7 +34,6 @@ const ( ModuleDisconnectedCommand DeleteModulesCommand DeleteVersionConfigCommand - GetAllVersionConfigCommand ActivateConfigCommand DeleteConfigsCommand @@ -102,10 +101,6 @@ func PrepareDeleteConfigVersionCommand(id string) []byte { return prepareCommand(DeleteVersionConfigCommand, Identity{Id: id}) } -func PrepareGetAllConfigVersionCommand(id string) []byte { - return prepareCommand(GetAllVersionConfigCommand, Identity{Id: id}) -} - func prepareCommand(command Command, payload interface{}) []byte { cmd := make([]byte, 8) binary.BigEndian.PutUint64(cmd, uint64(command)) diff --git a/cluster/const_string.go b/cluster/const_string.go index 836a8cc..07169c8 100644 --- a/cluster/const_string.go +++ b/cluster/const_string.go @@ -15,18 +15,17 @@ func _() { _ = x[ModuleDisconnectedCommand-5] _ = x[DeleteModulesCommand-6] _ = x[DeleteVersionConfigCommand-7] - _ = x[GetAllVersionConfigCommand-8] - _ = x[ActivateConfigCommand-9] - _ = x[DeleteConfigsCommand-10] - _ = x[UpsertConfigCommand-11] - _ = x[DeleteCommonConfigsCommand-12] - _ = x[UpsertCommonConfigCommand-13] - _ = x[BroadcastEventCommand-14] + _ = x[ActivateConfigCommand-8] + _ = x[DeleteConfigsCommand-9] + _ = x[UpsertConfigCommand-10] + _ = x[DeleteCommonConfigsCommand-11] + _ = x[UpsertCommonConfigCommand-12] + _ = x[BroadcastEventCommand-13] } -const _Command_name = "UpdateBackendDeclarationCommandDeleteBackendDeclarationCommandUpdateConfigSchemaCommandModuleConnectedCommandModuleDisconnectedCommandDeleteModulesCommandDeleteVersionConfigCommandGetAllVersionConfigCommandActivateConfigCommandDeleteConfigsCommandUpsertConfigCommandDeleteCommonConfigsCommandUpsertCommonConfigCommandBroadcastEventCommand" +const _Command_name = "UpdateBackendDeclarationCommandDeleteBackendDeclarationCommandUpdateConfigSchemaCommandModuleConnectedCommandModuleDisconnectedCommandDeleteModulesCommandDeleteVersionConfigCommandActivateConfigCommandDeleteConfigsCommandUpsertConfigCommandDeleteCommonConfigsCommandUpsertCommonConfigCommandBroadcastEventCommand" -var _Command_index = [...]uint16{0, 31, 62, 87, 109, 134, 154, 180, 206, 227, 247, 266, 292, 317, 338} +var _Command_index = [...]uint16{0, 31, 62, 87, 109, 134, 154, 180, 201, 221, 240, 266, 291, 312} func (i Command) String() string { i -= 1 diff --git a/controller/config.go b/controller/config.go index cd60355..77ea2b7 100644 --- a/controller/config.go +++ b/controller/config.go @@ -161,11 +161,9 @@ func (c *config) DeleteConfigVersion(req domain.ConfigIdRequest) (*domain.Delete // @Router /config/get_all_version [POST] func (c *config) GetAllVersion(req domain.ConfigIdRequest) ([]entity.VersionConfig, error) { var response []entity.VersionConfig - command := cluster.PrepareGetAllConfigVersionCommand(req.Id) - err := PerformSyncApplyWithError(command, &response) - if err != nil { - return nil, err - } + c.rstore.VisitReadonlyState(func(state state.ReadonlyState) { + response = state.VersionConfig().GetByConfigId(req.Id) + }) return response, nil } diff --git a/service/config.go b/service/config.go index bd1283a..647d650 100644 --- a/service/config.go +++ b/service/config.go @@ -129,10 +129,6 @@ func (cs configService) HandleUpsertConfigCommand(upsertConfig cluster.UpsertCon } } - var ( - removedVersionId string - versionConfig entity.VersionConfig - ) if upsertConfig.Create { config = state.WritableConfigs().Create(config) } else { @@ -147,7 +143,7 @@ func (cs configService) HandleUpsertConfigCommand(upsertConfig cluster.UpsertCon config.Version = oldCfg.Version + 1 state.WritableConfigs().UpdateById(config) - versionConfig = ConfigHistory.SaveConfigVersion(upsertConfig.VersionId, oldCfg, state) + ConfigHistory.SaveConfigVersion(upsertConfig.VersionId, oldCfg, state) } if holder.ClusterClient.IsLeader() { @@ -158,9 +154,6 @@ func (cs configService) HandleUpsertConfigCommand(upsertConfig cluster.UpsertCon "config": config, }).Errorf(codes.DatabaseOperationError, "upsert config: %v", err) } - if !upsertConfig.Create { - ConfigHistory.updateDB(versionConfig, removedVersionId) - } } cs.BroadcastActiveConfigs(state, config) diff --git a/service/version.go b/service/version.go index eb4236e..d46505a 100644 --- a/service/version.go +++ b/service/version.go @@ -36,14 +36,11 @@ func (configHistoryService) HandleDeleteVersionConfigCommand(cfg cluster.Identit return cluster.NewResponse(domain.DeleteResponse{Deleted: deleted}) } -func (configHistoryService) HandleGetAllVersionConfigCommand(cfg cluster.Identity, - state state.WritableState) cluster.ResponseWithError { - resp := state.VersionConfig().GetByConfigId(cfg.Id) - return cluster.NewResponse(resp) +func (configHistoryService) GetAllVersionConfigById(id string, state state.ReadonlyState) []entity.VersionConfig { + return state.VersionConfig().GetByConfigId(id) } -func (s configHistoryService) SaveConfigVersion(id string, oldConfig entity.Config, - state state.WritableState) entity.VersionConfig { +func (s configHistoryService) SaveConfigVersion(id string, oldConfig entity.Config, state state.WritableState) { cfg := entity.VersionConfig{ Id: id, ConfigVersion: oldConfig.Version, @@ -54,7 +51,6 @@ func (s configHistoryService) SaveConfigVersion(id string, oldConfig entity.Conf if holder.ClusterClient.IsLeader() { s.updateDB(cfg, removedVersionId) } - return cfg } func (configHistoryService) updateDB(cfg entity.VersionConfig, removedId string) { diff --git a/store/apply.go b/store/apply.go index 3cc3418..3c52455 100644 --- a/store/apply.go +++ b/store/apply.go @@ -145,13 +145,3 @@ func (s *Store) applyDeleteVersionConfigCommand(data []byte) (interface{}, error response := service.ConfigHistory.HandleDeleteVersionConfigCommand(cfg, s.state) return response, nil } - -func (s *Store) applyAllVersionConfigCommand(data []byte) (interface{}, error) { - cfg := cluster.Identity{} - err := json.Unmarshal(data, &cfg) - if err != nil { - return nil, errors.WithMessage(err, "unmarshal cluster.Identity") - } - response := service.ConfigHistory.HandleGetAllVersionConfigCommand(cfg, s.state) - return response, nil -} diff --git a/store/store.go b/store/store.go index 12731f1..eab4f63 100644 --- a/store/store.go +++ b/store/store.go @@ -132,7 +132,6 @@ func NewStateStore(st *state.State) *Store { cluster.UpsertCommonConfigCommand: store.applyUpsertCommonConfigCommand, cluster.BroadcastEventCommand: store.applyBroadcastEventCommand, cluster.DeleteVersionConfigCommand: store.applyDeleteVersionConfigCommand, - cluster.GetAllVersionConfigCommand: store.applyAllVersionConfigCommand, } return store }