github.com/m3db/m3@v1.5.0/src/cmd/tools/dtest/tests/remove_up_node.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  
    26  	"github.com/spf13/cobra"
    27  )
    28  
    29  var removeUpNodeTestCmd = &cobra.Command{
    30  	Use:   "remove_up_node",
    31  	Short: "Run a dtest where a node that is UP, is removed from the cluster. Node is left UP.",
    32  	Long: `
    33  	Perform the following operations on the provided set of nodes:
    34  	(1) Create a new cluster placement using all the provided nodes.
    35  	(2) Seed the nodes used in (1), with initial data on their respective file-systems.
    36  	(3) Start the nodes from (1), and wait until they are bootstrapped.
    37  	(4) Remove any one node from the cluster placement.
    38  	(5) Wait until all the shards in the placement are marked as available.
    39  `,
    40  	Example: `./dtest remove_up_node --m3db-build path/to/m3dbnode --m3db-config path/to/m3dbnode.yaml --dtest-config path/to/dtest.yaml`,
    41  	Run:     removeUpNodeDTest,
    42  }
    43  
    44  func removeUpNodeDTest(cmd *cobra.Command, args []string) {
    45  	if err := globalArgs.Validate(); err != nil {
    46  		printUsage(cmd)
    47  		return
    48  	}
    49  
    50  	rawLogger := newLogger(cmd)
    51  	defer rawLogger.Sync()
    52  	logger := rawLogger.Sugar()
    53  
    54  	dt := harness.New(globalArgs, rawLogger)
    55  	defer dt.Close()
    56  
    57  	nodes := dt.Nodes()
    58  	numNodes := len(nodes)
    59  	testCluster := dt.Cluster()
    60  
    61  	logger.Infof("setting up cluster")
    62  	setupNodes, err := testCluster.Setup(numNodes)
    63  	panicIfErr(err, "unable to setup cluster")
    64  	logger.Infof("setup cluster with %d nodes", numNodes)
    65  
    66  	logger.Infof("seeding nodes with initial data")
    67  	panicIfErr(dt.Seed(setupNodes), "unable to seed nodes")
    68  	logger.Infof("seeded nodes")
    69  
    70  	logger.Infof("starting cluster")
    71  	panicIfErr(testCluster.Start(), "unable to start nodes")
    72  	logger.Infof("started cluster with %d nodes", numNodes)
    73  
    74  	logger.Infof("waiting until all instances are bootstrapped")
    75  	panicIfErr(dt.WaitUntilAllBootstrapped(setupNodes), "unable to bootstrap all nodes")
    76  	logger.Infof("all nodes bootstrapped successfully!")
    77  
    78  	// remove first node from the cluster
    79  	removeNode := setupNodes[0]
    80  	panicIfErr(testCluster.RemoveNode(removeNode), "unable to remove node")
    81  	logger.Infof("removed node: %v", removeNode.String())
    82  
    83  	// wait until all shards are marked available again
    84  	logger.Infof("waiting till all shards are available")
    85  	panicIfErr(dt.WaitUntilAllShardsAvailable(), "all shards not available")
    86  	logger.Infof("all shards available!")
    87  }