本文整理汇总了Golang中github.com/youtube/vitess/go/vt/topo.Server.LockKeyspaceForAction方法的典型用法代码示例。如果您正苦于以下问题:Golang Server.LockKeyspaceForAction方法的具体用法?Golang Server.LockKeyspaceForAction怎么用?Golang Server.LockKeyspaceForAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/youtube/vitess/go/vt/topo.Server
的用法示例。
在下文中一共展示了Server.LockKeyspaceForAction方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: LockKeyspace
// LockKeyspace will lock the keyspace in the topology server.
// UnlockKeyspace should be called if this returns no error.
func (n *ActionNode) LockKeyspace(ctx context.Context, ts topo.Server, keyspace string) (lockPath string, err error) {
log.Infof("Locking keyspace %v for action %v", keyspace, n.Action)
span := trace.NewSpanFromContext(ctx)
span.StartClient("TopoServer.LockKeyspaceForAction")
span.Annotate("action", n.Action)
span.Annotate("keyspace", keyspace)
defer span.Finish()
return ts.LockKeyspaceForAction(ctx, keyspace, n.ToJSON())
}
示例2: LockKeyspace
// LockKeyspace will lock the keyspace in the topology server.
// UnlockKeyspace should be called if this returns no error.
func (n *ActionNode) LockKeyspace(ctx context.Context, ts topo.Server, keyspace string) (lockPath string, err error) {
log.Infof("Locking keyspace %v for action %v", keyspace, n.Action)
ctx, cancel := context.WithTimeout(ctx, *LockTimeout)
defer cancel()
span := trace.NewSpanFromContext(ctx)
span.StartClient("TopoServer.LockKeyspaceForAction")
span.Annotate("action", n.Action)
span.Annotate("keyspace", keyspace)
defer span.Finish()
j, err := n.ToJSON()
if err != nil {
return "", err
}
return ts.LockKeyspaceForAction(ctx, keyspace, j)
}
示例3: checkKeyspaceLockUnblocks
// checkKeyspaceLockUnblocks makes sure that a routine waiting on a lock
// is unblocked when another routine frees the lock
func checkKeyspaceLockUnblocks(ctx context.Context, t *testing.T, ts topo.Server) {
unblock := make(chan struct{})
finished := make(chan struct{})
// as soon as we're unblocked, we try to lock the keyspace
go func() {
<-unblock
lockPath, err := ts.LockKeyspaceForAction(ctx, "test_keyspace", "fake-content")
if err != nil {
t.Fatalf("LockKeyspaceForAction(test_keyspace) failed: %v", err)
}
if err = ts.UnlockKeyspaceForAction(ctx, "test_keyspace", lockPath, "fake-results"); err != nil {
t.Fatalf("UnlockKeyspaceForAction(test_keyspace): %v", err)
}
close(finished)
}()
// lock the keyspace
lockPath2, err := ts.LockKeyspaceForAction(ctx, "test_keyspace", "fake-content")
if err != nil {
t.Fatalf("LockKeyspaceForAction(test_keyspace) failed: %v", err)
}
// unblock the go routine so it starts waiting
close(unblock)
// sleep for a while so we're sure the go routine is blocking
time.Sleep(timeUntilLockIsTaken)
if err = ts.UnlockKeyspaceForAction(ctx, "test_keyspace", lockPath2, "fake-results"); err != nil {
t.Fatalf("UnlockKeyspaceForAction(test_keyspace): %v", err)
}
timeout := time.After(10 * time.Second)
select {
case <-finished:
case <-timeout:
t.Fatalf("unlocking timed out")
}
}
示例4: checkKeyspaceLockTimeout
func checkKeyspaceLockTimeout(ctx context.Context, t *testing.T, ts topo.Server) {
lockPath, err := ts.LockKeyspaceForAction(ctx, "test_keyspace", "fake-content")
if err != nil {
t.Fatalf("LockKeyspaceForAction: %v", err)
}
// test we can't take the lock again
fastCtx, cancel := context.WithTimeout(ctx, timeUntilLockIsTaken)
if _, err := ts.LockKeyspaceForAction(fastCtx, "test_keyspace", "unused-fake-content"); err != topo.ErrTimeout {
t.Fatalf("LockKeyspaceForAction(again): %v", err)
}
cancel()
// test we can interrupt taking the lock
interruptCtx, cancel := context.WithCancel(ctx)
go func() {
time.Sleep(timeUntilLockIsTaken)
cancel()
}()
if _, err := ts.LockKeyspaceForAction(interruptCtx, "test_keyspace", "unused-fake-content"); err != topo.ErrInterrupted {
t.Fatalf("LockKeyspaceForAction(interrupted): %v", err)
}
if err := ts.UnlockKeyspaceForAction(ctx, "test_keyspace", lockPath, "fake-results"); err != nil {
t.Fatalf("UnlockKeyspaceForAction(): %v", err)
}
// test we can't unlock again
if err := ts.UnlockKeyspaceForAction(ctx, "test_keyspace", lockPath, "fake-results"); err == nil {
t.Fatalf("UnlockKeyspaceForAction(again) worked")
}
}
示例5: CheckKeyspaceLock
func CheckKeyspaceLock(t *testing.T, ts topo.Server) {
if err := ts.CreateKeyspace("test_keyspace", &topo.Keyspace{}); err != nil {
t.Fatalf("CreateKeyspace: %v", err)
}
interrupted := make(chan struct{}, 1)
lockPath, err := ts.LockKeyspaceForAction("test_keyspace", "fake-content", 5*time.Second, interrupted)
if err != nil {
t.Fatalf("LockKeyspaceForAction: %v", err)
}
// test we can't take the lock again
if _, err := ts.LockKeyspaceForAction("test_keyspace", "unused-fake-content", time.Second/10, interrupted); err != topo.ErrTimeout {
t.Errorf("LockKeyspaceForAction(again): %v", err)
}
// test we can interrupt taking the lock
go func() {
time.Sleep(time.Second / 10)
close(interrupted)
}()
if _, err := ts.LockKeyspaceForAction("test_keyspace", "unused-fake-content", 5*time.Second, interrupted); err != topo.ErrInterrupted {
t.Errorf("LockKeyspaceForAction(interrupted): %v", err)
}
if err := ts.UnlockKeyspaceForAction("test_keyspace", lockPath, "fake-results"); err != nil {
t.Errorf("UnlockKeyspaceForAction(): %v", err)
}
// test we can't unlock again
if err := ts.UnlockKeyspaceForAction("test_keyspace", lockPath, "fake-results"); err == nil {
t.Error("UnlockKeyspaceForAction(again) worked")
}
// test we can't lock a non-existing keyspace
interrupted = make(chan struct{}, 1)
if _, err := ts.LockKeyspaceForAction("test_keyspace_666", "fake-content", 5*time.Second, interrupted); err == nil {
t.Fatalf("LockKeyspaceForAction(test_keyspace_666) worked for non-existing keyspace")
}
}
示例6: checkKeyspaceLockMissing
// checkKeyspaceLockMissing makes sure we can't lock a non-existing keyspace
func checkKeyspaceLockMissing(ctx context.Context, t *testing.T, ts topo.Server) {
if _, err := ts.LockKeyspaceForAction(ctx, "test_keyspace_666", "fake-content"); err == nil {
t.Fatalf("LockKeyspaceForAction(test_keyspace_666) worked for non-existing keyspace")
}
}
示例7: LockKeyspace
// LockKeyspace will lock the keyspace in the topology server.
// UnlockKeyspace should be called if this returns no error.
func (n *ActionNode) LockKeyspace(ts topo.Server, keyspace string, lockTimeout time.Duration, interrupted chan struct{}) (lockPath string, err error) {
log.Infof("Locking keyspace %v for action %v", keyspace, n.Action)
return ts.LockKeyspaceForAction(keyspace, n.ToJson(), lockTimeout, interrupted)
}