本文整理汇总了Golang中github.com/siddontang/go/log.Errorf函数的典型用法代码示例。如果您正苦于以下问题:Golang Errorf函数的具体用法?Golang Errorf怎么用?Golang Errorf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Errorf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:no2key,项目名称:redis-failover,代码行数:27,代码来源:group.go
示例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
}
开发者ID:BobbWu,项目名称:ledisdb,代码行数:25,代码来源:file_table.go
示例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
}
开发者ID:Aurlin,项目名称:ledisdb,代码行数:33,代码来源:snapshot.go
示例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
}
开发者ID:BobbWu,项目名称:ledisdb,代码行数:31,代码来源:replication.go
示例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
}
开发者ID:ehalpern,项目名称:go-mysql-elasticsearch,代码行数:33,代码来源:bulker.go
示例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
}
开发者ID:no2key,项目名称:redis-failover,代码行数:56,代码来源:group.go
示例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())
}
}
}
开发者ID:rechen,项目名称:wharf,代码行数:14,代码来源:file_store.go
示例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
}
开发者ID:ehalpern,项目名称:go-mysql,代码行数:15,代码来源:handler.go
示例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
}
开发者ID:rechen,项目名称:wharf,代码行数:26,代码来源:file_store.go
示例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
}
开发者ID:littleyang,项目名称:go-mysql-elasticsearch,代码行数:30,代码来源:sync.go
示例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
}
开发者ID:rechen,项目名称:wharf,代码行数:26,代码来源:file_store.go
示例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
}
开发者ID:xurenlu,项目名称:go-mysql,代码行数:16,代码来源:handler.go
示例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
}
开发者ID:ehalpern,项目名称:go-mysql,代码行数:16,代码来源:canal.go
示例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
}
开发者ID:rechen,项目名称:wharf,代码行数:17,代码来源:file_io.go
示例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
}
开发者ID:bandaot,项目名称:go-mysql-elasticsearch,代码行数:8,代码来源:river.go
示例16: run
func (c *Canal) run() error {
defer c.wg.Done()
if err := c.tryDump(); err != nil {
log.Errorf("canal dump mysql err: %v", err)
return err
}
close(c.dumpDoneCh)
if err := c.startSyncBinlog(); err != nil {
if !c.isClosed() {
log.Errorf("canal start sync binlog err: %v", err)
}
return err
}
return nil
}
开发者ID:darrenxyli,项目名称:go-mysql-elasticsearch,代码行数:19,代码来源:canal.go
示例17: Data
func (h *dumpParseHandler) Data(db string, table string, values []string) error {
if h.c.isClosed() {
return errCanalClosed
}
tableInfo, err := h.c.GetTable(db, table)
if err != nil {
log.Errorf("get %s.%s information err: %v", db, table, err)
return errors.Trace(err)
}
vs := make([]interface{}, len(values))
log.Debugf("Handling Data: %v", values)
for i, v := range values {
if v == "NULL" {
vs[i] = nil
} else if firstChar := v[0]; firstChar == '\'' || firstChar == '"' {
vs[i] = v[1 : len(v)-1]
} else {
if tableInfo.Columns[i].Type == schema.TYPE_NUMBER {
n, err := strconv.ParseInt(v, 10, 64)
if err != nil {
log.Errorf("parse row %v at %d error %v, skip", values, i, err)
return dump.ErrSkip
}
vs[i] = n
} else if tableInfo.Columns[i].Type == schema.TYPE_FLOAT {
f, err := strconv.ParseFloat(v, 64)
if err != nil {
log.Errorf("parse row %v at %d error %v, skip", values, i, err)
return dump.ErrSkip
}
vs[i] = f
} else {
log.Errorf("parse row %v at %d err: invalid type %v for value %v, skip", values, i, tableInfo.Columns[i].Type, v)
return dump.ErrSkip
}
}
}
events := newRowsEvent(tableInfo, InsertAction, [][]interface{}{vs})
return h.c.travelRowsEventHandler(events)
}
开发者ID:ehalpern,项目名称:go-mysql,代码行数:43,代码来源:dump.go
示例18: run
func (r *Replication) run() {
defer r.wg.Done()
syncTc := time.NewTicker(1 * time.Second)
purgeTc := time.NewTicker(1 * time.Hour)
for {
select {
case <-purgeTc.C:
n := (r.cfg.Replication.ExpiredLogDays * 24 * 3600)
r.m.Lock()
err := r.s.PurgeExpired(int64(n))
r.m.Unlock()
if err != nil {
log.Errorf("purge expired log error %s", err.Error())
}
case <-syncTc.C:
if r.cfg.Replication.SyncLog == 1 {
r.m.Lock()
err := r.s.Sync()
r.m.Unlock()
if err != nil {
log.Errorf("sync store error %s", err.Error())
}
}
if r.cfg.Replication.SyncLog != 2 {
//we will sync commit id every 1 second
r.m.Lock()
err := r.updateCommitID(r.commitID, true)
r.m.Unlock()
if err != nil {
log.Errorf("sync commitid error %s", err.Error())
}
}
case <-r.quit:
syncTc.Stop()
purgeTc.Stop()
return
}
}
}
开发者ID:rechen,项目名称:wharf,代码行数:42,代码来源:rpl.go
示例19: Apply
func (fsm *masterFSM) Apply(l *raft.Log) interface{} {
var a action
if err := json.Unmarshal(l.Data, &a); err != nil {
log.Errorf("decode raft log err %v", err)
return err
}
fsm.handleAction(&a)
return nil
}
开发者ID:no2key,项目名称:redis-failover,代码行数:11,代码来源:raft.go
示例20: doBulk
func (r *River) doBulk(reqs []*elastic.BulkRequest) error {
if len(reqs) == 0 {
return nil
}
if resp, err := r.es.Bulk(reqs); err != nil {
log.Errorf("sync docs err %v after binlog %s", err, r.canal.SyncedPosition())
return errors.Trace(err)
} else if resp.Errors {
for i := 0; i < len(resp.Items); i++ {
for action, item := range resp.Items[i] {
if len(item.Error) > 0 {
log.Errorf("%s index: %s, type: %s, id: %s, status: %d, error: %s",
action, item.Index, item.Type, item.ID, item.Status, item.Error)
}
}
}
}
return nil
}
开发者ID:littleyang,项目名称:go-mysql-elasticsearch,代码行数:21,代码来源:sync.go
注:本文中的github.com/siddontang/go/log.Errorf函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论