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

global db support #55

Merged
merged 4 commits into from
Jul 19, 2024
Merged

global db support #55

merged 4 commits into from
Jul 19, 2024

Conversation

ice-cronus
Copy link
Contributor

No description provided.

wip globaldb
@ice-cronus ice-cronus requested a review from a team as a code owner July 19, 2024 07:01
)

const (
globalDBYamlKey = "$wintr/connectors/storage/v2"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's with the '$' ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have in some configs global key wintr/connectors/storage/v2 for tenant-db and then it is used in modules by anchor, it'll be duplicated. So it is to separate them or we have to include it in every module

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand; give me an example

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@ice-ares ice-ares Jul 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i see. Then lets make it explicit, :

global: 
   wintr/connectors/storage/v2:
    ...

var cfg storageCfg
appcfg.MustLoadFromKey(globalDBYamlKey, &cfg)
if cfg.PrimaryURL != "" {
initGlobalDBCtx, cancel := context.WithTimeout(context.Background(), 30*stdlibtime.Second) //nolint:gomnd,mnd // .
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use background cuz otherwise pool will close in 30 secs

func init() {
var cfg storageCfg
appcfg.MustLoadFromKey(globalDBYamlKey, &cfg)
if cfg.PrimaryURL != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or len replicas > 0

}
}

func GlobalDB() *DB {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we dont do this and we just use it of its != nil. Wherever a *DB is needed check if u can use the globalDB instead.

And in case of MustConnect, u can just run the ddl on the globalDB

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here could be an issue probably if some package will use both tenant and global db. We dont have them rn, but probably would be an issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we need some kind on flag at least like

MustConnect(ctx context.Context, ddl, applicationYAMLKey string, global ...bool) *DB {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no; we`ll use one or the other; with globalDB having priority and being used if its !=nil

func MustConnect(ctx context.Context, ddl, applicationYAMLKey string) *DB {
var cfg config
appcfg.MustLoadFromKey(applicationYAMLKey, &cfg)
if globalDB != nil && cfg.WintrStorage.PrimaryURL == "" && len(cfg.WintrStorage.ReplicaURLs) == 0 && !cfg.WintrStorage.RunDDL {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, only if globalDB != nil

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll have issue with coin distribution and tokenomics. As var is global, coin distiribution will try to use global db as well, it seems to be unexpected, but tokenomics uses global for boosts

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, add a flag in the cfg named ignoreGlobal which if set to true, will use the package level connector

@ice-ares
Copy link
Contributor

Btw, make sure close() is idempotent. Cuz it will be run multiple times

@ice-ares ice-ares merged commit b0b5afa into master Jul 19, 2024
24 checks passed
@ice-ares ice-ares deleted the feature/global_db branch July 19, 2024 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants