Skip to content

Commit 4e26433

Browse files
committed
rename CheckOwnership -> CheckAndMoveOwnership
1 parent 87d499e commit 4e26433

6 files changed

Lines changed: 35 additions & 35 deletions

File tree

filenode/filenode.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ func (fn *fileNode) StoreKey(ctx context.Context, spaceId string, checkLimit boo
254254
if ownerRecordIndex == 0 {
255255
oldIdentity = storageKey.GroupId
256256
}
257-
if err = fn.index.CheckOwnership(ctx, storageKey, oldIdentity, ownerRecordIndex); err != nil {
257+
if err = fn.index.CheckAndMoveOwnership(ctx, storageKey, oldIdentity, ownerRecordIndex); err != nil {
258258
log.ErrorCtx(ctx, "check ownership error", zap.String("spaceId", spaceId), zap.Error(err))
259259
return storageKey, fileprotoerr.ErrUnexpected
260260
}
@@ -471,5 +471,5 @@ func (fn *fileNode) OwnershipTransfer(ctx context.Context, spaceId, oldIdentity,
471471
if err != nil {
472472
return
473473
}
474-
return fn.index.CheckOwnership(ctx, index.Key{GroupId: ownerPubKey.Account(), SpaceId: spaceId}, oldIdentity, ownerRecordIndex)
474+
return fn.index.CheckAndMoveOwnership(ctx, index.Key{GroupId: ownerPubKey.Account(), SpaceId: spaceId}, oldIdentity, ownerRecordIndex)
475475
}

filenode/filenode_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestFileNode_Add(t *testing.T) {
5353

5454
fx.index.EXPECT().CheckLimits(ctx, storeKey)
5555
fx.index.EXPECT().Migrate(ctx, storeKey)
56-
fx.index.EXPECT().CheckOwnership(ctx, storeKey, storeKey.GroupId, gomock.Any()).Return(nil)
56+
fx.index.EXPECT().CheckAndMoveOwnership(ctx, storeKey, storeKey.GroupId, gomock.Any()).Return(nil)
5757
fx.index.EXPECT().BlocksLock(ctx, []blocks.Block{b}).Return(func() {}, nil)
5858
fx.index.EXPECT().BlocksGetNonExistent(ctx, []blocks.Block{b}).Return([]blocks.Block{b}, nil)
5959
fx.store.EXPECT().Add(ctx, []blocks.Block{b})
@@ -92,7 +92,7 @@ func TestFileNode_Add(t *testing.T) {
9292
})
9393

9494
fx.index.EXPECT().Migrate(ctx, storeKey)
95-
fx.index.EXPECT().CheckOwnership(ctx, storeKey, storeKey.GroupId, gomock.Any()).Return(nil)
95+
fx.index.EXPECT().CheckAndMoveOwnership(ctx, storeKey, storeKey.GroupId, gomock.Any()).Return(nil)
9696
fx.index.EXPECT().CheckLimits(ctx, storeKey).Return(index.ErrLimitExceed)
9797

9898
resp, err := fx.handler.BlockPush(ctx, &fileproto.BlockPushRequest{
@@ -217,7 +217,7 @@ func TestFileNode_Check(t *testing.T) {
217217
})
218218

219219
fx.index.EXPECT().Migrate(ctx, storeKey)
220-
fx.index.EXPECT().CheckOwnership(ctx, storeKey, storeKey.GroupId, gomock.Any()).Return(nil)
220+
fx.index.EXPECT().CheckAndMoveOwnership(ctx, storeKey, storeKey.GroupId, gomock.Any()).Return(nil)
221221
fx.index.EXPECT().CidExistsInSpace(ctx, storeKey, testutil.BlocksToKeys(bs)).Return(testutil.BlocksToKeys(bs[:1]), nil)
222222
fx.index.EXPECT().CidExists(ctx, bs[1].Cid()).Return(true, nil)
223223
fx.index.EXPECT().CidExists(ctx, bs[2].Cid()).Return(false, nil)
@@ -260,7 +260,7 @@ func TestFileNode_BlocksBind(t *testing.T) {
260260

261261
fx.index.EXPECT().CheckLimits(ctx, storeKey)
262262
fx.index.EXPECT().Migrate(ctx, storeKey)
263-
fx.index.EXPECT().CheckOwnership(ctx, storeKey, storeKey.GroupId, gomock.Any()).Return(nil)
263+
fx.index.EXPECT().CheckAndMoveOwnership(ctx, storeKey, storeKey.GroupId, gomock.Any()).Return(nil)
264264
fx.index.EXPECT().CidEntries(ctx, cids).Return(cidEntries, nil)
265265
fx.index.EXPECT().FileBind(ctx, storeKey, fileId, cidEntries)
266266

@@ -295,7 +295,7 @@ func TestFileNode_FileInfo(t *testing.T) {
295295
})
296296

297297
fx.index.EXPECT().Migrate(ctx, storeKey)
298-
fx.index.EXPECT().CheckOwnership(ctx, storeKey, storeKey.GroupId, gomock.Any()).Return(nil)
298+
fx.index.EXPECT().CheckAndMoveOwnership(ctx, storeKey, storeKey.GroupId, gomock.Any()).Return(nil)
299299
fx.index.EXPECT().FileInfo(ctx, storeKey, fileId1, fileId2).Return([]index.FileInfo{{1, 1}, {2, 2}}, nil)
300300

301301
resp, err := fx.handler.FilesInfo(ctx, &fileproto.FilesInfoRequest{
@@ -376,7 +376,7 @@ func TestFileNode_SpaceInfo(t *testing.T) {
376376
})
377377

378378
fx.index.EXPECT().Migrate(ctx, storeKey)
379-
fx.index.EXPECT().CheckOwnership(ctx, storeKey, storeKey.GroupId, gomock.Any()).Return(nil)
379+
fx.index.EXPECT().CheckAndMoveOwnership(ctx, storeKey, storeKey.GroupId, gomock.Any()).Return(nil)
380380

381381
fx.index.EXPECT().GroupInfo(ctx, storeKey.GroupId).Return(index.GroupInfo{
382382
BytesUsage: 100,
@@ -421,7 +421,7 @@ func TestFileNode_SpaceInfo(t *testing.T) {
421421
})
422422

423423
fx.index.EXPECT().Migrate(ctx, storeKey)
424-
fx.index.EXPECT().CheckOwnership(ctx, storeKey, storeKey.GroupId, gomock.Any()).Return(nil)
424+
fx.index.EXPECT().CheckAndMoveOwnership(ctx, storeKey, storeKey.GroupId, gomock.Any()).Return(nil)
425425

426426
fx.index.EXPECT().GroupInfo(ctx, storeKey.GroupId).Return(index.GroupInfo{
427427
BytesUsage: 100,
@@ -463,7 +463,7 @@ func TestFileNode_StoreKey(t *testing.T) {
463463
}
464464

465465
fx.index.EXPECT().Migrate(ctx, expectedStoreKey)
466-
fx.index.EXPECT().CheckOwnership(ctx, expectedStoreKey, expectedStoreKey.GroupId, gomock.Any()).Return(nil)
466+
fx.index.EXPECT().CheckAndMoveOwnership(ctx, expectedStoreKey, expectedStoreKey.GroupId, gomock.Any()).Return(nil)
467467
fx.index.EXPECT().CheckLimits(ctx, expectedStoreKey)
468468
fx.aclService.EXPECT().ReadList(gomock.Any(), gomock.Any(), gomock.Any()).
469469
DoAndReturn(func(ctx context.Context, spaceId string, fn func(list.AclList) error) error {
@@ -577,7 +577,7 @@ func TestFileNode_SpaceLimitSet(t *testing.T) {
577577
})
578578

579579
fx.index.EXPECT().Migrate(ctx, storeKey)
580-
fx.index.EXPECT().CheckOwnership(ctx, storeKey, storeKey.GroupId, gomock.Any()).Return(nil)
580+
fx.index.EXPECT().CheckAndMoveOwnership(ctx, storeKey, storeKey.GroupId, gomock.Any()).Return(nil)
581581
fx.index.EXPECT().SetSpaceLimit(ctx, storeKey, uint64(12345))
582582
require.NoError(t, fx.SpaceLimitSet(ctx, storeKey.SpaceId, 12345))
583583
}

index/index.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ type Index interface {
7373
SpaceDelete(ctx context.Context, key Key) (ok bool, err error)
7474
MarkSpaceAsDeleted(ctx context.Context, key Key) (ok bool, err error)
7575

76-
CheckOwnership(ctx context.Context, key Key, oldIdentity string, aclRecordIndex int) error
76+
CheckAndMoveOwnership(ctx context.Context, key Key, oldIdentity string, aclRecordIndex int) error
7777

7878
app.ComponentRunnable
7979
}

index/mock_index/mock_index.go

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index/move.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/anyproto/any-sync-filenode/index/indexproto"
1414
)
1515

16-
func (ri *redisIndex) CheckOwnership(ctx context.Context, key Key, oldIdentity string, aclRecordIndex int) (err error) {
16+
func (ri *redisIndex) CheckAndMoveOwnership(ctx context.Context, key Key, oldIdentity string, aclRecordIndex int) (err error) {
1717
oKey := OwnerKey(key.SpaceId)
1818
_, release, err := ri.AcquireKey(ctx, oKey)
1919
if err != nil {

index/move_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,33 @@ func TestRedisIndex_CheckOwnership(t *testing.T) {
1313
t.Run("same owner", func(t *testing.T) {
1414
fx := newFixture(t)
1515
defer fx.Finish(t)
16-
err := fx.CheckOwnership(ctx, Key{"o1", "s1"}, "s1", 0)
16+
err := fx.CheckAndMoveOwnership(ctx, Key{"o1", "s1"}, "s1", 0)
1717
require.NoError(t, err)
18-
err = fx.CheckOwnership(ctx, Key{"o1", "s1"}, "", 0)
18+
err = fx.CheckAndMoveOwnership(ctx, Key{"o1", "s1"}, "", 0)
1919
require.NoError(t, err)
20-
err = fx.CheckOwnership(ctx, Key{"o1", "s1"}, "", 22)
20+
err = fx.CheckAndMoveOwnership(ctx, Key{"o1", "s1"}, "", 22)
2121
require.NoError(t, err)
2222
})
2323
t.Run("change owner", func(t *testing.T) {
2424
fx := newFixture(t)
2525
defer fx.Finish(t)
26-
err := fx.CheckOwnership(ctx, Key{"alice", "s1"}, "sn", 0)
26+
err := fx.CheckAndMoveOwnership(ctx, Key{"alice", "s1"}, "sn", 0)
2727
require.NoError(t, err)
28-
err = fx.CheckOwnership(ctx, Key{GroupId: "bob", SpaceId: "s1"}, "sn", 1)
28+
err = fx.CheckAndMoveOwnership(ctx, Key{GroupId: "bob", SpaceId: "s1"}, "sn", 1)
2929
require.NoError(t, err)
3030
})
3131
t.Run("old index", func(t *testing.T) {
3232
fx := newFixture(t)
3333
defer fx.Finish(t)
34-
err := fx.CheckOwnership(ctx, Key{"alice", "s1"}, "sn", 11)
34+
err := fx.CheckAndMoveOwnership(ctx, Key{"alice", "s1"}, "sn", 11)
3535
require.NoError(t, err)
36-
err = fx.CheckOwnership(ctx, Key{"bob", "s1"}, "sn", 9)
36+
err = fx.CheckAndMoveOwnership(ctx, Key{"bob", "s1"}, "sn", 9)
3737
require.NoError(t, err)
3838
})
3939
t.Run("no prev owner", func(t *testing.T) {
4040
fx := newFixture(t)
4141
defer fx.Finish(t)
42-
err := fx.CheckOwnership(ctx, Key{"alice", "s1"}, "", 12)
42+
err := fx.CheckAndMoveOwnership(ctx, Key{"alice", "s1"}, "", 12)
4343
assert.Error(t, err)
4444
})
4545
}

0 commit comments

Comments
 (0)