本文整理汇总了Golang中github.com/ngaut/log.Warn函数的典型用法代码示例。如果您正苦于以下问题:Golang Warn函数的具体用法?Golang Warn怎么用?Golang Warn使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Warn函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: handleConnection
func (tso *TimestampOracle) handleConnection(s *session) {
defer func() {
tso.connLock.Lock()
delete(tso.conns, s.conn)
tso.connLock.Unlock()
s.conn.Close()
tso.wg.Done()
}()
var buf [1]byte
for {
_, err := s.r.Read(buf[:])
if err != nil {
log.Warn(err)
return
}
resp := tso.getRespTS()
resp.Encode(s.w)
if s.r.Buffered() <= 0 {
err = s.w.Flush()
if err != nil {
log.Warn(err)
return
}
}
}
}
示例2: mustNewConn
func mustNewConn(urls []string, quit chan struct{}) *conn {
for {
conn, err := rpcConnectLeader(urls)
if err == nil {
return newConn(conn)
}
log.Warn(err)
conn, err = rpcConnect(urls)
if err == nil {
c := newConn(conn)
c.wg.Add(1)
go c.connectLeader(urls, reconnectPDTimeout)
return c
}
log.Warn(err)
select {
case <-time.After(connectPDTimeout):
break
case <-quit:
return nil
}
}
}
示例3: HandleMessage
func (this *NSQDataStream) HandleMessage(message *nsq.Message) error {
data := string(message.Body)
if data == "" {
log.Warn("数据丢失")
return nil
}
data = encrypt.GetEnDecoder(encrypt.TYPE_BASE64).Decode(data)
urlData, err := url.ParseQuery(data)
if err != nil {
log.Warn("解析数据失败")
return nil
}
//数据存放在队列中
if urlData.Get("date") != time.Now().Format("2006-01-02") {
return nil
}
this.Dispatch(urlData)
r := rand.New(rand.NewSource(time.Now().UnixNano()))
_ = time.Millisecond * time.Duration(r.Intn(1000)+200)
time.Sleep(time.Microsecond)
return nil
}
示例4: handleConnection
func (tso *TimestampOracle) handleConnection(s *session) {
defer func() {
tso.closeConn(s.conn)
tso.wg.Done()
}()
var buf [1]byte
for {
_, err := s.r.Read(buf[:])
if err != nil {
log.Warn(err)
return
}
resp := tso.getRespTS()
if resp == nil {
log.Errorf("get repsone timestamp timeout, close %v", s.conn.RemoteAddr())
return
}
resp.Encode(s.w)
if s.r.Buffered() <= 0 {
err = s.w.Flush()
if err != nil {
log.Warn(err)
return
}
}
}
}
示例5: watchLeader
func (c *client) watchLeader(leaderPath string, revision int64) {
defer c.wg.Done()
WATCH:
for {
log.Infof("[pd] start watch pd leader on path %v, revision %v", leaderPath, revision)
rch := c.etcdClient.Watch(context.Background(), leaderPath, clientv3.WithRev(revision))
select {
case resp := <-rch:
if resp.Canceled {
log.Warn("[pd] leader watcher canceled")
continue WATCH
}
leaderAddr, rev, err := getLeader(c.etcdClient, leaderPath)
if err != nil {
log.Warn(err)
continue WATCH
}
log.Infof("[pd] found new pd-server leader addr: %v", leaderAddr)
c.workerMutex.Lock()
c.worker.stop(errors.New("[pd] leader change"))
c.worker = newRPCWorker(leaderAddr, c.clusterID)
c.workerMutex.Unlock()
revision = rev
case <-c.quit:
return
}
}
}
示例6: TestAsyncCommit
func (s *TransactionTestSuit) TestAsyncCommit(c *C) {
conf := defaultTxnConf
conf.brokenCommitSecondaryTest = true
tx := newTxn(s.cli, conf)
// simulating broken commit
for i := 0; i < 10; i++ {
p := hbase.NewPut([]byte(fmt.Sprintf("test_%d", i)))
p.AddValue(cf, q, []byte(fmt.Sprintf("%d", tx.(*themisTxn).GetStartTS())))
tx.Put(themisTestTableName, p)
}
err := tx.Commit()
c.Assert(err, Equals, nil)
// wait until lock expired.
log.Warn("Wait for lock expired. Sleep...")
tick := 6
for tick > 0 {
time.Sleep(1 * time.Second)
tick--
log.Infof("remain %ds...", tick)
}
log.Warn("Try commit again")
// new transction will not see lock
for {
tx = newTxn(s.cli, defaultTxnConf)
for i := 0; i < 5; i++ {
p := hbase.NewPut([]byte(fmt.Sprintf("test_%d", i)))
p.AddValue(cf, q, []byte(fmt.Sprintf("%d", tx.(*themisTxn).GetStartTS())))
tx.Put(themisTestTableName, p)
}
err = tx.Commit()
if err == nil || !errorEqual(err, ErrRetryable) {
break
}
time.Sleep(100 * time.Millisecond)
}
c.Assert(err, Equals, nil)
for {
tx = newTxn(s.cli, defaultTxnConf)
for i := 5; i < 10; i++ {
p := hbase.NewPut([]byte(fmt.Sprintf("test_%d", i)))
p.AddValue(cf, q, []byte(fmt.Sprintf("%d", tx.(*themisTxn).GetStartTS())))
tx.Put(themisTestTableName, p)
}
err = tx.Commit()
if err == nil || !errorEqual(err, ErrRetryable) {
break
}
time.Sleep(100 * time.Millisecond)
}
c.Assert(err, Equals, nil)
}
示例7: updateTimestamp
func (tso *TimestampOracle) updateTimestamp() error {
prev := tso.ts.Load().(*atomicObject)
now := time.Now()
// ms
since := now.Sub(prev.physical).Nanoseconds() / 1e6
if since > 2*updateTimestampStep {
log.Warnf("clock offset: %v, prev: %v, now %v", since, prev.physical, now)
}
// Avoid the same physical time stamp
if since <= 0 {
log.Warn("invalid physical time stamp, re-update later again")
return nil
}
if now.Sub(tso.lastSavedTime).Nanoseconds()/1e6 > tso.cfg.SaveInterval {
if err := tso.saveTimestamp(now); err != nil {
return errors.Trace(err)
}
}
current := &atomicObject{
physical: now,
}
tso.ts.Store(current)
return nil
}
示例8: batchCommitSecondary
func (txn *themisTxn) batchCommitSecondary(wait bool) error {
//will batch commit all rows in a region
rsRowMap, err := txn.groupByRegion()
if err != nil {
return errors.Trace(err)
}
wg := sync.WaitGroup{}
for _, regionRowMap := range rsRowMap {
wg.Add(1)
_, firstRowM := getFirstEntity(regionRowMap)
go func(cli *themisRPC, tbl string, rMap map[string]*rowMutation, startTs, commitTs uint64) {
defer wg.Done()
err := cli.batchCommitSecondaryRows([]byte(tbl), rMap, startTs, commitTs)
if err != nil {
// fail of secondary commit will not stop the commits of next
// secondaries
if isWrongRegionErr(err) {
txn.client.CleanAllRegionCache()
log.Warn("region info outdated when committing secondary rows, don't panic")
}
}
}(txn.rpc, string(firstRowM.tbl), regionRowMap, txn.startTs, txn.commitTs)
}
if wait {
wg.Wait()
}
return nil
}
示例9: NewServer
func NewServer(cfg *config.Conf) (*Server, error) {
s := new(Server)
s.cfg = cfg
var err error
s.fingerprints = make(map[string]*LimitReqNode)
// s.users = make(map[string]*User)
// s.qpsOnServer = &LimitReqNode{}
s.mu = &sync.Mutex{}
s.restart = false
port := s.cfg.GetConfig().Global.Port
// get listenfd from file when restart
if os.Getenv("_GRACEFUL_RESTART") == "true" {
log.Info("graceful restart with previous listenfd")
//get the linstenfd
file := os.NewFile(3, "")
s.listener, err = net.FileListener(file)
if err != nil {
log.Warn("get linstener err ")
}
} else {
s.listener, err = net.Listen("tcp4", fmt.Sprintf(":%d", port))
}
if err != nil {
return nil, err
}
log.Infof("Dbatman Listen(tcp4) at [%d]", port)
return s, nil
}
示例10: extractLockInfoFromKeyErr
func extractLockInfoFromKeyErr(keyErr *pb.KeyError) (*pb.LockInfo, error) {
if locked := keyErr.GetLocked(); locked != nil {
return locked, nil
}
if keyErr.Retryable != nil {
err := errors.Errorf("tikv restarts txn: %s", keyErr.GetRetryable())
log.Warn(err)
return nil, errors.Annotate(err, txnRetryableMark)
}
if keyErr.Abort != nil {
err := errors.Errorf("tikv aborts txn: %s", keyErr.GetAbort())
log.Warn(err)
return nil, errors.Trace(err)
}
return nil, errors.Errorf("unexpected KeyError: %s", keyErr.String())
}
示例11: updateTicker
func (tso *TimestampOracle) updateTicker() {
// TODO: save latest TS to persistent storage(zookeeper/etcd...)
for {
select {
case <-tso.ticker.C:
prev := tso.ts.Load().(*atomicObject)
now := time.Now()
// ms
since := now.Sub(prev.physical).Nanoseconds() / 1e6
if since > 2*updateTimtestampStep {
log.Warnf("clock offset: %v, prev:%v, now %v", since, prev.physical, now)
}
// Avoid the same physical time stamp
if since <= 0 {
log.Warn("invalid physical time stamp")
continue
}
current := &atomicObject{
physical: now,
}
tso.ts.Store(current)
}
}
}
示例12: Run
func (session *Session) Run() error {
for {
data, err := session.fc.ReadPacket()
if err != nil {
log.Warn(err)
return err
}
if data[0] == ComQuit {
return errSessionQuit
}
if err := session.dispatch(data); err != nil {
if err == driver.ErrBadConn {
// TODO handle error
}
log.Warnf("dispatch error: %s", err.Error())
return err
}
session.fc.ResetSequence()
if session.closed {
// TODO return MySQL Go Away ?
return errors.New("session closed!")
}
}
return nil
}
示例13: Dispatch
func (this *NSQDataStream) Dispatch(data url.Values) {
var (
uidsAry = strings.Split(data.Get("uids"), ",")
info = make(map[string]interface{})
ginfoAry = this.GrabData(uidsAry)
)
data.Set("ua", encrypt.DefaultBase64.Decode(data.Get("ua")))
for k, _ := range data {
info[k] = data.Get(k)
}
if len(ginfoAry) == 0 {
return
}
info["ginfos"] = ginfoAry
j, err := json.Marshal(&info)
if err != nil {
log.Warn(err)
return
}
go this.Save(j)
}
示例14: cleanupPending
func (c *Client) cleanupPending(err error) {
log.Warn(err)
length := c.pending.Len()
for i := 0; i < length; i++ {
e := c.pending.Front()
c.pending.Remove(e)
e.Value.(*PipelineRequest).MarkDone(nil, err)
}
}
示例15: workerLoop
func (c *Client) workerLoop() {
for {
err := c.do()
if err != nil {
log.Warn(err)
}
time.Sleep(time.Second)
}
}