Skip to content

Commit

Permalink
Verify rwswitch status before update cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
dispensable committed Feb 2, 2024
1 parent c101cf9 commit e3b905f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cassandra/prefix_switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ const (
statusCr string = "br0w0cr1w0"
)

var (
allowRWStatus = map[string]bool{
statusBrw: true,
statusBrwCw: true,
statusBwCrw: true,
statusCrw: true,
statusCr: true,
}
)

type PrefixSwitcher struct {
trie *trie.Tree[rune, PrefixSwitchStatus]
defaultT PrefixSwitchStatus
Expand Down Expand Up @@ -309,6 +319,11 @@ func (s *PrefixSwitcher) LoadCfg(cfg *config.CassandraStoreCfg, cqlStore *Cassan
}

func (s *PrefixSwitcher) Upsert(cfg *config.CassandraStoreCfg, data map[string][]string, cqlStore *CassandraStore) error {
for rwStatus := range data {
if _, ok := allowRWStatus[rwStatus]; !ok {
return fmt.Errorf("%s is not a validate rwstatus", rwStatus)
}
}
dispatcherCfg := DisPatcherCfg(cfg.PrefixRWDispatcherCfg)
return dispatcherCfg.SaveToDB(data, cqlStore)
}
Expand Down

0 comments on commit e3b905f

Please sign in to comment.