This commit is contained in:
DeniskaRediska committed 2020-06-08 20:44:54 +03:00
1 parent 44715591ef
commit 3a8469c5a9
4 files changed
+11 -18

No files matched your search

+1 -1
View File
@@ -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, state)
VersionConfig.updateDB(versionConfig, removedVersionId)
}
}
+1 -4
View File
@@ -54,10 +54,7 @@ func (versionConfigService) updateState(version int32, id string, data entity.Co
return cfg, removedVersionId
}
func (versionConfigService) updateDB(cfg entity.VersionConfig, removedId string, state state.WritableState) {
if !state.VersionConfig().CheckCount() {
return
}
func (versionConfigService) updateDB(cfg entity.VersionConfig, removedId string) {
_, err := model.VersionStoreRep.Upsert(cfg)
if err != nil {
log.WithMetadata(map[string]interface{}{
+6 -11
View File
@@ -6,6 +6,8 @@ import (
"isp-config-service/entity"
)
const defaultVersionCount = 5
type WriteableVersionConfigStore interface {
ReadonlyVersionConfigStore
Update(config entity.VersionConfig) (removedId string)
@@ -14,22 +16,21 @@ type WriteableVersionConfigStore interface {
type ReadonlyVersionConfigStore interface {
GetByConfigId(id string) []entity.VersionConfig
CheckCount() bool
}
type VersionConfigStore struct {
VersionByConfigId map[string][]entity.VersionConfig
count int
}
func (s *VersionConfigStore) Update(req entity.VersionConfig) string {
if !(s.count > 0) {
return req.Id
count := config.Get().(*conf.Configuration).VersionConfigCount
if count <= 0 {
count = defaultVersionCount
}
var removedId string
store, found := s.VersionByConfigId[req.ConfigId]
if found {
if len(store) >= s.count {
if len(store) >= count {
removedId = store[0].Id
store = append(store[1:], req)
} else {
@@ -66,14 +67,8 @@ func (s VersionConfigStore) GetByConfigId(id string) []entity.VersionConfig {
return []entity.VersionConfig{}
}
func (s *VersionConfigStore) CheckCount() bool {
return s.count > 0
}
func NewVersionConfigStore() *VersionConfigStore {
count := config.Get().(*conf.Configuration).VersionConfigCount
return &VersionConfigStore{
count: count,
VersionByConfigId: make(map[string][]entity.VersionConfig),
}
}
+3 -2
View File
@@ -2,11 +2,12 @@ package store
import (
"bytes"
"testing"
"time"
"github.com/stretchr/testify/assert"
"isp-config-service/entity"
state2 "isp-config-service/store/state"
"testing"
"time"
)
type mockSnapshotSink struct {