当前位置: 首页>>代码示例>>Golang>>正文


Golang GsiClient.IndexState方法代码示例

本文整理汇总了Golang中github.com/couchbase/indexing/secondary/queryport/client.GsiClient.IndexState方法的典型用法代码示例。如果您正苦于以下问题:Golang GsiClient.IndexState方法的具体用法?Golang GsiClient.IndexState怎么用?Golang GsiClient.IndexState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/couchbase/indexing/secondary/queryport/client.GsiClient的用法示例。


在下文中一共展示了GsiClient.IndexState方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: WaitUntilIndexState

// WaitUntilIndexState comes to desired `state`,
// retry for every `period` mS until `timeout` mS.
func WaitUntilIndexState(
	client *qclient.GsiClient, defnIDs []uint64,
	state c.IndexState, period, timeout time.Duration) ([]c.IndexState, error) {

	expired := time.After(timeout * time.Millisecond)
	states := make([]c.IndexState, len(defnIDs))
	pending := len(defnIDs)
	for {
		select {
		case <-expired:
			return nil, errors.New("timeout")

		default:
		}
		for i, defnID := range defnIDs {
			if states[i] != state {
				st, err := client.IndexState(defnID)
				if err != nil {
					return nil, err
				} else if st == state {
					states[i] = state
					pending--
					continue
				}
			}
		}
		if pending == 0 {
			return states, nil
		}
		time.Sleep(period * time.Millisecond)
	}
}
开发者ID:jchris,项目名称:indexing,代码行数:34,代码来源:docmd.go

示例2: WaitTillIndexActive

func WaitTillIndexActive(defnID uint64, client *qc.GsiClient, indexActiveTimeoutSeconds int64) error {
	start := time.Now()
	for {
		elapsed := time.Since(start)
		if elapsed.Seconds() >= float64(indexActiveTimeoutSeconds) {
			err := errors.New(fmt.Sprintf("Index did not become active after %d seconds", indexActiveTimeoutSeconds))
			return err
		}
		state, e := client.IndexState(defnID)
		log.Printf("Index state is %v", state)
		if e != nil {
			log.Printf("Error while fetching index state for defnID %v", defnID)
			return e
		}

		if state == c.INDEX_STATE_ACTIVE {
			log.Printf("Index is now active")
			return nil
		} else {
			time.Sleep(1 * time.Second)
		}
	}
	return nil
}
开发者ID:jchris,项目名称:indexing,代码行数:24,代码来源:secondaryindexmanagement.go

示例3: HandleCommand


//.........这里部分代码省略.........
		for _, bindex := range cmd.Bindexes {
			v := strings.Split(bindex, ":")
			if len(v) < 0 {
				return fmt.Errorf("invalid index specified : %v", bindex)
			}
			bucket, iname = v[0], v[1]
			index, ok := GetIndex(client, bucket, iname)
			if ok {
				defnIDs = append(defnIDs, uint64(index.Definition.DefnId))
			} else {
				err = fmt.Errorf("index %v/%v unknown", bucket, iname)
				break
			}
		}
		if err == nil {
			err = client.BuildIndexes(defnIDs)
			fmt.Fprintf(w, "Index building for: %v\n", defnIDs)
		}

	case "drop":
		index, ok := GetIndex(client, cmd.Bucket, cmd.IndexName)
		if !ok {
			return fmt.Errorf("invalid index specified : %v", cmd.IndexName)
		}
		err = client.DropIndex(uint64(index.Definition.DefnId))
		if err == nil {
			fmt.Fprintf(w, "Index dropped %v/%v\n", bucket, iname)
		} else {
			err = fmt.Errorf("index %v/%v drop failed", bucket, iname)
			break
		}

	case "scan":
		var state c.IndexState

		index, _ := GetIndex(client, bucket, iname)
		defnID := uint64(index.Definition.DefnId)
		fmt.Fprintln(w, "Scan index:")
		_, err = WaitUntilIndexState(
			client, []uint64{defnID}, c.INDEX_STATE_ACTIVE,
			100 /*period*/, 20000 /*timeout*/)

		if err != nil {
			state, err = client.IndexState(defnID)
			fmt.Fprintf(w, "Index state: {%v, %v}\n", state, err)
		} else if cmd.Equal != nil {
			equals := []c.SecondaryKey{cmd.Equal}
			client.Lookup(
				uint64(defnID), equals, false, limit,
				cons, nil, callb)
		} else {
			err = client.Range(
				uint64(defnID), low, high, incl, false, limit,
				cons, nil, callb)
		}
		if err == nil {
			fmt.Fprintln(w, "Total number of entries: ", entries)
		}

	case "scanAll":
		var state c.IndexState

		index, found := GetIndex(client, bucket, iname)
		if !found {
			fmt.Fprintln(w, "Index not found")
			os.Exit(1)
开发者ID:jchris,项目名称:indexing,代码行数:67,代码来源:docmd.go


注:本文中的github.com/couchbase/indexing/secondary/queryport/client.GsiClient.IndexState方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。