Skip to content

Use connection pool in golibmc(again)#57

Merged
windreamer merged 48 commits intodouban:masterfrom
jumpeiMano:feature/connection-pool
Nov 16, 2017
Merged

Use connection pool in golibmc(again)#57
windreamer merged 48 commits intodouban:masterfrom
jumpeiMano:feature/connection-pool

Conversation

@jumpeiMano
Copy link
Contributor

@jumpeiMano jumpeiMano commented Nov 4, 2017

#54

Since I was to close the previous PR, I made a new PR.
I'm so sorry, but please confirm this!

Thanks.

@mckelvin
Copy link
Contributor

mckelvin commented Nov 6, 2017

@windreamer @ariesdevil Would you please review this PR?

@windreamer
Copy link
Contributor

@MOON-CLJ

src/golibmc.go Outdated
func (client *Client) putConn(cn *conn, err error) error {
client.lk.Lock()
if err == ErrBadConn ||
!client.putConnLocked(cn, nil) {
Copy link
Contributor

Choose a reason for hiding this comment

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

prefer one more tab indent

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made it to write on one line.
13e0dc5

Copy link
Contributor

Choose a reason for hiding this comment

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

got

errCode := C.client_quit(cn._imp)
C.client_destroy_broadcast_result(cn._imp)
err := networkError(errorMessage[errCode])
if isBadConnErr(err) {
Copy link
Contributor

@MOON-CLJ MOON-CLJ Nov 14, 2017

Choose a reason for hiding this comment

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

isBadConnErr => isNetworkError ?

the meanings of "badConn" term that i used is different from ErrBadConn https://github.com/douban/libmc/pull/57/files#diff-b21c9a32b7563e26c49d7f215bc5a656R87

Copy link
Contributor

Choose a reason for hiding this comment

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

okay, i see。 you want to put ErrBadConn together with all networkErrors,i am ok with this. ignore the above comment。

src/golibmc.go Outdated
if isBadConnErr(err) {
cn.client.lk.Lock()
defer cn.client.lk.Unlock()
cn.client.numOpen--
Copy link
Contributor

Choose a reason for hiding this comment

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

"cn.client.numOpen--" may need to put out of the "if isBadConnErr(err)" block,so quit will cause "cn.client.numOpen--". how do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh...surely...
Thank you, fixed.
ff59967


errCode := C.client_quit(client._imp)
C.client_destroy_broadcast_result(client._imp)
close(client.openerCh)
Copy link
Contributor

Choose a reason for hiding this comment

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

may close twice, check closed = true first?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's right. Fixed.
27ed975

return err
}
client.lk.Unlock()
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

the err returned is not used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, putConn () is mostly called from defer. How do you think it will be better?

return cn.createdAt.Add(timeout).Before(time.Now())
}

func (cn *conn) quit() error {
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. since quit is called internal and there is nothing todo but logging, maybe quit can log inside and not return err?
  2. numOpen should always -- ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Some use err in upstream processing like this..
  2. Fixed, thanks.
    ff59967

retryTimeout C.int
lk sync.Mutex
freeConns []*conn
numOpen int
Copy link
Contributor

Choose a reason for hiding this comment

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

better expose some counters to watch the stat of the pool

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a difficult problem. If user update their values after I expose, the behavior of the connection pool can be crazy. For example, it seems that database/sql is not disclosed. How do you think about it?
https://github.com/golang/go/blob/master/src/database/sql/sql.go#L319-L347

src/golibmc.go Outdated
}
client.lk.Lock()
defer client.lk.Unlock()
if !client.putConnLocked(cn, err) {
Copy link
Contributor

Choose a reason for hiding this comment

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

client.putConnLocked(cn, err) => client.putConnLocked(cn, nil)

maybe more clear

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed. Fixed.
250812d

src/golibmc.go Outdated
if !ok {
return nil, ErrMemcachedClosed
}
return ret.conn, nil
Copy link
Contributor

@MOON-CLJ MOON-CLJ Nov 14, 2017

Choose a reason for hiding this comment

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

should comment at least if here assume that ret.err is 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.

Well... I made it return ret.err.
c1060ec

src/golibmc.go Outdated
client.closed = true
client.lk.Unlock()
for _, cn := range client.freeConns {
if err := cn.quit(); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

suppose caller would always handle the err and call Quit again?
Or just go on to free them all ignoring the err (hold and return at last )?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. I think that ignoring the quit error is better. Fixed.
aba5a7b

src/golibmc.go Outdated
}
client.lk.Lock()
if !client.putConnLocked(cn, nil) {
client.numOpen--
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, thanks. Done.
ffa9660

@MOON-CLJ
Copy link
Contributor

LGTM, thank you for very wonderful work。

@MOON-CLJ
Copy link
Contributor

cc @windreamer

@windreamer windreamer merged commit 9e68117 into douban:master Nov 16, 2017
@jumpeiMano
Copy link
Contributor Author

Ohhhhh! Thank you so much for your review!

@jumpeiMano jumpeiMano deleted the feature/connection-pool branch September 22, 2018 10:33
tclh123 added a commit that referenced this pull request Feb 18, 2019
ChangeLog:

- use pickle protocol version 2 (#52)
- fix rvalue reference (#53)
- Fix tests (#55)
- golibmc_test: Fix fragile test case (#56)
- Use connection pool in golibmc(again) (#57)
- golibmc Quit ret err (#59)
- cmake: Incorporate gtest in a standard way (#58)
- Rename refactor (#60)
- sync rapidjson/itoa.h upstream fix (#65)
- split cppcheck (#67)
- split FSM_GET_BYTES_CAS (#68)
- Avoid noisy recv_err when broadcast quit (#73)
- Try to support updating some servers without affecting others (#74)
- make normalize_key cpdef & add warnings for unpickle unmarshal fail (#66)
- fix fcntl usage when set socket nonblock (#69)
- minor fix (#61)
- add condition log macro (#77)
- Define and use notWaitForRetryTimeout (#82)
- upgrade travis to gcc 7 (#91)
- add func errCodeToString (#79)
- Introduce a reconnect mechanism in waitPoll (#88)
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.

6 participants