Add push space logic and change storage interface

This commit is contained in:
mcrakhman 2022-09-28 09:18:04 +02:00 committed by Mikhail Iudin
parent 8cfe3df997
commit b8bdbacbce
No known key found for this signature in database
GPG Key ID: FAAAA8BAABDFF1C0
11 changed files with 150 additions and 107 deletions

View File

@ -7,8 +7,8 @@ import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/spacesyncproto"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/storage"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/peer"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/rpc/rpcerr"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/nodeconf"
treestorage "github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/storage"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/ldiff"
"go.uber.org/zap"
"strings"
@ -100,8 +100,12 @@ func (d *diffService) syncWithPeer(ctx context.Context, p peer.Peer) (err error)
cl := spacesyncproto.NewDRPCSpaceClient(p)
rdiff := remotediff.NewRemoteDiff(d.spaceId, cl)
newIds, changedIds, removedIds, err := d.diff.Diff(ctx, rdiff)
if err != nil {
return nil
err = rpcerr.Unwrap(err)
if err != nil && err != spacesyncproto.ErrSpaceMissing {
return err
}
if err == spacesyncproto.ErrSpaceMissing {
return d.sendPushSpaceRequest(ctx, cl)
}
d.pingTreesInCache(ctx, newIds)
@ -122,11 +126,11 @@ func (d *diffService) pingTreesInCache(ctx context.Context, trees []string) {
func (d *diffService) fillDiff(objectIds []string) {
var els = make([]ldiff.Element, 0, len(objectIds))
for _, id := range objectIds {
st, err := d.storage.Storage(id)
st, err := d.storage.TreeStorage(id)
if err != nil {
continue
}
heads, err := st.(treestorage.TreeStorage).Heads()
heads, err := st.Heads()
if err != nil {
continue
}
@ -138,6 +142,30 @@ func (d *diffService) fillDiff(objectIds []string) {
d.diff.Set(els...)
}
func (d *diffService) sendPushSpaceRequest(ctx context.Context, cl spacesyncproto.DRPCSpaceClient) (err error) {
aclStorage, err := d.storage.ACLStorage()
if err != nil {
return
}
root, err := aclStorage.Root()
if err != nil {
return
}
header, err := d.storage.SpaceHeader()
if err != nil {
return
}
_, err = cl.PushSpace(ctx, &spacesyncproto.PushSpaceRequest{
SpaceId: d.spaceId,
SpaceHeader: header,
AclRoot: root,
})
return
}
func concatStrings(strs []string) string {
var (
b strings.Builder

View File

@ -114,7 +114,7 @@ func (s *space) BuildTree(ctx context.Context, id string, listener synctree.Upda
)
}
store, err := s.storage.Storage(id)
store, err := s.storage.TreeStorage(id)
if err != nil && err != treestorage.ErrUnknownTreeId {
return
}

View File

@ -0,0 +1,13 @@
package spacesyncproto
import (
"errors"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/rpc/rpcerr"
)
var (
errGroup = rpcerr.ErrGroup(ErrCodes_ErrorOffset)
ErrUnexpected = errGroup.Register(errors.New("Unexpected error"), uint64(ErrCodes_Unexpected))
ErrSpaceMissing = errGroup.Register(errors.New("Space is missing"), uint64(ErrCodes_SpaceMissing))
)

View File

@ -7,6 +7,8 @@ import "pkg/acl/aclrecordproto/protos/aclrecord.proto";
enum ErrCodes {
Unexpected = 0;
SpaceMissing = 1;
ErrorOffset = 16;
}
service Space {

View File

@ -27,15 +27,21 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
type ErrCodes int32
const (
ErrCodes_Unexpected ErrCodes = 0
ErrCodes_Unexpected ErrCodes = 0
ErrCodes_SpaceMissing ErrCodes = 1
ErrCodes_ErrorOffset ErrCodes = 16
)
var ErrCodes_name = map[int32]string{
0: "Unexpected",
0: "Unexpected",
1: "SpaceMissing",
16: "ErrorOffset",
}
var ErrCodes_value = map[string]int32{
"Unexpected": 0,
"Unexpected": 0,
"SpaceMissing": 1,
"ErrorOffset": 16,
}
func (x ErrCodes) String() string {
@ -934,63 +940,64 @@ func init() {
}
var fileDescriptor_5855f4ef9cf24cdb = []byte{
// 887 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 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0x27, 0x31, 0xfe, 0x9a, 0xa0, 0x6f, 0x30, 0x68, 0x55, 0x58, 0x0b, 0xb6, 0x88, 0xfe, 0x83, 0x50,
0xeb, 0x30, 0x1e, 0xb5, 0x1c, 0xb6, 0x0b, 0x4d, 0x92, 0xeb, 0xe1, 0xd9, 0x99, 0x46, 0xd3, 0x6a,
0xf5, 0x5f, 0x38, 0xb0, 0x41, 0x18, 0x76, 0x17, 0xea, 0xf9, 0xf5, 0xcd, 0xde, 0x59, 0x75, 0xa5,
0x93, 0x68, 0xed, 0xf6, 0xca, 0xdb, 0x3e, 0xd5, 0xfe, 0x6b, 0x68, 0xcc, 0x8b, 0xc8, 0x4a, 0xc0,
0x65, 0xe5, 0xdb, 0x37, 0x57, 0xce, 0x65, 0x59, 0x4e, 0x60, 0xf3, 0xd4, 0x28, 0x14, 0x13, 0x76,
0x73, 0xd5, 0xad, 0x9f, 0xbd, 0x1e, 0xed, 0xd7, 0x4d, 0xee, 0x3b, 0x1f, 0x3b, 0xf7, 0x0e, 0xff,
0xbd, 0xe8, 0x38, 0xcf, 0x2f, 0x3a, 0xce, 0x7f, 0x17, 0x1d, 0xe7, 0xcf, 0xcb, 0x4e, 0xe5, 0xf9,
0x65, 0xa7, 0xf2, 0xe2, 0xb2, 0x53, 0xf9, 0xe1, 0xbd, 0x2b, 0xff, 0xd9, 0x3c, 0xdd, 0xa4, 0xcf,
0x27, 0xff, 0x07, 0x00, 0x00, 0xff, 0xff, 0xd8, 0x19, 0x98, 0xcc, 0x05, 0x09, 0x00, 0x00,
}
func (m *HeadSyncRange) Marshal() (dAtA []byte, err error) {

View File

@ -11,6 +11,8 @@ const CName = "commonspace.storage"
type SpaceStorage interface {
storage.Provider
ACLStorage() (storage.ListStorage, error)
SpaceHeader() (*spacesyncproto.SpaceHeader, error)
StoredIds() ([]string, error)
}

View File

@ -99,6 +99,8 @@ func (s *syncService) responsibleStreamCheckLoop(ctx context.Context) {
cl := spacesyncproto.NewDRPCSpaceClient(peer)
stream, err := cl.Stream(ctx)
if err != nil {
// so here probably the request is failed because there is no such space,
// but diffService should handle such cases by sending pushSpace
continue
}
// sending empty message for the server to understand from which space is it coming

View File

@ -3,20 +3,36 @@ package nodespace
import (
"context"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/spacesyncproto"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/storage"
)
type rpcHandler struct {
s *service
}
func (r *rpcHandler) PushSpace(ctx context.Context, request *spacesyncproto.PushSpaceRequest) (*spacesyncproto.PushSpaceResponse, error) {
return nil, nil
func (r *rpcHandler) PushSpace(ctx context.Context, req *spacesyncproto.PushSpaceRequest) (resp *spacesyncproto.PushSpaceResponse, err error) {
_, err = r.s.GetSpace(ctx, req.SpaceId)
if err == nil {
resp = &spacesyncproto.PushSpaceResponse{}
return
}
payload := storage.SpaceStorageCreatePayload{
RecWithId: req.AclRoot,
SpaceHeader: req.SpaceHeader,
Id: req.SpaceId,
}
_, err = r.s.spaceStorageProvider.CreateSpaceStorage(payload)
if err != nil {
err = spacesyncproto.ErrUnexpected
return
}
return
}
func (r *rpcHandler) HeadSync(ctx context.Context, req *spacesyncproto.HeadSyncRequest) (*spacesyncproto.HeadSyncResponse, error) {
sp, err := r.s.GetSpace(ctx, req.SpaceId)
if err != nil {
return nil, err
return nil, spacesyncproto.ErrSpaceMissing
}
return sp.SpaceSyncRpc().HeadSync(ctx, req)
}
@ -28,7 +44,7 @@ func (r *rpcHandler) Stream(stream spacesyncproto.DRPCSpace_StreamStream) error
}
sp, err := r.s.GetSpace(stream.Context(), msg.SpaceId)
if err != nil {
return err
return spacesyncproto.ErrSpaceMissing
}
return sp.SpaceSyncRpc().Stream(stream)
}

View File

@ -6,6 +6,7 @@ import (
"github.com/anytypeio/go-anytype-infrastructure-experiments/app/logger"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/spacesyncproto"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/commonspace/storage"
"github.com/anytypeio/go-anytype-infrastructure-experiments/common/net/rpc/server"
"github.com/anytypeio/go-anytype-infrastructure-experiments/config"
"github.com/anytypeio/go-anytype-infrastructure-experiments/node/nodespace/nodecache"
@ -27,14 +28,16 @@ type Service interface {
}
type service struct {
conf config.Space
spaceCache ocache.OCache
commonSpace commonspace.Service
conf config.Space
spaceCache ocache.OCache
commonSpace commonspace.Service
spaceStorageProvider storage.SpaceStorageProvider
}
func (s *service) Init(a *app.App) (err error) {
s.conf = a.MustComponent(config.CName).(*config.Config).Space
s.commonSpace = a.MustComponent(commonspace.CName).(commonspace.Service)
s.spaceStorageProvider = a.MustComponent(storage.CName).(storage.SpaceStorageProvider)
s.spaceCache = ocache.New(
func(ctx context.Context, id string) (value ocache.Object, err error) {
return s.commonSpace.GetSpace(ctx, id, nodecache.NewNodeCache(s.conf.GCTTL))

View File

@ -134,22 +134,11 @@ func (t *inMemoryTreeStorage) GetRawChange(ctx context.Context, changeId string)
}
type inMemoryStorageProvider struct {
objects map[string]Storage
objects map[string]TreeStorage
sync.RWMutex
}
func (i *inMemoryStorageProvider) AddStorage(id string, st Storage) error {
i.Lock()
defer i.Unlock()
if _, exists := i.objects[id]; exists {
return fmt.Errorf("storage already exists")
}
i.objects[id] = st
return nil
}
func (i *inMemoryStorageProvider) Storage(id string) (Storage, error) {
func (i *inMemoryStorageProvider) TreeStorage(id string) (TreeStorage, error) {
i.RLock()
defer i.RUnlock()
if tree, exists := i.objects[id]; exists {
@ -170,20 +159,8 @@ func (i *inMemoryStorageProvider) CreateTreeStorage(payload TreeStorageCreatePay
return res, nil
}
func (i *inMemoryStorageProvider) CreateACLListStorage(payload ACLListStorageCreatePayload) (ListStorage, error) {
i.Lock()
defer i.Unlock()
res, err := NewInMemoryACLListStorage(payload.ListId, payload.Records)
if err != nil {
return nil, err
}
i.objects[payload.ListId] = res
return res, nil
}
func NewInMemoryTreeStorageProvider() Provider {
return &inMemoryStorageProvider{
objects: make(map[string]Storage),
objects: make(map[string]TreeStorage),
}
}

View File

@ -2,7 +2,6 @@ package storage
import (
"errors"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/aclrecordproto"
"github.com/anytypeio/go-anytype-infrastructure-experiments/pkg/acl/treechangeproto"
)
@ -15,13 +14,7 @@ type TreeStorageCreatePayload struct {
Heads []string
}
type ACLListStorageCreatePayload struct {
ListId string
Records []*aclrecordproto.RawACLRecordWithId
}
type Provider interface {
Storage(id string) (Storage, error)
TreeStorage(id string) (TreeStorage, error)
CreateTreeStorage(payload TreeStorageCreatePayload) (TreeStorage, error)
CreateACLListStorage(payload ACLListStorageCreatePayload) (ListStorage, error)
}