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

Total records limit in the GetRecords reply #481

Merged
merged 1 commit into from
Feb 9, 2021
Merged
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
28 changes: 23 additions & 5 deletions net/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,24 @@ func (s *server) GetRecords(ctx context.Context, req *pb.GetRecordsRequest) (*pb
}
pbrecs.Logs = make([]*pb.GetRecordsReply_LogEntry, len(info.Logs))

var recordLimit = MaxPullLimit
for i, lg := range info.Logs {
var offset cid.Cid
var limit int
var pblg *pb.Log
var (
offset cid.Cid
limit int
pblg *pb.Log

// correct records-per-log limit
logsRemain = len(info.Logs) - i
logRecordLimit = recordLimit / logsRemain
)

if opts, ok := reqd[lg.ID]; ok {
offset = opts.Offset.Cid
limit = int(opts.Limit)
limit = minInt(int(opts.Limit), logRecordLimit)
} else {
offset = cid.Undef
limit = MaxPullLimit
limit = logRecordLimit
pblg = logToProto(lg)
}
recs, err := s.net.getLocalRecords(ctx, req.Body.ThreadID.ID, lg.ID, offset, limit)
Expand All @@ -202,6 +210,9 @@ func (s *server) GetRecords(ctx context.Context, req *pb.GetRecordsRequest) (*pb
}
pbrecs.Logs[i] = entry

// update remaining records limit
recordLimit -= len(recs)

log.Debugf("sending %d records in log %s to %s", len(recs), lg.ID, pid)
}

Expand Down Expand Up @@ -325,3 +336,10 @@ func addrsFromProto(pa []pb.ProtoAddr) []ma.Multiaddr {
}
return mas
}

func minInt(x, y int) int {
if x < y {
return x
}
return y
}