github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/cmd/tools/dtest/tests/add_down_node_bring_up.go (about)

     1  // Copyright (c) 2018 Uber Technologies, Inc.
     2  //
     3  // Permission is hereby granted, free of charge, to any person obtaining a copy
     4  // of this software and associated documentation files (the "Software"), to deal
     5  // in the Software without restriction, including without limitation the rights
     6  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     7  // copies of the Software, and to permit persons to whom the Software is
     8  // furnished to do so, subject to the following conditions:
     9  //
    10  // The above copyright notice and this permission notice shall be included in
    11  // all copies or substantial portions of the Software.
    12  //
    13  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    14  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    15  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    16  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    17  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    18  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    19  // THE SOFTWARE.
    20  
    21  package dtests
    22  
    23  import (
    24  	"github.com/m3db/m3/src/cmd/tools/dtest/harness"
    25  	"github.com/m3db/m3/src/m3em/node"
    26  
    27  	"github.com/spf13/cobra"
    28  )
    29  
    30  var (
    31  	addDownNodeAndBringUpTestCmd = &cobra.Command{
    32  		Use:   "add_down_node_bring_up",
    33  		Short: "Run a dtest where a node that is DOWN, is added to the cluster. Node is then brought up.",
    34  		Long: `
    35  		Perform the following operations on the provided set of nodes:
    36  		(1) Create a new cluster placement using all but one of the provided nodes.
    37  		(2) Seed the nodes used in (1), with initial data on their respective file-systems.
    38  		(3) Start the the nodes from (1), and wait until they are bootstrapped.
    39  		(4) Add the one unused node to the cluster placement, and start it's process.
    40  		(5) Wait until all the shards in the cluster placement are marked as available.
    41  `,
    42  		Example: `./dtest add_down_node_bring_up --m3db-build path/to/m3dbnode --m3db-config path/to/m3dbnode.yaml --dtest-config path/to/dtest.yaml`,
    43  		Run:     addDownNodeAndBringUpDTest,
    44  	}
    45  )
    46  
    47  func addDownNodeAndBringUpDTest(cmd *cobra.Command, args []string) {
    48  	if err := globalArgs.Validate(); err != nil {
    49  		printUsage(cmd)
    50  		return
    51  	}
    52  	rawLogger := newLogger(cmd)
    53  	defer rawLogger.Sync()
    54  	logger := rawLogger.Sugar()
    55  
    56  	dt := harness.New(globalArgs, rawLogger)
    57  	defer dt.Close()
    58  
    59  	nodes := dt.Nodes()
    60  	numNodes := len(nodes) - 1 // leaving one spare
    61  	testCluster := dt.Cluster()
    62  
    63  	logger.Infof("setting up cluster")
    64  	setupNodes, err := testCluster.Setup(numNodes)
    65  	panicIfErr(err, "unable to setup cluster")
    66  	logger.Infof("setup cluster with %d nodes", numNodes)
    67  
    68  	logger.Infof("seeding nodes with initial data")
    69  	panicIfErr(dt.Seed(setupNodes), "unable to seed nodes")
    70  	logger.Infof("seeded nodes")
    71  
    72  	panicIfErr(testCluster.Start(), "unable to start nodes")
    73  	logger.Infof("started cluster with %d nodes", numNodes)
    74  
    75  	logger.Infof("waiting until all instances are bootstrapped")
    76  	panicIfErr(dt.WaitUntilAllBootstrapped(setupNodes), "unable to bootstrap all nodes")
    77  	logger.Infof("all nodes bootstrapped successfully!")
    78  
    79  	// get a spare, ensure it's down and add to the cluster
    80  	logger.Infof("adding spare to the cluster")
    81  	spares := testCluster.SpareNodes()
    82  	panicIf(len(spares) < 1, "no spares to add to the cluster")
    83  	spare := spares[0]
    84  	panicIf(spare.Status() != node.StatusSetup, "expected node to be setup")
    85  	panicIfErr(testCluster.AddSpecifiedNode(spare), "unable to add node")
    86  	logger.Infof("added node: %v", spare.String())
    87  
    88  	// start added nodes
    89  	logger.Infof("starting added node")
    90  	panicIfErr(spare.Start(), "unable to start node")
    91  	logger.Infof("started added node")
    92  
    93  	// wait until all shards are marked available again
    94  	logger.Infof("waiting till all shards are available")
    95  	panicIfErr(dt.WaitUntilAllShardsAvailable(), "all shards not available")
    96  	logger.Infof("all shards available!")
    97  }