Skip to content

Commit afc5809

Browse files
authored
drop mst perf & remove panic cmds & adjust lock sequence (openGemini#574)
Signed-off-by: lihanxue <[email protected]>
1 parent d5dd147 commit afc5809

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

app/ts-meta/meta/store.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -761,8 +761,9 @@ func (s *Store) serveSnapshotV2() {
761761
}
762762
}
763763

764-
func (s *Store) deleteMeasurement(db string, rp *meta.RetentionPolicyInfo, mst string) error {
765-
s.cacheMu.RLock()
764+
func (s *Store) getNodeShardsMap(db string, rp *meta.RetentionPolicyInfo, mst string) map[uint64][]uint64 {
765+
s.mu.RLock()
766+
defer s.mu.RUnlock()
766767
nodeShardsMap := make(map[uint64][]uint64)
767768
for sgIdx := range rp.ShardGroups {
768769
for shIdx := range rp.ShardGroups[sgIdx].Shards {
@@ -780,6 +781,12 @@ func (s *Store) deleteMeasurement(db string, rp *meta.RetentionPolicyInfo, mst s
780781
}
781782
}
782783
}
784+
return nodeShardsMap
785+
}
786+
787+
func (s *Store) deleteMeasurement(db string, rp *meta.RetentionPolicyInfo, mst string) error {
788+
s.cacheMu.RLock()
789+
nodeShardsMap := s.getNodeShardsMap(db, rp, mst)
783790

784791
errChan := make(chan error)
785792
n := 0
@@ -907,7 +914,7 @@ func (s *Store) checkDelete(deleteType int) {
907914
n++
908915
go func(db string, rp *meta.RetentionPolicyInfo, mst string) {
909916
errChan <- s.deleteMeasurement(db, rp, mst)
910-
}(db.Name, rp.Clone(), rp.Measurements[mstIdx].Name)
917+
}(db.Name, rp, rp.Measurements[mstIdx].Name)
911918
}
912919
}
913920
})

app/ts-meta/meta/store_fsm.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,8 @@ func (fsm *storeFSM) executeCmd(cmd proto2.Command) interface{} {
417417
if handler, ok := applyFunc[cmd.GetType()]; ok {
418418
return handler(fsm, &cmd)
419419
}
420-
panic(fmt.Errorf("cannot apply command: %x", cmd.GetType()))
420+
fsm.Logger.Error("cannot apply command: %x", zap.Int32("typ", int32(cmd.GetType())))
421+
return nil
421422
}
422423

423424
func (fsm *storeFSM) applyReShardingCommand(cmd *proto2.Command) interface{} {

app/ts-meta/meta/store_internal_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package meta
1818

1919
import (
2020
"fmt"
21+
"math"
2122
"sync"
2223
"testing"
2324
"time"
@@ -812,3 +813,16 @@ func Test_applyInsertFiles(t *testing.T) {
812813
resErr = applyInsertFilesCommand(fsm, cmd)
813814
require.EqualError(t, resErr.(error), "UNIQUE constraint failed: files.mst_id, files.shard_id, files.sequence, files.level, files.extent, files.merge")
814815
}
816+
817+
func Test_executeCmdErr(t *testing.T) {
818+
s := &Store{Logger: logger.NewLogger(errno.ModuleUnknown).SetZapLogger(zap.NewNop())}
819+
fsm := (*storeFSM)(s)
820+
typ := proto2.Command_InsertFilesCommand
821+
cmd := &proto2.Command{Type: &typ}
822+
value := &proto2.InsertFilesCommand{}
823+
err := proto.SetExtension(cmd, proto2.E_InsertFilesCommand_Command, value)
824+
require.NoError(t, err)
825+
var errType proto2.Command_Type = math.MaxInt32
826+
cmd.Type = &errType
827+
fsm.executeCmd(*cmd)
828+
}

0 commit comments

Comments
 (0)