本文整理汇总了Golang中github.com/youtube/vitess/go/sync2.ServiceContext.IsRunning方法的典型用法代码示例。如果您正苦于以下问题:Golang ServiceContext.IsRunning方法的具体用法?Golang ServiceContext.IsRunning怎么用?Golang ServiceContext.IsRunning使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/youtube/vitess/go/sync2.ServiceContext
的用法示例。
在下文中一共展示了ServiceContext.IsRunning方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: run
func (rci *RowcacheInvalidator) run(ctx *sync2.ServiceContext) error {
for {
evs := binlog.NewEventStreamer(rci.dbname, rci.mysqld, rci.Position(), rci.processEvent)
// We wrap this code in a func so we can catch all panics.
// If an error is returned, we log it, wait 1 second, and retry.
// This loop can only be stopped by calling Close.
err := func() (inner error) {
defer func() {
if x := recover(); x != nil {
inner = fmt.Errorf("%v: uncaught panic:\n%s", x, tb.Stack(4))
}
}()
return evs.Stream(ctx)
}()
if err == nil || !ctx.IsRunning() {
break
}
if IsConnErr(err) {
rci.checker.CheckMySQL()
}
log.Errorf("binlog.ServeUpdateStream returned err '%v', retrying in 1 second.", err.Error())
rci.qe.queryServiceStats.InternalErrors.Add("Invalidation", 1)
time.Sleep(1 * time.Second)
}
log.Infof("Rowcache invalidator stopped")
return nil
}
示例2: nextStatement
// nextStatement returns the next statement encountered in the binlog stream. If there are
// positional comments, it updates the binlogFileStreamer state. It also ignores events that
// are not material. If it returns nil, it's the end of stream. If err is also nil, then
// it was due to a normal termination.
func (bls *binlogFileStreamer) nextStatement(ctx *sync2.ServiceContext, bufReader *bufio.Reader) (stmt []byte, err error) {
eventLoop:
for {
// Stop processing if we're shutting down
if !ctx.IsRunning() {
return nil, io.EOF
}
event, err := bls.readEvent(bufReader)
if err != nil {
if err == io.EOF {
return nil, nil
}
return nil, err
}
values := posRE.FindSubmatch(event)
if values != nil {
bls.blPos.ServerId = mustParseInt64(values[1])
bls.file.Set(mustParseInt64(values[2]))
// Make the fake Google GTID format we invented.
gtid := string(values[1]) + "-" + string(values[3])
bls.blPos.GTID = myproto.MustParseGTID(blsMysqlFlavor, gtid)
continue
}
values = rotateRE.FindSubmatch(event)
if values != nil {
err = bls.file.Rotate(path.Join(bls.dir, string(values[1])), mustParseInt64(values[2]))
if err != nil {
return nil, err
}
return nil, nil
}
if bytes.HasPrefix(event, eolfPrefix) {
return nil, nil
}
values = delimRE.FindSubmatch(event)
if values != nil {
bls.delim = values[1]
continue
}
for _, ignorePrefix := range ignorePrefixes {
if bytes.HasPrefix(event, ignorePrefix) {
continue eventLoop
}
}
return event, nil
}
}
示例3: WaitForChange
func (f *fileInfo) WaitForChange(ctx *sync2.ServiceContext) error {
for {
// Stop waiting if we're shutting down
if !ctx.IsRunning() {
return io.EOF
}
time.Sleep(100 * time.Millisecond)
fi, err := f.handle.Stat()
if err != nil {
return fmt.Errorf("stat error: %v", err)
}
if fi.Size() != f.lastPos {
return nil
}
}
}
示例4: parseEvents
// parseEvents processes the raw binlog dump stream from the server, one event
// at a time, and groups them into transactions. It is called from within the
// service function launched by Stream().
//
// If the sendTransaction func returns io.EOF, parseEvents returns ErrClientEOF.
// If the events channel is closed, parseEvents returns ErrServerEOF.
func (bls *BinlogStreamer) parseEvents(ctx *sync2.ServiceContext, events <-chan proto.BinlogEvent) (myproto.ReplicationPosition, error) {
var statements []proto.Statement
var format proto.BinlogFormat
var gtid myproto.GTID
var pos = bls.startPos
var autocommit = true
var err error
// A begin can be triggered either by a BEGIN query, or by a GTID_EVENT.
begin := func() {
if statements != nil {
// If this happened, it would be a legitimate error.
log.Errorf("BEGIN in binlog stream while still in another transaction; dropping %d statements: %v", len(statements), statements)
binlogStreamerErrors.Add("ParseEvents", 1)
}
statements = make([]proto.Statement, 0, 10)
autocommit = false
}
// A commit can be triggered either by a COMMIT query, or by an XID_EVENT.
// Statements that aren't wrapped in BEGIN/COMMIT are committed immediately.
commit := func(timestamp uint32) error {
trans := &proto.BinlogTransaction{
Statements: statements,
Timestamp: int64(timestamp),
TransactionID: myproto.EncodeGTID(gtid),
}
if err = bls.sendTransaction(trans); err != nil {
if err == io.EOF {
return ErrClientEOF
}
return fmt.Errorf("send reply error: %v", err)
}
statements = nil
autocommit = true
return nil
}
// Parse events.
for ctx.IsRunning() {
var ev proto.BinlogEvent
var ok bool
select {
case ev, ok = <-events:
if !ok {
// events channel has been closed, which means the connection died.
log.Infof("reached end of binlog event stream")
return pos, ErrServerEOF
}
case <-ctx.ShuttingDown:
log.Infof("stopping early due to BinlogStreamer service shutdown")
return pos, nil
}
// Validate the buffer before reading fields from it.
if !ev.IsValid() {
return pos, fmt.Errorf("can't parse binlog event, invalid data: %#v", ev)
}
// We need to keep checking for FORMAT_DESCRIPTION_EVENT even after we've
// seen one, because another one might come along (e.g. on log rotate due to
// binlog settings change) that changes the format.
if ev.IsFormatDescription() {
format, err = ev.Format()
if err != nil {
return pos, fmt.Errorf("can't parse FORMAT_DESCRIPTION_EVENT: %v, event data: %#v", err, ev)
}
continue
}
// We can't parse anything until we get a FORMAT_DESCRIPTION_EVENT that
// tells us the size of the event header.
if format.IsZero() {
// The only thing that should come before the FORMAT_DESCRIPTION_EVENT
// is a fake ROTATE_EVENT, which the master sends to tell us the name
// of the current log file.
if ev.IsRotate() {
continue
}
return pos, fmt.Errorf("got a real event before FORMAT_DESCRIPTION_EVENT: %#v", ev)
}
// Strip the checksum, if any. We don't actually verify the checksum, so discard it.
ev, _, err = ev.StripChecksum(format)
if err != nil {
return pos, fmt.Errorf("can't strip checksum from binlog event: %v, event data: %#v", err, ev)
}
// Update the GTID if the event has one. The actual event type could be
// something special like GTID_EVENT (MariaDB, MySQL 5.6), or it could be
// an arbitrary event with a GTID in the header (Google MySQL).
if ev.HasGTID(format) {
gtid, err = ev.GTID(format)
if err != nil {
//.........这里部分代码省略.........