示例#1
0
文件: main.go 项目: tartavull/dvid
// DoServe opens a datastore then creates both web and rpc servers for the datastore
func DoServe(cmd dvid.Command) error {
	// Capture ctrl+c and other interrupts.  Then handle graceful shutdown.
	stopSig := make(chan os.Signal)
	go func() {
		for sig := range stopSig {
			log.Printf("Stop signal captured: %q.  Shutting down...\n", sig)
			if *memprofile != "" {
				log.Printf("Storing memory profiling to %s...\n", *memprofile)
				f, err := os.Create(*memprofile)
				if err != nil {
					log.Fatal(err)
				}
				pprof.WriteHeapProfile(f)
				f.Close()
			}
			if *cpuprofile != "" {
				log.Printf("Stopping CPU profiling to %s...\n", *cpuprofile)
				pprof.StopCPUProfile()
			}
			server.Shutdown()
			time.Sleep(1 * time.Second)
			os.Exit(0)
		}
	}()
	signal.Notify(stopSig, os.Interrupt, os.Kill, syscall.SIGTERM)

	// Load server configuration.
	configPath := cmd.Argument(1)
	if configPath == "" {
		return fmt.Errorf("serve command must be followed by the path to the TOML configuration file")
	}
	instanceConfig, logConfig, backend, err := server.LoadConfig(configPath)
	if err != nil {
		return fmt.Errorf("Error loading configuration file %q: %v\n", configPath, err)
	}
	logConfig.SetLogger()

	// Initialize storage and datastore layer
	initMetadata, err := storage.Initialize(cmd.Settings(), backend)
	if err != nil {
		return fmt.Errorf("Unable to initialize storage: %v\n", err)
	}
	if err := datastore.Initialize(initMetadata, instanceConfig); err != nil {
		return fmt.Errorf("Unable to initialize datastore: %v\n", err)
	}

	// add handlers to help us track memory usage - they don't track memory until they're told to
	profiler.AddMemoryProfilingHandlers()

	// Uncomment if you want to start profiling automatically
	// profiler.StartProfiling()

	// listen on port 6060 (pick a port) for profiling.
	go http.ListenAndServe(":6060", nil)

	// Serve HTTP and RPC
	server.Serve()
	return nil
}
示例#2
0
文件: common.go 项目: hanslovsky/dvid
// Initialize the storage systems given a configuration, path to datastore.  Unlike cluster
// and google cloud storage systems, which get initialized on DVID start using init(), the
// local storage system waits until it receives a path and configuration data from a
// "serve" command.
func Initialize(path string, config dvid.Config) error {
	create := false
	kvEngine, err := NewKeyValueStore(path, create, config)
	if err != nil {
		return err
	}
	return storage.Initialize(kvEngine, kvEngine.String())
}
示例#3
0
func openStore(create bool) {
	dvid.Infof("Opening test datastore.  Create = %v\n", create)
	if create {
		var err error
		testStore.backend, err = getTestStoreConfig()
		if err != nil {
			log.Fatalf("Unable to get testable storage configuration: %v\n", err)
		}
	}
	initMetadata, err := storage.Initialize(dvid.Config{}, testStore.backend)
	if err != nil {
		log.Fatalf("Can't initialize test datastore: %v\n", err)
	}
	if err := Initialize(initMetadata, &InstanceConfig{}); err != nil {
		log.Fatalf("Can't initialize datastore management: %v\n", err)
	}
	dvid.Infof("Storage initialized.  initMetadata = %v\n", initMetadata)
}
示例#4
0
// CloseReopenStore forces close of the underlying storage engine and then reopening
// the datastore.  Useful for testing metadata persistence.
func CloseReopenStore() {
	mu.Lock()
	defer mu.Unlock()
	dvid.BlockOnActiveCgo()
	if engine == nil {
		log.Fatalf("Attempted to close and reopen non-existant engine!")
	}
	engine.Close()

	var err error
	create := false
	engine, err = local.NewKeyValueStore(dbpath, create, dvid.Config{})
	if err != nil {
		log.Fatalf("Error reopening test db at %s: %v\n", dbpath, err)
	}
	if err = storage.Initialize(engine, "testdb"); err != nil {
		log.Fatalf("CloseReopenStore: bad storage.Initialize(): %v\n", err)
	}
	if err = datastore.Initialize(); err != nil {
		log.Fatalf("CloseReopenStore: can't initialize datastore management: %v\n", err)
	}
}
示例#5
0
func UseStore() {
	mu.Lock()
	defer mu.Unlock()
	if count == 0 {
		dbpath = filepath.Join(os.TempDir(), fmt.Sprintf("dvid-test-%s", uuid.NewV4()))
		var err error
		engine, err = local.CreateBlankStore(dbpath)
		if err != nil {
			log.Fatalf("Can't create a blank test datastore: %v\n", err)
		}
		if err = storage.Initialize(engine, "testdb"); err != nil {
			log.Fatalf("Can't initialize test datastore: %v\n", err)
		}
		if err = datastore.InitMetadata(engine); err != nil {
			log.Fatalf("Can't write blank datastore metadata: %v\n", err)
		}
		if err = datastore.Initialize(); err != nil {
			log.Fatalf("Can't initialize datastore management: %v\n", err)
		}
	}
	count++
}