summaryrefslogtreecommitdiffstats
path: root/src/crimson/os/seastore/journal.h
blob: a5c9029c43cb21e99ceae0b587e80c08c6bf313e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#pragma once

#include <memory>

#include "crimson/os/seastore/ordering_handle.h"
#include "crimson/os/seastore/seastore_types.h"
#include "crimson/os/seastore/segment_seq_allocator.h"
#include "crimson/os/seastore/cached_extent.h"

namespace crimson::os::seastore {

namespace random_block_device {
class RBMDevice;
}

class SegmentManagerGroup;
class SegmentProvider;
class JournalTrimmer;

class Journal {
public:
  virtual JournalTrimmer &get_trimmer() = 0;

  virtual writer_stats_t get_writer_stats() const = 0;

  /**
   * initializes journal for mkfs writes -- must run prior to calls
   * to submit_record.
   */
  using open_for_mkfs_ertr = crimson::errorator<
    crimson::ct_error::input_output_error
    >;
  using open_for_mkfs_ret = open_for_mkfs_ertr::future<journal_seq_t>;
  virtual open_for_mkfs_ret open_for_mkfs() = 0;

  /**
   * initializes journal for new writes -- must run prior to calls
   * to submit_record.  Should be called after replay if not a new
   * Journal.
   */
  using open_for_mount_ertr = open_for_mkfs_ertr;
  using open_for_mount_ret = open_for_mkfs_ret;
  virtual open_for_mount_ret open_for_mount() = 0;

  /// close journal
  using close_ertr = crimson::errorator<
    crimson::ct_error::input_output_error>;
  virtual close_ertr::future<> close() = 0;

  /**
   * submit_record
   *
   * write record with the ordering handle
   */
  using submit_record_ertr = crimson::errorator<
    crimson::ct_error::erange,
    crimson::ct_error::input_output_error
    >;
  using submit_record_ret = submit_record_ertr::future<
    record_locator_t
    >;
  virtual submit_record_ret submit_record(
    record_t &&record,
    OrderingHandle &handle
  ) = 0;

  /**
   * flush
   *
   * Wait for all outstanding IOs on handle to commit.
   * Note, flush() machinery must go through the same pipeline
   * stages and locks as submit_record.
   */
  virtual seastar::future<> flush(OrderingHandle &handle) = 0;

  /// sets write pipeline reference
  virtual void set_write_pipeline(WritePipeline *_write_pipeline) = 0;

  /**
   * Read deltas and pass to delta_handler
   *
   * record_block_start (argument to delta_handler) is the start of the
   * of the first block in the record
   */
  using replay_ertr = crimson::errorator<
    crimson::ct_error::input_output_error,
    crimson::ct_error::invarg,
    crimson::ct_error::enoent,
    crimson::ct_error::erange>;
  using replay_ret = replay_ertr::future<>;
  using delta_handler_t = std::function<
    replay_ertr::future<std::pair<bool, CachedExtentRef>>(
      const record_locator_t&,
      const delta_info_t&,
      const journal_seq_t&, // dirty_tail
      const journal_seq_t&, // alloc_tail
      sea_time_point modify_time)>;
  virtual replay_ret replay(
    delta_handler_t &&delta_handler) = 0;

  virtual seastar::future<> finish_commit(
    transaction_type_t type) = 0;

  virtual ~Journal() {}

  virtual backend_type_t get_type() = 0;

  virtual bool is_checksum_needed() = 0; 
};
using JournalRef = std::unique_ptr<Journal>;

namespace journal {

JournalRef make_segmented(
  SegmentProvider &provider,
  JournalTrimmer &trimmer);

JournalRef make_circularbounded(
  JournalTrimmer &trimmer,
  crimson::os::seastore::random_block_device::RBMDevice* device,
  std::string path);

}

}