本文整理匯總了Golang中github.com/netflix/rend/metrics.IncCounter函數的典型用法代碼示例。如果您正苦於以下問題:Golang IncCounter函數的具體用法?Golang IncCounter怎麽用?Golang IncCounter使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了IncCounter函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Touch
func (h Handler) Touch(cmd common.TouchRequest) error {
// read metadata
// for 0 to metadata.numChunks
// touch item
// touch metadata
// We get the metadata and not GAT it in case the key is *just* about to expire.
// In this case if a chunk expires during the operation, we fail the touch instead of
// leaving a key in an inconsistent state where the metadata lives on and the data is
// incomplete. The metadata is touched last to make sure the data exists first.
metaKey, metaData, err := getMetadata(h.rw, cmd.Key)
if err != nil {
if err == common.ErrKeyNotFound {
metrics.IncCounter(MetricCmdTouchMissesMeta)
}
return err
}
// First touch all the chunks as a batch
for i := 0; i < int(metaData.NumChunks); i++ {
chunkKey := chunkKey(cmd.Key, i)
if err := binprot.WriteTouchCmd(h.rw.Writer, chunkKey, cmd.Exptime); err != nil {
return err
}
}
if err := h.rw.Flush(); err != nil {
return err
}
miss := false
for i := 0; i < int(metaData.NumChunks); i++ {
if err := simpleCmdLocal(h.rw, false); err != nil {
if err == common.ErrKeyNotFound && !miss {
metrics.IncCounter(MetricCmdTouchMissesChunk)
miss = true
}
}
}
if miss {
return common.ErrKeyNotFound
}
// Then touch the metadata
if err := binprot.WriteTouchCmd(h.rw.Writer, metaKey, cmd.Exptime); err != nil {
return err
}
if err := simpleCmdLocal(h.rw, true); err != nil {
if err == common.ErrKeyNotFound {
metrics.IncCounter(MetricCmdTouchMissesMeta)
}
return err
}
return nil
}
示例2: Delete
func (h Handler) Delete(cmd common.DeleteRequest) error {
// read metadata
// delete metadata
// for 0 to metadata.numChunks
// delete item
metaKey, metaData, err := getMetadata(h.rw, cmd.Key)
if err != nil {
if err == common.ErrKeyNotFound {
metrics.IncCounter(MetricCmdDeleteMissesMeta)
}
return err
}
// Delete metadata first
if err := binprot.WriteDeleteCmd(h.rw.Writer, metaKey); err != nil {
return err
}
if err := simpleCmdLocal(h.rw, true); err != nil {
if err == common.ErrKeyNotFound {
metrics.IncCounter(MetricCmdDeleteMissesMeta)
}
return err
}
// Then delete data chunks
for i := 0; i < int(metaData.NumChunks); i++ {
chunkKey := chunkKey(cmd.Key, i)
if err := binprot.WriteDeleteCmd(h.rw.Writer, chunkKey); err != nil {
return err
}
}
if err := h.rw.Flush(); err != nil {
return err
}
miss := false
for i := 0; i < int(metaData.NumChunks); i++ {
if err := simpleCmdLocal(h.rw, false); err != nil {
if err == common.ErrKeyNotFound && !miss {
metrics.IncCounter(MetricCmdDeleteMissesChunk)
miss = true
}
}
}
if miss {
return common.ErrKeyNotFound
}
return nil
}
示例3: Gat
func (l *L1OnlyOrca) Gat(req common.GATRequest) error {
metrics.IncCounter(MetricCmdGat)
//log.Println("gat", string(req.Key))
metrics.IncCounter(MetricCmdGatL1)
res, err := l.l1.GAT(req)
if err == nil {
if res.Miss {
metrics.IncCounter(MetricCmdGatMissesL1)
// TODO: Account for L2
metrics.IncCounter(MetricCmdGatMisses)
} else {
metrics.IncCounter(MetricCmdGatHits)
metrics.IncCounter(MetricCmdGatHitsL1)
}
l.res.GAT(res)
// There is no GetEnd call required here since this is only ever
// done in the binary protocol, where there's no END marker.
// Calling l.res.GetEnd was a no-op here and is just useless.
//l.res.GetEnd(0, false)
} else {
metrics.IncCounter(MetricCmdGatErrors)
metrics.IncCounter(MetricCmdGatErrorsL1)
}
return err
}
示例4: Get
func (l *L1OnlyOrca) Get(req common.GetRequest) error {
metrics.IncCounter(MetricCmdGet)
metrics.IncCounterBy(MetricCmdGetKeys, uint64(len(req.Keys)))
//debugString := "get"
//for _, k := range req.Keys {
// debugString += " "
// debugString += string(k)
//}
//println(debugString)
metrics.IncCounter(MetricCmdGetL1)
metrics.IncCounterBy(MetricCmdGetKeysL1, uint64(len(req.Keys)))
resChan, errChan := l.l1.Get(req)
var err error
// Read all the responses back from l.l1.
// The contract is that the resChan will have GetResponse's for get hits and misses,
// and the errChan will have any other errors, such as an out of memory error from
// memcached. If any receive happens from errChan, there will be no more responses
// from resChan.
for {
select {
case res, ok := <-resChan:
if !ok {
resChan = nil
} else {
if res.Miss {
metrics.IncCounter(MetricCmdGetMissesL1)
metrics.IncCounter(MetricCmdGetMisses)
} else {
metrics.IncCounter(MetricCmdGetHits)
metrics.IncCounter(MetricCmdGetHitsL1)
}
l.res.Get(res)
}
case getErr, ok := <-errChan:
if !ok {
errChan = nil
} else {
metrics.IncCounter(MetricCmdGetErrors)
metrics.IncCounter(MetricCmdGetErrorsL1)
err = getErr
}
}
if resChan == nil && errChan == nil {
break
}
}
if err == nil {
l.res.GetEnd(req.NoopOpaque, req.NoopEnd)
}
return err
}
示例5: Set
func (l *L1L2Orca) Set(req common.SetRequest) error {
//log.Println("set", string(req.Key))
// Try L2 first
metrics.IncCounter(MetricCmdSetL2)
start := timer.Now()
err := l.l2.Set(req)
metrics.ObserveHist(HistSetL2, timer.Since(start))
// If we fail to set in L2, don't set in L1
if err != nil {
metrics.IncCounter(MetricCmdSetErrorsL2)
metrics.IncCounter(MetricCmdSetErrors)
return err
}
metrics.IncCounter(MetricCmdSetSuccessL2)
// Now set in L1. If L1 fails, we log the error and fail the request.
// If a user was writing a new piece of information, the error would be OK,
// since the next GET would be able to put the L2 information back into L1.
// In the case that the user was overwriting information, a failed set in L1
// and successful one in L2 would leave us inconsistent. If the response was
// positive in this situation, it would look like the server successfully
// processed the request but didn't store the information. Clients will
// retry failed writes. In this case L2 will get two writes for the same key
// but this is better because it is more correct overall, though less
// efficient. Note there are no retries at this level.
//
// It should be noted that errors on a straight set are nearly always fatal
// for the connection. It's likely that if this branch is taken that the
// connections to everyone will be severed (for this one client connection)
// and that the client will reconnect to try again.
metrics.IncCounter(MetricCmdSetL1)
start = timer.Now()
err = l.l1.Set(req)
metrics.ObserveHist(HistSetL1, timer.Since(start))
if err != nil {
metrics.IncCounter(MetricCmdSetErrorsL1)
metrics.IncCounter(MetricCmdSetErrors)
return err
}
metrics.IncCounter(MetricCmdSetSuccessL1)
metrics.IncCounter(MetricCmdSetSuccess)
return l.res.Set(req.Opaque, req.Quiet)
}
示例6: Replace
func (l *L1OnlyOrca) Replace(req common.SetRequest) error {
//log.Println("replace", string(req.Key))
metrics.IncCounter(MetricCmdReplaceL1)
start := timer.Now()
err := l.l1.Replace(req)
metrics.ObserveHist(HistReplaceL1, timer.Since(start))
if err == nil {
metrics.IncCounter(MetricCmdReplaceStoredL1)
metrics.IncCounter(MetricCmdReplaceStored)
err = l.res.Replace(req.Opaque, req.Quiet)
} else if err == common.ErrKeyNotFound {
metrics.IncCounter(MetricCmdReplaceNotStoredL1)
metrics.IncCounter(MetricCmdReplaceNotStored)
} else {
metrics.IncCounter(MetricCmdReplaceErrorsL1)
metrics.IncCounter(MetricCmdReplaceErrors)
}
return err
}
示例7: Set
func (l *L1L2BatchOrca) Set(req common.SetRequest) error {
//log.Println("set", string(req.Key))
// Try L2 first
metrics.IncCounter(MetricCmdSetL2)
start := timer.Now()
err := l.l2.Set(req)
metrics.ObserveHist(HistSetL2, timer.Since(start))
// If we fail to set in L2, don't do anything in L1
if err != nil {
metrics.IncCounter(MetricCmdSetErrorsL2)
metrics.IncCounter(MetricCmdSetErrors)
return err
}
metrics.IncCounter(MetricCmdSetSuccessL2)
// Replace the entry in L1.
metrics.IncCounter(MetricCmdSetReplaceL1)
start = timer.Now()
err = l.l1.Replace(req)
metrics.ObserveHist(HistReplaceL1, timer.Since(start))
if err != nil {
if err == common.ErrKeyNotFound {
// For a replace not stored in L1, there's no problem.
// There is no hot data to replace
metrics.IncCounter(MetricCmdSetReplaceNotStoredL1)
} else {
metrics.IncCounter(MetricCmdSetReplaceErrorsL1)
metrics.IncCounter(MetricCmdSetErrors)
return err
}
} else {
metrics.IncCounter(MetricCmdSetReplaceStoredL1)
}
metrics.IncCounter(MetricCmdSetSuccess)
return l.res.Set(req.Opaque, req.Quiet)
}
示例8: Delete
func (l *L1OnlyOrca) Delete(req common.DeleteRequest) error {
//log.Println("delete", string(req.Key))
metrics.IncCounter(MetricCmdDeleteL1)
start := timer.Now()
err := l.l1.Delete(req)
metrics.ObserveHist(HistDeleteL1, timer.Since(start))
if err == nil {
metrics.IncCounter(MetricCmdDeleteHits)
metrics.IncCounter(MetricCmdDeleteHitsL1)
l.res.Delete(req.Opaque)
} else if err == common.ErrKeyNotFound {
metrics.IncCounter(MetricCmdDeleteMissesL1)
metrics.IncCounter(MetricCmdDeleteMisses)
} else {
metrics.IncCounter(MetricCmdDeleteErrorsL1)
metrics.IncCounter(MetricCmdDeleteErrors)
}
return err
}
示例9: Touch
func (l *L1OnlyOrca) Touch(req common.TouchRequest) error {
//log.Println("touch", string(req.Key))
metrics.IncCounter(MetricCmdTouchL1)
start := timer.Now()
err := l.l1.Touch(req)
metrics.ObserveHist(HistTouchL1, timer.Since(start))
if err == nil {
metrics.IncCounter(MetricCmdTouchHitsL1)
metrics.IncCounter(MetricCmdTouchHits)
l.res.Touch(req.Opaque)
} else if err == common.ErrKeyNotFound {
metrics.IncCounter(MetricCmdTouchMissesL1)
metrics.IncCounter(MetricCmdTouchMisses)
} else {
metrics.IncCounter(MetricCmdTouchMissesL1)
metrics.IncCounter(MetricCmdTouchMisses)
}
return err
}
示例10: Add
func (l *L1OnlyOrca) Add(req common.SetRequest) error {
//log.Println("add", string(req.Key))
metrics.IncCounter(MetricCmdAddL1)
start := timer.Now()
err := l.l1.Add(req)
metrics.ObserveHist(HistAddL1, timer.Since(start))
if err == nil {
metrics.IncCounter(MetricCmdAddStoredL1)
metrics.IncCounter(MetricCmdAddStored)
err = l.res.Add(req.Opaque, req.Quiet)
} else if err == common.ErrKeyExists {
metrics.IncCounter(MetricCmdAddNotStoredL1)
metrics.IncCounter(MetricCmdAddNotStored)
} else {
metrics.IncCounter(MetricCmdAddErrorsL1)
metrics.IncCounter(MetricCmdAddErrors)
}
return err
}
示例11: readRequestHeader
func readRequestHeader(r io.Reader) (RequestHeader, error) {
buf := bufPool.Get().([]byte)
br, err := io.ReadAtLeast(r, buf, ReqHeaderLen)
metrics.IncCounterBy(common.MetricBytesReadRemote, uint64(br))
if err != nil {
bufPool.Put(buf)
return emptyReqHeader, err
}
if buf[0] != MagicRequest {
bufPool.Put(buf)
metrics.IncCounter(MetricBinaryRequestHeadersBadMagic)
return emptyReqHeader, ErrBadMagic
}
rh := reqHeadPool.Get().(RequestHeader)
rh.Magic = buf[0]
rh.Opcode = buf[1]
rh.KeyLength = binary.BigEndian.Uint16(buf[2:4])
rh.ExtraLength = buf[4]
// ignore DataType, unused
//rh.DataType = buf[5]
rh.DataType = 0
// ignore VBucket, unused
//rh.VBucket = binary.BigEndian.Uint16(buf[6:8])
rh.VBucket = 0
rh.TotalBodyLength = binary.BigEndian.Uint32(buf[8:12])
rh.OpaqueToken = binary.BigEndian.Uint32(buf[12:16])
// ignore CAS, unused in rend
//rh.CASToken = binary.BigEndian.Uint64(buf[16:24])
rh.CASToken = 0
bufPool.Put(buf)
metrics.IncCounter(MetricBinaryRequestHeadersParsed)
return rh, nil
}
示例12: Set
func (l *L1OnlyOrca) Set(req common.SetRequest) error {
//log.Println("set", string(req.Key))
metrics.IncCounter(MetricCmdSetL1)
start := timer.Now()
err := l.l1.Set(req)
metrics.ObserveHist(HistSetL1, timer.Since(start))
if err == nil {
metrics.IncCounter(MetricCmdSetSuccessL1)
metrics.IncCounter(MetricCmdSetSuccess)
err = l.res.Set(req.Opaque, req.Quiet)
} else {
metrics.IncCounter(MetricCmdSetErrorsL1)
metrics.IncCounter(MetricCmdSetErrors)
}
return err
}
示例13: Touch
func (l *L1OnlyOrca) Touch(req common.TouchRequest) error {
metrics.IncCounter(MetricCmdTouch)
//log.Println("touch", string(req.Key))
metrics.IncCounter(MetricCmdTouchL1)
err := l.l1.Touch(req)
if err == nil {
metrics.IncCounter(MetricCmdTouchHitsL1)
metrics.IncCounter(MetricCmdTouchHits)
l.res.Touch(req.Opaque)
} else if err == common.ErrKeyNotFound {
metrics.IncCounter(MetricCmdTouchMissesL1)
metrics.IncCounter(MetricCmdTouchMisses)
} else {
metrics.IncCounter(MetricCmdTouchMissesL1)
metrics.IncCounter(MetricCmdTouchMisses)
}
return err
}
示例14: Add
func (l *L1OnlyOrca) Add(req common.SetRequest) error {
metrics.IncCounter(MetricCmdAdd)
//log.Println("add", string(req.Key))
metrics.IncCounter(MetricCmdAddL1)
err := l.l1.Add(req)
if err == nil {
metrics.IncCounter(MetricCmdAddStoredL1)
metrics.IncCounter(MetricCmdAddStored)
err = l.res.Add(req.Opaque, req.Quiet)
} else if err == common.ErrKeyExists {
metrics.IncCounter(MetricCmdAddNotStoredL1)
metrics.IncCounter(MetricCmdAddNotStored)
} else {
metrics.IncCounter(MetricCmdAddErrorsL1)
metrics.IncCounter(MetricCmdAddErrors)
}
return err
}
示例15: Replace
func (l *L1OnlyOrca) Replace(req common.SetRequest) error {
metrics.IncCounter(MetricCmdReplace)
//log.Println("replace", string(req.Key))
metrics.IncCounter(MetricCmdReplaceL1)
err := l.l1.Replace(req)
if err == nil {
metrics.IncCounter(MetricCmdReplaceStoredL1)
metrics.IncCounter(MetricCmdReplaceStored)
err = l.res.Replace(req.Opaque, req.Quiet)
} else if err == common.ErrKeyNotFound {
metrics.IncCounter(MetricCmdReplaceNotStoredL1)
metrics.IncCounter(MetricCmdReplaceNotStored)
} else {
metrics.IncCounter(MetricCmdReplaceErrorsL1)
metrics.IncCounter(MetricCmdReplaceErrors)
}
return err
}