// This file contains the methods related to replication.
// WriteComBinlogDump writes a ComBinlogDump command.
// See http://dev.mysql.com/doc/internals/en/com-binlog-dump.html for syntax.
// Returns a SQLError.
765256
func (c *Conn) WriteComBinlogDump(serverID uint32, binlogFilename string, binlogPos uint32, flags uint16) error {
	c.sequence = 0
	length := 1 + // ComBinlogDump
		4 + // binlog-pos
		2 + // flags
		4 + // server-id
		len(binlogFilename) // binlog-filename
	data := c.startEphemeralPacket(length)
	pos := writeByte(data, 0, ComBinlogDump)
	pos = writeUint32(data, pos, binlogPos)
	pos = writeUint16(data, pos, flags)
	pos = writeUint32(data, pos, serverID)
	_ = writeEOFString(data, pos, binlogFilename)
	if err := c.writeEphemeralPacket(); err != nil {
		return NewSQLError(CRServerGone, SSUnknownSQLState, "%v", err)
	}
	return nil
}
282778
func (c *CommitLog) Append(p []byte) (offset int64, err error) {
	l := Log(p)
	if c.checkSplit() {
		if err := c.split(); err != nil {
			return offset, err
		}
	}
	offset = c.NewestOffset()
	l.PutOffset(offset)
	if _, err := c.activeSegment().Write(l); err != nil {
		return offset, err
	}
	return offset, nil
}
649749
func (s *Logging) Write(b []byte) (int, error) {
	s.mutex.RLock()
	w := s.writer
	s.mutex.RUnlock()

	return w.Write(b)
}
1270454
func (dbInst *DB) WriteBatch(batch *leveldb.Batch, sync bool) error {
	wo := dbInst.writeOptsNoSync
	if sync {
		wo = dbInst.writeOptsSync
	}
	if err := dbInst.db.Write(batch, wo); err != nil {
		return errors.Wrap(err, "error writing batch to leveldb")
	}
	return nil
}
30233
func Dump(c context.Context, w io.Writer) (n int, err error) {
	return logging.Get(c).(*MemLogger).Dump(w)
}
1268087
func (c *Peer) WriteBulk(s string) {
	c.Block(func(w *Writer) {
		w.WriteBulk(s)
	})
}
1038497
func (wal *baseWAL) WriteSync(msg WALMessage) {
	if wal == nil {
		return
	}

	wal.Write(msg)
	if err := wal.FlushAndSync(); err != nil {
		panic(fmt.Sprintf("Error flushing consensus wal buf to file. Error: %v \n", err))
	}
}
569246
func (f DumFile) Write(p []byte) (n int, err error) {
	return 0, f.err
}
969051
func (m *MemLogger) Dump(w io.Writer) (n int, err error) {
	amt := 0
	for i, msg := range m.Messages() {
		if i == 0 {
			amt, err = fmt.Fprintf(w, "\nDUMP LOG:\n")
			n += amt
			if err != nil {
				return
			}
		}
		if msg.Data == nil {
			amt, err = fmt.Fprintf(w, "  %s: %s\n", msg.Level, msg.Msg)
			n += amt
			if err != nil {
				return
			}
		} else {
			amt, err = fmt.Fprintf(w, "  %s: %s: %s\n", msg.Level, msg.Msg, logging.Fields(msg.Data))
			n += amt
			if err != nil {
				return
			}
		}
	}
	return
}
320334
func (mlf *MockLogFile) Write(contents []byte) {
	mlf.mu.Lock()
	defer mlf.mu.Unlock()

	mlf.logBuffer = append(mlf.logBuffer, contents...)
}
1072970
func (writer KlogWriter) Write(data []byte) (n int, err error) {
	klog.InfoDepth(1, string(data))
	return len(data), nil
}
1177334
func (commit *Commit) Dump(wr io.Writer) error {
	funcMap := template.FuncMap{
		"indent": func(content string) (string, error) {
			var out bytes.Buffer
			scanner := bufio.NewScanner(strings.NewReader(content))
			for scanner.Scan() {
				if _, err := fmt.Fprintln(&out, "    ", scanner.Text()); err != nil {
					return "", err
				}
			}
			if err := scanner.Err(); err != nil {
				return "", err
			}
			return out.String(), nil
		},
	}

	tpl := template.Must(template.New("commit").Funcs(funcMap).Parse(commitTemplate))
	return tpl.Execute(wr, commit)
}
649847
func (s *SeriesSegment) WriteLogEntry(data []byte) (offset int64, err error) {
	if !s.CanWrite(data) {
		return 0, ErrSeriesSegmentNotWritable
	}

	offset = JoinSeriesOffset(s.id, s.size)
	if _, err := s.w.Write(data); err != nil {
		return 0, err
	}
	s.size += uint32(len(data))

	return offset, nil
}
1299105
func (w *LogWriter) Write(p []byte) (int, error) {
	w.bufferLock.Lock()
	defer w.bufferLock.Unlock()

	w.buffer = append(w.buffer, p...)

	for len(w.buffer) > w.maxChunkSize {
		chunk := w.buffer[:w.maxChunkSize]
		w.buffer = w.buffer[w.maxChunkSize:]
		w.send(chunk)
	}

	return len(p), nil
}
549582
func (s *NFSBackup) Dump(dest io.Writer) (err error) {
	err = s.Caller.Execute(dest, s.getDumpCommand())
	return
}
37858
func (l *logger) Write(p []byte) (n int, err error) {
	l.locker.Lock()
	for _, w := range l.writers {
		n, err = w.Output().Write(p)
		if err != nil {
			return
		}
	}
	l.locker.Unlock()
	return
}
687369
func (w *BatchedFileWriter) Write(p []byte) (n int, err error) {
	return w.file.Write(p)
}