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

Use pika's codis implementation #1754

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
#Please look at Pika's codis, current repo's codis' etcd is "broken". Use pika's codis until further notice.
https://github.com/OpenAtomFoundation/pika


TODO
1. faster connection using redhub
2. higher throughput, lower latency and to maintain professionally.

<img src="doc/pictures/logo-3.png" height=80></img>

[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/CodisLabs/codis?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
Expand Down
13 changes: 13 additions & 0 deletions pkg/models/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,19 @@ func (s *Store) Release() error {
return s.client.Delete(s.LockPath())
}

func (s *Store) ReleaseByToken(token string) error {
if b, err := s.client.Read(s.LockPath(), false); err != nil {
return err
} else if b != nil {
if t, err := Decode(b); err != nil {
return err
} else if t.Token == token {
return s.Release()
}
}
return nil
}

func (s *Store) LoadTopom(must bool) (*Topom, error) {
return LoadTopom(s.client, s.product, must)
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/models/topom.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ type Topom struct {
func (t *Topom) Encode() []byte {
return jsonEncode(t)
}

func Decode(b []byte) (*Topom, error) {
s := &Topom{}
if err := jsonDecode(s, b); err != nil {
return nil, err
}
return s, nil
}
2 changes: 1 addition & 1 deletion pkg/topom/topom.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (s *Topom) Close() error {
defer s.store.Close()

if s.online {
if err := s.store.Release(); err != nil {
if err := s.store.ReleaseByToken(s.model.Token); err != nil {
log.ErrorErrorf(err, "store: release lock of %s failed", s.config.ProductName)
return errors.Errorf("store: release lock of %s failed", s.config.ProductName)
}
Expand Down