本文整理汇总了Golang中github.com/siddontang/go/log.Infof函数的典型用法代码示例。如果您正苦于以下问题:Golang Infof函数的具体用法?Golang Infof怎么用?Golang Infof使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Infof函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: tryDump
func (c *Canal) tryDump() error {
if len(c.master.Name) > 0 && c.master.Position > 0 {
// we will sync with binlog name and position
log.Infof("skip dump, use last binlog replication pos (%s, %d)", c.master.Name, c.master.Position)
return nil
}
if c.dumper == nil {
log.Info("skip dump, no mysqldump")
return nil
}
h := &dumpParseHandler{c: c}
start := time.Now()
log.Info("try dump MySQL and parse")
if err := c.dumper.DumpAndParse(h); err != nil {
return err
}
log.Infof("dump MySQL and parse OK, use %0.2f seconds, start binlog replication at (%s, %d)",
time.Now().Sub(start).Seconds(), h.name, h.pos)
c.master.Update(h.name, uint32(h.pos))
c.master.Save(true)
return nil
}
示例2: readIndexFile
func readIndexFile(configDir string, rule *config.Rule) ([]byte, error) {
if rule.IndexFile != "" {
// Index file explicitly specified. Fail if not found.
path := rule.IndexFile
if !strings.HasPrefix(rule.IndexFile, "/") {
// indexFile is relative to config dir
path = configDir + "/" + rule.IndexFile
}
log.Infof("Using index setting from %s", path)
return ioutil.ReadFile(path)
} else {
var path string
// No index file specified. Read file if default (<cfdDir>/<idx>.idx.josn) exists
// strip trailing -[0-9]+ so indexes with version suffixes match a base settings file
if m := regexp.MustCompile("(.+)-[0-9]+").FindStringSubmatch(rule.Index); len(m) == 0 {
path = configDir + "/" + rule.Index + ".idx.json"
} else {
path = configDir + "/" + m[0] + ".idx.json"
}
data, err := ioutil.ReadFile(path)
if os.IsNotExist(err) {
return nil, nil
} else {
log.Infof("Using index settings from %s", path)
return data, err
}
}
}
示例3: Elect
// Elect a best slave which has the most up-to-date data with master
func (g *Group) Elect() (string, error) {
g.m.Lock()
defer g.m.Unlock()
var addr string
var checkOffset int64 = 0
var checkPriority int = 0
for _, slave := range g.Slaves {
m, err := slave.doRelpInfo()
if err != nil {
log.Infof("slave %s get replication info err %v, skip it", slave.Addr, err)
continue
}
if m["slave"] == MasterType {
log.Errorf("server %s is not slave now, skip it", slave.Addr)
continue
}
if m["master_link_status"] == "up" {
log.Infof("slave %s master_link_status is up, master %s may be not down???",
slave.Addr, g.Master.Addr)
return "", ErrNodeAlive
}
priority, _ := strconv.Atoi(m["slave_priority"])
replOffset, _ := strconv.ParseInt(m["slave_repl_offset"], 10, 64)
used := false
// like redis-sentinel, first check priority, then salve repl offset
if checkPriority < priority {
used = true
} else if checkPriority == priority {
if checkOffset < replOffset {
used = true
}
}
if used {
addr = slave.Addr
checkPriority = priority
checkOffset = replOffset
}
}
if len(addr) == 0 {
log.Errorf("no proper candidate to be promoted")
return "", ErrNoCandidate
}
log.Infof("select slave %s as new master, priority:%d, repl_offset:%d", addr, checkPriority, checkOffset)
return addr, nil
}
示例4: startSyncBinlog
func (c *Canal) startSyncBinlog() error {
pos := mysql.Position{c.master.Name, c.master.Position}
log.Infof("start sync binlog at %v", pos)
s, err := c.syncer.StartSync(pos)
if err != nil {
return errors.Errorf("start sync replication at %v error %v", pos, err)
}
timeout := time.Second
forceSavePos := false
for {
ev, err := s.GetEventTimeout(timeout)
if err != nil && err != replication.ErrGetEventTimeout {
return errors.Trace(err)
} else if err == replication.ErrGetEventTimeout {
timeout = 2 * timeout
continue
}
timeout = time.Second
//next binlog pos
pos.Pos = ev.Header.LogPos
forceSavePos = false
switch e := ev.Event.(type) {
case *replication.RotateEvent:
pos.Name = string(e.NextLogName)
pos.Pos = uint32(e.Position)
// r.ev <- pos
forceSavePos = true
log.Infof("rotate binlog to %v", pos)
case *replication.RowsEvent:
// we only focus row based event
if err = c.handleRowsEvent(ev); err != nil {
log.Errorf("handle rows event error %v", err)
return errors.Trace(err)
}
case *replication.TableMapEvent:
continue
default:
}
c.master.Update(pos.Name, pos.Pos)
c.master.Save(forceSavePos)
}
return nil
}
示例5: parseMetadataFile
func (d *Dumper) parseMetadataFile(meta string, w io.Writer) error {
log.Infof("Parsing: %s", meta)
if file, err := os.Open(meta); err != nil {
return err
} else {
defer file.Close()
scanner := bufio.NewScanner(file)
binLogExp := regexp.MustCompile("\\s+Log:\\s+(.+)")
binLogPosExp := regexp.MustCompile("\\s+Pos:\\s+(\\d+)")
binLog := ""
binLogPos := ""
for scanner.Scan() {
line := scanner.Text()
if m := binLogExp.FindStringSubmatch(line); len(m) > 0 {
binLog = m[1]
} else if m := binLogPosExp.FindStringSubmatch(line); len(m) > 0 {
binLogPos = m[1]
}
}
if err = scanner.Err(); err != nil {
return err
} else {
stmnt := fmt.Sprintf("CHANGE MASTER TO MASTER_LOG_FILE='%s', MASTER_LOG_POS=%s;\n", binLog, binLogPos)
log.Debug(stmnt)
_, err = fmt.Fprintf(w, stmnt)
return err
}
}
}
示例6: slaveof
func (app *App) slaveof(masterAddr string, restart bool, readonly bool) error {
app.m.Lock()
defer app.m.Unlock()
//in master mode and no slaveof, only set readonly
if len(app.cfg.SlaveOf) == 0 && len(masterAddr) == 0 {
app.cfg.SetReadonly(readonly)
return nil
}
if !app.ldb.ReplicationUsed() {
return fmt.Errorf("slaveof must enable replication")
}
app.cfg.SlaveOf = masterAddr
if len(masterAddr) == 0 {
log.Infof("slaveof no one, stop replication")
if err := app.m.stopReplication(); err != nil {
return err
}
app.cfg.SetReadonly(readonly)
} else {
return app.m.startReplication(masterAddr, restart)
}
return nil
}
示例7: Promote
// Promote the slave to master, then let other slaves replicate from it
func (g *Group) Promote(addr string) error {
g.m.Lock()
defer g.m.Unlock()
node := g.Slaves[addr]
if err := node.slaveof("no", "one"); err != nil {
return err
}
delete(g.Slaves, addr)
g.Master = node
host, port, _ := net.SplitHostPort(addr)
for _, slave := range g.Slaves {
if err := slave.slaveof(host, port); err != nil {
// if we go here, the replication topology may be wrong
// so use fatal level and we should fix it manually
log.Fatalf("slaveof %s to master %s err %v", slave.Addr, addr, err)
} else {
log.Infof("slaveof %s to master %s ok", slave.Addr, addr)
}
}
return nil
}
示例8: Close
func (c *Canal) Close() {
log.Infof("close canal")
c.m.Lock()
defer c.m.Unlock()
if c.isClosed() {
return
}
c.closed.Set(true)
close(c.quit)
c.connLock.Lock()
c.conn.Close()
c.conn = nil
c.connLock.Unlock()
if c.syncer != nil {
c.syncer.Close()
c.syncer = nil
}
c.master.Close()
c.wg.Wait()
}
示例9: Close
func (r *River) Close() {
log.Infof("closing river")
close(r.quit)
r.canal.Close()
r.wg.Wait()
}
示例10: mysqldump
func (d *Dumper) mysqldump(w io.Writer) error {
log.Trace("mysqldump")
args := make([]string, 0, 16)
// Common args
seps := strings.Split(d.Addr, ":")
args = append(args, fmt.Sprintf("--host=%s", seps[0]))
if len(seps) > 1 {
args = append(args, fmt.Sprintf("--port=%s", seps[1]))
}
args = append(args, fmt.Sprintf("--user=%s", d.User))
args = append(args, fmt.Sprintf("--password=%s", d.Password))
args = append(args, "--master-data")
args = append(args, "--single-transaction")
args = append(args, "--skip-lock-tables")
// Disable uncessary data
args = append(args, "--compact")
args = append(args, "--skip-opt")
args = append(args, "--quick")
// We only care about data
args = append(args, "--no-create-info")
// Multi row is easy for us to parse the data
args = append(args, "--skip-extended-insert")
for db, tables := range d.IgnoreTables {
for _, table := range tables {
args = append(args, fmt.Sprintf("--ignore-table=%s.%s", db, table))
}
}
if len(d.Tables) == 0 && len(d.Databases) == 0 {
args = append(args, "--all-databases")
} else if len(d.Tables) == 0 {
args = append(args, "--databases")
args = append(args, d.Databases...)
} else {
args = append(args, d.TableDB)
args = append(args, d.Tables...)
// If we only dump some tables, the dump data will not have database name
// which makes us hard to parse, so here we add it manually.
w.Write([]byte(fmt.Sprintf("USE `%s`;\n", d.TableDB)))
}
cmd := exec.Command(d.ExecutionPath, args...)
cmd.Stderr = d.ErrOut
cmd.Stdout = w
log.Infof("Executing dump: %+v", cmd)
return cmd.Run()
}
示例11: doRole
func (g *Group) doRole() error {
v, err := g.Master.doRole()
if err != nil {
return ErrNodeDown
}
// the first line is server type
serverType, _ := redis.String(v[0], nil)
if serverType != MasterType {
log.Errorf("server %s is not master now", g.Master.Addr)
return ErrNodeType
}
// second is master replication offset,
g.Master.Offset, _ = redis.Int64(v[1], nil)
// then slave list [host, port, offset]
slaves, _ := redis.Values(v[2], nil)
nodes := make(map[string]*Node, len(slaves))
for i := 0; i < len(slaves); i++ {
ss, _ := redis.Strings(slaves[i], nil)
var n Node
n.Addr = fmt.Sprintf("%s:%s", ss[0], ss[1])
n.Offset, _ = strconv.ParseInt(fmt.Sprintf("%s", ss[2]), 10, 64)
nodes[n.Addr] = &n
}
// we don't care slave add or remove too much, so only log
for addr, _ := range nodes {
if _, ok := g.Slaves[addr]; !ok {
log.Infof("slave %s added", addr)
}
}
for addr, slave := range g.Slaves {
if _, ok := nodes[addr]; !ok {
log.Infof("slave %s removed", addr)
slave.close()
}
}
g.Slaves = nodes
return nil
}
示例12: createIndex
func (r *River) createIndex(idx string, settings map[string]interface{}) error {
exists, err := r.es.IndexExists(idx).Do()
if exists {
log.Warnf("Index '%s' already exists; settings and mappings not updated", idx)
return nil
}
log.Infof("Creating index with settings from %v: %v", idx, settings)
_, err = r.es.CreateIndex(idx).BodyJson(settings).Do()
return err
}
示例13: parseDumpFile
func (d *Dumper) parseDumpFile(dump string, w io.Writer) error {
log.Infof("Parsing: %s", dump)
lastSlash := strings.LastIndex(dump, "/") + 1
database := strings.Split(dump[lastSlash:len(dump)], ".")[0]
stmnt := fmt.Sprintf("CREATE DATABASE IF NOT EXISTS `%s`;\n\nUSE `%s`;\n", database, database)
log.Debug(stmnt)
if _, err := fmt.Fprintf(w, stmnt); err != nil {
return err
} else if file, err := os.Open(dump); err != nil {
return err
} else {
defer file.Close()
scanner := bufio.NewScanner(file)
scanner.Buffer(make([]byte, 1024*1024), 1024*1024)
insertExp := regexp.MustCompile("^INSERT INTO `.+` VALUES$")
valuesExp := regexp.MustCompile("^\\(.+\\)[;,]$")
n := 0
for scanner.Scan() {
n = n + 1
if n%10000 == 0 {
log.Infof("%d lines parsed ", n)
}
line := scanner.Text()
if insertExp.FindString(line) != "" {
stmnt := fmt.Sprintf("%s\n", line)
_, err = w.Write([]byte(stmnt))
} else if valuesExp.FindString(line) != "" {
stmnt := fmt.Sprintf("%s\n", line)
_, err = w.Write([]byte(stmnt))
}
if err != nil {
log.Errorf("Failed after %d lines parsed due to %v: %v", n, err, line)
return err
}
}
log.Infof("Parsing completed with %d lines parsed", n)
return scanner.Err()
}
}
示例14: removeSlave
func (app *App) removeSlave(c *client, activeQuit bool) {
addr := c.slaveListeningAddr
app.slock.Lock()
defer app.slock.Unlock()
if _, ok := app.slaves[addr]; ok {
delete(app.slaves, addr)
log.Infof("remove slave %s", addr)
asyncNotifyUint64(app.slaveSyncAck, c.lastLogID.Get())
}
}
示例15: setMasters
func (a *App) setMasters(addrs []string) error {
if a.cluster != nil {
if a.cluster.IsLeader() {
return a.cluster.SetMasters(addrs, 10*time.Second)
} else {
log.Infof("%s is not leader, skip", a.c.Addr)
}
} else {
a.masters.SetMasters(addrs)
}
return nil
}