diff --git a/debug/spacechecker/spacechecker.go b/debug/spacechecker/spacechecker.go index 1879844e..85c4e46b 100644 --- a/debug/spacechecker/spacechecker.go +++ b/debug/spacechecker/spacechecker.go @@ -7,6 +7,7 @@ import ( "os" "path/filepath" + anystore "github.com/anyproto/any-store" "github.com/anyproto/any-sync/app" "github.com/anyproto/any-sync/app/logger" "github.com/anyproto/any-sync/commonspace/spacestorage" @@ -65,7 +66,7 @@ func (s *spaceChecker) Check(ctx context.Context, spaceId string) (res Result, e // 1. Get local status from index storage localStatusStr, localErr := s.getLocalStatus(ctx, spaceId, &res) - if localErr != nil { + if localErr != nil && !errors.Is(localErr, anystore.ErrDocNotFound) { return res, fmt.Errorf("get local status: %w", localErr) } @@ -108,6 +109,7 @@ func (s *spaceChecker) Fix(ctx context.Context, spaceId string) (Result, error) switch { // coordStatus: removed, localStatus: not removed or storageExists: true - remove space and switch local status + // also handles case when local entry doesn't exist (localStatus: unknown) case coordStatus == "removed" && (localStatus != "removed" || storageExists): if storageExists { err = s.storageService.DeleteSpaceStorage(ctx, spaceId) @@ -162,14 +164,14 @@ func (s *spaceChecker) Fix(ctx context.Context, spaceId string) (Result, error) } func (s *spaceChecker) getLocalStatus(ctx context.Context, spaceId string, res *Result) (statusStr string, err error) { - status, err := s.storageService.IndexStorage().SpaceStatus(ctx, spaceId) + entry, err := s.storageService.IndexStorage().SpaceStatusEntry(ctx, spaceId) if err != nil { res.LocalStatus = "unknown" res.LocalStatusError = err.Error() res.Log = append(res.Log, fmt.Sprintf("localStatus: error getting status: %s", err)) return "unknown", err } - statusStr = localStatusString(status) + statusStr = localStatusString(entry.Status) res.LocalStatus = statusStr res.Log = append(res.Log, fmt.Sprintf("localStatus: %s", statusStr)) return statusStr, nil diff --git a/nodestorage/indexstorage.go b/nodestorage/indexstorage.go index 24271929..fcb6d6b6 100644 --- a/nodestorage/indexstorage.go +++ b/nodestorage/indexstorage.go @@ -67,6 +67,7 @@ type IndexStorage interface { UpdateHashes(ctx context.Context, updateFunc func(spaceId, newHash, oldHash string) (newNewHash, newOldHash string, shouldUpdate bool)) (err error) SetSpaceStatus(ctx context.Context, spaceId string, status SpaceStatus, recId string) (err error) SpaceStatus(ctx context.Context, spaceId string) (status SpaceStatus, err error) + SpaceStatusEntry(ctx context.Context, spaceId string) (entry SpaceStatusEntry, err error) MarkArchived(ctx context.Context, spaceId string, compressedSize, uncompressedSize int64) (err error) MarkError(ctx context.Context, spaceId string, errString string) (err error) DeletionLogId(ctx context.Context) (id string, err error) diff --git a/nodestorage/mock_nodestorage/mock_nodestorage.go b/nodestorage/mock_nodestorage/mock_nodestorage.go index d2f1b650..e7edc9c9 100644 --- a/nodestorage/mock_nodestorage/mock_nodestorage.go +++ b/nodestorage/mock_nodestorage/mock_nodestorage.go @@ -494,6 +494,21 @@ func (mr *MockIndexStorageMockRecorder) SpaceStatus(ctx, spaceId any) *gomock.Ca return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SpaceStatus", reflect.TypeOf((*MockIndexStorage)(nil).SpaceStatus), ctx, spaceId) } +// SpaceStatusEntry mocks base method. +func (m *MockIndexStorage) SpaceStatusEntry(ctx context.Context, spaceId string) (nodestorage.SpaceStatusEntry, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "SpaceStatusEntry", ctx, spaceId) + ret0, _ := ret[0].(nodestorage.SpaceStatusEntry) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// SpaceStatusEntry indicates an expected call of SpaceStatusEntry. +func (mr *MockIndexStorageMockRecorder) SpaceStatusEntry(ctx, spaceId any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SpaceStatusEntry", reflect.TypeOf((*MockIndexStorage)(nil).SpaceStatusEntry), ctx, spaceId) +} + // UpdateHash mocks base method. func (m *MockIndexStorage) UpdateHash(ctx context.Context, updates ...nodestorage.SpaceUpdate) error { m.ctrl.T.Helper()