diff --git a/go/vt/topo/consultopo/replication_graph.go b/go/vt/topo/consultopo/replication_graph.go index 4a22ce3e2d5..2dbccf7ee70 100644 --- a/go/vt/topo/consultopo/replication_graph.go +++ b/go/vt/topo/consultopo/replication_graph.go @@ -49,16 +49,21 @@ func (s *Server) UpdateShardReplicationFields(ctx context.Context, cell, keyspac if version == nil { // We have to create, and we catch ErrNodeExists. _, err = s.Create(ctx, cell, p, data) - if err != topo.ErrNodeExists { - return err - } - } else { - // We have to update, and we catch ErrBadVersion. - _, err = s.Update(ctx, cell, p, data, version) - if err != topo.ErrBadVersion { - return err + if err == topo.ErrNodeExists { + // Node was created by another process, try + // again. + continue } + return err + } + + // We have to update, and we catch ErrBadVersion. + _, err = s.Update(ctx, cell, p, data, version) + if err == topo.ErrBadVersion { + // Node was updated by another process, try again. + continue } + return err } } diff --git a/go/vt/topo/etcd2topo/replication_graph.go b/go/vt/topo/etcd2topo/replication_graph.go index 0262c997515..7feecc8531f 100644 --- a/go/vt/topo/etcd2topo/replication_graph.go +++ b/go/vt/topo/etcd2topo/replication_graph.go @@ -53,16 +53,21 @@ func (s *Server) UpdateShardReplicationFields(ctx context.Context, cell, keyspac if version == nil { // We have to create, and we catch ErrNodeExists. _, err = s.Create(ctx, cell, p, data) - if err != topo.ErrNodeExists { - return err - } - } else { - // We have to update, and we catch ErrBadVersion. - _, err = s.Update(ctx, cell, p, data, version) - if err != topo.ErrBadVersion { - return err + if err == topo.ErrNodeExists { + // Node was created by another process, try + // again. + continue } + return err + } + + // We have to update, and we catch ErrBadVersion. + _, err = s.Update(ctx, cell, p, data, version) + if err == topo.ErrBadVersion { + // Node was updated by another process, try again. + continue } + return err } } diff --git a/go/vt/topo/zk2topo/replication_graph.go b/go/vt/topo/zk2topo/replication_graph.go index 7120cda6bd8..66b127d358c 100644 --- a/go/vt/topo/zk2topo/replication_graph.go +++ b/go/vt/topo/zk2topo/replication_graph.go @@ -56,16 +56,21 @@ func (zs *Server) UpdateShardReplicationFields(ctx context.Context, cell, keyspa if version == nil { // We have to create, and we catch ErrNodeExists. _, err = zs.Create(ctx, cell, zkPath, data) - if err != topo.ErrNodeExists { - return err - } - } else { - // We have to update, and we catch ErrBadVersion. - _, err = zs.Update(ctx, cell, zkPath, data, version) - if err != topo.ErrBadVersion { - return err + if err == topo.ErrNodeExists { + // Node was created by another process, try + // again. + continue } + return err + } + + // We have to update, and we catch ErrBadVersion. + _, err = zs.Update(ctx, cell, zkPath, data, version) + if err == topo.ErrBadVersion { + // Node was updated by another process, try again. + continue } + return err } }