[#0] tree: Split GetOpLog stream
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
45dd5a692f
commit
134e5324d7
1 changed files with 45 additions and 26 deletions
|
@ -219,19 +219,26 @@ func (s *Service) startStream(ctx context.Context, cid cid.ID, treeID string,
|
||||||
|
|
||||||
rawCID := make([]byte, sha256.Size)
|
rawCID := make([]byte, sha256.Size)
|
||||||
cid.Encode(rawCID)
|
cid.Encode(rawCID)
|
||||||
|
from := height
|
||||||
|
const batchSize = 10_000
|
||||||
|
|
||||||
|
for {
|
||||||
|
count := 0
|
||||||
req := &GetOpLogRequest{
|
req := &GetOpLogRequest{
|
||||||
Body: &GetOpLogRequest_Body{
|
Body: &GetOpLogRequest_Body{
|
||||||
ContainerId: rawCID,
|
ContainerId: rawCID,
|
||||||
TreeId: treeID,
|
TreeId: treeID,
|
||||||
Height: height,
|
Height: from,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if err := SignMessage(req, s.key); err != nil {
|
if err := SignMessage(req, s.key); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := treeClient.GetOpLog(ctx, req)
|
streamCtx, cancel := context.WithCancel(ctx)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
c, err := treeClient.GetOpLog(streamCtx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("can't initialize client: %w", err)
|
return fmt.Errorf("can't initialize client: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -245,12 +252,24 @@ func (s *Service) startStream(ctx context.Context, cid cid.ID, treeID string,
|
||||||
if err := m.Meta.FromBytes(lm.GetMeta()); err != nil {
|
if err := m.Meta.FromBytes(lm.GetMeta()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
from = m.Time
|
||||||
opsCh <- m
|
opsCh <- m
|
||||||
|
count++
|
||||||
|
if count == batchSize {
|
||||||
|
break // c.Recv()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
// count == batchSize
|
||||||
|
// close current stream and start new one
|
||||||
|
cancel()
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if errors.Is(err, io.EOF) {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
if !errors.Is(err, io.EOF) {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// synchronizeTree synchronizes operations getting them from different nodes.
|
// synchronizeTree synchronizes operations getting them from different nodes.
|
||||||
|
|
Loading…
Add table
Reference in a new issue