Skip to content

Commit

Permalink
Remove old space hash
Browse files Browse the repository at this point in the history
  • Loading branch information
mcrakhman committed Sep 11, 2024
1 parent 56a8bd3 commit 027e9ae
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 75 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ toolchain go1.22.1
require (
github.com/ahmetb/govvv v0.3.0
github.com/akrylysov/pogreb v0.10.3-0.20240803013244-523613e335e9
github.com/anyproto/any-sync v0.5.1
github.com/anyproto/any-sync v0.5.2-0.20240911141811-ef4316aedb9c
github.com/anyproto/go-chash v0.1.0
github.com/gogo/protobuf v1.3.2
github.com/prometheus/client_golang v1.19.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ github.com/akrylysov/pogreb v0.10.3-0.20240803013244-523613e335e9 h1:GnBlbnor8ge
github.com/akrylysov/pogreb v0.10.3-0.20240803013244-523613e335e9/go.mod h1:fPb3n+7H42SxX84B4/os7POrR+UGRKSRr3kNS5+xq/c=
github.com/anyproto/any-sync v0.5.1 h1:JjluGnZlJ8z0r48fkw+mAJKlTYYSyeXaBb833Fec9/Y=
github.com/anyproto/any-sync v0.5.1/go.mod h1:oLo4tkNYdum85NCE1QaRzy4KPK+RlBMkhTH6U27ZvX0=
github.com/anyproto/any-sync v0.5.2-0.20240911141811-ef4316aedb9c h1:NqZe7tBRxkU68J3ZkEPvQ22NUygJCN//6IRfzwBKr1g=
github.com/anyproto/any-sync v0.5.2-0.20240911141811-ef4316aedb9c/go.mod h1:oLo4tkNYdum85NCE1QaRzy4KPK+RlBMkhTH6U27ZvX0=
github.com/anyproto/go-chash v0.1.0 h1:I9meTPjXFRfXZHRJzjOHC/XF7Q5vzysKkiT/grsogXY=
github.com/anyproto/go-chash v0.1.0/go.mod h1:0UjNQi3PDazP0fINpFYu6VKhuna+W/V+1vpXHAfNgLY=
github.com/anyproto/go-slip10 v1.0.0 h1:uAEtSuudR3jJBOfkOXf3bErxVoxbuKwdoJN55M1i6IA=
Expand Down
38 changes: 1 addition & 37 deletions nodehead/nodehead.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ func New() NodeHead {
type NodeHead interface {
SetHead(spaceId, head string) (part int, err error)
GetHead(spaceId string) (head string, err error)
SetOldHead(spaceId, head string) (part int, err error)
GetOldHead(spaceId string) (head string, err error)
DeleteHeads(spaceId string) error
ReloadHeadFromStore(spaceId string) error
LDiff(partId int) ldiff.Diff
Expand All @@ -64,11 +62,6 @@ func (n *nodeHead) Init(a *app.App) (err error) {
log.Error("can't set head", zap.Error(e))
}
})
n.spaceStore.OnWriteOldHash(func(_ context.Context, spaceId, hash string) {
if _, e := n.SetOldHead(spaceId, hash); e != nil {
log.Error("can't set old head", zap.Error(e))
}
})
n.spaceStore.OnDeleteStorage(func(_ context.Context, spaceId string) {
if e := n.DeleteHeads(spaceId); e != nil {
log.Error("can't delete space from nodehead", zap.Error(e))
Expand Down Expand Up @@ -117,20 +110,7 @@ func (n *nodeHead) loadHeadFromStore(spaceId string) (err error) {
if err != nil {
return
}
if _, err = n.SetHead(spaceId, hash); err != nil {
return
}
oldHash, err := ss.ReadOldSpaceHash()
if err != nil {
return
}
// that means that the hash was not set before
if oldHash == "" {
oldHash = hash
}
if _, err = n.SetOldHead(spaceId, oldHash); err != nil {
return
}
_, err = n.SetHead(spaceId, hash)
return
}

Expand Down Expand Up @@ -158,13 +138,6 @@ func (n *nodeHead) SetHead(spaceId, head string) (part int, err error) {
return
}

func (n *nodeHead) SetOldHead(spaceId, head string) (part int, err error) {
n.mu.Lock()
defer n.mu.Unlock()
n.oldHashes[spaceId] = head
return
}

func (n *nodeHead) Ranges(ctx context.Context, part int, ranges []ldiff.Range, resBuf []ldiff.RangeResult) (results []ldiff.RangeResult, err error) {
return n.LDiff(part).Ranges(ctx, ranges, resBuf)
}
Expand Down Expand Up @@ -199,15 +172,6 @@ func (n *nodeHead) GetHead(spaceId string) (hash string, err error) {
return el.Head, nil
}

func (n *nodeHead) GetOldHead(spaceId string) (hash string, err error) {
n.mu.Lock()
defer n.mu.Unlock()
if hash, ok := n.oldHashes[spaceId]; ok {
return hash, nil
}
return "", ErrSpaceNotFound
}

func (n *nodeHead) ReloadHeadFromStore(spaceId string) error {
return n.loadHeadFromStore(spaceId)
}
Expand Down
19 changes: 0 additions & 19 deletions nodehead/nodehead_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,37 +102,18 @@ func TestNodeHead_GetSpaceHash(t *testing.T) {
assert.Equal(t, ErrSpaceNotFound, err)
}

func TestNodeHead_GetOldSpaceHash(t *testing.T) {
fx := newFixture(t, "")
defer fx.Finish(t)
hash := "af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262"
_, err := fx.SetOldHead("space1", hash)
require.NoError(t, err)

head, err := fx.GetOldHead("space1")
require.NoError(t, err)
assert.Equal(t, hash, head)

_, err = fx.GetOldHead("not found")
assert.Equal(t, ErrSpaceNotFound, err)
}

func TestNodeHead_DeleteHeads(t *testing.T) {
fx := newFixture(t, "")
defer fx.Finish(t)
hash := "af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262"
_, err := fx.SetHead("space1", hash)
require.NoError(t, err)
_, err = fx.SetOldHead("space1", hash)
require.NoError(t, err)

err = fx.NodeHead.(*nodeHead).DeleteHeads("space1")
require.NoError(t, err)

_, err = fx.GetHead("space1")
assert.Equal(t, ErrSpaceNotFound, err)
_, err = fx.GetOldHead("space1")
assert.Equal(t, ErrSpaceNotFound, err)
}

func newFixture(t *testing.T, dataPath string) *fixture {
Expand Down
1 change: 0 additions & 1 deletion nodespace/rpchandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ func (r *rpcHandler) tryNodeHeadSync(req *spacesyncproto.HeadSyncRequest) (resp
}
log.Debug("got head sync with nodehead", zap.String("spaceId", req.SpaceId))
return &spacesyncproto.HeadSyncResponse{
DiffType: spacesyncproto.DiffType_Precalculated,
Results: []*spacesyncproto.HeadSyncResult{
{
Hash: hashB,
Expand Down
1 change: 0 additions & 1 deletion nodestorage/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ var (
spaceSettingsIdKey = []byte("spaceSettingsId")
deletedKey = []byte("spaceDeleted")
spaceHashKey = []byte("spaceHash")
oldSpaceHashKey = []byte("oldSpaceHash")
)

func (s spaceKeys) SpaceIdKey() []byte {
Expand Down
15 changes: 0 additions & 15 deletions nodestorage/spacestorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,6 @@ func (s *spaceStorage) WriteSpaceHash(hash string) error {
return s.objDb.Put(spaceHashKey, []byte(hash))
}

func (s *spaceStorage) WriteOldSpaceHash(hash string) error {
if s.service.onWriteHash != nil {
defer s.service.onWriteOldHash(context.Background(), s.spaceId, hash)
}
return s.objDb.Put(oldSpaceHashKey, []byte(hash))
}

func (s *spaceStorage) ReadSpaceHash() (hash string, err error) {
v, err := s.objDb.Get(spaceHashKey)
if err != nil {
Expand All @@ -281,14 +274,6 @@ func (s *spaceStorage) ReadSpaceHash() (hash string, err error) {
return string(v), nil
}

func (s *spaceStorage) ReadOldSpaceHash() (hash string, err error) {
v, err := s.objDb.Get(oldSpaceHashKey)
if err != nil {
return "", err
}
return string(v), nil
}

func (s *spaceStorage) Close(ctx context.Context) (err error) {
defer s.service.unlockSpaceStorage(s.spaceId)
return s.objDb.Close()
Expand Down
1 change: 0 additions & 1 deletion nodestorage/storageservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type NodeStorage interface {
AllSpaceIds() (ids []string, err error)
OnDeleteStorage(onDelete func(ctx context.Context, spaceId string))
OnWriteHash(onWrite func(ctx context.Context, spaceId, hash string))
OnWriteOldHash(onWrite func(ctx context.Context, spaceId, hash string))
StoreDir(spaceId string) (path string)
DeleteSpaceStorage(ctx context.Context, spaceId string) error
}
Expand Down

0 comments on commit 027e9ae

Please sign in to comment.