1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-08 05:57:03 +09:00

Fix EOF error

This commit is contained in:
mcrakhman 2024-07-30 20:57:43 +02:00
parent e70272d79f
commit 2b9a8ee4cc
No known key found for this signature in database
GPG key ID: DED12CFEF5B8396B
9 changed files with 184 additions and 110 deletions

View file

@ -54,6 +54,10 @@ func (l *loadIterator) NextBatch(maxSize int) (batch IteratorBatch, err error) {
l.lastChange = c l.lastChange = c
rawEntry := l.cache[c.Id] rawEntry := l.cache[c.Id]
if rawEntry.removed { if rawEntry.removed {
batch.Heads = slice.DiscardFromSlice(batch.Heads, func(s string) bool {
return slices.Contains(c.PreviousIds, s)
})
batch.Heads = append(batch.Heads, c.Id)
return true return true
} }
if curSize+rawEntry.size > maxSize && len(batch.Batch) != 0 { if curSize+rawEntry.size > maxSize && len(batch.Batch) != 0 {

View file

@ -45,8 +45,10 @@ func (r *responseProducer) NewResponse(batchSize int) (*Response, error) {
} }
func (r *responseProducer) EmptyResponse() *Response { func (r *responseProducer) EmptyResponse() *Response {
headsCopy := make([]string, len(r.tree.Heads()))
copy(headsCopy, r.tree.Heads())
return &Response{ return &Response{
heads: r.tree.Heads(), heads: headsCopy,
spaceId: r.spaceId, spaceId: r.spaceId,
objectId: r.objectId, objectId: r.objectId,
root: r.tree.Header(), root: r.tree.Header(),

View file

@ -154,7 +154,7 @@ func (s *syncHandler) HandleStreamRequest(ctx context.Context, rq syncdeps.Reque
return nil, err return nil, err
} }
var returnReq *objectmessages.Request var returnReq *objectmessages.Request
if slice.UnsortedEquals(curHeads, request.Heads) { if slice.UnsortedEquals(curHeads, request.Heads) || slice.ContainsSorted(request.Heads, curHeads) {
resp := producer.EmptyResponse() resp := producer.EmptyResponse()
s.tree.Unlock() s.tree.Unlock()
protoResp, err := resp.ProtoMessage() protoResp, err := resp.ProtoMessage()

View file

@ -2,17 +2,20 @@ package spacesyncproto
import ( import (
"errors" "errors"
"github.com/anyproto/any-sync/net/rpc/rpcerr" "github.com/anyproto/any-sync/net/rpc/rpcerr"
) )
var ( var (
errGroup = rpcerr.ErrGroup(ErrCodes_ErrorOffset) errGroup = rpcerr.ErrGroup(ErrCodes_ErrorOffset)
ErrUnexpected = errGroup.Register(errors.New("unexpected error"), uint64(ErrCodes_Unexpected)) ErrUnexpected = errGroup.Register(errors.New("unexpected error"), uint64(ErrCodes_Unexpected))
ErrSpaceMissing = errGroup.Register(errors.New("space is missing"), uint64(ErrCodes_SpaceMissing)) ErrSpaceMissing = errGroup.Register(errors.New("space is missing"), uint64(ErrCodes_SpaceMissing))
ErrSpaceExists = errGroup.Register(errors.New("space exists"), uint64(ErrCodes_SpaceExists)) ErrSpaceExists = errGroup.Register(errors.New("space exists"), uint64(ErrCodes_SpaceExists))
ErrSpaceNotInCache = errGroup.Register(errors.New("space not in cache"), uint64(ErrCodes_SpaceNotInCache)) ErrSpaceNotInCache = errGroup.Register(errors.New("space not in cache"), uint64(ErrCodes_SpaceNotInCache))
ErrSpaceIsDeleted = errGroup.Register(errors.New("space is deleted"), uint64(ErrCodes_SpaceIsDeleted)) ErrSpaceIsDeleted = errGroup.Register(errors.New("space is deleted"), uint64(ErrCodes_SpaceIsDeleted))
ErrPeerIsNotResponsible = errGroup.Register(errors.New("peer is not responsible for space"), uint64(ErrCodes_PeerIsNotResponsible)) ErrPeerIsNotResponsible = errGroup.Register(errors.New("peer is not responsible for space"), uint64(ErrCodes_PeerIsNotResponsible))
ErrReceiptInvalid = errGroup.Register(errors.New("space receipt is not valid"), uint64(ErrCodes_ReceiptIsInvalid)) ErrReceiptInvalid = errGroup.Register(errors.New("space receipt is not valid"), uint64(ErrCodes_ReceiptIsInvalid))
ErrDuplicateRequest = errGroup.Register(errors.New("duplicate request"), uint64(ErrCodes_DuplicateRequest))
ErrTooManyRequestsFromPeer = errGroup.Register(errors.New("too many requests from peer"), uint64(ErrCodes_TooManyRequestsFromPeer))
) )

View file

@ -12,6 +12,8 @@ enum ErrCodes {
PeerIsNotResponsible = 5; PeerIsNotResponsible = 5;
ReceiptIsInvalid = 6; ReceiptIsInvalid = 6;
InvalidPayload = 7; InvalidPayload = 7;
DuplicateRequest = 8;
TooManyRequestsFromPeer = 9;
ErrorOffset = 100; ErrorOffset = 100;
} }

View file

@ -25,15 +25,17 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
type ErrCodes int32 type ErrCodes int32
const ( const (
ErrCodes_Unexpected ErrCodes = 0 ErrCodes_Unexpected ErrCodes = 0
ErrCodes_SpaceMissing ErrCodes = 1 ErrCodes_SpaceMissing ErrCodes = 1
ErrCodes_SpaceExists ErrCodes = 2 ErrCodes_SpaceExists ErrCodes = 2
ErrCodes_SpaceNotInCache ErrCodes = 3 ErrCodes_SpaceNotInCache ErrCodes = 3
ErrCodes_SpaceIsDeleted ErrCodes = 4 ErrCodes_SpaceIsDeleted ErrCodes = 4
ErrCodes_PeerIsNotResponsible ErrCodes = 5 ErrCodes_PeerIsNotResponsible ErrCodes = 5
ErrCodes_ReceiptIsInvalid ErrCodes = 6 ErrCodes_ReceiptIsInvalid ErrCodes = 6
ErrCodes_InvalidPayload ErrCodes = 7 ErrCodes_InvalidPayload ErrCodes = 7
ErrCodes_ErrorOffset ErrCodes = 100 ErrCodes_DuplicateRequest ErrCodes = 8
ErrCodes_TooManyRequestsFromPeer ErrCodes = 9
ErrCodes_ErrorOffset ErrCodes = 100
) )
var ErrCodes_name = map[int32]string{ var ErrCodes_name = map[int32]string{
@ -45,19 +47,23 @@ var ErrCodes_name = map[int32]string{
5: "PeerIsNotResponsible", 5: "PeerIsNotResponsible",
6: "ReceiptIsInvalid", 6: "ReceiptIsInvalid",
7: "InvalidPayload", 7: "InvalidPayload",
8: "DuplicateRequest",
9: "TooManyRequestsFromPeer",
100: "ErrorOffset", 100: "ErrorOffset",
} }
var ErrCodes_value = map[string]int32{ var ErrCodes_value = map[string]int32{
"Unexpected": 0, "Unexpected": 0,
"SpaceMissing": 1, "SpaceMissing": 1,
"SpaceExists": 2, "SpaceExists": 2,
"SpaceNotInCache": 3, "SpaceNotInCache": 3,
"SpaceIsDeleted": 4, "SpaceIsDeleted": 4,
"PeerIsNotResponsible": 5, "PeerIsNotResponsible": 5,
"ReceiptIsInvalid": 6, "ReceiptIsInvalid": 6,
"InvalidPayload": 7, "InvalidPayload": 7,
"ErrorOffset": 100, "DuplicateRequest": 8,
"TooManyRequestsFromPeer": 9,
"ErrorOffset": 100,
} }
func (x ErrCodes) String() string { func (x ErrCodes) String() string {
@ -1709,87 +1715,89 @@ func init() {
} }
var fileDescriptor_80e49f1f4ac27799 = []byte{ var fileDescriptor_80e49f1f4ac27799 = []byte{
// 1273 bytes of a gzipped FileDescriptorProto // 1300 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x57, 0x4d, 0x6f, 0x1b, 0xc5, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x57, 0xcb, 0x6f, 0x1b, 0x45,
0x1b, 0xf7, 0x6e, 0x9c, 0xd8, 0x7e, 0xb2, 0x76, 0xb7, 0x13, 0xb7, 0xf5, 0xdf, 0xad, 0x1c, 0x6b, 0x18, 0xf7, 0x6e, 0x9c, 0xd8, 0xfe, 0xb2, 0x76, 0xb7, 0x13, 0xb7, 0x31, 0x6e, 0xe5, 0x5a, 0x2b,
0xf5, 0x17, 0x8a, 0x72, 0xc8, 0x2b, 0x42, 0x6a, 0x81, 0x43, 0x9a, 0xa4, 0x64, 0x81, 0x36, 0xd1, 0x84, 0xa2, 0x1c, 0xda, 0x26, 0x41, 0x48, 0x2d, 0x70, 0x48, 0xf3, 0x20, 0x0b, 0xa4, 0x89, 0xc6,
0x98, 0xaa, 0x12, 0x12, 0x87, 0xc9, 0xee, 0x24, 0x5e, 0x58, 0xef, 0x9a, 0x9d, 0x71, 0x1b, 0x1f, 0xad, 0x2a, 0x21, 0x71, 0x98, 0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f, 0xf5, 0xb4, 0xb7, 0x57, 0x3d, 0xed, 0xaf, 0xab, 0x9e, 0xf6,
0xff, 0x62, 0xd6, 0x1a, 0x50, 0x9f, 0x0d, 0x00, 0x00, 0xcb, 0x75, 0xaf, 0xf2, 0xf6, 0xba, 0x57, 0xf9, 0xf3, 0xba, 0x57, 0xf9, 0xa6, 0xbb, 0xf8, 0xbf,
0xb5, 0xb3, 0x15, 0xf9, 0x67, 0xe7, 0xdf, 0x00, 0x00, 0x00, 0xff, 0xff, 0xa6, 0xd2, 0x9a, 0xb5,
0xd2, 0x0d, 0x00, 0x00,
} }
func (m *HeadSyncRange) Marshal() (dAtA []byte, err error) { func (m *HeadSyncRange) Marshal() (dAtA []byte, err error) {

View file

@ -99,11 +99,11 @@ func (r *requestManager) HandleDeprecatedObjectSync(ctx context.Context, req *sp
func (r *requestManager) HandleStreamRequest(ctx context.Context, rq syncdeps.Request, stream drpc.Stream) error { func (r *requestManager) HandleStreamRequest(ctx context.Context, rq syncdeps.Request, stream drpc.Stream) error {
size := rq.MsgSize() size := rq.MsgSize()
if !r.incomingGuard.TryTake(fullId(rq.PeerId(), rq.ObjectId())) { if !r.incomingGuard.TryTake(fullId(rq.PeerId(), rq.ObjectId())) {
return nil return spacesyncproto.ErrDuplicateRequest
} }
defer r.incomingGuard.Release(fullId(rq.PeerId(), rq.ObjectId())) defer r.incomingGuard.Release(fullId(rq.PeerId(), rq.ObjectId()))
if !r.limit.Take(rq.PeerId()) { if !r.limit.Take(rq.PeerId()) {
return nil return spacesyncproto.ErrTooManyRequestsFromPeer
} }
defer r.limit.Release(rq.PeerId()) defer r.limit.Release(rq.PeerId())
r.metric.UpdateQueueSize(size, syncdeps.MsgTypeIncomingRequest, true) r.metric.UpdateQueueSize(size, syncdeps.MsgTypeIncomingRequest, true)

View file

@ -4,6 +4,9 @@ import (
"hash/fnv" "hash/fnv"
"math/rand" "math/rand"
"sort" "sort"
"golang.org/x/exp/constraints"
"golang.org/x/exp/slices"
) )
func DifferenceRemovedAdded(a, b []string) (removed []string, added []string) { func DifferenceRemovedAdded(a, b []string) (removed []string, added []string) {
@ -119,6 +122,27 @@ func UnsortedEquals(s1, s2 []string) bool {
return SortedEquals(s1Sorted, s2Sorted) return SortedEquals(s1Sorted, s2Sorted)
} }
func ContainsSorted[T constraints.Ordered](first []T, second []T) bool {
if len(first) < len(second) {
return false
}
slices.Sort(first)
slices.Sort(second)
i := 0
j := 0
for i < len(first) && j < len(second) {
if first[i] == second[j] {
i++
j++
} else if first[i] < second[j] {
i++
} else {
j++
}
}
return j == len(second)
}
func DiscardFromSlice[T any](elements []T, isDiscarded func(T) bool) []T { func DiscardFromSlice[T any](elements []T, isDiscarded func(T) bool) []T {
var ( var (
finishedIdx = 0 finishedIdx = 0

View file

@ -103,3 +103,34 @@ func TestCompareMaps(t *testing.T) {
}) })
} }
} }
func TestContainsSorted(t *testing.T) {
tests := []struct {
name string
first []int
second []int
expected bool
}{
{"both empty", []int{}, []int{}, true},
{"first empty", []int{}, []int{1}, false},
{"second empty", []int{1, 2, 3}, []int{}, true},
{"both non-empty and first contains second", []int{1, 2, 3, 4, 5}, []int{2, 3, 4}, true},
{"both non-empty and first does not contain second", []int{1, 2, 3, 4, 5}, []int{3, 4, 6}, false},
{"both non-empty and first shorter than second", []int{1, 2, 3}, []int{1, 2, 3, 4}, false},
{"both non-empty and first equals second", []int{1, 2, 3}, []int{1, 2, 3}, true},
{"both non-empty and first contains second at the beginning", []int{1, 2, 3, 4, 5}, []int{1, 2, 3}, true},
{"both non-empty and first contains second at the end", []int{1, 2, 3, 4, 5}, []int{3, 4, 5}, true},
{"non-consecutive elements", []int{1, 3, 5, 7, 9}, []int{3, 7}, true},
{"unsorted first contains sorted second", []int{5, 1, 3, 2, 4}, []int{2, 3, 4}, true},
{"unsorted first does not contain sorted second", []int{5, 1, 3, 2, 4}, []int{3, 4, 6}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := ContainsSorted(tt.first, tt.second)
if result != tt.expected {
t.Errorf("ContainsSorted(%v, %v) = %v; want %v", tt.first, tt.second, result, tt.expected)
}
})
}
}