本文整理汇总了Golang中github.com/siddontang/go/log.Errorf函数的典型用法代码示例。如果您正苦于以下问题:Golang Errorf函数的具体用法?Golang Errorf怎么用?Golang Errorf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Errorf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: doCommand
func (n *Node) doCommand(cmd string, args ...interface{}) (interface{}, error) {
var err error
var v interface{}
for i := 0; i < 3; i++ {
if n.conn == nil {
n.conn, err = redis.DialTimeout("tcp", n.Addr, 5*time.Second, 0, 0)
if err != nil {
log.Errorf("dial %s error: %v, try again", n.Addr, err)
continue
}
}
v, err = n.conn.Do(cmd, args...)
if err != nil {
log.Errorf("do %s command for %s error: %v, try again", cmd, n.Addr, err)
n.conn.Close()
n.conn = nil
continue
} else {
return v, nil
}
}
// go here means do command error, maybe redis is down.
return nil, err
}
示例2: newTableReader
func newTableReader(base string, index int64, useMmap bool) (*tableReader, error) {
if index <= 0 {
return nil, fmt.Errorf("invalid index %d", index)
}
t := new(tableReader)
t.base = base
t.index = index
t.useMmap = useMmap
var err error
if err = t.check(); err != nil {
log.Errorf("check %d error: %s, try to repair", t.index, err.Error())
if err = t.repair(); err != nil {
log.Errorf("repair %d error: %s", t.index, err.Error())
return nil, err
}
}
t.close()
return t, nil
}
示例3: checkSnapshots
func (s *snapshotStore) checkSnapshots() error {
cfg := s.cfg
snapshots, err := ioutil.ReadDir(cfg.Snapshot.Path)
if err != nil {
log.Errorf("read %s error: %s", cfg.Snapshot.Path, err.Error())
return err
}
names := []string{}
for _, info := range snapshots {
if path.Ext(info.Name()) == ".tmp" {
log.Errorf("temp snapshot file name %s, try remove", info.Name())
os.Remove(path.Join(cfg.Snapshot.Path, info.Name()))
continue
}
if _, err := parseSnapshotName(info.Name()); err != nil {
log.Errorf("invalid snapshot file name %s, err: %s", info.Name(), err.Error())
continue
}
names = append(names, info.Name())
}
//from old to new
sort.Strings(names)
s.names = names
s.purge(false)
return nil
}
示例4: fullSync
func (m *master) fullSync() error {
log.Info("begin full sync")
if err := m.conn.Send("fullsync"); err != nil {
return err
}
m.state.Set(replSyncState)
dumpPath := path.Join(m.app.cfg.DataDir, "master.dump")
f, err := os.OpenFile(dumpPath, os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return err
}
defer os.Remove(dumpPath)
err = m.conn.ReceiveBulkTo(f)
f.Close()
if err != nil {
log.Errorf("read dump data error %s", err.Error())
return err
}
if _, err = m.app.ldb.LoadDumpFile(dumpPath); err != nil {
log.Errorf("load dump file error %s", err.Error())
return err
}
return nil
}
示例5: Submit
// Submit submits the current batch of actions in bulk and resets Count to 0.
func (b *Bulker) Submit() error {
size := b.bulker.NumberOfActions()
if size == 0 {
return nil
}
b.LastResponse, b.LastError = b.bulker.Do()
if b.LastError != nil {
log.Errorf("Bulk update %d/%d failed due to %v: %+v", size, b.MaxActions, b.LastError, b.LastResponse)
return b.LastError
}
if b.LastResponse.Errors {
var buffer bytes.Buffer
failed := b.LastResponse.Failed()
count := len(failed)
buffer.WriteString(fmt.Sprintf("%v actions failed in bulk update:\n", count))
for i, er := range failed {
buffer.WriteString(fmt.Sprintf("\t%v:%v\n", er, er.Error))
if i == 2 {
if count > 3 {
buffer.WriteString(fmt.Sprintf("\t...\n"))
}
break
}
}
log.Errorf(buffer.String())
// show bulk errors but continue
//b.LastError = errors.Errorf("%v actions failed during bulk update", count)
} else {
log.Debugf("Bulk update %d/%d succeeded", size, b.MaxActions)
}
return b.LastError
}
示例6: 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
}
示例7: purgeTableReaders
func (s *FileStore) purgeTableReaders(purges []*tableReader) {
for _, r := range purges {
dataName := fmtTableDataName(r.base, r.index)
metaName := fmtTableMetaName(r.base, r.index)
r.Close()
if err := os.Remove(dataName); err != nil {
log.Errorf("purge table data %s err: %s", dataName, err.Error())
}
if err := os.Remove(metaName); err != nil {
log.Errorf("purge table meta %s err: %s", metaName, err.Error())
}
}
}
示例8: flushEventHandlers
func (c *Canal) flushEventHandlers() error {
c.rsLock.Lock()
defer c.rsLock.Unlock()
var err error
for _, h := range c.rsHandlers {
if err = h.Complete(); err != nil && err != ErrHandleInterrupted {
log.Errorf("Complete %v err: %v", h, err)
} else if err == ErrHandleInterrupted {
log.Errorf("Complete %v err, interrupted", h)
return ErrHandleInterrupted
}
}
return nil
}
示例9: Close
func (s *FileStore) Close() error {
close(s.quit)
s.wm.Lock()
s.rm.Lock()
if r, err := s.w.Flush(); err != nil {
if err != errNilHandler {
log.Errorf("close err: %s", err.Error())
}
} else {
r.Close()
s.w.Close()
}
for i := range s.rs {
s.rs[i].Close()
}
s.rs = tableReaders{}
s.rm.Unlock()
s.wm.Unlock()
return nil
}
示例10: Do
func (h *rowsEventHandler) Do(e *canal.RowsEvent) error {
rule, ok := h.r.rules[ruleKey(e.Table.Schema, e.Table.Name)]
if !ok {
return nil
}
var reqs []*elastic.BulkRequest
var err error
switch e.Action {
case canal.InsertAction:
reqs, err = h.r.makeInsertRequest(rule, e.Rows)
case canal.DeleteAction:
reqs, err = h.r.makeDeleteRequest(rule, e.Rows)
case canal.UpdateAction:
reqs, err = h.r.makeUpdateRequest(rule, e.Rows)
default:
return errors.Errorf("invalid rows action %s", e.Action)
}
if err != nil {
return errors.Errorf("make %s ES request err %v", e.Action, err)
}
if err := h.r.doBulk(reqs); err != nil {
log.Errorf("do ES bulks err %v, stop", err)
return canal.ErrHandleInterrupted
}
return nil
}
示例11: load
func (s *FileStore) load() error {
fs, err := ioutil.ReadDir(s.base)
if err != nil {
return err
}
s.rs = make(tableReaders, 0, len(fs))
var r *tableReader
var index int64
for _, f := range fs {
if _, err := fmt.Sscanf(f.Name(), "%08d.data", &index); err == nil {
if r, err = newTableReader(s.base, index, s.cfg.Replication.UseMmap); err != nil {
log.Errorf("load table %s err: %s", f.Name(), err.Error())
} else {
s.rs = append(s.rs, r)
}
}
}
if err := s.rs.check(); err != nil {
return err
}
return nil
}
示例12: travelRowsEventHandler
func (c *Canal) travelRowsEventHandler(e *RowsEvent) error {
c.rsLock.Lock()
defer c.rsLock.Unlock()
var err error
for _, h := range c.rsHandlers {
if err = h.Do(e); err != nil && err != ErrHandleInterrupted {
log.Errorf("handle %v err: %v", h, err)
} else if err == ErrHandleInterrupted {
log.Errorf("handle %v err, interrupted", h)
return ErrHandleInterrupted
}
}
return nil
}
示例13: run
func (c *Canal) run() error {
defer c.wg.Done()
if err := c.tryDump(); err != nil {
log.Errorf("Dump failed due to: %v", err)
return err
}
close(c.dumpDoneCh)
if err := c.startSyncBinlog(); err != nil {
if !c.isClosed() {
log.Errorf("Sync failed due to: %v", err)
}
return errors.Trace(err)
}
return nil
}
示例14: Close
func (m *mmapReadFile) Close() error {
if m.m != nil {
if err := m.m.Unmap(); err != nil {
log.Errorf("unmap %s error %s", m.name, err.Error())
}
m.m = nil
}
if m.f != nil {
if err := m.f.Close(); err != nil {
log.Errorf("close %s error %s", m.name, err.Error())
}
m.f = nil
}
return nil
}
示例15: Run
func (r *River) Run() error {
if err := r.canal.Start(); err != nil {
log.Errorf("start canal err %v", err)
return err
}
return nil
}