func saveDB(destDB, srcDB string, idx uint64, v3 bool) {
	// open src db to safely copy db state
	if v3 {
		var src *bolt.DB
		ch := make(chan *bolt.DB, 1)
		go func() {
			db, err := bolt.Open(srcDB, 0444, &bolt.Options{ReadOnly: true})
			if err != nil {
				log.Fatal(err)
			}
			ch <- db
		}()
		select {
		case src = <-ch:
		case <-time.After(time.Second):
			log.Println("waiting to acquire lock on", srcDB)
			src = <-ch
		}
		defer src.Close()

		tx, err := src.Begin(false)
		if err != nil {
			log.Fatal(err)
		}

		// copy srcDB to destDB
		dest, err := os.Create(destDB)
		if err != nil {
			log.Fatal(err)
		}
		if _, err := tx.WriteTo(dest); err != nil {
			log.Fatal(err)
		}
		dest.Close()
		if err := tx.Rollback(); err != nil {
			log.Fatal(err)
		}
	}

	db, err := bolt.Open(destDB, 0644, &bolt.Options{})
	if err != nil {
		log.Fatal(err)
	}
	tx, err := db.Begin(true)
	if err != nil {
		log.Fatal(err)
	}

	// remove membership information; should be clobbered by --force-new-cluster
	for _, bucket := range []string{"members", "members_removed", "cluster"} {
		tx.DeleteBucket([]byte(bucket))
	}

	// update consistent index to match hard state
	if !v3 {
		idxBytes := make([]byte, 8)
		binary.BigEndian.PutUint64(idxBytes, idx)
		b, err := tx.CreateBucketIfNotExists([]byte("meta"))
		if err != nil {
			log.Fatal(err)
		}
		b.Put([]byte("consistent_index"), idxBytes)
	}

	if err := tx.Commit(); err != nil {
		log.Fatal(err)
	}
	if err := db.Close(); err != nil {
		log.Fatal(err)
	}
}
func saveDB(destDB, srcDB string, idx uint64, v3 bool) {
	
	if v3 {
		var src *bolt.DB
		ch := make(chan *bolt.DB, 1)
		go func() {
			db, err := bolt.Open(srcDB, 0444, &bolt.Options{ReadOnly: true})
			if err != nil {
				log.Fatal(err)
			}
			ch <- db
		}()
		select {
		case src = <-ch:
		case <-time.After(time.Second):
			log.Println("waiting to acquire lock on", srcDB)
			src = <-ch
		}
		defer src.Close()

		tx, err := src.Begin(false)
		if err != nil {
			log.Fatal(err)
		}

		
		dest, err := os.Create(destDB)
		if err != nil {
			log.Fatal(err)
		}
		if _, err := tx.WriteTo(dest); err != nil {
			log.Fatal(err)
		}
		dest.Close()
		if err := tx.Rollback(); err != nil {
			log.Fatal(err)
		}
	}

	db, err := bolt.Open(destDB, 0644, &bolt.Options{})
	if err != nil {
		log.Fatal(err)
	}
	tx, err := db.Begin(true)
	if err != nil {
		log.Fatal(err)
	}

	
	for _, bucket := range []string{"members", "members_removed", "cluster"} {
		tx.DeleteBucket([]byte(bucket))
	}

	
	if !v3 {
		idxBytes := make([]byte, 8)
		binary.BigEndian.PutUint64(idxBytes, idx)
		b, err := tx.CreateBucketIfNotExists([]byte("meta"))
		if err != nil {
			log.Fatal(err)
		}
		b.Put([]byte("consistent_index"), idxBytes)
	}

	if err := tx.Commit(); err != nil {
		log.Fatal(err)
	}
	if err := db.Close(); err != nil {
		log.Fatal(err)
	}
}
func saveDB ( destDB , srcDB string , idx uint64 , v3 bool ) { // open src db to safely copy db state if v3 { var src * bolt . DB ch := make ( chan * bolt . DB , 1 ) go func ( ) { db , err := bolt . Open ( srcDB , 0444 , & bolt . Options { ReadOnly : true } ) if err != nil { log . Fatal ( err ) } ch <- db } ( ) select { case src = <- ch : case <- time . After ( time . Second ) : log . Println ( " " , srcDB ) src = <- ch } defer src . Close ( ) tx , err := src . Begin ( false ) if err != nil { log . Fatal ( err ) } // copy srcDB to destDB dest , err := os . Create ( destDB ) if err != nil { log . Fatal ( err ) } if _ , err := tx . WriteTo ( dest ) ; err != nil { log . Fatal ( err ) } dest . Close ( ) if err := tx . Rollback ( ) ; err != nil { log . Fatal ( err ) } } db , err := bolt . Open ( destDB , 0644 , & bolt . Options { } ) if err != nil { log . Fatal ( err ) } tx , err := db . Begin ( true ) if err != nil { log . Fatal ( err ) } // remove membership information; should be clobbered by --force-new-cluster for _ , bucket := range [ ] string { " " , " " , " " } { tx . DeleteBucket ( [ ] byte ( bucket ) ) } // update consistent index to match hard state if ! v3 { idxBytes := make ( [ ] byte , 8 ) binary . BigEndian . PutUint64 ( idxBytes , idx ) b , err := tx . CreateBucketIfNotExists ( [ ] byte ( " " ) ) if err != nil { log . Fatal ( err ) } b . Put ( [ ] byte ( " " ) , idxBytes ) } if err := tx . Commit ( ) ; err != nil { log . Fatal ( err ) } if err := db . Close ( ) ; err != nil { log . Fatal ( err ) } }
// saveDB copies the v3 backend and strips cluster information.
saveDB copies the v3 backend and strips cluster information .