func main() { logging.SetLogLevel(logging.Warn) runtime.GOMAXPROCS(runtime.NumCPU()) cmdOptions, _, fset, err := querycmd.ParseArgs(os.Args[1:]) if err != nil { logging.Fatalf("%v\n", err) os.Exit(1) } else if cmdOptions.Help || len(cmdOptions.OpType) < 1 { usage(fset) os.Exit(0) } config := c.SystemConfig.SectionConfig("queryport.client.", true) client, err := qclient.NewGsiClient(cmdOptions.Server, config) if err != nil { logging.Fatalf("%v\n", err) os.Exit(1) } if err = querycmd.HandleCommand(client, cmdOptions, false, os.Stdout); err != nil { fmt.Fprintf(os.Stderr, "Error occured %v\n", err) } client.Close() }
func doMemdbTests( cluster string, client *qclient.GsiClient) (err error) { for _, args := range memdbCommands { cmd, _, _, err := querycmd.ParseArgs(args) if err != nil { log.Fatal(err) } err = querycmd.HandleCommand(client, cmd, true, os.Stdout) if err != nil { fmt.Printf("%#v\n", cmd) fmt.Printf(" %v\n", err) } fmt.Println() } return }
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 }