*: reflow comments to 80 characters
This reformats the entire Metropolis codebase to have comments no longer
than 80 characters, implementing CR/66.
This has been done half manually, as we don't have a good integration
between commentwrap/Bazel, but that can be implemented if we decide to
go for this tool/limit.
Change-Id: If1fff0b093ef806f5dc00551c11506e8290379d0
diff --git a/metropolis/pkg/supervisor/supervisor_node.go b/metropolis/pkg/supervisor/supervisor_node.go
index a7caf82..a3bf5e4 100644
--- a/metropolis/pkg/supervisor/supervisor_node.go
+++ b/metropolis/pkg/supervisor/supervisor_node.go
@@ -25,23 +25,28 @@
"github.com/cenkalti/backoff/v4"
)
-// node is a supervision tree node. It represents the state of a Runnable within this tree, its relation to other tree
-// elements, and contains supporting data needed to actually supervise it.
+// node is a supervision tree node. It represents the state of a Runnable
+// within this tree, its relation to other tree elements, and contains
+// supporting data needed to actually supervise it.
type node struct {
- // The name of this node. Opaque string. It's used to make up the 'dn' (distinguished name) of a node within
- // the tree. When starting a runnable inside a tree, this is where that name gets used.
+ // The name of this node. Opaque string. It's used to make up the 'dn'
+ // (distinguished name) of a node within the tree. When starting a runnable
+ // inside a tree, this is where that name gets used.
name string
runnable Runnable
// The supervisor managing this tree.
sup *supervisor
- // The parent, within the tree, of this node. If this is the root node of the tree, this is nil.
+ // The parent, within the tree, of this node. If this is the root node of
+ // the tree, this is nil.
parent *node
- // Children of this tree. This is represented by a map keyed from child node names, for easy access.
+ // Children of this tree. This is represented by a map keyed from child
+ // node names, for easy access.
children map[string]*node
- // Supervision groups. Each group is a set of names of children. Sets, and as such groups, don't overlap between
- // each other. A supervision group indicates that if any child within that group fails, all others should be
- // canceled and restarted together.
+ // Supervision groups. Each group is a set of names of children. Sets, and
+ // as such groups, don't overlap between each other. A supervision group
+ // indicates that if any child within that group fails, all others should
+ // be canceled and restarted together.
groups []map[string]bool
// The current state of the runnable in this node.
@@ -55,19 +60,21 @@
ctxC context.CancelFunc
}
-// nodeState is the state of a runnable within a node, and in a way the node itself.
-// This follows the state diagram from go/supervision.
+// nodeState is the state of a runnable within a node, and in a way the node
+// itself. This follows the state diagram from go/supervision.
type nodeState int
const (
- // A node that has just been created, and whose runnable has been started already but hasn't signaled anything yet.
+ // A node that has just been created, and whose runnable has been started
+ // already but hasn't signaled anything yet.
nodeStateNew nodeState = iota
- // A node whose runnable has signaled being healthy - this means it's ready to serve/act.
+ // A node whose runnable has signaled being healthy - this means it's ready
+ // to serve/act.
nodeStateHealthy
// A node that has unexpectedly returned or panicked.
nodeStateDead
- // A node that has declared that its done with its work and should not be restarted, unless a supervision tree
- // failure requires that.
+ // A node that has declared that its done with its work and should not be
+ // restarted, unless a supervision tree failure requires that.
nodeStateDone
// A node that has returned after being requested to cancel.
nodeStateCanceled
@@ -101,8 +108,9 @@
dnKey = contextKey("dn")
)
-// fromContext retrieves a tree node from a runnable context. It takes a lock on the tree and returns an unlock
-// function. This unlock function needs to be called once mutations on the tree/supervisor/node are done.
+// fromContext retrieves a tree node from a runnable context. It takes a lock
+// on the tree and returns an unlock function. This unlock function needs to be
+// called once mutations on the tree/supervisor/node are done.
func fromContext(ctx context.Context) (*node, func()) {
sup, ok := ctx.Value(supervisorKey).(*supervisor)
if !ok {
@@ -120,12 +128,13 @@
return sup.nodeByDN(dnParent), sup.mu.Unlock
}
-// All the following 'internal' supervisor functions must only be called with the supervisor lock taken. Getting a lock
-// via fromContext is enough.
+// All the following 'internal' supervisor functions must only be called with
+// the supervisor lock taken. Getting a lock via fromContext is enough.
-// dn returns the distinguished name of a node. This distinguished name is a period-separated, inverse-DNS-like name.
-// For instance, the runnable 'foo' within the runnable 'bar' will be called 'root.bar.foo'. The root of the tree is
-// always named, and has the dn, 'root'.
+// dn returns the distinguished name of a node. This distinguished name is a
+// period-separated, inverse-DNS-like name. For instance, the runnable 'foo'
+// within the runnable 'bar' will be called 'root.bar.foo'. The root of the
+// tree is always named, and has the dn, 'root'.
func (n *node) dn() string {
if n.parent != nil {
return fmt.Sprintf("%s.%s", n.parent.dn(), n.name)
@@ -133,8 +142,9 @@
return n.name
}
-// groupSiblings is a helper function to get all runnable group siblings of a given runnable name within this node.
-// All children are always in a group, even if that group is unary.
+// groupSiblings is a helper function to get all runnable group siblings of a
+// given runnable name within this node. All children are always in a group,
+// even if that group is unary.
func (n *node) groupSiblings(name string) map[string]bool {
for _, m := range n.groups {
if _, ok := m[name]; ok {
@@ -144,11 +154,12 @@
return nil
}
-// newNode creates a new node with a given parent. It does not register it with the parent (as that depends on group
-// placement).
+// newNode creates a new node with a given parent. It does not register it with
+// the parent (as that depends on group placement).
func newNode(name string, runnable Runnable, sup *supervisor, parent *node) *node {
- // We use exponential backoff for failed runnables, but at some point we cap at a given backoff time.
- // To achieve this, we set MaxElapsedTime to 0, which will cap the backoff at MaxInterval.
+ // We use exponential backoff for failed runnables, but at some point we
+ // cap at a given backoff time. To achieve this, we set MaxElapsedTime to
+ // 0, which will cap the backoff at MaxInterval.
bo := backoff.NewExponentialBackOff()
bo.MaxElapsedTime = 0
@@ -165,11 +176,12 @@
return n
}
-// resetNode sets up all the dynamic fields of the node, in preparation of starting a runnable. It clears the node's
-// children, groups and resets its context.
+// resetNode sets up all the dynamic fields of the node, in preparation of
+// starting a runnable. It clears the node's children, groups and resets its
+// context.
func (n *node) reset() {
- // Make new context. First, acquire parent context. For the root node that's Background, otherwise it's the
- // parent's context.
+ // Make new context. First, acquire parent context. For the root node
+ // that's Background, otherwise it's the parent's context.
var pCtx context.Context
if n.parent == nil {
pCtx = context.Background()
@@ -263,7 +275,8 @@
return nil
}
-// signal sequences state changes by signals received from runnables and updates a node's status accordingly.
+// signal sequences state changes by signals received from runnables and
+// updates a node's status accordingly.
func (n *node) signal(signal SignalType) {
switch signal {
case SignalHealthy: