// N.B. This function must be called with the Write Lock
335176
func (t *Throttler) isAllowed(operation string) bool {
	credits := t.credits[operation]
	if credits < minimumCredits {
		t.metrics.ThrottledDebugSpans.Inc(1)
		return false
	}
	t.credits[operation] = credits - minimumCredits
	return true
}
1138631
func (ctx *context) Writef(format string, a ...interface{}) (n int, err error) {
	return ctx.writer.Writef(format, a...)
}
827772
func (c *rwConn) Write(p []byte) (int, error) {
	n, err := c.BufWriter.Write(p)
	if err := c.BufWriter.Flush(); err != nil {
		return 0, err
	}
	return n, err
}
903557
func (m Map) unsortedWriteBuf(w byteSliceWriter) {
	// scratch buffer for intermediate writes
	buf := bufPool.Get()
	defer bufPool.Put(buf)

	first := true
	for k, v := range m {
		if first {
			first = false
		} else {
			w.WriteByte(' ')
		}

		w.WriteString(k)
		w.WriteString(`="`)

		fmt.Fprint(buf, v)
		// pull out byte slice from buff
		b := buf.Bytes()
		blen := buf.Len()
		p := 0
		for i := 0; i < blen; i++ {
			switch b[i] {
			case '"':
				w.Write(b[p:i])
				w.WriteString(`\"`)
				p = i + 1
			case '\t':
				w.Write(b[p:i])
				w.WriteString(`\t`)
				p = i + 1
			case '\r':
				w.Write(b[p:i])
				w.WriteString(`\r`)
				p = i + 1
			case '\n':
				w.Write(b[p:i])
				w.WriteString(`\n`)
				p = i + 1
			}
		}
		if p < blen {
			w.Write(b[p:blen])
		}

		w.WriteByte('"')
		// truncate intermediate buf so it is clean for next loop
		buf.Truncate(0)
	}
}
1318226
func WALWithNBlocks(t *testing.T, numBlocks int) (data []byte, err error) {
	var b bytes.Buffer
	wr := bufio.NewWriter(&b)

	if err := WALGenerateNBlocks(t, wr, numBlocks); err != nil {
		return []byte{}, err
	}

	wr.Flush()
	return b.Bytes(), nil
}
104768
func (db *DB) WriteBatch(batch *leveldb.Batch) (err error) {
	err = db.ldb.Write(batch, nil)
	if err != nil {
		metrics.GetOrRegisterCounter("DB.writebatchFail", nil).Inc(1)
		return err
	}
	metrics.GetOrRegisterCounter("DB.writebatch", nil).Inc(1)
	return nil
}
517821
func Writeln(w io.Writer, bs []byte) (int, error) {
	n, err := w.Write(bs)
	if err == nil {
		if !bytes.HasSuffix(bs, _newLine) {
			_, err = w.Write(_newLine)
		}
	}

	return n, err
}
403554
func (be *BinaryEncoder) WriteBytes(value []byte) {
	be.WriteInt32(int32(len(value)))
	copy(be.buffer[be.pos:], value)
	be.pos += len(value)
}
312374
func (meta *Meta) WriteBinary(w io.Writer) error {
	return binary.Write(w, byteorder.Native, meta)
}
500111
func (c *Characteristic) HandleWriteFunc(f func(r Request, data []byte) (status byte)) {
	c.HandleWrite(WriteHandlerFunc(f))
}
190808
func (bufc *bufConn) Write(b []byte) (int, error) {
	return bufc.conn.Write(b)
}
540453
func (w *Writer) WriteBigInt(bi *big.Int) {
	w.writeByte(TagLong)
	w.writeString(bi.String())
	w.writeByte(TagSemicolon)
}
1176520
func (mBatch *cLevelDBBatch) WriteSync() {
	err := mBatch.db.db.Write(mBatch.db.woSync, mBatch.batch)
	if err != nil {
		panic(err)
	}
}
729434
func (s *Stream) Write(b []byte) (n int, err error) {
	s.sendLock.Lock()
	defer s.sendLock.Unlock()
	total := 0
	for total < len(b) {
		n, err := s.write(b[total:])
		total += n
		if err != nil {
			return total, err
		}
	}
	return total, nil
}
635984
func (s *Statistics) N() uint64 {
	s.RLock()
	defer s.RUnlock()
	return s.samples
}
1260013
func (c *circbufWriter) Write(p []byte) (nn int, err error) {
	// If the last write returned an error, return it here. Note there is a
	// small chance of missing an error if multiple writes occure at the same
	// time where the last write nils out the error before it can be returned
	// here.
	c.bufLock.Lock()
	defer c.bufLock.Unlock()
	if c.err != nil {
		return nn, c.err
	}

	// Write to the buffer
	nn, err = c.buf.Write(p)

	// Signal to flush the buffer
	select {
	case c.flushCh <- struct{}{}:
	default:
		// flush is blocked
	}
	return nn, err
}
377127
func leveldb_writebatch_iterate_delete(p unsafe.Pointer, k *C.char, klen C.size_t) {
	b := (*leveldb.Batch)(p)
	key := slice(unsafe.Pointer(k), int(klen))
	b.Delete(key)
}