Exemple #1
0
func vector2ts(vector timestamp.Vector) *qclient.TsConsistency {
	if vector == nil {
		return nil
	}
	vbnos := make([]uint16, 0, 1024)
	seqnos := make([]uint64, 0, 1024)
	vbuuids := make([]uint64, 0, 1024)
	for _, entry := range vector.Entries() {
		vbnos = append(vbnos, uint16(entry.Position()))
		seqnos = append(seqnos, uint64(entry.Value()))
		vbuuids = append(vbuuids, uint64(guard2Vbuuid(entry.Guard())))
	}
	return qclient.NewTsConsistency(vbnos, seqnos, vbuuids)
}
Exemple #2
0
func doConsistency(
	cluster string, maxvb int, client *qclient.GsiClient) (err error) {

	b, err := common.ConnectBucket(cluster, "default", "beer-sample")
	if err != nil {
		log.Fatal(err)
	}
	defer b.Close()

	vbnos := make([]uint16, maxvb)
	for i := range vbnos {
		vbnos[i] = uint16(i)
	}

	// Drop index
	args := []string{"-type", "drop", "-bucket", "beer-sample", "-index", "index-city"}
	cmd, _, _, _ := querycmd.ParseArgs(args)
	querycmd.HandleCommand(client, cmd, true, os.Stdout)

	// Create index
	args = []string{
		"-type", "create", "-bucket", "beer-sample", "-index", "index-city",
		"-fields", "city",
	}
	cmd, _, _, err = querycmd.ParseArgs(args)
	if err != nil {
		log.Fatal(err)
	}
	querycmd.HandleCommand(client, cmd, true, os.Stdout)

	// Wait for index to come active.
	index, ok := querycmd.GetIndex(client, "beer-sample", "index-city")
	if !ok {
		log.Fatalf("cannot get definition ID")
	}
	defnID := uint64(index.Definition.DefnId)
	_, err = querycmd.WaitUntilIndexState(
		client, []uint64{defnID}, common.INDEX_STATE_ACTIVE,
		100 /*period*/, 20000 /*timeout*/)

	synch := make(chan bool, 1)
	// Get the latest seqnos,vbuuid and vbucket that contains `docid`.
	seqnos, vbuuids, vbno, vbuuid, seqno := setValueConst(b, maxvb, constDocValue1)
	equal := common.SecondaryKey(querycmd.Arg2Key(constEqualLookup1))
	equals := []common.SecondaryKey{equal}

	anyConsistency(client, defnID, equals)

	// query-consistency without any new mutations.
	ts := qclient.NewTsConsistency(vbnos, seqnos, vbuuids)
	queryConsistency(client, defnID, ts, equals, synch)
	<-synch

	// query-consistency with a new mutation.
	equal = common.SecondaryKey(querycmd.Arg2Key(constEqualLookup2))
	equals = []common.SecondaryKey{equal}
	seqno++
	ts = ts.Override(vbno, seqno, vbuuid)
	queryConsistency(client, defnID, ts, equals, synch)
	time.Sleep(2 * time.Second)
	setValueConst(b, maxvb, constDocValue2)
	<-synch

	// query-consistency with a new mutation.
	equal = common.SecondaryKey(querycmd.Arg2Key(constEqualLookup3))
	equals = []common.SecondaryKey{equal}
	seqno++
	ts = qclient.NewTsConsistency([]uint16{vbno}, []uint64{seqno}, []uint64{vbuuid})
	queryConsistency(client, defnID, ts, equals, synch)
	time.Sleep(2 * time.Second)
	setValueConst(b, maxvb, constDocValue3)
	<-synch

	// session-consistency without any new mutations.
	sessionConsistency(client, defnID, equals, synch)
	<-synch

	// session-consistency with a new mutation.
	setValueConst(b, maxvb, constDocValue4)
	equal = common.SecondaryKey(querycmd.Arg2Key(constEqualLookup4))
	equals = []common.SecondaryKey{equal}
	sessionConsistency(client, defnID, equals, synch)
	<-synch

	// session-consistency with a new mutation.
	equal = common.SecondaryKey(querycmd.Arg2Key(constEqualLookup5))
	equals = []common.SecondaryKey{equal}
	setValueConst(b, maxvb, constDocValue5)
	sessionConsistency(client, defnID, equals, synch)
	<-synch
	return nil
}