// initializes a new server that does not yet have an ID. func initializeServer(u *url.URL, s *influxdb.Server, b *influxdb.Broker, w io.Writer, initBroker bool) { // TODO: Create replica using the messaging client. if initBroker { // Create replica on broker. if err := b.CreateReplica(1, u); err != nil { log.Fatalf("replica creation error: %s", err) } } // Create messaging client. c := messaging.NewClient(1) c.SetLogOutput(w) if err := c.Open(filepath.Join(s.Path(), messagingClientFile), []*url.URL{b.URL()}); err != nil { log.Fatalf("messaging client error: %s", err) } if err := s.SetClient(c); err != nil { log.Fatalf("set client error: %s", err) } if initBroker { // Initialize the server. if err := s.Initialize(b.URL()); err != nil { log.Fatalf("server initialization error: %s", err) } } }
// creates and initializes a server. func openServer(config *Config, b *influxdb.Broker, initServer, initBroker, configExists bool, joinURLs []*url.URL, w io.Writer) *influxdb.Server { // Create and open the server. s := influxdb.NewServer() s.SetLogOutput(w) s.WriteTrace = config.Logging.WriteTracing s.RetentionAutoCreate = config.Data.RetentionAutoCreate s.RecomputePreviousN = config.ContinuousQuery.RecomputePreviousN s.RecomputeNoOlderThan = time.Duration(config.ContinuousQuery.RecomputeNoOlderThan) s.ComputeRunsPerInterval = config.ContinuousQuery.ComputeRunsPerInterval s.ComputeNoMoreThan = time.Duration(config.ContinuousQuery.ComputeNoMoreThan) if err := s.Open(config.Data.Dir); err != nil { log.Fatalf("failed to open data server: %v", err.Error()) } // If the server is uninitialized then initialize or join it. if initServer { if len(joinURLs) == 0 { initializeServer(config.DataURL(), s, b, w, initBroker) } else { joinServer(s, config.DataURL(), joinURLs) } } if !configExists { // We are spining up a server that has no config, // but already has an initialized data directory joinURLs = []*url.URL{b.URL()} openServerClient(s, joinURLs, w) } else { if len(joinURLs) == 0 { // If a config exists, but no joinUrls are specified, fall back to the broker URL // TODO: Make sure we have a leader, and then spin up the server joinURLs = []*url.URL{b.URL()} } openServerClient(s, joinURLs, w) } return s }