func main()

in cmd/ndb-pod-initializer/main.go [276:322]


func main() {

	ctx := context.Background()
	podHostname := os.Getenv("HOSTNAME")

	// Wait for the hostname to be updated in the DNS
	waitForPodDNSUpdate(ctx, podHostname)

	// Persist the nodeId into a file for the other scripts/commands to use
	connectstring := os.Getenv("NDB_CONNECTSTRING")
	nodeId, nodeIdPool, nodeType := writeNodeIDToFile(podHostname, connectstring)

	if nodeType == mgmapi.NodeTypeMGM {
		log.Println("Pod initializer succeeded.")
		return
	}

	// Connect to the Management Server
	var err error
	var mgmClient mgmapi.MgmClient
	mgmClient, err = mgmapi.NewMgmClient(connectstring)
	failOnError(err, "Failed to connect to management server : %s", err)
	defer mgmClient.Disconnect()

	if nodeType == mgmapi.NodeTypeNDB && !isSystemRestart(mgmClient) {
		// Wait for the existing data nodes to finish
		// handling previous data node failure
		log.Println("Waiting for other data nodes to complete Node failure handling...")
		if !waitForDataNodeFailureHandlingToComplete(nodeId, podHostname) {
			// The method failed as either server or the ndbinfo database is not available.
			// Fallback to waitForNodeIdAvailability logic. This is used only as a fallback
			// as the nodeId is freed early in the node failure handling process and due
			// to that waitForNodeIdAvailability is less reliable than checking ndbinfo
			// database.
			log.Println("Falling back to checking if nodeId is available..")
			waitForNodeIdAvailability(nodeId, nodeType, mgmClient)
		}
		log.Println("Done")
	}

	if nodeType == mgmapi.NodeTypeAPI {
		// Wait for all the nodeIds to become available for MySQL nodes
		for _, id := range nodeIdPool {
			waitForNodeIdAvailability(id, nodeType, mgmClient)
		}
	}
}