// IncWrites increments the writes count to this entity.
506826
func (c *RefCount) IncWrites() {
	tracebackEvent(c, c.NumRef(), incWritesEvent)
	n := atomic.AddInt32(&c.writes, 1)
	ref := c.NumRef()

	if n > 0 && ref < 1 {
		err := fmt.Errorf("write after free: writes=%d, ref=%d", n, ref)
		panicRef(c, err)
	}

	if n > 1 {
		err := fmt.Errorf("double write: writes=%d, ref=%d", n, ref)
		panicRef(c, err)
	}
}
326122
func (s *syncWriter) Write(p []byte) (n int, err error) {
	s.mu.Lock()
	defer s.mu.Unlock()
	return s.lw.Write(p)
}
542513
func (cw *countWriter) Write(p []byte) (n int, err error) {
	n, err = cw.w.Write(p)
	atomic.AddUint64(&cw.written, uint64(n))
	return
}
1248380
func (w *minifyWriter) Write(b []byte) (int, error) {
	return w.pw.Write(b)
}
710306
func (w *etmWriter) Write(b []byte) (int, error) {
	if err := w.WriteMsg(b); err != nil {
		return 0, err
	}
	return len(b), nil
}
496011
func (w *SyncWriter) Write(b []byte) error {
	if _, err := w.w.Write(b); err != nil {
		return err
	}
	return w.syncFn()
}
632500
func (c *RefCounter) Increment(path string) int {
	return c.incdec(path, func(minfo *minfo) {
		minfo.count++
	})
}
927637
func (r *retryCounter) Increment(oid string) {
	r.cmu.Lock()
	defer r.cmu.Unlock()

	r.count[oid]++
}
317758
func (w *Writer) WriteInline(s string) {
	fmt.Fprintf(w.w, "+%s\r\n", toInline(s))
}
174661
func (w *fdSyncWriter) Write(p []byte) (n int, err error) {
	w.Lock()
	n, err = w.fdWriter.Write(p)
	w.Unlock()
	return n, err
}
938375
func (w *TermsWriter) writeBlocks(prefixLength, count int) (err error) {
	assert(count > 0)

	// Root block better writes all remaining pending entries:
	assert(prefixLength > 0 || count == len(w.pending))

	lastSuffixLeadLabel := -1

	// True if we saw at least one term in this block (we record if a
	// block only points to sub-blocks in the terms index so we can
	// avoid seeking to it when we are looking for a term):
	hasTerms := false
	hasSubBlocks := false

	end := len(w.pending)
	start := end - count
	nextBlockStart := start
	nextFloorLeadLabel := -1

	for i, ent := range w.pending[start:] {
		var suffixLeadLabel int
		if ent.isTerm() {
			term := ent.(*PendingTerm)
			if len(term.term) == prefixLength {
				// suffix is 0, ie prefix 'foo' and term is 'foo' so the
				// term has empty string suffix in this block
				assert(lastSuffixLeadLabel == -1)
				suffixLeadLabel = -1
			} else {
				suffixLeadLabel = int(term.term[prefixLength])
			}
		} else {
			block := ent.(*PendingBlock)
			assert(len(block.prefix) > prefixLength)
			suffixLeadLabel = int(block.prefix[prefixLength])
		}

		if suffixLeadLabel != lastSuffixLeadLabel {
			if itemsInBlock := i + count - nextBlockStart; itemsInBlock >= w.owner.minItemsInBlock &&
				end-nextBlockStart > w.owner.maxItemsInBlock {
				// The count is too large for one block, so we must break
				// it into "floor" blocks, where we record the leading
				// label of the suffix of the first term in each floor
				// block, so at search time we can jump to the right floor
				// block. We just use a naive greedy segmenter here: make a
				// new floor block as soon as we have at least
				// minItemsInBlock. This is not always best: it often
				// produces a too-small block as the final block:
				isFloor := itemsInBlock < count
				var block *PendingBlock
				if block, err = w.writeBlock(prefixLength, isFloor,
					nextFloorLeadLabel, nextBlockStart, i+count, hasTerms,
					hasSubBlocks); err != nil {
					return
				}
				w.newBlocks = append(w.newBlocks, block)

				hasTerms = false
				hasSubBlocks = false
				nextFloorLeadLabel = suffixLeadLabel
				nextBlockStart = i + count
			}

			lastSuffixLeadLabel = suffixLeadLabel
		}

		if ent.isTerm() {
			hasTerms = true
		} else {
			hasSubBlocks = true
		}
	}

	// Write last block, if any:
	if nextBlockStart < end {
		itemsInBlock := end - nextBlockStart
		isFloor := itemsInBlock < count
		var block *PendingBlock
		if block, err = w.writeBlock(prefixLength, isFloor,
			nextFloorLeadLabel, nextBlockStart, end, hasTerms,
			hasSubBlocks); err != nil {
			return
		}
		w.newBlocks = append(w.newBlocks, block)
	}

	assert(len(w.newBlocks) > 0)

	firstBlock := w.newBlocks[0]

	assert(firstBlock.isFloor || len(w.newBlocks) == 1)

	if err = firstBlock.compileIndex(w.newBlocks,
		w.owner.scratchBytes, w.owner.scratchIntsRef); err != nil {
		return
	}

	// Remove slice from the top of the pending stack, that we just wrote:
	w.pending = w.pending[:start]

	// Append new block
	w.pending = append(w.pending, firstBlock)

	w.newBlocks = nil
	return nil
}
1001687
func (c *ChecksumWriter) Write(p []byte) (n int, err error) {
	c.sum.Size += int64(len(p))

	for _, h := range c.hashes {
		h.Write(p)
	}

	return len(p), nil
}
1013290
func (mw *Writer) Write(buf []byte) (int, error) {
	if mw.err != nil {
		return 0, mw.err
	}

	var wrCnt int
	for _, b := range buf {
		zeros, ones := numBits(b)

		// If possible, avoid flushing to maintain high efficiency.
		if ensured := mw.bufCnt < EnsureRawBytes; ensured {
			goto skipEncode
		}
		if huffLen, _ := mw.computeHuffLen(mw.buf0s+zeros, mw.buf1s+ones); huffLen > 0 {
			goto skipEncode
		}

		mw.err = mw.encodeBlock(FinalNil)
		if mw.err != nil {
			break
		}

	skipEncode:
		mw.buf0s += zeros
		mw.buf1s += ones
		mw.buf[mw.bufCnt] = b
		mw.bufCnt++
		wrCnt++
	}

	mw.InputOffset += int64(wrCnt)
	return wrCnt, mw.err
}
38604
func writeHeaders(w io.Writer, statusCode int, headers http.Header) {
	fmt.Fprintf(w, "%d %s\n", statusCode, http.StatusText(statusCode))
	for k, v := range headers {
		fmt.Fprintf(w, "%s: %s\n", k, v[0])
	}
}
1159217
func (mw multiWriter) Write(p []byte) (int, error) {
	done := make(chan result, len(mw))
	for _, w := range mw {
		go send(w, p, done)
	}
	endResult := result{n: len(p)}
	for _ = range mw {
		res := <-done
		if res.err != nil && (endResult.err == nil || res.n < endResult.n) {
			endResult = res
		}
	}
	return endResult.n, endResult.err
}
153268
func (p *parallelWriter) Write(ctx context.Context, blocks [][]byte) error {
	var wg sync.WaitGroup

	for i := range p.writers {
		if p.writers[i] == nil {
			p.errs[i] = errDiskNotFound
			continue
		}

		wg.Add(1)
		go func(i int) {
			defer wg.Done()
			_, p.errs[i] = p.writers[i].Write(blocks[i])
			if p.errs[i] != nil {
				p.writers[i] = nil
			}
		}(i)
	}
	wg.Wait()

	// If nilCount >= p.writeQuorum, we return nil. This is because HealFile() uses
	// CreateFile with p.writeQuorum=1 to accommodate healing of single disk.
	// i.e if we do no return here in such a case, reduceWriteQuorumErrs() would
	// return a quorum error to HealFile().
	nilCount := 0
	for _, err := range p.errs {
		if err == nil {
			nilCount++
		}
	}
	if nilCount >= p.writeQuorum {
		return nil
	}
	return reduceWriteQuorumErrs(ctx, p.errs, objectOpIgnoredErrs, p.writeQuorum)
}
1121039
func (w *Writer) Write(buf []byte) (int, error) {
	return w.Writer.Write(buf)
}