Example #1
0
// addKeyVersions, add a mutation's keyversions to buffer.
func (b *endpointBuffers) addKeyVersions(
	bucket string, vbno uint16, vbuuid uint64, kv *c.KeyVersions) {

	if kv != nil && kv.Length() > 0 {
		uuid := c.StreamID(bucket, vbno)
		if _, ok := b.vbs[uuid]; !ok {
			nMuts := 16 // to avoid reallocs.
			b.vbs[uuid] = c.NewVbKeyVersions(bucket, vbno, vbuuid, nMuts)
		}
		b.vbs[uuid].AddKeyVersions(kv)
	}
}
Example #2
0
func TestStreamBegin(t *testing.T) {
	maxBuckets, maxvbuckets, mutChanSize := 2, 8, 1000
	logging.SetLogLevel(logging.Silent)

	// start server
	appch := make(chan interface{}, mutChanSize)
	prefix := "indexer.dataport."
	config := c.SystemConfig.SectionConfig(prefix, true /*trim*/)
	daemon, err := NewServer(addr, maxvbuckets, config, appch)
	if err != nil {
		t.Fatal(err)
	}

	// start client
	flags := transport.TransportFlag(0).SetProtobuf()
	prefix = "projector.dataport.client."
	config = c.SystemConfig.SectionConfig(prefix, true /*trim*/)
	client, _ := NewClient(
		"cluster", "backfill", addr, flags, maxvbuckets, config)
	vbmaps := makeVbmaps(maxvbuckets, maxBuckets) // vbmaps
	for i := 0; i < maxBuckets; i++ {
		if err := client.SendVbmap(vbmaps[i]); err != nil {
			t.Fatal(err)
		}
	}

	// test a live StreamBegin
	bucket, vbno, vbuuid := "default0", uint16(maxvbuckets), uint64(1111)
	uuid := c.StreamID(bucket, vbno)
	vals, err := client.Getcontext()
	if err != nil {
		t.Fatal(err)
	}
	vbChans := vals[0].(map[string]chan interface{})
	if _, ok := vbChans[uuid]; ok {
		t.Fatal("duplicate id")
	}
	vb := c.NewVbKeyVersions(bucket, vbno, vbuuid, 1)
	seqno, docid, maxCount := uint64(10), []byte("document-name"), 10
	kv := c.NewKeyVersions(seqno, docid, maxCount)
	kv.AddStreamBegin()
	vb.AddKeyVersions(kv)
	err = client.SendKeyVersions([]*c.VbKeyVersions{vb}, true)
	client.Getcontext() // syncup
	if err != nil {
		t.Fatal(err)
	} else if _, ok := vbChans[uuid]; !ok {
		fmt.Printf("%v %v\n", len(vbChans), uuid)
		t.Fatal("failed StreamBegin")
	}
	client.Close()
	daemon.Close()
}
Example #3
0
// sendVbmap to the other end, carrying connection -> vbuckets map.
func (c *Client) sendVbmap(
	vbmap *common.VbConnectionMap,
	vbChans map[string]chan interface{}) map[string]chan interface{} {

	vbmaps := make(map[int]*common.VbConnectionMap)
	for i := range c.conn2Vbs {
		vbmaps[i] = &common.VbConnectionMap{
			Bucket:   vbmap.Bucket,
			Vbuckets: make([]uint16, 0, len(vbmap.Vbuckets)),
			Vbuuids:  make([]uint64, 0, len(vbmap.Vbuuids)),
		}
	}
	var idx int

	// connection channels.
	idxMap := make(map[int][]uint16)
	for i, vbno := range vbmap.Vbuckets {
		uuid := common.StreamID(vbmap.Bucket, vbno)
		vbChans[uuid], idx = c.addVbucket(uuid)
		vbmaps[idx].Vbuckets = append(vbmaps[idx].Vbuckets, vbno)
		vbmaps[idx].Vbuuids = append(vbmaps[idx].Vbuuids, vbmap.Vbuuids[i])
		if _, ok := idxMap[idx]; !ok {
			idxMap[idx] = make([]uint16, 0)
		}
	}
	for idx, vbnos := range idxMap {
		logging.Tracef(
			"%v mapped vbucket {%v,%v} on conn%v\n",
			c.logPrefixes[idx], vbmap.Bucket, vbnos, idx)
	}

	// send the new vbmap to the other end, for each connection.
	for i, vbmap := range vbmaps {
		c.connChans[i] <- vbmap
	}
	return vbChans
}