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

GetRecords improvement #471

Merged
merged 2 commits into from
Dec 11, 2020
Merged
Show file tree
Hide file tree
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
23 changes: 17 additions & 6 deletions net/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -691,11 +691,9 @@ func (n *net) AddRecord(
return lstore.ErrLogNotFound
}

knownRecord, err := n.bstore.Has(rec.Cid())
if err != nil {
if knownRecord, err := n.isKnown(rec.Cid()); err != nil {
return err
}
if knownRecord {
} else if knownRecord {
return nil
}

Expand Down Expand Up @@ -931,7 +929,7 @@ func (n *net) loadUnknownRecords(
last core.Record,
) ([]core.ThreadRecord, cid.Cid, error) {
// check if last record was already loaded and processed
if exist, err := n.bstore.Has(last.Cid()); err != nil {
if exist, err := n.isKnown(last.Cid()); err != nil {
return nil, cid.Undef, err
} else if exist || !last.Cid().Defined() {
return nil, cid.Undef, nil
Expand Down Expand Up @@ -1034,6 +1032,10 @@ func (n *net) loadUnknownRecords(
return tRecords, head, nil
}

func (n *net) isKnown(rec cid.Cid) (bool, error) {
return n.bstore.Has(rec)
}

func (n *net) currentHead(tid thread.ID, lid peer.ID) (cid.Cid, error) {
var head cid.Cid
heads, err := n.store.Heads(tid, lid)
Expand Down Expand Up @@ -1104,6 +1106,15 @@ func (n *net) getLocalRecords(
offset cid.Cid,
limit int,
) ([]core.Record, error) {
if offset != cid.Undef {
// ensure that we know about requested offset
if knownRecord, err := n.isKnown(offset); err != nil {
return nil, err
} else if !knownRecord {
return nil, nil
}
}

lg, err := n.store.GetLog(id, lid)
if err != nil {
return nil, err
Expand Down Expand Up @@ -1416,7 +1427,7 @@ func (n *net) threadOffsets(tid thread.ID) (map[peer.ID]cid.Cid, error) {
for _, lg := range info.Logs {
var has bool
if lg.Head.Defined() {
has, err = n.bstore.Has(lg.Head)
has, err = n.isKnown(lg.Head)
if err != nil {
return nil, err
}
Expand Down
6 changes: 2 additions & 4 deletions net/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,9 @@ func (s *server) PushRecord(ctx context.Context, req *pb.PushRecordRequest) (*pb
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
knownRecord, err := s.net.bstore.Has(rec.Cid())
if err != nil {
if knownRecord, err := s.net.isKnown(rec.Cid()); err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
if knownRecord {
} else if knownRecord {
return &pb.PushRecordReply{}, nil
}

Expand Down