Handling a race condition better, and better error message.

This commit is contained in:
Alain Jobart 2015-04-23 07:50:32 -07:00
Родитель 810aca09a3
Коммит 651e804fc7
2 изменённых файлов: 7 добавлений и 4 удалений

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

@ -156,10 +156,11 @@ func NewActionAgent(
// try to initialize the tablet if we have to
if err := agent.InitTablet(port, securePort); err != nil {
return nil, err
return nil, fmt.Errorf("agent.InitTablet failed: %v", err)
}
// Publish and set the TargetTabletType. Not a global var since it should never be changed.
// Publish and set the TargetTabletType. Not a global var
// since it should never be changed.
statsTabletType := stats.NewString("TargetTabletType")
statsTabletType.Set(*targetTabletType)

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

@ -97,8 +97,10 @@ func (agent *ActionAgent) InitTablet(port, securePort int) error {
return fmt.Errorf("CreateKeyspace(%v) failed: %v", *initKeyspace, err)
}
// create the shard
if err := topo.CreateShard(agent.TopoServer, *initKeyspace, shard); err != nil {
// create the shard (it may already exist if
// someone else just created it, this code is
// not protected by a lock of any kind)
if err := topo.CreateShard(agent.TopoServer, *initKeyspace, shard); err != nil && err != topo.ErrNodeExists {
return fmt.Errorf("CreateShard(%v/%v) failed: %v", *initKeyspace, shard, err)
}