-
Notifications
You must be signed in to change notification settings - Fork 260
Store fixes; Windows compile #247
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| // Copyright 2017 Microsoft. All rights reserved. | ||
| // MIT License | ||
|
|
||
| // +build linux | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this work? I thought it had to be above header?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Certainly does in 1.11
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| package netlink | ||
|
|
||
| import ( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| // Copyright 2017 Microsoft. All rights reserved. | ||
| // MIT License | ||
|
|
||
| // +build linux | ||
|
|
||
| package netlink | ||
|
|
||
| import ( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| // Copyright 2017 Microsoft. All rights reserved. | ||
| // MIT License | ||
|
|
||
| // +build linux | ||
|
|
||
| package netlink | ||
|
|
||
| import ( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| // Copyright 2017 Microsoft. All rights reserved. | ||
| // MIT License | ||
|
|
||
| // +build linux | ||
|
|
||
| package netlink | ||
|
|
||
| import ( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| // Copyright 2017 Microsoft. All rights reserved. | ||
| // MIT License | ||
|
|
||
| package netlink |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| // Copyright 2017 Microsoft. All rights reserved. | ||
| // MIT License | ||
|
|
||
| // +build linux | ||
|
|
||
| package netlink | ||
|
|
||
| import ( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| // Copyright 2017 Microsoft. All rights reserved. | ||
| // MIT License | ||
|
|
||
| // +build linux | ||
|
|
||
| package netlink | ||
|
|
||
| import ( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,6 @@ | ||
| // Copyright 2017 Microsoft. All rights reserved. | ||
| // MIT License | ||
|
|
||
| // +build linux | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we rename? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh you are just doing this because its already included by default via the naming?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was just being consistent with what's there. |
||
|
|
||
| package network | ||
|
|
||
| import ( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,6 @@ | ||
| // Copyright 2017 Microsoft. All rights reserved. | ||
| // MIT License | ||
|
|
||
| // +build windows | ||
|
|
||
| package network | ||
|
|
||
| import ( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| package epcommon |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,6 @@ | ||
| // Copyright 2017 Microsoft. All rights reserved. | ||
| // MIT License | ||
|
|
||
| // +build linux | ||
|
|
||
| package network | ||
|
|
||
| import ( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,6 @@ | ||
| // Copyright 2017 Microsoft. All rights reserved. | ||
| // MIT License | ||
|
|
||
| // +build linux | ||
|
|
||
| package network | ||
|
|
||
| import ( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,6 @@ | ||
| // Copyright 2017 Microsoft. All rights reserved. | ||
| // MIT License | ||
|
|
||
| // +build windows | ||
|
|
||
| package network | ||
|
|
||
| import ( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,10 +21,10 @@ const ( | |
| lockExtension = ".lock" | ||
|
|
||
| // Maximum number of retries before failing a lock call. | ||
| lockMaxRetries = 20 | ||
| lockMaxRetries = 200 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any reason changing this to 200?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The timeout (2s) was woefully small. 20 seconds is still reasonably low. Arguably, there should be no need whatsoever for a timeout in a correctly operating system. In fact, in a subsequent change I have which removes the store entirely and moves this to boltdb, there is no timeout.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok |
||
|
|
||
| // Delay between lock retries. | ||
| lockRetryDelayInMilliseconds = 100 | ||
| lockRetryDelay = 100 * time.Millisecond | ||
| ) | ||
|
|
||
| // jsonFileStore is an implementation of KeyValueStore using a local JSON file. | ||
|
|
@@ -61,27 +61,22 @@ func (kvs *jsonFileStore) Read(key string, value interface{}) error { | |
| file, err := os.Open(kvs.fileName) | ||
| if err != nil { | ||
| if os.IsNotExist(err) { | ||
| return nil | ||
| return ErrKeyNotFound | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not breaking anything right when CNI/CNM called first time on boot up when there is no state file.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, but it's a question of correctness, not obfuscation. The store package should behave and return errors as expected - a read of something which doesn't exist should return a not-found error.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah I got it. I'm just making sure we tested that scenario? |
||
| } | ||
| return err | ||
| } | ||
| defer file.Close() | ||
|
|
||
| // Decode to raw JSON messages. | ||
| err = json.NewDecoder(file).Decode(&kvs.data) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| err = file.Close() | ||
| if err != nil { | ||
| if err := json.NewDecoder(file).Decode(&kvs.data); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| kvs.inSync = true | ||
| } | ||
|
|
||
| raw := kvs.data[key] | ||
| if raw == nil { | ||
| raw, ok := kvs.data[key] | ||
| if !ok { | ||
| return ErrKeyNotFound | ||
| } | ||
|
|
||
|
|
@@ -118,18 +113,17 @@ func (kvs *jsonFileStore) flush() error { | |
| if err != nil { | ||
| return err | ||
| } | ||
| defer file.Close() | ||
|
|
||
| buf, err := json.MarshalIndent(&kvs.data, "", "\t") | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| _, err = file.Write(buf) | ||
| if err != nil { | ||
| if _, err := file.Write(buf); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return file.Close() | ||
| return nil | ||
| } | ||
|
|
||
| // Lock locks the store for exclusive access. | ||
|
|
@@ -153,21 +147,20 @@ func (kvs *jsonFileStore) Lock(block bool) error { | |
| break | ||
| } | ||
|
|
||
| if !block || i == lockMaxRetries { | ||
| return ErrStoreLocked | ||
| if !block { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again not your code. But a better pattern would be to have:
|
||
| return ErrNonBlockingLockIsAlreadyLocked | ||
| } | ||
|
|
||
| time.Sleep(time.Duration(lockRetryDelayInMilliseconds) * time.Millisecond) | ||
| } | ||
| if i == lockMaxRetries { | ||
| return ErrTimeoutLockingStore | ||
| } | ||
|
|
||
| // Write the process ID for easy identification. | ||
| _, err = lockFile.WriteString(strconv.Itoa(os.Getpid())) | ||
| if err != nil { | ||
| return err | ||
| time.Sleep(lockRetryDelay) | ||
| } | ||
| defer lockFile.Close() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how defer works in a loop . Just clarifying if open called multiple times and is close getting called for each open?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The defer of close is outside the loop.... It's only called at function exit, and only in the case that the open succeeded.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry! I missed it |
||
|
|
||
| err = lockFile.Close() | ||
| if err != nil { | ||
| // Write the process ID for easy identification. | ||
| if _, err = lockFile.WriteString(strconv.Itoa(os.Getpid())); err != nil { | ||
| return err | ||
| } | ||
|
|
||
|
|
@@ -198,9 +191,12 @@ func (kvs *jsonFileStore) Unlock() error { | |
|
|
||
| // GetModificationTime returns the modification time of the persistent store. | ||
| func (kvs *jsonFileStore) GetModificationTime() (time.Time, error) { | ||
| kvs.Mutex.Lock() | ||
| defer kvs.Mutex.Unlock() | ||
|
|
||
| info, err := os.Stat(kvs.fileName) | ||
| if err != nil { | ||
| log.Printf("os.stat() for file %v failed with error %v", kvs.fileName, err) | ||
| log.Printf("os.stat() for file %v failed: %v", kvs.fileName, err) | ||
| return time.Time{}.UTC(), err | ||
| } | ||
|
|
||
|
|
||
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.
@jhowardmsft - I know its not you but typically no punctuation across other golang projects.
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.
Also. Typically the "[cni]" portion would be done via a logrus context or equivalent. (Again just FYI)
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.
Yeah, but I'm not changing the world here :)