Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the calculation of remaining bytes while sending snapshot to client. #19116

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions server/etcdserver/api/v3rpc/maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,13 @@ func (ms *maintenanceServer) Snapshot(sr *pb.SnapshotRequest, srv pb.Maintenance

sent := int64(0)
total := snap.Size()
totalByteToSend := total + int64(h.Size())
size := humanize.Bytes(uint64(total))

start := time.Now()
ms.lg.Info("sending database snapshot to client",
zap.Int64("total-bytes", total),
zap.String("size", size),
zap.Int64("total-bytes-to-send", totalByteToSend),
zap.String("database-size", size),
zap.String("storage-version", storageVersion),
)
for total-sent > 0 {
Expand All @@ -178,7 +179,7 @@ func (ms *maintenanceServer) Snapshot(sr *pb.SnapshotRequest, srv pb.Maintenance
// No, the client will still receive non-nil response
// until server closes the stream with EOF
resp := &pb.SnapshotResponse{
RemainingBytes: uint64(total - sent),
RemainingBytes: uint64(totalByteToSend - sent),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a test?

Copy link
Contributor Author

@ishan16696 ishan16696 Jan 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, Can you please tell me where should I add the unit test for this as I don't see a test file of name : maintenance_test.go ?

Blob: buf[:n],
Version: storageVersion,
}
Expand All @@ -202,8 +203,8 @@ func (ms *maintenanceServer) Snapshot(sr *pb.SnapshotRequest, srv pb.Maintenance
}

ms.lg.Info("successfully sent database snapshot to client",
zap.Int64("total-bytes", total),
zap.String("size", size),
zap.Int64("total-bytes-sent", totalByteToSend),
zap.String("database-size", size),
zap.Duration("took", time.Since(start)),
zap.String("storage-version", storageVersion),
)
Expand Down
Loading