Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GO-4146 new spacestore #2052

Draft
wants to merge 85 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
4520728
GO-4146 WIP spacestorage initial
mcrakhman Dec 13, 2024
194b13b
GO-4709 WIP add differ
mcrakhman Dec 13, 2024
9755a78
GO-4709 Mark seen heads
mcrakhman Dec 13, 2024
29bb18d
GO-4709 Update any-sync change differ
mcrakhman Dec 13, 2024
2d8126c
GO-4709 Update any-sync
mcrakhman Dec 16, 2024
e706420
GO-4146 Add tree exporter
mcrakhman Dec 23, 2024
add103e
GO-4146 Zip folder where the data is saved
mcrakhman Dec 23, 2024
45d776d
GO-4146 Move zip folder function to utils, write tests
mcrakhman Dec 23, 2024
7515b12
GO-4146 Add import tree method
mcrakhman Dec 23, 2024
ce99127
GO-4146 Use new archives in debugtree
mcrakhman Dec 23, 2024
2495ffd
GO-4146 Fix storages
mcrakhman Dec 24, 2024
df32d80
GO-4146 Changes throughout the project
mcrakhman Dec 24, 2024
f334cd2
GO-4146 Implement missing spacestorage methods and make stuff compile
mcrakhman Dec 24, 2024
9091731
GO-4146 Implement BindSpaceId
mcrakhman Dec 24, 2024
83862d0
GO-4146 Fix storage creation
mcrakhman Dec 27, 2024
eabbe94
GO-4146 Merge branch 'main' into GO-4146-new-spacestore
mcrakhman Dec 27, 2024
3941b8b
GO-4146 Fix treeexporter
mcrakhman Dec 27, 2024
0e90079
GO-4146 Fix storage missing error
mcrakhman Dec 30, 2024
abe560c
GO-4146 Fix errors
mcrakhman Dec 31, 2024
07ef481
GO-4146 Add synchronous
mcrakhman Dec 31, 2024
96cdc97
GO-4146 Debug spacestore
mcrakhman Jan 1, 2025
89ef08e
GO-4146 Update any-sync
mcrakhman Jan 4, 2025
e6c264f
GO-4146 Get deleted tree ids logic
mcrakhman Jan 4, 2025
e544078
GO-4146 Change deletion logic
mcrakhman Jan 5, 2025
34fc5ed
GO-4146 WIP account migration
mcrakhman Jan 6, 2025
f087215
GO-4812 WIP migration protos
mcrakhman Jan 7, 2025
e2e6e97
GO-4812 Synchronize migrations
mcrakhman Jan 7, 2025
856beaf
GO-4812 Add concurrent migration logic
mcrakhman Jan 7, 2025
c64eaed
GO-4146 Merge branch 'GO-4812-space-store-migration' into GO-4146-new…
mcrakhman Jan 7, 2025
4de02f5
GO-4146 WIP migration logic
mcrakhman Jan 7, 2025
60b8526
GO-4146 Fix migration start
mcrakhman Jan 8, 2025
96e694e
GO-4146 Remove all contents when migration failed
mcrakhman Jan 8, 2025
aa90cc2
GO-4146 Fix progress, update any-sync
mcrakhman Jan 8, 2025
0e2f51b
GO-4146 Migration and spacestore fixes
mcrakhman Jan 8, 2025
9cac2a3
GO-4146 Add cancel migration
mcrakhman Jan 9, 2025
6e11423
GO-4146 Fix old store ids
mcrakhman Jan 9, 2025
8625ea1
GO-4146 Update reindex counter
mcrakhman Jan 9, 2025
3301bc4
GO-4146 Add migration canceled error code
mcrakhman Jan 9, 2025
c380ce2
GO-4146 Use orders from store
mcrakhman Jan 9, 2025
800e12c
GO-4146 Add method for binds
mcrakhman Jan 10, 2025
836da9d
GO-4146 Not reindex full
mcrakhman Jan 10, 2025
333c3f7
GO-4146 Merge branch 'GO-4709-implement-change-differ' into GO-4146-n…
mcrakhman Jan 10, 2025
f655263
GO-4146 Update any-sync
mcrakhman Jan 10, 2025
50d69cb
GO-4146 Add not enough storage
mcrakhman Jan 10, 2025
0b4805f
GO-4146 Update any-sync
mcrakhman Jan 10, 2025
eea4cdf
GO-4146 Update any-sync and any-store
mcrakhman Jan 10, 2025
e404fab
GO-4825: WIP: migrate object => space bindings
deff7 Jan 10, 2025
dcecc37
GO-4825: Fix objectstore path
deff7 Jan 10, 2025
5e71f8c
GO-4825 Merge branch 'GO-4146-new-spacestore' of github.com:anyproto/…
deff7 Jan 10, 2025
68fbcfd
GO-4825: Remove debug code
deff7 Jan 10, 2025
caa55f1
GO-4825: Remove config dep
deff7 Jan 10, 2025
97c255d
Merge pull request #2000 from anyproto/go-4825-migrate-objectidspacei…
deff7 Jan 10, 2025
6f5910b
GO-4146 Update migrator
mcrakhman Jan 13, 2025
9a9428f
GO-4146: WIP Tests
deff7 Jan 13, 2025
1dc96d8
GO-4146 Merge branch 'GO-4146-new-spacestore' of github.com:anyproto/…
deff7 Jan 13, 2025
9f014a5
GO-4146: WIP Migrator finisher component
deff7 Jan 13, 2025
378b991
GO-4146: WIP Migration verifier
deff7 Jan 13, 2025
33eeb76
GO-4146: WIP Migration verifier: full comparison
deff7 Jan 13, 2025
b303374
GO-4146: Refactor verifier
deff7 Jan 13, 2025
61c716d
GO-4146: Add new debug method
deff7 Jan 14, 2025
4714a07
GO-4146: Optimize comparison: use anystore iterator
deff7 Jan 15, 2025
b4e7e1a
GO-4146: Fix iteration methods
deff7 Jan 15, 2025
6c939cd
GO-4146: Update any-sync
deff7 Jan 15, 2025
aafe234
GO-4146 Update any-sync
mcrakhman Jan 15, 2025
e460a42
GO-4146 Update any-sync
mcrakhman Jan 15, 2025
d754be7
GO-4146: Add badger test
deff7 Jan 16, 2025
f9cb263
GO-4146: Add space id resolving verification
deff7 Jan 16, 2025
37babff
GO-4146: Fix corrupted badger handling
deff7 Jan 21, 2025
cb7562f
GO-4146: Estimate db size
deff7 Jan 21, 2025
b3595bf
GO-4146: Estimate db size: add multiplier
deff7 Jan 21, 2025
34d0cf3
GO-4146: Estimate db size: add typed error
deff7 Jan 21, 2025
7182a84
Merge pull request #2028 from anyproto/GO-4146-estimate-size
deff7 Jan 22, 2025
88abd69
GO-4146 Update any-sync
mcrakhman Jan 22, 2025
0bdf62e
GO-4146 Merge remote-tracking branch 'refs/remotes/origin/main' into …
fat-fellow Jan 22, 2025
e7832e5
Fix merge main
fat-fellow Jan 22, 2025
0ac863c
GO-4146 Fix merge main
fat-fellow Jan 22, 2025
c90c5d6
GO-4146 Merge branch 'main' of ssh://github.com/anyproto/anytype-hear…
requilence Jan 23, 2025
0640c23
GO-4146: Fix collection name
deff7 Jan 23, 2025
6842e82
GO-4146 Update any-sync
mcrakhman Jan 23, 2025
08960a6
GO-4146 Update any-sync and any-store
mcrakhman Jan 24, 2025
c0122a1
GO-4146 Update any-sync
mcrakhman Jan 27, 2025
7a50936
GO-4146 Update any-sync
mcrakhman Jan 27, 2025
75512f4
GO-4146 Merge remote-tracking branch 'refs/remotes/origin/main' into …
fat-fellow Jan 27, 2025
626b837
GO-4146 merge main
fat-fellow Jan 27, 2025
a3011cb
GO-4146: Migration: Disable network id check
deff7 Jan 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions account_stop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"method_name":"AccountStop","middle_time":0,"error_code":101,"description":"application is not running"}
750 changes: 413 additions & 337 deletions clientlibrary/service/service.pb.go

