small ref
This commit is contained in:
1 parent
3a8469c5a9
commit
6387947b22
4 files changed
+22
-20
No files matched your search
+2
-2
@@ -147,7 +147,7 @@ func (cs configService) HandleUpsertConfigCommand(upsertConfig cluster.UpsertCon
|
||||
config.Version = oldCfg.Version + 1
|
||||
state.WritableConfigs().UpdateById(config)
|
||||
|
||||
versionConfig, removedVersionId = VersionConfig.updateState(oldCfg.Version, oldCfg.Id, oldCfg.Data, state)
|
||||
_ = ConfigHistory.SaveConfigVersion(oldCfg, state)
|
||||
}
|
||||
|
||||
if holder.ClusterClient.IsLeader() {
|
||||
@@ -159,7 +159,7 @@ func (cs configService) HandleUpsertConfigCommand(upsertConfig cluster.UpsertCon
|
||||
}).Errorf(codes.DatabaseOperationError, "upsert config: %v", err)
|
||||
}
|
||||
if !upsertConfig.Create {
|
||||
VersionConfig.updateDB(versionConfig, removedVersionId)
|
||||
ConfigHistory.updateDB(versionConfig, removedVersionId)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+14
-12
@@ -12,12 +12,12 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
VersionConfig = versionConfigService{}
|
||||
ConfigHistory = configHistoryService{}
|
||||
)
|
||||
|
||||
type versionConfigService struct{}
|
||||
type configHistoryService struct{}
|
||||
|
||||
func (versionConfigService) HandleDeleteVersionConfigCommand(cfg cluster.Identity,
|
||||
func (configHistoryService) HandleDeleteVersionConfigCommand(cfg cluster.Identity,
|
||||
state state.WritableState) cluster.ResponseWithError {
|
||||
state.WriteableVersionConfigStore().Delete(cfg.Id)
|
||||
var (
|
||||
@@ -36,25 +36,27 @@ func (versionConfigService) HandleDeleteVersionConfigCommand(cfg cluster.Identit
|
||||
return cluster.NewResponse(domain.DeleteResponse{Deleted: deleted})
|
||||
}
|
||||
|
||||
func (versionConfigService) HandleGetAllVersionConfigCommand(cfg cluster.Identity,
|
||||
func (configHistoryService) HandleGetAllVersionConfigCommand(cfg cluster.Identity,
|
||||
state state.WritableState) cluster.ResponseWithError {
|
||||
resp := state.VersionConfig().GetByConfigId(cfg.Id)
|
||||
return cluster.NewResponse(resp)
|
||||
}
|
||||
|
||||
func (versionConfigService) updateState(version int32, id string, data entity.ConfigData,
|
||||
writableState state.WritableState) (entity.VersionConfig, string) {
|
||||
func (s configHistoryService) SaveConfigVersion(oldConfig entity.Config, writableState state.WritableState) entity.VersionConfig {
|
||||
cfg := entity.VersionConfig{
|
||||
Id: state.GenerateId(),
|
||||
ConfigVersion: version,
|
||||
ConfigId: id,
|
||||
Data: data,
|
||||
Id: state.GenerateId(), //todo all node generate own id
|
||||
ConfigVersion: oldConfig.Version,
|
||||
ConfigId: oldConfig.Id,
|
||||
Data: oldConfig.Data,
|
||||
}
|
||||
removedVersionId := writableState.WriteableVersionConfigStore().Update(cfg)
|
||||
return cfg, removedVersionId
|
||||
if holder.ClusterClient.IsLeader() {
|
||||
s.updateDB(cfg, removedVersionId)
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
|
||||
func (versionConfigService) updateDB(cfg entity.VersionConfig, removedId string) {
|
||||
func (configHistoryService) updateDB(cfg entity.VersionConfig, removedId string) {
|
||||
_, err := model.VersionStoreRep.Upsert(cfg)
|
||||
if err != nil {
|
||||
log.WithMetadata(map[string]interface{}{
|
||||
|
||||
+2
-2
@@ -142,7 +142,7 @@ func (s *Store) applyDeleteVersionConfigCommand(data []byte) (interface{}, error
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "unmarshal cluster.Identity")
|
||||
}
|
||||
response := service.VersionConfig.HandleDeleteVersionConfigCommand(cfg, s.state)
|
||||
response := service.ConfigHistory.HandleDeleteVersionConfigCommand(cfg, s.state)
|
||||
return response, nil
|
||||
}
|
||||
|
||||
@@ -152,6 +152,6 @@ func (s *Store) applyAllVersionConfigCommand(data []byte) (interface{}, error) {
|
||||
if err != nil {
|
||||
return nil, errors.WithMessage(err, "unmarshal cluster.Identity")
|
||||
}
|
||||
response := service.VersionConfig.HandleGetAllVersionConfigCommand(cfg, s.state)
|
||||
response := service.ConfigHistory.HandleGetAllVersionConfigCommand(cfg, s.state)
|
||||
return response, nil
|
||||
}
|
||||
@@ -23,14 +23,14 @@ type VersionConfigStore struct {
|
||||
}
|
||||
|
||||
func (s *VersionConfigStore) Update(req entity.VersionConfig) string {
|
||||
count := config.Get().(*conf.Configuration).VersionConfigCount
|
||||
if count <= 0 {
|
||||
count = defaultVersionCount
|
||||
limit := config.Get().(*conf.Configuration).VersionConfigCount
|
||||
if limit <= 0 {
|
||||
limit = defaultVersionCount
|
||||
}
|
||||
var removedId string
|
||||
store, found := s.VersionByConfigId[req.ConfigId]
|
||||
if found {
|
||||
if len(store) >= count {
|
||||
if len(store) >= limit {
|
||||
removedId = store[0].Id
|
||||
store = append(store[1:], req)
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user