@@ -2,18 +2,16 @@ package processorephemeral
22
33import (
44 "context"
5- "fmt"
65 "sync"
76 "time"
87
98 "github.com/google/uuid"
109 "go.uber.org/fx"
11- "go.uber.org/yarpc"
1210 "go.uber.org/zap"
1311
1412 sharddistributorv1 "github.com/uber/cadence/.gen/proto/sharddistributor/v1"
1513 "github.com/uber/cadence/common/clock"
16- "github.com/uber/cadence/service/sharddistributor/client/spectatorclient "
14+ "github.com/uber/cadence/service/sharddistributor/canary/pinger "
1715)
1816
1917//go:generate mockgen -package $GOPACKAGE -destination canary_client_mock_test.go github.com/uber/cadence/.gen/proto/sharddistributor/v1 ShardDistributorExecutorCanaryAPIYARPCClient
@@ -26,7 +24,6 @@ const (
2624type ShardCreator struct {
2725 logger * zap.Logger
2826 timeSource clock.TimeSource
29- spectators * spectatorclient.Spectators
3027 canaryClient sharddistributorv1.ShardDistributorExecutorCanaryAPIYARPCClient
3128 namespaces []string
3229
@@ -40,7 +37,6 @@ type ShardCreatorParams struct {
4037
4138 Logger * zap.Logger
4239 TimeSource clock.TimeSource
43- Spectators * spectatorclient.Spectators
4440 CanaryClient sharddistributorv1.ShardDistributorExecutorCanaryAPIYARPCClient
4541}
4642
@@ -49,7 +45,6 @@ func NewShardCreator(params ShardCreatorParams, namespaces []string) *ShardCreat
4945 return & ShardCreator {
5046 logger : params .Logger ,
5147 timeSource : params .TimeSource ,
52- spectators : params .Spectators ,
5348 canaryClient : params .CanaryClient ,
5449 stopChan : make (chan struct {}),
5550 goRoutineWg : sync.WaitGroup {},
@@ -100,83 +95,8 @@ func (s *ShardCreator) process(ctx context.Context) {
10095 shardKey := uuid .New ().String ()
10196 s .logger .Info ("Creating shard" , zap .String ("shardKey" , shardKey ), zap .String ("namespace" , namespace ))
10297
103- // Get spectator for this namespace
104- spectator , err := s .spectators .ForNamespace (namespace )
105- if err != nil {
106- s .logger .Warn ("No spectator for namespace, skipping shard creation" ,
107- zap .String ("namespace" , namespace ),
108- zap .String ("shardKey" , shardKey ),
109- zap .Error (err ))
110- continue
111- }
112-
113- // Create shard and get owner via spectator (spectator will create if not exists)
114- owner , err := spectator .GetShardOwner (ctx , shardKey )
115- if err != nil {
116- s .logger .Error ("Failed to get/create shard owner" ,
117- zap .Error (err ),
118- zap .String ("namespace" , namespace ),
119- zap .String ("shardKey" , shardKey ))
120- continue
121- }
122-
123- s .logger .Info ("Shard created, got owner from spectator" ,
124- zap .String ("shardKey" , shardKey ),
125- zap .String ("namespace" , namespace ),
126- zap .String ("executor_id" , owner .ExecutorID ))
127-
128- // Now ping the owner to verify
129- if err := s .pingShardOwner (ctx , owner , namespace , shardKey ); err != nil {
130- s .logger .Error ("Failed to ping shard owner" ,
131- zap .Error (err ),
132- zap .String ("namespace" , namespace ),
133- zap .String ("shardKey" , shardKey ))
134- }
98+ pinger .PingShard (ctx , s .canaryClient , s .logger , namespace , shardKey )
13599 }
136100 }
137101 }
138102}
139-
140- func (s * ShardCreator ) pingShardOwner (ctx context.Context , owner * spectatorclient.ShardOwner , namespace , shardKey string ) error {
141- s .logger .Debug ("Pinging shard owner after creation" ,
142- zap .String ("namespace" , namespace ),
143- zap .String ("shardKey" , shardKey ),
144- zap .String ("expected_executor_id" , owner .ExecutorID ))
145-
146- // Create ping request
147- request := & sharddistributorv1.PingRequest {
148- ShardKey : shardKey ,
149- Namespace : namespace ,
150- }
151-
152- // SIMPLE CANARY CODE: Just pass the shard key and namespace!
153- // The SpectatorPeerChooser library code handles routing to the right executor
154- response , err := s .canaryClient .Ping (ctx , request , yarpc .WithShardKey (shardKey ), yarpc .WithHeader (spectatorclient .NamespaceHeader , namespace ))
155- if err != nil {
156- return fmt .Errorf ("ping rpc failed: %w" , err )
157- }
158-
159- // Verify response matches the owner we got from spectator
160- if response .GetExecutorId () != owner .ExecutorID {
161- s .logger .Warn ("Executor ID mismatch" ,
162- zap .String ("namespace" , namespace ),
163- zap .String ("shardKey" , shardKey ),
164- zap .String ("expected" , owner .ExecutorID ),
165- zap .String ("actual" , response .GetExecutorId ()))
166- }
167-
168- if ! response .GetOwnsShard () {
169- s .logger .Warn ("Executor does not own shard" ,
170- zap .String ("namespace" , namespace ),
171- zap .String ("shardKey" , shardKey ),
172- zap .String ("executor_id" , response .GetExecutorId ()))
173- return fmt .Errorf ("executor %s does not own shard %s" , response .GetExecutorId (), shardKey )
174- }
175-
176- s .logger .Info ("Successfully verified shard owner after creation" ,
177- zap .String ("namespace" , namespace ),
178- zap .String ("shardKey" , shardKey ),
179- zap .String ("executor_id" , response .GetExecutorId ()))
180-
181- return nil
182- }
0 commit comments