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


Golang Server.WriteTabletAction方法代码示例

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


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

示例1: CheckActions

func CheckActions(t *testing.T, ts topo.Server) {
	cell := getLocalCell(t, ts)
	tablet := &topo.Tablet{
		Alias:    topo.TabletAlias{Cell: cell, Uid: 1},
		Hostname: "localhost",
		IPAddr:   "10.11.12.13",
		Portmap: map[string]int{
			"vt":    3333,
			"mysql": 3334,
		},
		Parent:   topo.TabletAlias{},
		Keyspace: "test_keyspace",
		Type:     topo.TYPE_MASTER,
		State:    topo.STATE_READ_WRITE,
		KeyRange: newKeyRange("-10"),
	}
	if err := ts.CreateTablet(tablet); err != nil {
		t.Fatalf("CreateTablet: %v", err)
	}
	tabletAlias := topo.TabletAlias{Cell: cell, Uid: 1}

	actionPath, err := ts.WriteTabletAction(tabletAlias, "contents1")
	if err != nil {
		t.Fatalf("WriteTabletAction: %v", err)
	}

	interrupted := make(chan struct{}, 1)
	if _, err := ts.WaitForTabletAction(actionPath, time.Second/100, interrupted); err != topo.ErrTimeout {
		t.Errorf("WaitForTabletAction returned %v", err)
	}
	go func() {
		time.Sleep(time.Second / 10)
		close(interrupted)
	}()
	if _, err := ts.WaitForTabletAction(actionPath, time.Second*5, interrupted); err != topo.ErrInterrupted {
		t.Errorf("WaitForTabletAction returned %v", err)
	}

	// wait for the result in one thread
	wg1 := sync.WaitGroup{}
	wg1.Add(1)
	go func() {
		defer wg1.Done()
		interrupted := make(chan struct{}, 1)
		var err error
		for i := 0; i <= 30; i++ {
			var result string
			result, err = ts.WaitForTabletAction(actionPath, time.Second, interrupted)
			if err == topo.ErrTimeout {
				// we waited for one second, didn't see the
				// result, try again up to 30 seconds.
				t.Logf("WaitForTabletAction timed out at try %v/30", i)
				continue
			}
			if err != nil {
				t.Errorf("WaitForTabletAction returned: %v", err)
			}
			if result != "contents3" {
				t.Errorf("WaitForTabletAction returned bad result: %v", result)
			}
			return
		}
		t.Errorf("WaitForTabletAction timed out: %v", err)
	}()

	// process the action in another thread
	done := make(chan struct{}, 1)
	wg2 := sync.WaitGroup{}
	wg2.Add(1)
	go ts.ActionEventLoop(tabletAlias, func(ap, data string) error {
		// the actionPath sent back to the action processor
		// is the exact one we have in normal cases,
		// but for the tee, we add extra information.
		if ap != actionPath && !strings.HasSuffix(ap, actionPath) {
			t.Errorf("Bad action path: %v", ap)
		}
		if data != "contents1" {
			t.Errorf("Bad data: %v", data)
		}
		ta, contents, version, err := ts.ReadTabletActionPath(ap)
		if err != nil {
			t.Errorf("Error from ReadTabletActionPath: %v", err)
		}
		if contents != data {
			t.Errorf("Bad contents: %v", contents)
		}
		if ta != tabletAlias {
			t.Errorf("Bad tablet alias: %v", ta)
		}

		if err := ts.UpdateTabletAction(ap, "contents2", version); err != nil {
			t.Errorf("UpdateTabletAction failed: %v", err)
		}
		if err := ts.StoreTabletActionResponse(ap, "contents3"); err != nil {
			t.Errorf("StoreTabletActionResponse failed: %v", err)
		}
		if err := ts.UnblockTabletAction(ap); err != nil {
			t.Errorf("UnblockTabletAction failed: %v", err)
		}

//.........这里部分代码省略.........
开发者ID:kingpro,项目名称:vitess,代码行数:101,代码来源:action.go

示例2: CheckActions

func CheckActions(t *testing.T, ts topo.Server) {
	cell := getLocalCell(t, ts)
	tablet := &topo.Tablet{
		Cell:     cell,
		Uid:      1,
		Parent:   topo.TabletAlias{},
		Addr:     "localhost:3333",
		Keyspace: "test_keyspace",
		Type:     topo.TYPE_MASTER,
		State:    topo.STATE_READ_WRITE,
		KeyRange: newKeyRange("-10"),
	}
	if err := ts.CreateTablet(tablet); err != nil {
		t.Fatalf("CreateTablet: %v", err)
	}
	tabletAlias := topo.TabletAlias{cell, 1}

	actionPath, err := ts.WriteTabletAction(tabletAlias, "contents1")
	if err != nil {
		t.Fatalf("WriteTabletAction: %v", err)
	}

	interrupted := make(chan struct{}, 1)
	if _, err := ts.WaitForTabletAction(actionPath, time.Second/100, interrupted); err != topo.ErrTimeout {
		t.Errorf("WaitForTabletAction returned %v", err)
	}
	go func() {
		time.Sleep(time.Second / 10)
		close(interrupted)
	}()
	if _, err := ts.WaitForTabletAction(actionPath, time.Second*5, interrupted); err != topo.ErrInterrupted {
		t.Errorf("WaitForTabletAction returned %v", err)
	}

	wg := sync.WaitGroup{}

	// wait for the result in one thread
	wg.Add(1)
	go func() {
		interrupted := make(chan struct{}, 1)
		result, err := ts.WaitForTabletAction(actionPath, time.Second*10, interrupted)
		if err != nil {
			t.Errorf("WaitForTabletAction returned %v", err)
		}
		if result != "contents3" {
			t.Errorf("WaitForTabletAction returned bad result: %v", result)
		}
		wg.Done()
	}()

	// process the action in another thread
	done := make(chan struct{}, 1)
	wg.Add(1)
	go ts.ActionEventLoop(tabletAlias, func(ap, data string) error {
		// the actionPath sent back to the action processor
		// is the exact one we have in normal cases,
		// but for the tee, we add extra information.
		if ap != actionPath && !strings.HasSuffix(ap, actionPath) {
			t.Errorf("Bad action path: %v", ap)
		}
		if data != "contents1" {
			t.Errorf("Bad data: %v", data)
		}
		ta, contents, version, err := ts.ReadTabletActionPath(ap)
		if err != nil {
			t.Errorf("Error from ReadTabletActionPath: %v", err)
		}
		if contents != data {
			t.Errorf("Bad contents: %v", contents)
		}
		if ta != tabletAlias {
			t.Errorf("Bad tablet alias: %v", ta)
		}

		if err := ts.UpdateTabletAction(ap, "contents2", version); err != nil {
			t.Errorf("UpdateTabletAction failed: %v", err)
		}
		if err := ts.StoreTabletActionResponse(ap, "contents3"); err != nil {
			t.Errorf("StoreTabletActionResponse failed: %v", err)
		}
		if err := ts.UnblockTabletAction(ap); err != nil {
			t.Errorf("UnblockTabletAction failed: %v", err)
		}

		wg.Done()
		return nil
	}, done)
	close(done)
	wg.Wait()
}
开发者ID:CERN-Stage-3,项目名称:vitess,代码行数:90,代码来源:action.go

示例3: CheckLotsOfActions

func CheckLotsOfActions(t *testing.T, ts topo.Server) {
	cell := getLocalCell(t, ts)
	tablet := &topo.Tablet{
		Alias:    topo.TabletAlias{Cell: cell, Uid: 1},
		Hostname: "localhost",
		IPAddr:   "10.11.12.13",
		Portmap: map[string]int{
			"vt":    3333,
			"mysql": 3334,
		},
		Parent:   topo.TabletAlias{},
		Keyspace: "test_keyspace",
		Type:     topo.TYPE_MASTER,
		State:    topo.STATE_READ_WRITE,
		KeyRange: newKeyRange("-10"),
	}
	if err := ts.CreateTablet(tablet); err != nil {
		t.Fatalf("CreateTablet: %v", err)
	}

	nActions := 64
	paths := make([]string, nActions)

	// write the actions in parallel, save the paths
	writeWG := sync.WaitGroup{}
	for i := 0; i < nActions; i++ {
		writeWG.Add(1)
		go func(i int) {
			var err error
			paths[i], err = ts.WriteTabletAction(tablet.Alias, fmt.Sprintf("contents %v", i))
			if err != nil {
				t.Fatalf("WriteTabletAction(%v): %v", i, err)
			}
			t.Logf("WriteTabletAction(%v) done", i)
			writeWG.Done()
		}(i)
	}
	writeWG.Wait()

	// wait for all actions in parallel
	waitWG := sync.WaitGroup{}
	interrupted := make(chan struct{}, 1)
	for i := 0; i < nActions; i++ {
		waitWG.Add(1)
		go func(i int) {
			if _, err := ts.WaitForTabletAction(paths[i], time.Second*30, interrupted); err != nil {
				t.Fatalf("WaitForTabletAction returned %v", err)
			}
			t.Logf("WaitForTabletAction(%v) done", i)
			waitWG.Done()
		}(i)
	}

	// and unblock them all in parallel
	unblockWG := sync.WaitGroup{}
	for i := 0; i < nActions; i++ {
		unblockWG.Add(1)
		go func(i int) {
			defer unblockWG.Done()
			ta, contents, _, err := ts.ReadTabletActionPath(paths[i])
			if err != nil {
				t.Errorf("Error from ReadTabletActionPath: %v", err)
			}
			t.Logf("ReadTabletActionPath(%v) done", i)
			if contents != fmt.Sprintf("contents %v", i) {
				t.Errorf("Bad contents: %v", contents)
			}
			if ta != tablet.Alias {
				t.Errorf("Bad tablet alias: %v", ta)
			}

			if err := ts.StoreTabletActionResponse(paths[i], fmt.Sprintf("contents after %v", i)); err != nil {
				t.Errorf("StoreTabletActionResponse failed: %v", err)
			}
			t.Logf("StoreTabletActionResponse(%v) done", i)
			if err := ts.UnblockTabletAction(paths[i]); err != nil {
				t.Errorf("UnblockTabletAction failed: %v", err)
			}
			t.Logf("UnblockTabletAction(%v) done", i)
		}(i)
	}
	unblockWG.Wait()

	waitWG.Wait()
}
开发者ID:chinna1986,项目名称:vitess,代码行数:85,代码来源:action.go


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