diff --git a/common/commonspace/space.go b/common/commonspace/space.go index 3d181f52..5fbc675b 100644 --- a/common/commonspace/space.go +++ b/common/commonspace/space.go @@ -50,6 +50,7 @@ func (s *space) Init(ctx context.Context) error { s.rpc = &rpcHandler{s: s} s.diffService.Init(s.getObjectIds()) s.syncService.Init() + // basically this provides access for the external cache to use space's tree building functions s.cache.SetBuildFunc(s.BuildTree) return nil } @@ -67,7 +68,7 @@ func (s *space) DiffService() diffservice.DiffService { } func (s *space) CreateTree(ctx context.Context, payload tree.ObjectTreeCreatePayload, listener synctree.UpdateListener) (tree.ObjectTree, error) { - return synctree.CreateSyncTree(ctx, payload, s.syncService, listener, nil, s.storage.CreateTreeStorage) + return synctree.CreateSyncTree(ctx, payload, s.syncService, listener, s.aclList, s.storage.CreateTreeStorage) } func (s *space) BuildTree(ctx context.Context, id string, listener synctree.UpdateListener) (t tree.ObjectTree, err error) { @@ -109,7 +110,6 @@ func (s *space) BuildTree(ctx context.Context, id string, listener synctree.Upda if err != nil { return } - // TODO: maybe it is better to use the tree that we already built and just replace the storage // now we are sure that we can save it to the storage store, err = s.storage.CreateTreeStorage(payload) if err != nil { diff --git a/common/commonspace/spacetree/spacetree.go b/common/commonspace/spacetree/spacetree.go new file mode 100644 index 00000000..9cb4ff16 --- /dev/null +++ b/common/commonspace/spacetree/spacetree.go @@ -0,0 +1 @@ +package spacetree diff --git a/common/commonspace/syncservice/streampool.go b/common/commonspace/syncservice/streampool.go index 0e2626e9..5eb97170 100644 --- a/common/commonspace/syncservice/streampool.go +++ b/common/commonspace/syncservice/streampool.go @@ -21,7 +21,7 @@ type StreamPool interface { SyncClient AddAndReadStreamSync(stream spacesyncproto.SpaceStream) (err error) AddAndReadStreamAsync(stream spacesyncproto.SpaceStream) - HasStream(peerId string) bool + HasActiveStream(peerId string) bool Close() (err error) } @@ -55,8 +55,8 @@ func newStreamPool(messageHandler MessageHandler) StreamPool { } } -func (s *streamPool) HasStream(peerId string) (res bool) { - _, err := s.getStream(peerId) +func (s *streamPool) HasActiveStream(peerId string) (res bool) { + _, err := s.getOrDeleteStream(peerId) return err == nil } @@ -83,7 +83,7 @@ func (s *streamPool) SendSync( } func (s *streamPool) SendAsync(peerId string, message *spacesyncproto.ObjectSyncMessage) (err error) { - stream, err := s.getStream(peerId) + stream, err := s.getOrDeleteStream(peerId) if err != nil { return } @@ -91,7 +91,7 @@ func (s *streamPool) SendAsync(peerId string, message *spacesyncproto.ObjectSync return stream.Send(message) } -func (s *streamPool) getStream(id string) (stream spacesyncproto.SpaceStream, err error) { +func (s *streamPool) getOrDeleteStream(id string) (stream spacesyncproto.SpaceStream, err error) { s.Lock() defer s.Unlock() stream, exists := s.peerStreams[id] diff --git a/common/commonspace/syncservice/syncservice.go b/common/commonspace/syncservice/syncservice.go index 736d40b7..ed88f8ab 100644 --- a/common/commonspace/syncservice/syncservice.go +++ b/common/commonspace/syncservice/syncservice.go @@ -85,7 +85,7 @@ func (s *syncService) responsibleStreamCheckLoop(ctx context.Context) { return } for _, peer := range respPeers { - if s.streamPool.HasStream(peer.Id()) { + if s.streamPool.HasActiveStream(peer.Id()) { continue } cl := spacesyncproto.NewDRPCSpaceClient(peer) diff --git a/common/commonspace/synctree/synctree.go b/common/commonspace/synctree/synctree.go index e45c3ffa..7e4341e2 100644 --- a/common/commonspace/synctree/synctree.go +++ b/common/commonspace/synctree/synctree.go @@ -15,6 +15,7 @@ type UpdateListener interface { Rebuild(tree tree.ObjectTree) } +// SyncTree sends head updates to sync service and also sends new changes to update listener type SyncTree struct { tree.ObjectTree syncService syncservice.SyncService diff --git a/pkg/acl/tree/objecttree.go b/pkg/acl/tree/objecttree.go index c2b3e0b9..7c1df882 100644 --- a/pkg/acl/tree/objecttree.go +++ b/pkg/acl/tree/objecttree.go @@ -43,6 +43,7 @@ type ObjectTree interface { Heads() []string Root() *Change HasChange(string) bool + DebugDump() (string, error) Iterate(convert ChangeConvertFunc, iterate ChangeIterateFunc) error IterateFrom(id string, convert ChangeConvertFunc, iterate ChangeIterateFunc) error @@ -51,7 +52,6 @@ type ObjectTree interface { ChangesAfterCommonSnapshot(snapshotPath, heads []string) ([]*aclpb.RawTreeChangeWithId, error) Storage() storage.TreeStorage - DebugDump() (string, error) AddContent(ctx context.Context, content SignableChangeContent) (AddResult, error) AddRawChanges(ctx context.Context, changes ...*aclpb.RawTreeChangeWithId) (AddResult, error) diff --git a/pkg/acl/tree/rawtreevalidator.go b/pkg/acl/tree/rawtreevalidator.go index 86a0082f..01cb1105 100644 --- a/pkg/acl/tree/rawtreevalidator.go +++ b/pkg/acl/tree/rawtreevalidator.go @@ -12,6 +12,6 @@ func ValidateRawTree(payload storage.TreeStorageCreatePayload, aclList list.ACLL return } - _, err = BuildObjectTree(treeStorage, nil, aclList) + _, err = BuildObjectTree(treeStorage, aclList) return }