Large diffs are not rendered by default.

44 changes: 25 additions & 19 deletions cmd/debugtree/debugtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ import (
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"time"

"github.com/goccy/go-graphviz"
"github.com/gogo/protobuf/jsonpb"
"github.com/gogo/protobuf/proto"

"github.com/anyproto/anytype-heart/core/block/editor/state"
"github.com/anyproto/anytype-heart/core/debug/treearchive"
"github.com/anyproto/anytype-heart/core/debug/exporter"
"github.com/anyproto/anytype-heart/pkg/lib/core/smartblock"
"github.com/anyproto/anytype-heart/pkg/lib/pb/model"
"github.com/anyproto/anytype-heart/util/pbtypes"
Expand All @@ -42,22 +45,20 @@ func main() {
return
}
fmt.Println("opening file...")
st := time.Now()
archive, err := treearchive.Open(*file)
var (
st = time.Now()
ctx = context.Background()
)
res, err := exporter.ImportStorage(ctx, *file)
if err != nil {
log.Fatal("can't open debug file:", err)
log.Fatal("can't import the tree:", err)
}
defer archive.Close()
fmt.Printf("open archive done in %.1fs\n", time.Since(st).Seconds())

importer := treearchive.NewTreeImporter(archive.ListStorage(), archive.TreeStorage())
st = time.Now()
err = importer.Import(*fromRoot, "")
objectTree, err := res.CreateReadableTree(*fromRoot, "")
if err != nil {
log.Fatal("can't import the tree", err)
log.Fatal("can't create readable tree:", err)
}
fmt.Printf("import tree done in %.1fs\n", time.Since(st).Seconds())

fmt.Printf("open archive done in %.1fs\n", time.Since(st).Seconds())
importer := exporter.NewTreeImporter(objectTree)
if *makeJson {
treeJson, err := importer.Json()
if err != nil {
Expand All @@ -83,10 +84,11 @@ func main() {
}
fmt.Println("Change:")
fmt.Println(pbtypes.Sprint(ch.Model))
err = importer.Import(*fromRoot, ch.Id)
objectTree, err = res.CreateReadableTree(*fromRoot, ch.Id)
if err != nil {
log.Fatal("can't import the tree before", ch.Id, err)
log.Fatal("can't create readable tree:", err)
}
importer = exporter.NewTreeImporter(objectTree)
}
ot := importer.ObjectTree()
di, err := ot.Debug(state.ChangeParser{})
Expand Down Expand Up @@ -126,12 +128,16 @@ func main() {

if *objectStore {
fmt.Println("fetch object store info..")
ls, err := archive.LocalStore()
f, err := os.Open(filepath.Join(res.FolderPath, "localstore.json"))
if err != nil {
fmt.Println("can't open objectStore info:", err)
} else {
fmt.Println(pbtypes.Sprint(ls))
log.Fatal("can't open objectStore info:", err)
}
defer f.Close()
info := &model.ObjectInfo{}
if err = jsonpb.Unmarshal(f, info); err != nil {
log.Fatal("can't unmarshal objectStore info:", err)
}
fmt.Println(pbtypes.Sprint(info))
}

if *makeTree {
Expand Down
2 changes: 1 addition & 1 deletion cmd/grpcserver/performance.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func getTableSizes(mw *core.Middleware) (tables map[string]uint64) {
tables = make(map[string]uint64)
cfg := mw.GetApp().MustComponent(config.CName).(*config.Config)

db, err := sql.Open("sqlite3", cfg.GetSpaceStorePath())
db, err := sql.Open("sqlite3", cfg.GetSqliteStorePath())
if err != nil {
fmt.Println("Error opening database:", err)
return
Expand Down
31 changes: 31 additions & 0 deletions core/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/anyproto/anytype-heart/core/application"
"github.com/anyproto/anytype-heart/core/session"
"github.com/anyproto/anytype-heart/pb"
"github.com/anyproto/anytype-heart/space/spacecore/storage/migrator"
)

func (mw *Middleware) AccountCreate(cctx context.Context, req *pb.RpcAccountCreateRequest) *pb.RpcAccountCreateResponse {
Expand Down Expand Up @@ -49,6 +50,35 @@ func (mw *Middleware) AccountRecover(cctx context.Context, _ *pb.RpcAccountRecov
}
}

func (mw *Middleware) AccountMigrate(cctx context.Context, req *pb.RpcAccountMigrateRequest) *pb.RpcAccountMigrateResponse {
err := mw.applicationService.AccountMigrate(cctx, req)
code := mapErrorCode(err,
errToCode(application.ErrBadInput, pb.RpcAccountMigrateResponseError_BAD_INPUT),
errToCode(application.ErrAccountNotFound, pb.RpcAccountMigrateResponseError_ACCOUNT_NOT_FOUND),
errToCode(context.Canceled, pb.RpcAccountMigrateResponseError_CANCELED),
errTypeToCode(&migrator.NotEnoughFreeSpaceError{}, pb.RpcAccountMigrateResponseError_NOT_ENOUGH_FREE_SPACE),
)
return &pb.RpcAccountMigrateResponse{
Error: &pb.RpcAccountMigrateResponseError{
Code: code,
Description: getErrorDescription(err),
},
}
}

func (mw *Middleware) AccountMigrateCancel(cctx context.Context, req *pb.RpcAccountMigrateCancelRequest) *pb.RpcAccountMigrateCancelResponse {
err := mw.applicationService.AccountMigrateCancel(cctx, req)
code := mapErrorCode(err,
errToCode(application.ErrBadInput, pb.RpcAccountMigrateCancelResponseError_BAD_INPUT),
)
return &pb.RpcAccountMigrateCancelResponse{
Error: &pb.RpcAccountMigrateCancelResponseError{
Code: code,
Description: getErrorDescription(err),
},
}
}

func (mw *Middleware) AccountSelect(cctx context.Context, req *pb.RpcAccountSelectRequest) *pb.RpcAccountSelectResponse {
account, err := mw.applicationService.AccountSelect(cctx, req)
code := mapErrorCode(err,
Expand All @@ -64,6 +94,7 @@ func (mw *Middleware) AccountSelect(cctx context.Context, req *pb.RpcAccountSele
errToCode(application.ErrAnotherProcessIsRunning, pb.RpcAccountSelectResponseError_ANOTHER_ANYTYPE_PROCESS_IS_RUNNING),
errToCode(application.ErrIncompatibleVersion, pb.RpcAccountSelectResponseError_FAILED_TO_FETCH_REMOTE_NODE_HAS_INCOMPATIBLE_PROTO_VERSION),
errToCode(application.ErrFailedToStartApplication, pb.RpcAccountSelectResponseError_FAILED_TO_RUN_NODE),
errToCode(application.ErrAccountStoreIsNotMigrated, pb.RpcAccountSelectResponseError_ACCOUNT_STORE_NOT_MIGRATED),
)
return &pb.RpcAccountSelectResponse{
Config: nil,
Expand Down
3 changes: 1 addition & 2 deletions core/acl/aclservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/anyproto/any-sync/app"
"github.com/anyproto/any-sync/commonspace/acl/aclclient"
"github.com/anyproto/any-sync/commonspace/object/acl/list"
"github.com/anyproto/any-sync/commonspace/object/acl/liststorage"
"github.com/anyproto/any-sync/coordinator/coordinatorclient"
"github.com/anyproto/any-sync/coordinator/coordinatorproto"
"github.com/anyproto/any-sync/nodeconf"
Expand Down Expand Up @@ -392,7 +391,7 @@ func (a *aclService) ViewInvite(ctx context.Context, inviteCid cid.Cid, inviteFi
if len(recs) == 0 {
return domain.InviteView{}, fmt.Errorf("no acl records found for space: %s, %w", res.SpaceId, ErrAclRequestFailed)
}
store, err := liststorage.NewInMemoryAclListStorage(recs[0].Id, recs)
store, err := list.NewInMemoryStorage(recs[0].Id, recs)
if err != nil {
return domain.InviteView{}, convertedOrAclRequestError(err)
}
Expand Down
15 changes: 15 additions & 0 deletions core/anytype/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,12 @@ import (
"github.com/anyproto/anytype-heart/space/spacecore/clientserver"
"github.com/anyproto/anytype-heart/space/spacecore/credentialprovider"
"github.com/anyproto/anytype-heart/space/spacecore/localdiscovery"
"github.com/anyproto/anytype-heart/space/spacecore/oldstorage"
"github.com/anyproto/anytype-heart/space/spacecore/peermanager"
"github.com/anyproto/anytype-heart/space/spacecore/peerstore"
"github.com/anyproto/anytype-heart/space/spacecore/storage"
"github.com/anyproto/anytype-heart/space/spacecore/storage/migrator"
"github.com/anyproto/anytype-heart/space/spacecore/storage/migratorfinisher"
"github.com/anyproto/anytype-heart/space/spacecore/typeprovider"
"github.com/anyproto/anytype-heart/space/spacefactory"
"github.com/anyproto/anytype-heart/space/virtualspaceservice"
Expand Down Expand Up @@ -208,6 +211,18 @@ func appVersion(a *app.App, clientWithVersion string) string {
return clientWithVersion + "/middle:" + middleVersion + "/any-sync:" + anySyncVersion
}

func BootstrapMigration(a *app.App, components ...app.Component) {
for _, c := range components {
a.Register(c)
}
a.Register(migratorfinisher.New()).
Register(clientds.New()).
Register(oldstorage.New()).
Register(storage.New()).
Register(process.New()).
Register(migrator.New())
}

func Bootstrap(a *app.App, components ...app.Component) {
for _, c := range components {
a.Register(c)
Expand Down
23 changes: 20 additions & 3 deletions core/anytype/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const (
const (
SpaceStoreBadgerPath = "spacestore"
SpaceStoreSqlitePath = "spaceStore.db"
SpaceStoreNewPath = "spaceStoreNew"
)

var (
Expand All @@ -69,6 +70,7 @@ type Config struct {
DisableThreadsSyncEvents bool
DontStartLocalNetworkSyncAutomatically bool
PeferYamuxTransport bool
DisableNetworkIdCheck bool
SpaceStorageMode storage.SpaceStorageMode
NetworkMode pb.RpcAccountNetworkMode
NetworkCustomConfigFilePath string `json:",omitempty"` // not saved to config
Expand Down Expand Up @@ -293,12 +295,27 @@ func (c *Config) FSConfig() (FSConfig, error) {
return FSConfig{IPFSStorageAddr: res.CustomFileStorePath}, nil
}

func (c *Config) GetRepoPath() string {
return c.RepoPath
}

func (c *Config) GetConfigPath() string {
return filepath.Join(c.RepoPath, ConfigFileName)
}

func (c *Config) GetSpaceStorePath() string {
return filepath.Join(c.RepoPath, "spaceStore.db")
func (c *Config) GetSqliteStorePath() string {
return filepath.Join(c.RepoPath, SpaceStoreSqlitePath)
}

func (c *Config) GetOldSpaceStorePath() string {
if c.GetSpaceStorageMode() == storage.SpaceStorageModeBadger {
return filepath.Join(c.RepoPath, SpaceStoreBadgerPath)
}
return c.GetSqliteStorePath()
}

func (c *Config) GetNewSpaceStorePath() string {
return filepath.Join(c.RepoPath, SpaceStoreNewPath)
}

func (c *Config) GetTempDirPath() string {
Expand Down Expand Up @@ -391,7 +408,7 @@ func (c *Config) GetNodeConfWithError() (conf nodeconf.Configuration, err error)
if err := yaml.Unmarshal(confBytes, &conf); err != nil {
return nodeconf.Configuration{}, errors.Join(ErrNetworkFileFailedToRead, err)
}
if c.NetworkId != "" && c.NetworkId != conf.NetworkId {
if !c.DisableNetworkIdCheck && c.NetworkId != "" && c.NetworkId != conf.NetworkId {
log.Warnf("Network id mismatch: %s != %s", c.NetworkId, conf.NetworkId)
return nodeconf.Configuration{}, errors.Join(ErrNetworkIdMismatch, fmt.Errorf("network id mismatch: %s != %s", c.NetworkId, conf.NetworkId))
}
Expand Down
14 changes: 11 additions & 3 deletions core/application/account_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,23 @@ var (
ErrNoMnemonicProvided = errors.New("no mnemonic provided")
ErrIncompatibleVersion = errors.New("can't fetch account's data because remote nodes have incompatible protocol version. Please update anytype to the latest version")

ErrAnotherProcessIsRunning = errors.New("another anytype process is running")
ErrFailedToFindAccountInfo = errors.New("failed to find account info")
ErrAccountIsDeleted = errors.New("account is deleted")
ErrAnotherProcessIsRunning = errors.New("another anytype process is running")
ErrFailedToFindAccountInfo = errors.New("failed to find account info")
ErrAccountIsDeleted = errors.New("account is deleted")
ErrAccountStoreIsNotMigrated = errors.New("account store is not migrated")
)

func (s *Service) AccountSelect(ctx context.Context, req *pb.RpcAccountSelectRequest) (*model.Account, error) {
if req.Id == "" {
return nil, ErrEmptyAccountID
}
curMigration := s.migrationManager.getOrCreateMigration(req.RootPath, req.Id)
if !curMigration.successful() {
return nil, ErrAccountStoreIsNotMigrated
}
if s.migrationManager.isRunning() {
return nil, ErrMigrationRunning
}

if runtime.GOOS != "android" && runtime.GOOS != "ios" {
s.traceRecorder.start()
Expand Down
Loading
Loading