本文整理汇总了Golang中github.com/siddontang/go/log.Infof函数的典型用法代码示例。如果您正苦于以下问题:Golang Infof函数的具体用法?Golang Infof怎么用?Golang Infof使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Infof函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:darrenxyli,项目名称:go-mysql-elasticsearch,代码行数:28,代码来源:dump.go
示例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
}
}
}
开发者ID:ehalpern,项目名称:go-mysql-elasticsearch,代码行数:28,代码来源:river.go
示例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
}
开发者ID:no2key,项目名称:redis-failover,代码行数:56,代码来源:group.go
示例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
}
开发者ID:xurenlu,项目名称:go-mysql,代码行数:52,代码来源:sync.go
示例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
}
}
}
开发者ID:ehalpern,项目名称:go-mysql,代码行数:34,代码来源:dump.go
示例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
}
开发者ID:BobbWu,项目名称:ledisdb,代码行数:29,代码来源:replication.go
示例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
}
开发者ID:no2key,项目名称:redis-failover,代码行数:28,代码来源:group.go
示例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()
}
开发者ID:darrenxyli,项目名称:go-mysql-elasticsearch,代码行数:28,代码来源:canal.go
示例9: Close
func (r *River) Close() {
log.Infof("closing river")
close(r.quit)
r.canal.Close()
r.wg.Wait()
}
开发者ID:bandaot,项目名称:go-mysql-elasticsearch,代码行数:8,代码来源:river.go
示例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()
}
开发者ID:ehalpern,项目名称:go-mysql,代码行数:58,代码来源:dump.go
示例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
}
开发者ID:no2key,项目名称:redis-failover,代码行数:44,代码来源:group.go
示例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
}
开发者ID:ehalpern,项目名称:go-mysql-elasticsearch,代码行数:10,代码来源:river.go
示例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()
}
}
开发者ID:ehalpern,项目名称:go-mysql,代码行数:41,代码来源:dump.go
示例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())
}
}
开发者ID:BobbWu,项目名称:ledisdb,代码行数:12,代码来源:replication.go
示例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
}
开发者ID:no2key,项目名称:redis-failover,代码行数:12,代码来源:app.go
示例16: ResolveWildcards
// resolve paths like:
// /zk/nyc/vt/tablets/*/action
// /zk/global/vt/keyspaces/*/shards/*/action
// /zk/*/vt/tablets/*/action
// into real existing paths
//
// If you send paths that don't contain any wildcard and
// don't exist, this function will return an empty array.
func ResolveWildcards(zconn Conn, zkPaths []string) ([]string, error) {
// check all the paths start with /zk/ before doing anything
// time consuming
// relax this in case we are not talking to a metaconn and
// just want to talk to a specified instance.
// for _, zkPath := range zkPaths {
// if _, err := ZkCellFromZkPath(zkPath); err != nil {
// return nil, err
// }
// }
results := make([][]string, len(zkPaths))
wg := &sync.WaitGroup{}
mu := &sync.Mutex{}
var firstError error
for i, zkPath := range zkPaths {
wg.Add(1)
parts := strings.Split(zkPath, "/")
go func(i int) {
defer wg.Done()
subResult, err := resolveRecursive(zconn, parts, true)
if err != nil {
mu.Lock()
if firstError != nil {
log.Infof("Multiple error: %v", err)
} else {
firstError = err
}
mu.Unlock()
} else {
results[i] = subResult
}
}(i)
}
wg.Wait()
if firstError != nil {
return nil, firstError
}
result := make([]string, 0, 32)
for i := 0; i < len(zkPaths); i++ {
subResult := results[i]
if subResult != nil {
result = append(result, subResult...)
}
}
return result, nil
}
开发者ID:jameswei,项目名称:xcodis,代码行数:59,代码来源:zk.go
示例17: handleQueryEvent
func (c *Canal) handleQueryEvent(e *replication.BinlogEvent) error {
ev := e.Event.(*replication.QueryEvent)
query, err := replication.ParseQuery(string(ev.Query))
log.Debugf("query parsed: %v, %v", query, err)
if err == replication.ErrIgnored {
return nil
} else if err != nil {
log.Infof("failed to parse: %v, %v", string(ev.Query), err)
return nil
} else {
schema := string(ev.Schema)
if query.Schema != "" {
// Schema overridden in query
schema = query.Schema
}
table, err := c.GetTable(schema, query.Table)
if err == errTableIgnored {
// ignore
return nil
} else if err != nil {
return errors.Trace(err)
}
switch query.Operation {
case replication.ADD:
// Flush everything before changing schema
c.flushEventHandlers()
table.AddColumn(query.Column, query.Type, query.Extra)
log.Infof("Adding new column %v %v to %v.%v", query.Column, query.Type, schema, query.Table)
break
case replication.MODIFY:
case replication.DELETE:
default:
}
return nil
}
}
开发者ID:ehalpern,项目名称:go-mysql,代码行数:37,代码来源:sync.go
示例18: tryDump
func (c *Canal) tryDump() error {
if len(c.master.Name) > 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.Errorf("Skip dump, no dumper provided")
return nil
}
h := &dumpParseHandler{c: c}
start := time.Now()
log.Info("Start dump")
if err := c.dumper.DumpAndParse(h); err != nil {
return errors.Trace(err)
}
log.Infof("Dump completed in %0.2f seconds", time.Now().Sub(start).Seconds())
c.master.Update(h.name, uint32(h.pos))
c.master.Save(true)
return nil
}
开发者ID:ehalpern,项目名称:go-mysql,代码行数:24,代码来源:dump.go
示例19: newZk
func newZk(cfg *Config, fsm *masterFSM) (Cluster, error) {
z := new(Zk)
var err error
if !strings.HasPrefix(cfg.Zk.BaseDir, "/zk") {
return nil, fmt.Errorf("invalid zk base dir %s, must have prefix /zk", cfg.Zk.BaseDir)
}
addr := strings.Join(cfg.Zk.Addr, ",")
if addr == "memory" {
// only for test
log.Infof("only for test, use memory")
z.conn = zkhelper.NewConn()
} else {
z.conn, err = zkhelper.ConnectToZk(addr)
}
if err != nil {
return nil, err
}
z.c = cfg
z.fsm = fsm
z.isLeader.Set(false)
z.leaderCh = make(chan bool, 1)
z.actionCh = make(chan *zkAction, 10)
z.quit = make(chan struct{})
if _, err = zkhelper.CreateOrUpdate(z.conn, cfg.Zk.BaseDir, "", 0, zkhelper.DefaultDirACLs(), true); err != nil {
log.Errorf("create %s error: %v", cfg.Zk.BaseDir, err)
return nil, err
}
onRetryLock := func() {
z.noticeLeaderCh(false)
}
z.elector = createElection(z.conn, cfg.Zk.BaseDir, cfg.Addr, onRetryLock)
z.checkLeader()
return z, nil
}
开发者ID:no2key,项目名称:redis-failover,代码行数:45,代码来源:zk.go
示例20: loadMasterInfo
func loadMasterInfo(name string) (*masterInfo, error) {
var m masterInfo
m.name = name
f, err := os.Open(name)
if err != nil && !os.IsNotExist(err) {
return nil, errors.Trace(err)
} else if os.IsNotExist(err) {
log.Infof("No MasterInfo recorded at %v", name)
return &m, nil
}
defer f.Close()
_, err = toml.DecodeReader(f, &m)
return &m, err
}
开发者ID:ehalpern,项目名称:go-mysql,代码行数:18,代码来源:master.go
注:本文中的github.com/siddontang/go/log.Infof函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论