本文整理汇总了Golang中github.com/youtube/vitess/go/vt/mysqlctl/replication.DecodePosition函数的典型用法代码示例。如果您正苦于以下问题:Golang DecodePosition函数的具体用法?Golang DecodePosition怎么用?Golang DecodePosition使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DecodePosition函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: PromoteSlaveWhenCaughtUp
// PromoteSlaveWhenCaughtUp waits for this slave to be caught up on
// replication up to the provided point, and then makes the slave the
// shard master.
func (agent *ActionAgent) PromoteSlaveWhenCaughtUp(ctx context.Context, position string) (string, error) {
pos, err := replication.DecodePosition(position)
if err != nil {
return "", err
}
// TODO(alainjobart) change the flavor API to take the context directly
// For now, extract the timeout from the context, or wait forever
var waitTimeout time.Duration
if deadline, ok := ctx.Deadline(); ok {
waitTimeout = deadline.Sub(time.Now())
if waitTimeout <= 0 {
waitTimeout = time.Millisecond
}
}
if err := agent.MysqlDaemon.WaitMasterPos(pos, waitTimeout); err != nil {
return "", err
}
pos, err = agent.MysqlDaemon.PromoteSlave(agent.hookExtraEnv())
if err != nil {
return "", err
}
if err := agent.MysqlDaemon.SetReadOnly(false); err != nil {
return "", err
}
if _, err := topotools.ChangeType(ctx, agent.TopoServer, agent.TabletAlias, topodatapb.TabletType_MASTER, topotools.ClearHealthMap); err != nil {
return "", err
}
return replication.EncodePosition(pos), nil
}
示例2: WaitBlpPosition
// WaitBlpPosition will wait for the filtered replication to reach at least
// the provided position.
func WaitBlpPosition(ctx context.Context, mysqld MysqlDaemon, sql string, replicationPosition string) error {
position, err := replication.DecodePosition(replicationPosition)
if err != nil {
return err
}
for {
select {
case <-ctx.Done():
return ctx.Err()
default:
}
qr, err := mysqld.FetchSuperQuery(ctx, sql)
if err != nil {
return err
}
if len(qr.Rows) != 1 {
return fmt.Errorf("QueryBlpCheckpoint(%v) returned unexpected row count: %v", sql, len(qr.Rows))
}
var pos replication.Position
if !qr.Rows[0][0].IsNull() {
pos, err = replication.DecodePosition(qr.Rows[0][0].String())
if err != nil {
return err
}
}
if pos.AtLeast(position) {
return nil
}
log.Infof("Sleeping 1 second waiting for binlog replication(%v) to catch up: %v != %v", sql, pos, position)
time.Sleep(1 * time.Second)
}
}
示例3: positionCmd
func positionCmd(subFlags *flag.FlagSet, args []string) error {
subFlags.Parse(args)
if len(args) < 3 {
return fmt.Errorf("Not enough arguments for position operation.")
}
pos1, err := replication.DecodePosition(args[1])
if err != nil {
return err
}
switch args[0] {
case "equal":
pos2, err := replication.DecodePosition(args[2])
if err != nil {
return err
}
fmt.Println(pos1.Equal(pos2))
case "at_least":
pos2, err := replication.DecodePosition(args[2])
if err != nil {
return err
}
fmt.Println(pos1.AtLeast(pos2))
case "append":
gtid, err := replication.DecodeGTID(args[2])
if err != nil {
return err
}
fmt.Println(replication.AppendGTID(pos1, gtid))
}
return nil
}
示例4: WaitBlpPosition
// WaitBlpPosition will wait for the filtered replication to reach at least
// the provided position.
func WaitBlpPosition(mysqld MysqlDaemon, sql string, replicationPosition string, waitTimeout time.Duration) error {
position, err := replication.DecodePosition(replicationPosition)
if err != nil {
return err
}
timeOut := time.Now().Add(waitTimeout)
for {
if time.Now().After(timeOut) {
break
}
qr, err := mysqld.FetchSuperQuery(sql)
if err != nil {
return err
}
if len(qr.Rows) != 1 {
return fmt.Errorf("QueryBlpCheckpoint(%v) returned unexpected row count: %v", sql, len(qr.Rows))
}
var pos replication.Position
if !qr.Rows[0][0].IsNull() {
pos, err = replication.DecodePosition(qr.Rows[0][0].String())
if err != nil {
return err
}
}
if pos.AtLeast(position) {
return nil
}
log.Infof("Sleeping 1 second waiting for binlog replication(%v) to catch up: %v != %v", sql, pos, position)
time.Sleep(1 * time.Second)
}
return fmt.Errorf("WaitBlpPosition(%v) timed out", sql)
}
示例5: ServeUpdateStream
// ServeUpdateStream is part of the UpdateStream interface
func (updateStream *UpdateStreamImpl) ServeUpdateStream(position string, sendReply func(reply *binlogdatapb.StreamEvent) error) (err error) {
pos, err := replication.DecodePosition(position)
if err != nil {
return err
}
updateStream.actionLock.Lock()
if !updateStream.IsEnabled() {
updateStream.actionLock.Unlock()
log.Errorf("Unable to serve client request: update stream service is not enabled")
return fmt.Errorf("update stream service is not enabled")
}
updateStream.stateWaitGroup.Add(1)
updateStream.actionLock.Unlock()
defer updateStream.stateWaitGroup.Done()
streamCount.Add("Updates", 1)
defer streamCount.Add("Updates", -1)
log.Infof("ServeUpdateStream starting @ %#v", pos)
evs := NewEventStreamer(updateStream.dbname, updateStream.mysqld, pos, func(reply *binlogdatapb.StreamEvent) error {
if reply.Category == binlogdatapb.StreamEvent_SE_ERR {
updateStreamErrors.Add("UpdateStream", 1)
} else {
updateStreamEvents.Add(reply.Category.String(), 1)
}
return sendReply(reply)
})
svm := &sync2.ServiceManager{}
svm.Go(evs.Stream)
updateStream.streams.Add(svm)
defer updateStream.streams.Delete(svm)
return svm.Join()
}
示例6: StreamTables
// StreamTables is part of the UpdateStream interface
func (updateStream *UpdateStreamImpl) StreamTables(position string, tables []string, charset *binlogdatapb.Charset, sendReply func(reply *binlogdatapb.BinlogTransaction) error) (err error) {
pos, err := replication.DecodePosition(position)
if err != nil {
return err
}
updateStream.actionLock.Lock()
if !updateStream.IsEnabled() {
updateStream.actionLock.Unlock()
log.Errorf("Unable to serve client request: Update stream service is not enabled")
return fmt.Errorf("update stream service is not enabled")
}
updateStream.stateWaitGroup.Add(1)
updateStream.actionLock.Unlock()
defer updateStream.stateWaitGroup.Done()
streamCount.Add("Tables", 1)
defer streamCount.Add("Tables", -1)
log.Infof("ServeUpdateStream starting @ %#v", pos)
// Calls cascade like this: binlog.Streamer->TablesFilterFunc->func(*binlogdatapb.BinlogTransaction)->sendReply
f := TablesFilterFunc(tables, func(reply *binlogdatapb.BinlogTransaction) error {
keyrangeStatements.Add(int64(len(reply.Statements)))
keyrangeTransactions.Add(1)
return sendReply(reply)
})
bls := NewStreamer(updateStream.dbname, updateStream.mysqld, charset, pos, f)
svm := &sync2.ServiceManager{}
svm.Go(bls.Stream)
updateStream.streams.Add(svm)
defer updateStream.streams.Delete(svm)
return svm.Join()
}
示例7: PromoteSlaveWhenCaughtUp
// PromoteSlaveWhenCaughtUp waits for this slave to be caught up on
// replication up to the provided point, and then makes the slave the
// shard master.
func (agent *ActionAgent) PromoteSlaveWhenCaughtUp(ctx context.Context, position string) (string, error) {
pos, err := replication.DecodePosition(position)
if err != nil {
return "", err
}
if err := agent.MysqlDaemon.WaitMasterPos(ctx, pos); err != nil {
return "", err
}
pos, err = agent.MysqlDaemon.PromoteSlave(agent.hookExtraEnv())
if err != nil {
return "", err
}
// If using semi-sync, we need to enable it before going read-write.
if *enableSemiSync {
if err := agent.enableSemiSync(true); err != nil {
return "", err
}
}
if err := agent.MysqlDaemon.SetReadOnly(false); err != nil {
return "", err
}
if _, err := topotools.ChangeType(ctx, agent.TopoServer, agent.TabletAlias, topodatapb.TabletType_MASTER); err != nil {
return "", err
}
return replication.EncodePosition(pos), nil
}
示例8: InitSlave
// InitSlave sets replication master and position, and waits for the
// reparent_journal table entry up to context timeout
func (agent *ActionAgent) InitSlave(ctx context.Context, parent *topodatapb.TabletAlias, position string, timeCreatedNS int64) error {
pos, err := replication.DecodePosition(position)
if err != nil {
return err
}
ti, err := agent.TopoServer.GetTablet(ctx, parent)
if err != nil {
return err
}
cmds, err := agent.MysqlDaemon.SetSlavePositionCommands(pos)
if err != nil {
return err
}
cmds2, err := agent.MysqlDaemon.SetMasterCommands(ti.Hostname, int(ti.PortMap["mysql"]))
if err != nil {
return err
}
cmds = append(cmds, cmds2...)
cmds = append(cmds, "START SLAVE")
if err := agent.MysqlDaemon.ExecuteSuperQueryList(cmds); err != nil {
return err
}
agent.initReplication = true
// wait until we get the replicated row, or our context times out
return agent.MysqlDaemon.WaitForReparentJournal(ctx, timeCreatedNS)
}
示例9: StreamTables
// StreamTables is part of the UpdateStream interface
func (updateStream *UpdateStreamImpl) StreamTables(ctx context.Context, position string, tables []string, charset *binlogdatapb.Charset, sendReply func(reply *binlogdatapb.BinlogTransaction) error) (err error) {
pos, err := replication.DecodePosition(position)
if err != nil {
return err
}
updateStream.actionLock.Lock()
if !updateStream.IsEnabled() {
updateStream.actionLock.Unlock()
log.Errorf("Unable to serve client request: Update stream service is not enabled")
return fmt.Errorf("update stream service is not enabled")
}
updateStream.stateWaitGroup.Add(1)
updateStream.actionLock.Unlock()
defer updateStream.stateWaitGroup.Done()
streamCount.Add("Tables", 1)
defer streamCount.Add("Tables", -1)
log.Infof("ServeUpdateStream starting @ %#v", pos)
// Calls cascade like this: binlog.Streamer->TablesFilterFunc->func(*binlogdatapb.BinlogTransaction)->sendReply
f := TablesFilterFunc(tables, func(reply *binlogdatapb.BinlogTransaction) error {
tablesStatements.Add(int64(len(reply.Statements)))
tablesTransactions.Add(1)
return sendReply(reply)
})
bls := NewStreamer(updateStream.dbname, updateStream.mysqld, charset, pos, 0, f)
streamCtx, cancel := context.WithCancel(ctx)
i := updateStream.streams.Add(cancel)
defer updateStream.streams.Delete(i)
return bls.Stream(streamCtx)
}
示例10: processTablet
func (maxPosSearch *maxReplPosSearch) processTablet(tablet *topodatapb.Tablet) {
defer maxPosSearch.waitGroup.Done()
maxPosSearch.wrangler.logger.Infof("getting replication position from %v", topoproto.TabletAliasString(tablet.Alias))
slaveStatusCtx, cancelSlaveStatus := context.WithTimeout(maxPosSearch.ctx, maxPosSearch.waitSlaveTimeout)
defer cancelSlaveStatus()
status, err := maxPosSearch.wrangler.tmc.SlaveStatus(slaveStatusCtx, tablet)
if err != nil {
maxPosSearch.wrangler.logger.Warningf("failed to get replication status from %v, ignoring tablet: %v", topoproto.TabletAliasString(tablet.Alias), err)
return
}
replPos, err := replication.DecodePosition(status.Position)
if err != nil {
maxPosSearch.wrangler.logger.Warningf("cannot decode slave %v position %v: %v", topoproto.TabletAliasString(tablet.Alias), status.Position, err)
return
}
maxPosSearch.maxPosLock.Lock()
if maxPosSearch.maxPosTablet == nil || !maxPosSearch.maxPos.AtLeast(replPos) {
maxPosSearch.maxPos = replPos
maxPosSearch.maxPosTablet = tablet
}
maxPosSearch.maxPosLock.Unlock()
}
示例11: PopulateReparentJournal
// PopulateReparentJournal adds an entry into the reparent_journal table.
func (agent *ActionAgent) PopulateReparentJournal(ctx context.Context, timeCreatedNS int64, actionName string, masterAlias *topodatapb.TabletAlias, position string) error {
pos, err := replication.DecodePosition(position)
if err != nil {
return err
}
cmds := mysqlctl.CreateReparentJournal()
cmds = append(cmds, mysqlctl.PopulateReparentJournal(timeCreatedNS, actionName, topoproto.TabletAliasString(masterAlias), pos))
return agent.MysqlDaemon.ExecuteSuperQueryList(cmds)
}
示例12: NewBinlogPlayerKeyRange
// NewBinlogPlayerKeyRange returns a new BinlogPlayer pointing at the server
// replicating the provided keyrange, starting at the startPosition,
// and updating _vt.blp_checkpoint with uid=startPosition.Uid.
// If !stopPosition.IsZero(), it will stop when reaching that position.
func NewBinlogPlayerKeyRange(dbClient VtClient, tablet *topodatapb.Tablet, keyRange *topodatapb.KeyRange, uid uint32, startPosition string, stopPosition string, blplStats *Stats) (*BinlogPlayer, error) {
result := &BinlogPlayer{
tablet: tablet,
dbClient: dbClient,
keyRange: keyRange,
uid: uid,
blplStats: blplStats,
}
var err error
result.position, err = replication.DecodePosition(startPosition)
if err != nil {
return nil, err
}
if stopPosition != "" {
result.stopPosition, err = replication.DecodePosition(stopPosition)
if err != nil {
return nil, err
}
}
return result, nil
}
示例13: Fresher
// Fresher compares two event tokens. It returns a negative number if
// ev1<ev2, zero if they're equal, and a positive number if
// ev1>ev2. In case of doubt (we don't have enough information to know
// for sure), it returns a negative number.
func Fresher(ev1, ev2 *querypb.EventToken) int {
if ev1 == nil || ev2 == nil {
// Either one is nil, we don't know.
return -1
}
if ev1.Timestamp != ev2.Timestamp {
// The timestamp is enough to set them apart.
return int(ev1.Timestamp - ev2.Timestamp)
}
if ev1.Shard != "" && ev1.Shard == ev2.Shard {
// They come from the same shard. See if we have positions.
if ev1.Position == "" || ev2.Position == "" {
return -1
}
// We can parse them.
pos1, err := replication.DecodePosition(ev1.Position)
if err != nil {
return -1
}
pos2, err := replication.DecodePosition(ev2.Position)
if err != nil {
return -1
}
// Then compare.
if pos1.Equal(pos2) {
return 0
}
if pos1.AtLeast(pos2) {
return 1
}
return -1
}
// We do not know.
return -1
}
示例14: NewBinlogPlayerKeyRange
// NewBinlogPlayerKeyRange returns a new BinlogPlayer pointing at the server
// replicating the provided keyrange, starting at the startPosition,
// and updating _vt.blp_checkpoint with uid=startPosition.Uid.
// If !stopPosition.IsZero(), it will stop when reaching that position.
func NewBinlogPlayerKeyRange(dbClient VtClient, endPoint *pbt.EndPoint, keyspaceIDType pbt.KeyspaceIdType, keyRange *pbt.KeyRange, uid uint32, startPosition string, stopPosition string, blplStats *Stats) (*BinlogPlayer, error) {
result := &BinlogPlayer{
endPoint: endPoint,
dbClient: dbClient,
keyspaceIDType: keyspaceIDType,
keyRange: keyRange,
uid: uid,
blplStats: blplStats,
}
var err error
result.position, err = replication.DecodePosition(startPosition)
if err != nil {
return nil, err
}
if stopPosition != "" {
result.stopPosition, err = replication.DecodePosition(stopPosition)
if err != nil {
return nil, err
}
}
return result, nil
}
示例15: NewBinlogPlayerTables
// NewBinlogPlayerTables returns a new BinlogPlayer pointing at the server
// replicating the provided tables, starting at the startPosition,
// and updating _vt.blp_checkpoint with uid=startPosition.Uid.
// If !stopPosition.IsZero(), it will stop when reaching that position.
func NewBinlogPlayerTables(dbClient VtClient, endPoint *pbt.EndPoint, tables []string, uid uint32, startPosition string, stopPosition string, blplStats *Stats) (*BinlogPlayer, error) {
result := &BinlogPlayer{
endPoint: endPoint,
dbClient: dbClient,
tables: tables,
uid: uid,
blplStats: blplStats,
}
var err error
result.position, err = replication.DecodePosition(startPosition)
if err != nil {
return nil, err
}
if stopPosition != "" {
var err error
result.stopPosition, err = replication.DecodePosition(stopPosition)
if err != nil {
return nil, err
}
}
return result, nil
}