pub fn write_batch(&self, batch: &[UpdateMetadata]) -> io::Result<u64> {
        self.check_error()?;

        let batch_bytes = serialize_batch(batch);
        let ret = batch_bytes.len() as u64;

        let mut log = self.inner.active_log.lock();

        if let Err(e) = maybe!(log.file.write_all(&batch_bytes)) {
            self.set_error(&e);
            return Err(e);
        }

        if let Err(e) = maybe!(log.file.sync_all())
            .and_then(|_| self.inner.directory_lock.sync_all())
        {
            self.set_error(&e);
            return Err(e);
        }

        log.bytes_written += batch_bytes.len() as u64;

        if log.bytes_written
            > self.inner.snapshot_size.load(Ordering::Acquire).max(64 * 1024)
        {
            let next_offset = log.log_sequence_number + 1;
            let next_path =
                log_path(&self.inner.storage_directory, next_offset);

            // open new log
            let mut next_log_file_opts = fs::OpenOptions::new();
            next_log_file_opts.create(true).read(true).write(true);

            let next_log_file = match maybe!(next_log_file_opts.open(next_path))
            {
                Ok(nlf) => nlf,
                Err(e) => {
                    self.set_error(&e);
                    return Err(e);
                }
            };

            let next_log_and_stats = LogAndStats {
                file: next_log_file,
                log_sequence_number: next_offset,
                bytes_written: 0,
            };

            // replace log
            let old_log_and_stats =
                std::mem::replace(&mut *log, next_log_and_stats);

            // send to snapshot writer
            self.inner
                .worker_outbox
                .send(WorkerMessage::LogReadyToCompact {
                    log_and_stats: old_log_and_stats,
                })
                .expect("unable to send log to compact to worker");
        }

        Ok(ret)
    }
Write a batch of metadata. `None` for the second half of the outer tuple represents a
deletion. Returns the bytes written.
src/metadata_store.rs