func printFlogs(vbnos []uint16, flogs couchbase.FailoverLog) {
	for i, vbno := range vbnos {
		common.Infof("Failover log for vbucket %v\n", vbno)
		common.Infof("   %#v\n", flogs[uint16(i)])
	}
	common.Infof("\n")
}
func receive(ch chan *couchbase.UprFeed) {
	// bucket -> Opcode -> #count
	counts := make(map[string]map[mcd.CommandCode]int)

	var tick <-chan time.Time
	if options.stats > 0 {
		tick = time.Tick(time.Millisecond * time.Duration(options.stats))
	}

	finTimeout := time.After(time.Millisecond * time.Duration(options.duration))
	uprFeeds := make([]*couchbase.UprFeed, 0)
loop:
	for {
		select {
		case uprFeed := <-ch:
			uprFeeds = append(uprFeeds, uprFeed)

		case msg, ok := <-rch:
			if ok == false {
				break loop
			}
			bucket, e := msg[0].(string), msg[1].(*mc.UprEvent)
			if e.Opcode == mcd.UPR_MUTATION {
				common.Tracef("UprMutation KEY -- %v\n", string(e.Key))
				common.Tracef("     %v\n", string(e.Value))
			}
			if _, ok := counts[bucket]; !ok {
				counts[bucket] = make(map[mcd.CommandCode]int)
			}
			if _, ok := counts[bucket][e.Opcode]; !ok {
				counts[bucket][e.Opcode] = 0
			}
			counts[bucket][e.Opcode]++

		case <-tick:
			for bucket, m := range counts {
				common.Infof("%q %s\n", bucket, sprintCounts(m))
			}
			common.Infof("\n")

		case <-finTimeout:
			for _, uprFeed := range uprFeeds {
				endUpr(uprFeed, listOfVbnos(options.maxVbno))
			}
			break loop
		}
	}
	fmt.Println("sleep wait ....")
	time.Sleep(10000 * time.Millisecond)
}
func startBucket(cluster, bucketn string, ch chan *couchbase.UprFeed) int {
	defer func() {
		if r := recover(); r != nil {
			fmt.Printf("%s:\n%s\n", r, debug.Stack())
			common.StackTrace(string(debug.Stack()))
		}
	}()

	common.Infof("Connecting with %q\n", bucketn)
	b, err := common.ConnectBucket(cluster, "default", bucketn)
	mf(err, "bucket")

	uprFeed, err := b.StartUprFeed("rawupr", uint32(0))
	mf(err, "- upr")

	vbnos := listOfVbnos(options.maxVbno)

	flogs, err := b.GetFailoverLogs(vbnos)
	mf(err, "- upr failoverlogs")

	if options.printflogs {
		printFlogs(vbnos, flogs)
	}

	ch <- uprFeed

	go startUpr(uprFeed, flogs)

	for {
		e, ok := <-uprFeed.C
		if ok == false {
			common.Infof("Closing for bucket %q\n", bucketn)
		}
		rch <- []interface{}{bucketn, e}
	}
}