summaryrefslogtreecommitdiffstats
path: root/src/os/SequencerPosition.h
blob: 5ba4699a2ff5280a5d744b4da5cedd1bf57c7694 (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
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#ifndef __CEPH_OS_SEQUENCERPOSITION_H
#define __CEPH_OS_SEQUENCERPOSITION_H

#include "include/types.h"
#include "include/encoding.h"
#include "common/Formatter.h"

#include <ostream>

/**
 * transaction and op offset
 */
struct SequencerPosition {
  uint64_t seq;  ///< seq
  uint32_t trans; ///< transaction in that seq (0-based)
  uint32_t op;    ///< op in that transaction (0-based)

  SequencerPosition(uint64_t s=0, int32_t t=0, int32_t o=0) : seq(s), trans(t), op(o) {}

  auto operator<=>(const SequencerPosition&) const = default;

  void encode(ceph::buffer::list& bl) const {
    ENCODE_START(1, 1, bl);
    encode(seq, bl);
    encode(trans, bl);
    encode(op, bl);
    ENCODE_FINISH(bl);
  }
  void decode(ceph::buffer::list::const_iterator& p) {
    DECODE_START(1, p);
    decode(seq, p);
    decode(trans, p);
    decode(op, p);
    DECODE_FINISH(p);
  }
  void dump(ceph::Formatter *f) const {
    f->dump_unsigned("seq", seq);
    f->dump_unsigned("trans", trans);
    f->dump_unsigned("op", op);
  }
  static void generate_test_instances(std::list<SequencerPosition*>& o) {
    o.push_back(new SequencerPosition);
    o.push_back(new SequencerPosition(1, 2, 3));
    o.push_back(new SequencerPosition(4, 5, 6));
  }
};
WRITE_CLASS_ENCODER(SequencerPosition)

inline std::ostream& operator<<(std::ostream& out, const SequencerPosition& t) {
  return out << t.seq << "." << t.trans << "." << t.op;
}

#endif