Skip to content

Commit

Permalink
Fixed PageSize management in IndexRange and DomainRange functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Sixtysixter committed Nov 6, 2024
1 parent 2b248ca commit 05135d2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
6 changes: 3 additions & 3 deletions erigon-lib/kv/remotedb/kv_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ func (tx *tx) DomainGet(name kv.Domain, k, k2 []byte) (v []byte, step uint64, er

func (tx *tx) DomainRange(name kv.Domain, fromKey, toKey []byte, ts uint64, asc order.By, limit int) (it stream.KV, err error) {
return stream.PaginateKV(func(pageToken string) (keys, vals [][]byte, nextPageToken string, err error) {
reply, err := tx.db.remoteKV.DomainRange(tx.ctx, &remote.DomainRangeReq{TxId: tx.id, Table: name.String(), FromKey: fromKey, ToKey: toKey, Ts: ts, OrderAscend: bool(asc), Limit: int64(limit)})
reply, err := tx.db.remoteKV.DomainRange(tx.ctx, &remote.DomainRangeReq{TxId: tx.id, Table: name.String(), FromKey: fromKey, ToKey: toKey, Ts: ts, OrderAscend: bool(asc), Limit: int64(limit), PageToken: pageToken})
if err != nil {
return nil, nil, "", err
}
Expand All @@ -659,7 +659,7 @@ func (tx *tx) HistorySeek(name kv.History, k []byte, ts uint64) (v []byte, ok bo
}
func (tx *tx) HistoryRange(name kv.History, fromTs, toTs int, asc order.By, limit int) (it stream.KV, err error) {
return stream.PaginateKV(func(pageToken string) (keys, vals [][]byte, nextPageToken string, err error) {
reply, err := tx.db.remoteKV.HistoryRange(tx.ctx, &remote.HistoryRangeReq{TxId: tx.id, Table: string(name), FromTs: int64(fromTs), ToTs: int64(toTs), OrderAscend: bool(asc), Limit: int64(limit)})
reply, err := tx.db.remoteKV.HistoryRange(tx.ctx, &remote.HistoryRangeReq{TxId: tx.id, Table: string(name), FromTs: int64(fromTs), ToTs: int64(toTs), OrderAscend: bool(asc), Limit: int64(limit), PageToken: pageToken})
if err != nil {
return nil, nil, "", err
}
Expand All @@ -669,7 +669,7 @@ func (tx *tx) HistoryRange(name kv.History, fromTs, toTs int, asc order.By, limi

func (tx *tx) IndexRange(name kv.InvertedIdx, k []byte, fromTs, toTs int, asc order.By, limit int) (timestamps stream.U64, err error) {
return stream.PaginateU64(func(pageToken string) (arr []uint64, nextPageToken string, err error) {
req := &remote.IndexRangeReq{TxId: tx.id, Table: string(name), K: k, FromTs: int64(fromTs), ToTs: int64(toTs), OrderAscend: bool(asc), Limit: int64(limit)}
req := &remote.IndexRangeReq{TxId: tx.id, Table: string(name), K: k, FromTs: int64(fromTs), ToTs: int64(toTs), OrderAscend: bool(asc), Limit: int64(limit), PageToken: pageToken}
reply, err := tx.db.remoteKV.IndexRange(tx.ctx, req)
if err != nil {
return nil, "", err
Expand Down
32 changes: 14 additions & 18 deletions erigon-lib/kv/remotedbserver/remotedbserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,15 +605,13 @@ func (s *KvServer) IndexRange(_ context.Context, req *remote.IndexRangeReq) (*re
}
reply.Timestamps = append(reply.Timestamps, v)
limit--
}
if len(reply.Timestamps) == int(req.PageSize) && it.HasNext() {
next, err := it.Next()
if err != nil {
return err
}
reply.NextPageToken, err = marshalPagination(&remote.IndexPagination{NextTimeStamp: int64(next), Limit: int64(limit)})
if err != nil {
return err

if len(reply.Timestamps) == int(req.PageSize) && it.HasNext() {
reply.NextPageToken, err = marshalPagination(&remote.IndexPagination{NextTimeStamp: int64(v), Limit: int64(limit)})
if err != nil {
return err
}
break
}
}
return nil
Expand Down Expand Up @@ -691,15 +689,13 @@ func (s *KvServer) DomainRange(_ context.Context, req *remote.DomainRangeReq) (*
reply.Keys = append(reply.Keys, key)
reply.Values = append(reply.Values, value)
limit--
}
if len(reply.Keys) == int(req.PageSize) && it.HasNext() {
nextK, _, err := it.Next()
if err != nil {
return err
}
reply.NextPageToken, err = marshalPagination(&remote.PairsPagination{NextKey: nextK, Limit: int64(limit)})
if err != nil {
return err

if len(reply.Keys) == int(req.PageSize) && it.HasNext() {
reply.NextPageToken, err = marshalPagination(&remote.PairsPagination{NextKey: k, Limit: int64(limit)})
if err != nil {
return err
}
break
}
}
return nil
Expand Down

0 comments on commit 05135d2

Please sign in to comment.