本文整理汇总了Golang中github.com/youtube/vitess/go/vt/topo.ShardInfo.Version方法的典型用法代码示例。如果您正苦于以下问题:Golang ShardInfo.Version方法的具体用法?Golang ShardInfo.Version怎么用?Golang ShardInfo.Version使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/youtube/vitess/go/vt/topo.ShardInfo
的用法示例。
在下文中一共展示了ShardInfo.Version方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: UpdateShard
// UpdateShard is part of the topo.Server interface
func (tee *Tee) UpdateShard(ctx context.Context, si *topo.ShardInfo, existingVersion int64) (newVersion int64, err error) {
if newVersion, err = tee.primary.UpdateShard(ctx, si, existingVersion); err != nil {
// failed on primary, not updating secondary
return
}
// if we have a mapping between shard version in first topo
// and shard version in second topo, replace the version number.
// if not, this will probably fail and log.
tee.mu.Lock()
svm, ok := tee.shardVersionMapping[si.Keyspace()+"/"+si.ShardName()]
if ok && svm.readFromVersion == existingVersion {
existingVersion = svm.readFromSecondVersion
delete(tee.shardVersionMapping, si.Keyspace()+"/"+si.ShardName())
}
tee.mu.Unlock()
if newVersion2, serr := tee.secondary.UpdateShard(ctx, si, existingVersion); serr != nil {
// not critical enough to fail
if serr == topo.ErrNoNode {
// the shard doesn't exist on the secondary, let's
// just create it
if serr = tee.secondary.CreateShard(ctx, si.Keyspace(), si.ShardName(), si.Shard); serr != nil {
log.Warningf("secondary.CreateShard(%v,%v) failed (after UpdateShard returned ErrNoNode): %v", si.Keyspace(), si.ShardName(), serr)
} else {
log.Infof("secondary.UpdateShard(%v, %v) failed with ErrNoNode, CreateShard then worked.", si.Keyspace(), si.ShardName())
si, gerr := tee.secondary.GetShard(ctx, si.Keyspace(), si.ShardName())
if gerr != nil {
log.Warningf("Failed to re-read shard(%v, %v) after creating it on secondary: %v", si.Keyspace(), si.ShardName(), gerr)
} else {
tee.mu.Lock()
tee.shardVersionMapping[si.Keyspace()+"/"+si.ShardName()] = versionMapping{
readFromVersion: newVersion,
readFromSecondVersion: si.Version(),
}
tee.mu.Unlock()
}
}
} else {
log.Warningf("secondary.UpdateShard(%v, %v) failed: %v", si.Keyspace(), si.ShardName(), serr)
}
} else {
tee.mu.Lock()
tee.shardVersionMapping[si.Keyspace()+"/"+si.ShardName()] = versionMapping{
readFromVersion: newVersion,
readFromSecondVersion: newVersion2,
}
tee.mu.Unlock()
}
return
}