Пример #1
0
// Shutdown handles graceful cleanup of server functions before exiting DVID.
// This may not be so graceful if the chunk handler uses cgo since the interrupt
// may be caught during cgo execution.
func Shutdown() {
	// Stop accepting HTTP requests.
	httpAvail = false

	// Wait for chunk handlers.
	waits := 0
	for {
		active := MaxChunkHandlers - len(HandlerToken)
		if waits >= 20 {
			dvid.Infof("Already waited for 20 seconds.  Continuing with shutdown...")
			break
		} else if active > 0 {
			dvid.Infof("Waiting for %d chunk handlers to finish...\n", active)
			waits++
		} else {
			dvid.Infof("No chunk handlers active. Proceeding...\n")
			break
		}
		time.Sleep(1 * time.Second)
	}
	dvid.Infof("Waiting 5 seconds for any HTTP requests to drain...\n")
	time.Sleep(5 * time.Second)
	datastore.Shutdown()
	dvid.BlockOnActiveCgo()
	rpc.Shutdown()
	dvid.Shutdown()
	shutdownCh <- struct{}{}
}
Пример #2
0
func CloseStore() {
	mu.Lock()
	defer mu.Unlock()
	count--
	if count == 0 {
		dvid.BlockOnActiveCgo()
		if engine == nil {
			log.Fatalf("Attempted to close non-existant engine!")
		}
		// Close engine and delete store.
		engine.Close()
		engine = nil
		if err := os.RemoveAll(dbpath); err != nil {
			log.Fatalf("Unable to cleanup test store: %s\n", dbpath)
		}
	}
}
Пример #3
0
// Shutdown handles graceful cleanup of server functions before exiting DVID.
// This may not be so graceful if the chunk handler uses cgo since the interrupt
// may be caught during cgo execution.
func Shutdown() {
	waits := 0
	for {
		active := MaxChunkHandlers - len(HandlerToken)
		if waits >= 20 {
			log.Printf("Already waited for 20 seconds.  Continuing with shutdown...")
			break
		} else if active > 0 {
			log.Printf("Waiting for %d chunk handlers to finish...\n", active)
			waits++
		} else {
			log.Println("No chunk handlers active...")
			break
		}
		time.Sleep(1 * time.Second)
	}
	datastore.Close()
	dvid.BlockOnActiveCgo()
}
Пример #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)
	}
}