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

util/kvencoder: use reference count to keep single domain instance #7094

Merged
merged 3 commits into from
Jul 19, 2018

Conversation

tiancaiamao
Copy link
Contributor

What have you changed? (mandatory)

BootstrapSession should not be called many times and we should keep
just a single domain instance

What is the type of the changes? (mandatory)

  • Improvement (non-breaking change which is an improvement to an existing feature)

How has this PR been tested? (mandatory)

unit test

@winkyao

BootstrapSession should not be called many times and we should keep
just a single domain instance
}

// New new a KvEncoder
func New(dbName string, idAlloc autoid.Allocator) (KvEncoder, error) {
kvEnc := &kvEncoder{}
if atomic.LoadInt64(&refCount) == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

how about CAS(0, 1)?

Copy link
Member

Choose a reason for hiding this comment

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

Or just hold a lock during initGlobal?

}
if domGlobal != nil {
domGlobal.Close()
}
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

return error instead of nil?

@tiancaiamao
Copy link
Contributor Author

PTAL @coocood @holys

@@ -77,27 +78,48 @@ type KvEncoder interface {
Close() error
}

var (
// refCount is used to ensure that there is only one domain.Domain instance.
refCount int64
Copy link
Member

Choose a reason for hiding this comment

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

can we remove refCount? seems we can use domGlobal != nil to replace?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, we can't

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When refCount decrease to 0, we set domGlobal = nil

Copy link
Member

Choose a reason for hiding this comment

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

So refCount == 0 is equal to domGolbal == 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.

Nope

@zz-jason
Copy link
Member

@tiancaiamao Please add some proper labels for this PR.

Copy link
Contributor

@winkyao winkyao left a comment

Choose a reason for hiding this comment

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

LGTM

@coocood
Copy link
Member

coocood commented Jul 19, 2018

LGTM

@coocood coocood added the status/LGT2 Indicates that a PR has LGTM 2. label Jul 19, 2018
@coocood
Copy link
Member

coocood commented Jul 19, 2018

/run-all-tests

@holys
Copy link
Contributor

holys commented Jul 19, 2018

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/tools status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants