github.com/m3db/m3@v1.5.0/src/cmd/tools/dtest/tests/replace_down_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 ( 30 replaceDownNodeTestCmd = &cobra.Command{ 31 Use: "replace_down_node", 32 Short: "Run a dtest where a node that is DOWN, is replaced from the cluster. Node is left DOWN.", 33 Long: ` 34 Perform the following operations on the provided set of nodes: 35 (1) Create a new cluster placement using all but one of the provided nodes. 36 (2) Seed the nodes used in (1), with initial data on their respective file-systems. 37 (3) Start the nodes from (1), and wait until they are bootstrapped. 38 (4) Stop the process on any one node in the cluster. 39 (5) The node from (4) is replaced with the unused node, in the cluster placement. 40 (6) Wait until all the shards in the cluster placement are marked as available. 41 `, 42 Example: `./dtest replace_down_node --m3db-build path/to/m3dbnode --m3db-config path/to/m3dbnode.yaml --dtest-config path/to/dtest.yaml`, 43 Run: replaceDownNodeDTest, 44 } 45 ) 46 47 func replaceDownNodeDTest(cmd *cobra.Command, args []string) { 48 if err := globalArgs.Validate(); err != nil { 49 printUsage(cmd) 50 return 51 } 52 53 rawLogger := newLogger(cmd) 54 defer rawLogger.Sync() 55 logger := rawLogger.Sugar() 56 57 dt := harness.New(globalArgs, rawLogger) 58 defer dt.Close() 59 60 nodes := dt.Nodes() 61 numNodes := len(nodes) - 1 // leaving spare to replace with 62 testCluster := dt.Cluster() 63 64 logger.Infof("setting up cluster") 65 setupNodes, err := testCluster.Setup(numNodes) 66 panicIfErr(err, "unable to setup cluster") 67 logger.Infof("setup cluster with %d nodes", numNodes) 68 69 logger.Infof("seeding nodes with initial data") 70 panicIfErr(dt.Seed(setupNodes), "unable to seed nodes") 71 logger.Infof("seeded nodes") 72 73 logger.Infof("starting cluster") 74 panicIfErr(testCluster.Start(), "unable to start nodes") 75 logger.Infof("started cluster with %d nodes", numNodes) 76 77 logger.Infof("waiting until all instances are bootstrapped") 78 panicIfErr(dt.WaitUntilAllBootstrapped(setupNodes), "unable to bootstrap all nodes") 79 logger.Infof("all nodes bootstrapped successfully!") 80 81 // bring down and replace first node from the cluster 82 replaceNode := setupNodes[0] 83 logger.Infof("bringing node down: %v", replaceNode.String()) 84 panicIfErr(replaceNode.Stop(), "unable to bring node down") 85 86 logger.Infof("replacing node: %v", replaceNode.String()) 87 newNodes, err := testCluster.ReplaceNode(replaceNode) 88 panicIfErr(err, "unable to replace node") 89 logger.Infof("replaced node: %s", replaceNode.ID()) 90 91 // start added nodes 92 logger.Infof("starting replacement nodes: %+v", newNodes) 93 for _, n := range newNodes { 94 panicIfErr(n.Start(), "unable to start node") 95 } 96 97 // wait until all shards are marked available again 98 logger.Infof("waiting till all shards are available") 99 panicIfErr(dt.WaitUntilAllShardsAvailable(), "all shards not available") 100 logger.Infof("all shards available!") 101 }