當前位置: 首頁>>代碼示例>>Golang>>正文


Golang log.Warn函數代碼示例

本文整理匯總了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
			}
		}
	}
}
開發者ID:siddontang,項目名稱:tso,代碼行數:30,代碼來源:server.go

示例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
		}
	}
}
開發者ID:jmptrader,項目名稱:tidb,代碼行數:25,代碼來源:conn.go

示例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
}
開發者ID:qgweb,項目名稱:new,代碼行數:27,代碼來源:ds.go

示例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
			}
		}
	}
}
開發者ID:pingcap,項目名稱:tso,代碼行數:31,代碼來源:server.go

示例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
		}
	}
}
開發者ID:yubobo,項目名稱:tidb,代碼行數:28,代碼來源:client.go

示例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)
}
開發者ID:pingcap,項目名稱:go-themis,代碼行數:55,代碼來源:txn_test.go

示例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
}
開發者ID:pingcap,項目名稱:tso,代碼行數:28,代碼來源:server.go

示例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
}
開發者ID:pingcap,項目名稱:go-themis,代碼行數:29,代碼來源:themis_txn.go

示例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
}
開發者ID:bytedance,項目名稱:dbatman,代碼行數:35,代碼來源:server.go

示例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())
}
開發者ID:yubobo,項目名稱:tidb,代碼行數:16,代碼來源:snapshot.go

示例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)
		}
	}
}
開發者ID:siddontang,項目名稱:tso,代碼行數:26,代碼來源:server.go

示例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
}
開發者ID:wangjild,項目名稱:dbatman,代碼行數:34,代碼來源:session.go

示例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)
}
開發者ID:qgweb,項目名稱:new,代碼行數:27,代碼來源:ds.go

示例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)
	}
}
開發者ID:yzl11,項目名稱:vessel,代碼行數:9,代碼來源:client.go

示例15: workerLoop

func (c *Client) workerLoop() {
	for {
		err := c.do()
		if err != nil {
			log.Warn(err)
		}
		time.Sleep(time.Second)
	}
}
開發者ID:disksing,項目名稱:tso,代碼行數:9,代碼來源:client.go


注:本文中的github.com/ngaut/log.Warn函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。