Skip to content
This repository has been archived by the owner on Oct 17, 2018. It is now read-only.

Dgromov/update handlers #69

Closed
wants to merge 3 commits into from
Closed

Dgromov/update handlers #69

wants to merge 3 commits into from

Conversation

dgromov
Copy link
Contributor

@dgromov dgromov commented Jul 6, 2017

No description provided.

@dgromov dgromov requested review from cw9 and xichen2020 July 6, 2017 03:21
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 88.599% when pulling ef62f1f on dgromov/update_handlers into 6cabb14 on master.

@@ -39,6 +44,8 @@ imports:
- process
- time
- watch
- name: github.com/pborman/uuid
Copy link
Contributor

Choose a reason for hiding this comment

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

Ping this in glide.yaml?

)

// Namespaces returns the version and the persisted namespaces in kv store.
// Namespaces returns the version ad the persisted namespaces in kv store.
Copy link
Contributor

Choose a reason for hiding this comment

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

ad -> and

@@ -86,3 +89,97 @@ func Namespace(namespaces *schema.Namespaces, namespaceName string) (*schema.Nam

return namespace, nil
}

// CreateNamespace creates a blank namespace with a given name.
func CreateNamespace(store kv.TxnStore,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I usually prefer to format function declarations as

func CreateNamespace(
  store kv.TxnStore,
  namespaceKey, namespaceName, ruleSetKey string,
  propagationDelay time.Duration,
) error {
  ...
}

feels a bit easier to read

// CreateNamespace creates a blank namespace with a given name.
func CreateNamespace(store kv.TxnStore,
namespaceKey, namespaceName, ruleSetKey string,
propDelay time.Duration) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

It might make sense to make these standalone methods member functions of a handler struct so you don't need to always pass store or propDelay around, instead they'll be stored in the handler object after creation, e.g., something like

type HandlerOptions struct {
  PropagationDelay time.Duration
}

type Handler struct {
   store kv.TxnStore
   opts HandlerOptions
   ...
}

func NewHandler(store kv.TxnStore, opts HandlerOptions) Handler {
   return Handler{store: store, opts: opts}
}

func (h Handler) CreateNamespace(key, name, ruleSetKey string) error {
   // use h.store and h.opts.PropagationDelay here
   ...
}

if err != nil {
if err == errMultipleMatches {
return kv.ErrAlreadyExists
} else if err != kv.ErrNotFound {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: a bit cleaner and less nesting to write

if err == errMultipleMatches {
  return kv.ErrAlreadyExists
}
if err != nil && err != kv.ErrNotFound {
  return err
}


// A rule with no snapshots should not be added.
if m.Snapshots == nil {
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be an error. Also if you are already checking the length below, you don't need this.


ls := len(m.Snapshots)
if ls == 0 {
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

Should probably be an error.

continue
}

lastSnap := m.Snapshots[ls-1]
Copy link
Contributor

Choose a reason for hiding this comment

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

lastSnapshot is probably a better name.

}
}

for _, r := range diff.RollupRules {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this function is pretty long. Might make sense to break this function into two smaller functions applyMappingRuleChanges and applyRollupRuleChanges.

}

// AppendToRuleSet appends a ruleset diff onto the end of a ruleset
func appendToRuleSet(orig, diff *schema.RuleSet) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

applyRuleChanges might be a better name.

@dgromov dgromov closed this Jul 26, 2017
@dgromov
Copy link
Contributor Author

dgromov commented Jul 26, 2017

Closing this PR in favor of #72

@dgromov dgromov deleted the dgromov/update_handlers branch July 26, 2017 18:29
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.

3 participants