@@ -57,13 +57,15 @@ func (ps *pubSub) close() {
5757}
5858
5959func (ps * pubSub ) handlePublisher (ctx context.Context , stream apiv2.Dgraph_StreamExtSnapshotServer ) error {
60+ count := 0
6061 for {
6162 select {
6263 case <- ctx .Done ():
6364 glog .Info ("[import] Context cancelled, stopping receive goroutine." )
6465 return ctx .Err ()
6566 default :
6667 msg , err := stream .Recv ()
68+
6769 if err != nil {
6870 if ! errors .Is (err , io .EOF ) {
6971 glog .Errorf ("[import] Error receiving from in stream: %v" , err )
@@ -72,6 +74,11 @@ func (ps *pubSub) handlePublisher(ctx context.Context, stream apiv2.Dgraph_Strea
7274 return nil
7375 }
7476 ps .publish (msg )
77+ glog .Info ("send a package ----------------------" , count )
78+ count ++
79+ if err := stream .Send (& apiv2.StreamExtSnapshotResponse {Finish : false }); err != nil {
80+ return err
81+ }
7582 }
7683 }
7784
@@ -114,7 +121,7 @@ Loop:
114121 return nil
115122}
116123
117- func (ps * pubSub ) runLocalSubscriber (ctx context.Context ) error {
124+ func (ps * pubSub ) runLocalSubscriber (ctx context.Context , stream pb. Worker_StreamExtSnapshotServer ) error {
118125 buffer := ps .subscribe ()
119126 size := 0
120127 glog .Infof ("[import:flush] flushing external snapshot in badger db" )
@@ -150,8 +157,16 @@ Loop:
150157 if err := sw .Flush (); err != nil {
151158 return err
152159 }
160+
153161 glog .Infof ("[import:flush] successfully flushed data in badger db" )
154- return postStreamProcessing (ctx )
162+ if err := postStreamProcessing (ctx ); err != nil {
163+ return err
164+ }
165+ glog .Info ("stream is closed" )
166+ if err := stream .Send (& apiv2.StreamExtSnapshotResponse {Finish : true }); err != nil {
167+ glog .Errorf ("[import] failed to send close on in: %v" , err )
168+ }
169+ return nil
155170}
156171
157172func ProposeDrain (ctx context.Context , drainMode * apiv2.UpdateExtSnapshotStreamingStateRequest ) ([]uint32 , error ) {
@@ -237,12 +252,19 @@ func pipeTwoStream(in apiv2.Dgraph_StreamExtSnapshotServer, out pb.Worker_Stream
237252 glog .Infof ("[import] [forward from group-%v to group-%v] forwarding stream" , currentGroup , groupId )
238253
239254 defer func () {
240- if err := in .Send (& apiv2.StreamExtSnapshotResponse {}); err != nil {
255+ if err := in .Send (& apiv2.StreamExtSnapshotResponse {Finish : true }); err != nil {
241256 glog .Errorf ("[import] [forward from group %v to group %v] failed to send close on in" +
242257 " stream for group [%v]: %v" , currentGroup , groupId , groupId , err )
243258 }
244259 }()
245- defer out .CloseSend ()
260+
261+ defer func () {
262+ // Wait for ACK from the out stream
263+ if err := out .CloseSend (); err != nil {
264+ glog .Errorf ("[import] [forward from group %v to group %v] failed to receive ACK from group [%v]: %v" ,
265+ currentGroup , groupId , groupId , err )
266+ }
267+ }()
246268
247269 ps := & pubSub {}
248270 eg , egCtx := errgroup .WithContext (in .Context ())
@@ -279,7 +301,7 @@ func (w *grpcWorker) UpdateExtSnapshotStreamingState(ctx context.Context,
279301 return nil , errors .New ("UpdateExtSnapshotStreamingStateRequest cannot have both Start and Finish set to true" )
280302 }
281303
282- glog .Infof ("[import] Applying import mode proposal: %v" , req )
304+ glog .Infof ("[import] Applying import mode proposal: %v" , req . Finish , req . DropData , req . Start )
283305 err := groups ().Node .proposeAndWait (ctx , & pb.Proposal {ExtSnapshotState : req })
284306
285307 return & pb.Status {}, err
@@ -363,9 +385,10 @@ func streamInGroup(stream apiv2.Dgraph_StreamExtSnapshotServer, forward bool) er
363385 successfulNodes := make (map [string ]bool )
364386
365387 for _ , member := range groups ().state .Groups [node .gid ].Members {
388+ glog .Info ("memers are======================>" , groups ().state .Groups [node .gid ].Members )
366389 if member .Addr == node .MyAddr {
367390 eg .Go (func () error {
368- if err := ps .runLocalSubscriber (errGCtx ); err != nil {
391+ if err := ps .runLocalSubscriber (errGCtx , stream ); err != nil {
369392 glog .Errorf ("[import:flush] failed to run local subscriber: %v" , err )
370393 updateNodeStatus (& ps .RWMutex , successfulNodes , member .Addr , false )
371394 return err
@@ -379,6 +402,7 @@ func streamInGroup(stream apiv2.Dgraph_StreamExtSnapshotServer, forward bool) er
379402 // We are not going to return any error from here because we care about the majority of nodes.
380403 // If the majority of nodes are able to receive the data, the remaining ones can catch up later.
381404 if forward {
405+ glog .Infof ("[import] Streaming external snapshot to [%v] from [%v] forward [%v]" , member .Addr , node .MyAddr )
382406 eg .Go (func () error {
383407 glog .Infof (`[import:forward] streaming external snapshot to [%v] from [%v]` , member .Addr , node .MyAddr )
384408 if member .AmDead {
@@ -398,7 +422,11 @@ func streamInGroup(stream apiv2.Dgraph_StreamExtSnapshotServer, forward bool) er
398422 glog .Errorf ("failed to establish stream with peer %v: %v" , member .Addr , err )
399423 return nil
400424 }
401- defer peerStream .CloseSend ()
425+ defer func () {
426+ if err := peerStream .CloseSend (); err != nil {
427+ glog .Errorf ("[import:forward] failed to receive ACK from [%v]: %v" , member .Addr , err )
428+ }
429+ }()
402430
403431 forwardReq := & apiv2.StreamExtSnapshotRequest {Forward : false }
404432 if err := peerStream .Send (forwardReq ); err != nil {
@@ -422,18 +450,20 @@ func streamInGroup(stream apiv2.Dgraph_StreamExtSnapshotServer, forward bool) er
422450
423451 eg .Go (func () error {
424452 defer ps .close ()
425- defer func () {
426- if err := stream .Send (& apiv2.StreamExtSnapshotResponse {}); err != nil {
427- glog .Errorf ("[import] failed to send close on in: %v" , err )
428- }
429- }()
453+ // defer func() {
454+
455+ // }()
456+ glog .Info ("stream is started" )
430457 if err := ps .handlePublisher (errGCtx , stream ); err != nil {
431458 return err
432459 }
433460
461+ glog .Info ("sent false ---------------------------->" )
434462 return nil
435463 })
436464
465+ glog .Info ("here---------------------" )
466+
437467 if err := eg .Wait (); err != nil {
438468 return err
439469 }
@@ -444,7 +474,7 @@ func streamInGroup(stream apiv2.Dgraph_StreamExtSnapshotServer, forward bool) er
444474 glog .Error ("[import] Majority of nodes failed to receive data." )
445475 return errors .New ("failed to send data to majority of the nodes" )
446476 }
447-
477+ glog . Info ( "done---------------------" )
448478 return nil
449479}
450480
0 commit comments