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

#pragma once

#include "crimson/osd/backfill_state.h"
#include "crimson/osd/pg.h"
#include "osd/PeeringState.h"

namespace crimson::osd {

// PeeringFacade -- main implementation of the BackfillState::PeeringFacade
// interface. We have the abstraction to decuple BackfillState from Peering
// State, and thus cut depedencies in unit testing. The second implemention
// is BackfillFixture::PeeringFacade and sits in test_backfill.cc.
struct PeeringFacade final : BackfillState::PeeringFacade {
  PeeringState& peering_state;

  hobject_t earliest_backfill() const override {
    return peering_state.earliest_backfill();
  }

  const std::set<pg_shard_t>& get_backfill_targets() const override {
    return peering_state.get_backfill_targets();
  }

  const hobject_t& get_peer_last_backfill(pg_shard_t peer) const override {
    return peering_state.get_peer_info(peer).last_backfill;
  }

  const eversion_t& get_last_update() const override {
    return peering_state.get_info().last_update;
  }

  const eversion_t& get_log_tail() const override {
    return peering_state.get_info().log_tail;
  }

  const PGLog& get_pg_log() const override {
    return peering_state.get_pg_log();
  }

  void scan_log_after(eversion_t v, scan_log_func_t f) const override {
    peering_state.get_pg_log().get_log().scan_log_after(v, std::move(f));
  }

  bool is_backfill_target(pg_shard_t peer) const override {
    return peering_state.is_backfill_target(peer);
  }
  void update_complete_backfill_object_stats(const hobject_t &hoid,
                                             const pg_stat_t &stats) override {
    peering_state.update_complete_backfill_object_stats(hoid, stats);
  }

  bool is_backfilling() const override {
    return peering_state.is_backfilling();
  }

  void prepare_backfill_for_missing(
    const hobject_t &soid,
    const eversion_t &v,
    const std::vector<pg_shard_t> &peers) override {
    return peering_state.prepare_backfill_for_missing(soid, v, peers);
  }
  PeeringFacade(PeeringState& peering_state)
    : peering_state(peering_state) {
  }
};

// PGFacade -- a facade (in the GoF-defined meaning) simplifying the huge
// interface of crimson's PG class. The motivation is to have an inventory
// of behaviour that must be provided by a unit test's mock.
struct PGFacade final : BackfillState::PGFacade {
  PG& pg;

  const eversion_t& get_projected_last_update() const override {
    return pg.projected_last_update;
  }

  const PGLog::IndexedLog& get_projected_log() const override {
    return pg.projected_log;
  }

  PGFacade(PG& pg) : pg(pg) {}
  std::ostream &print(std::ostream &out) const override {
    return out << pg;
  }
};

} // namespace crimson::osd