MCPcopy Index your code
hub / github.com/CodisLabs/codis / lockFs

Method lockFs

pkg/models/fs/fsclient.go:67–96  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

65}
66
67func (c *Client) lockFs() error {
68 if c.lockfd != nil {
69 return errors.Errorf("lock again")
70 }
71 if err := mkdirFor(c.LockFile); err != nil {
72 return err
73 }
74 f, err := os.OpenFile(c.LockFile, os.O_WRONLY|os.O_CREATE, 0644)
75 if err != nil {
76 return errors.Trace(err)
77 }
78 if err := syscall.Flock(int(f.Fd()), syscall.LOCK_EX|syscall.LOCK_NB); err != nil {
79 f.Close()
80 return errors.Trace(err)
81 }
82 var data = map[string]interface{}{
83 "pid": os.Getpid(),
84 "now": time.Now().String(),
85 }
86 b, err := json.MarshalIndent(data, "", " ")
87 if err != nil {
88 log.WarnErrorf(err, "fsclient - lock encode json failed")
89 } else if err := f.Truncate(0); err != nil {
90 log.WarnErrorf(err, "fsclient - lock truncate failed")
91 } else if _, err := f.Write(b); err != nil {
92 log.WarnErrorf(err, "fsclient - lock write failed")
93 }
94 c.lockfd = f
95 return nil
96}
97
98func (c *Client) unlockFs() {
99 if c.lockfd == nil {

Callers 5

CreateMethod · 0.95
UpdateMethod · 0.95
DeleteMethod · 0.95
ReadMethod · 0.95
ListMethod · 0.95

Calls 6

mkdirForFunction · 0.85
ErrorfMethod · 0.80
WarnErrorfMethod · 0.80
CloseMethod · 0.65
StringMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected