Add compatibility flag to lock for all serving graph updates.

This commit is contained in:
Anthony Yeh 2015-06-05 02:22:42 -07:00
Родитель 9341a267e0
Коммит 2f24bcdf4a
1 изменённых файлов: 17 добавлений и 1 удалений

Просмотреть файл

@ -5,6 +5,7 @@
package topotools
import (
"flag"
"fmt"
"sync"
"time"
@ -17,6 +18,8 @@ import (
"golang.org/x/net/context"
)
var lockSrvShard = flag.Bool("lock_srvshard", true, "serialize serving graph updates by locking the SrvShard")
// RebuildShard updates the SrvShard objects and underlying serving graph.
//
// Re-read from TopologyServer to make sure we are using the side
@ -339,7 +342,20 @@ func retryUpdateEndpoints(ctx context.Context, ts topo.Server, cell, keyspace, s
// UpdateTabletEndpoints fixes up any entries in the serving graph that relate
// to a given tablet.
func UpdateTabletEndpoints(ctx context.Context, ts topo.Server, tablet *topo.Tablet) error {
func UpdateTabletEndpoints(ctx context.Context, ts topo.Server, tablet *topo.Tablet) (err error) {
if *lockSrvShard {
// This lock is only necessary until all tablets are upgraded to lock-free.
actionNode := actionnode.RebuildSrvShard()
lockPath, err := actionNode.LockSrvShard(ctx, ts, tablet.Alias.Cell, tablet.Keyspace, tablet.Shard)
if err != nil {
return fmt.Errorf("can't lock shard for UpdateTabletEndpoints(%v): %v", tablet, err)
}
defer func() {
actionNode.UnlockSrvShard(ctx, ts, tablet.Alias.Cell, tablet.Keyspace, tablet.Shard, lockPath, err)
}()
}
srvTypes, err := ts.GetSrvTabletTypesPerShard(ctx, tablet.Alias.Cell, tablet.Keyspace, tablet.Shard)
if err != nil {
if err != topo.ErrNoNode {