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

Edge trigger node updates #3873

Merged
merged 8 commits into from
Mar 1, 2018
Merged

Edge trigger node updates #3873

merged 8 commits into from
Mar 1, 2018

Conversation

chelseakomlo
Copy link
Contributor

@chelseakomlo chelseakomlo commented Feb 14, 2018

Refactor to move client update node mechanism to be edge triggered instead of periodic.

See here for original comment: #3781 (diff)

@chelseakomlo chelseakomlo changed the title [WIP] Edge trigger node updates Edge trigger node updates Feb 16, 2018
client/client.go Outdated

var nodeHasChanged bool

for name, new_val := range response.Attributes {
Copy link
Contributor

Choose a reason for hiding this comment

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

Go style would be newVal

if first.IOPS != second.IOPS {
return false
}
if len(first.Networks) != len(second.Networks) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This just checks the length?

client/client.go Outdated
// watchNodeUpdates blocks until it is edge triggered. Once triggered,
// it will update the client node copy and re-register the node.
func (c *Client) watchNodeUpdates() {
c.logger.Printf("[DEBUG] client: starting process to watch for node updates.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove

if changed, _, _ := c.hasNodeChanged(attrHash, metaHash); changed {
t.Fatalf("Unexpected hash change.")
}
// these constants are only defined when nomad_test is enabled, so these fail
Copy link
Contributor

Choose a reason for hiding this comment

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

I fixed that so the comment isn't accurate and you probably don't need the nolint

go c1.watchNodeUpdates()
c1.updateNode()
// This needs to be directly called as otherwise the client hangs on
// attempt to register with a server. S[ecifically, retryRegisterNode is
Copy link
Contributor

Choose a reason for hiding this comment

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

Spelling error

// attempt to register with a server. S[ecifically, retryRegisterNode is
// blocking

// test that the client's copy of the node is also updated
Copy link
Contributor

Choose a reason for hiding this comment

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

Capitalize the start of your comments


err := fm.Run()
require.Nil(err)
require.NotEqual(0, node.Resources.CPU)
Copy link
Contributor

Choose a reason for hiding this comment

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

NotZero

client/client.go Outdated
@@ -1506,6 +1517,9 @@ func (c *Client) watchNodeUpdates(attrHash, metaHash uint64) {

c.retryRegisterNode()
Copy link
Contributor

Choose a reason for hiding this comment

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

IIUC, If this retryRegister method returns without registering because it timed out, it won't try again until the next node update comes through triggerNodeUpdate. Is that desirable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dadgar and I talked about this. The node should be registered before watching for updates and the functionality that comes below, if I'm understanding this comment correctly.

client/client.go Outdated
@@ -209,6 +212,7 @@ func NewClient(cfg *config.Config, consulCatalog consul.CatalogAPI, consulServic
allocUpdates: make(chan *structs.Allocation, 64),
shutdownCh: make(chan struct{}),
triggerDiscoveryCh: make(chan struct{}),
triggerNodeUpdate: make(chan struct{}, 64),
Copy link
Contributor

Choose a reason for hiding this comment

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

I would drop to like 8

client/client.go Outdated
return false
}
f := second.Networks[i]
if e != f {
Copy link
Contributor

Choose a reason for hiding this comment

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

This comparison is a pointer comparison and not a value comparison?

client/client.go Outdated

hasChanged = false
syncTicker.Stop()
syncTicker = time.NewTicker(c.retryIntv(nodeUpdateRetryIntv))
Copy link
Contributor

Choose a reason for hiding this comment

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

Use a timer and reset

// our linter without explicit disabling.
c1 := TestClient(t, func(c *config.Config) {
c.Options = map[string]string{
driver.ShutdownPeriodicAfter: "true", // nolint: varcheck
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't need the nolint

client/client.go Outdated
hasChanged = false
timer.Reset(c.retryIntv(nodeUpdateRetryIntv))
case <-c.triggerNodeUpdate:
hasChanged = true
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not put all timer logic in this case and then remove the if statement at the top of the timer case and the reset at the bottom:

case <-c.triggerNodeUpdate:
  if hasChanged {
     continue
  }
  hasChanged = true
  timer.Reset(c.retryIntv(nodeUpdateRetryIntv))

client/client.go Outdated
c.logger.Printf("[DEBUG] client: state changed, updating node.")
case <-timer.C:
if !hasChanged {
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

Right now this code could never fire even if there is a node update

@chelseakomlo chelseakomlo merged commit a17690c into master Mar 1, 2018
@chelseakomlo chelseakomlo deleted the r-edge-trigger-node-watcher branch March 1, 2018 20:19
@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants