-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Conversation
BootstrapSession should not be called many times and we should keep just a single domain instance
util/kvencoder/kv_encoder.go
Outdated
} | ||
|
||
// New new a KvEncoder | ||
func New(dbName string, idAlloc autoid.Allocator) (KvEncoder, error) { | ||
kvEnc := &kvEncoder{} | ||
if atomic.LoadInt64(&refCount) == 0 { |
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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?
util/kvencoder/kv_encoder.go
Outdated
} | ||
if domGlobal != nil { | ||
domGlobal.Close() | ||
} | ||
return nil |
There was a problem hiding this comment.
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?
@@ -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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we can't
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope
@tiancaiamao Please add some proper labels for this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
LGTM |
/run-all-tests |
LGTM |
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)
How has this PR been tested? (mandatory)
unit test
@winkyao