<commit_before>#ifndef MONSOON_HISTORY_DIR_IO_TXFILE_H
#define MONSOON_HISTORY_DIR_IO_TXFILE_H

#include <cstddef>
#include <cstdint>
#include <map>
#include <optional>
#include <shared_mutex>
#include <utility>
#include <vector>
#include <monsoon/io/fd.h>
#include <monsoon/history/dir/io/tx_sequencer.h>
#include <monsoon/history/dir/io/wal.h>
#include <boost/intrusive/set.hpp>
#include <boost/intrusive/options.hpp>

namespace monsoon::history::io {


class txfile_transaction_error
: public std::runtime_error
{
  public:
  using std::runtime_error::runtime_error;
  ~txfile_transaction_error();
};

class txfile_bad_transaction
: public std::logic_error
{
  public:
  using std::logic_error::logic_error;
  ~txfile_bad_transaction();
};

class txfile_read_only_transaction
: public txfile_bad_transaction
{
  public:
  using txfile_bad_transaction::txfile_bad_transaction;
  ~txfile_read_only_transaction();
};


/**
 * \brief A transactional file.
 * \details
 * A transactional file works by creating the illusion of a file that is
 * modified by atomically committable transactions.
 *
 * The model of the transaction isolation implemented by this file is the serializable isolation:
 * - the transaction won't be able to read data that is not committed
 * - the transaction, when re-reading data previously read, will read the same data and won't see commits from other transactions
 *
 * Furthermore, this class guarantees that data that was successfully committed
 * will be stored on disk even in the event of a crash of the binary or the system.
 *
 * The txfile achieves this by using a WAL (Write Ahead Log) to record operations.
 * A designated region holds this WAL.
 *
 * Operations on the logical view of the file pretend the WAL doesn't exist,
 * by translating all offset for file operations to the end of the WAL.
 * For instance: a read or write at offset 0 would correspond to the first byte
 * after the WAL in the actual file.
 *
 * The number of transactions and the size of modifications by them are limited
 * by the size of the WAL.
 * If the WAL region fills up and can't be compacted, any transactions in flight<commit_msg>Clarify and correct transaction isolation level.<commit_after>#ifndef MONSOON_HISTORY_DIR_IO_TXFILE_H
#define MONSOON_HISTORY_DIR_IO_TXFILE_H

#include <cstddef>
#include <cstdint>
#include <map>
#include <optional>
#include <shared_mutex>
#include <utility>
#include <vector>
#include <monsoon/io/fd.h>
#include <monsoon/history/dir/io/tx_sequencer.h>
#include <monsoon/history/dir/io/wal.h>
#include <boost/intrusive/set.hpp>
#include <boost/intrusive/options.hpp>

namespace monsoon::history::io {


class txfile_transaction_error
: public std::runtime_error
{
  public:
  using std::runtime_error::runtime_error;
  ~txfile_transaction_error();
};

class txfile_bad_transaction
: public std::logic_error
{
  public:
  using std::logic_error::logic_error;
  ~txfile_bad_transaction();
};

class txfile_read_only_transaction
: public txfile_bad_transaction
{
  public:
  using txfile_bad_transaction::txfile_bad_transaction;
  ~txfile_read_only_transaction();
};


/**
 * \brief A transactional file.
 * \details
 * A transactional file works by creating the illusion of a file that is
 * modified by atomically committable transactions.
 *
 * The model of the transaction isolation implemented by this file is the repeatable read isolation:
 * - the transaction will see all of the data committed before it started.
 * - the transaction will see none of the data committed before it started.
 *
 * Furthermore, this class guarantees that data that was successfully committed
 * will be stored on disk even in the event of a crash of the binary or the system.
 *
 * The txfile achieves this by using a WAL (Write Ahead Log) to record operations.
 * A designated region holds this WAL.
 *
 * Operations on the logical view of the file pretend the WAL doesn't exist,
 * by translating all offset for file operations to the end of the WAL.
 * For instance: a read or write at offset 0 would correspond to the first byte
 * after the WAL in the actual file.
 *
 * The number of transactions and the size of modifications by them are limited
 * by the size of the WAL.
 * If the WAL region fills up and can't be compacted, any transactions in flight
{'fraction_non_alphanumeric': 0.0744013020227854, 'fraction_numerical': 0.00046500813764240875, 'mean_word_length': 4.829268292682927, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6717820', 'n_tokens_mistral': 1280, 'n_tokens_neox': 1247, 'n_words': 500}