Fix ocache and streampool bugs, fix push space

This commit is contained in:
mcrakhman 2022-10-19 22:21:44 +02:00 committed by Mikhail Iudin
parent 524cf07d56
commit bb156e1bd0
No known key found for this signature in database
GPG Key ID: FAAAA8BAABDFF1C0
3 changed files with 6 additions and 5 deletions

View File

@ -52,11 +52,13 @@ type streamPool struct {
}
func newStreamPool(messageHandler MessageHandler) StreamPool {
return &streamPool{
s := &streamPool{
peerStreams: make(map[string]spacesyncproto.SpaceStream),
messageHandler: messageHandler,
wg: &sync.WaitGroup{},
}
s.lastUsage.Store(time.Now().Unix())
return s
}
func (s *streamPool) LastUsage() time.Time {

View File

@ -356,7 +356,6 @@ func (c *oCache) GC() {
c.mu.Unlock()
return
}
deadline := c.timeNow().Add(-c.ttl)
var toClose []*entry
for _, e := range c.data {
if e.isClosing {
@ -366,7 +365,8 @@ func (c *oCache) GC() {
if lug, ok := e.value.(ObjectLastUsage); ok {
lu = lug.LastUsage()
}
if !e.locked() && e.refCount <= 0 && lu.Before(deadline) {
deadline := lu.Add(c.ttl)
if !e.locked() && e.refCount <= 0 && c.timeNow().After(deadline) {
e.isClosing = true
e.close = make(chan struct{})
toClose = append(toClose, e)

View File

@ -4,7 +4,6 @@ import (
"context"
"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/commonspace/treegetter"
)
type rpcHandler struct {
@ -17,7 +16,7 @@ func (r *rpcHandler) PushSpace(ctx context.Context, req *spacesyncproto.PushSpac
err = spacesyncproto.ErrSpaceExists
return
}
if err != treegetter.ErrSpaceNotFound {
if err != storage.ErrSpaceStorageMissing {
err = spacesyncproto.ErrUnexpected
return
}