Skip to content

loose coupling MongoDB #80

@hellodword

Description

@hellodword

Have you read a contributing guide?

  • I have read CONTRIBUTING.md
  • I have searched the existing requests and didn't find any that were similar
  • I have considered creating a pull request instead and want to proceed

Clear and concise description of the problem

Db() *mongo.Database
Tx(ctx context.Context, f func(txCtx mongo.SessionContext) error) error

mongo is used in many parts of the project's source code:

https://github.com/search?q=repo%3Aanyproto%2Fany-sync-coordinator+%2Fmongo%2F+language%3AGo+NOT+path%3A%2F%5Edb%5C%2F%2F&type=code

Suggested solution

Same with the consensusnode It's much better in the consensusnode: https://github.com/anyproto/any-sync-consensusnode/blob/40bce1dbff2598befc37ad0c5a8fc16094f6a68d/db/db.go#L27-L40

I believe it is better to extend the interface and abstract mongo within the database layer. This would make it easier for both users and developers to add and use other databases.

For example, in my expected use case, which is a personal self-hosted environment, mongo is too heavy, it'll be great if we can add some lightweight or embedded database.

$ docker compose stats --no-stream --format "table {{.Name}}\t{{.MemUsage}}"
NAME                                                 MEM USAGE
any-sync-dockercompose-netcheck-1                    19.05MiB
any-sync-dockercompose-any-sync-node-1-1             31.32MiB
any-sync-dockercompose-any-sync-filenode-1           43.5MiB
any-sync-dockercompose-any-sync-consensusnode-1      33.27MiB
any-sync-dockercompose-any-sync-coordinator-1        35.17MiB

any-sync-dockercompose-generateconfig-processing-1   20.54MiB
any-sync-dockercompose-generateconfig-anyconf-1      25.71MiB

any-sync-dockercompose-any-sync-node-3-1             31.77MiB
any-sync-dockercompose-any-sync-node-2-1             32MiB
any-sync-dockercompose-minio-1                       183.1MiB
any-sync-dockercompose-mongo-1-1                     308.5MiB
any-sync-dockercompose-redis-1                       26.3MiB

Alternative

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions