]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab ft=cpp | |
3 | ||
4 | /* | |
5 | * Ceph - scalable distributed file system | |
6 | * | |
7 | * Copyright (C) 2019 Red Hat, Inc. | |
8 | * | |
9 | * This is free software; you can redistribute it and/or | |
10 | * modify it under the terms of the GNU Lesser General Public | |
11 | * License version 2.1, as published by the Free Software | |
12 | * Foundation. See file COPYING. | |
13 | * | |
14 | */ | |
15 | ||
16 | ||
17 | #pragma once | |
18 | ||
19 | #include "rgw/rgw_service.h" | |
20 | #include "rgw/rgw_period_history.h" | |
21 | #include "rgw/rgw_period_puller.h" | |
22 | ||
23 | #include "svc_meta_be.h" | |
24 | ||
25 | ||
26 | class RGWMetadataLog; | |
27 | class RGWMetadataLogHistory; | |
28 | class RGWCoroutine; | |
29 | ||
30 | class RGWSI_Zone; | |
31 | class RGWSI_SysObj; | |
32 | class RGWSI_RADOS; | |
33 | ||
34 | namespace mdlog { | |
35 | class ReadHistoryCR; | |
36 | class WriteHistoryCR; | |
37 | } | |
38 | ||
39 | class RGWSI_MDLog : public RGWServiceInstance | |
40 | { | |
41 | friend class mdlog::ReadHistoryCR; | |
42 | friend class mdlog::WriteHistoryCR; | |
43 | ||
44 | // maintain a separate metadata log for each period | |
45 | std::map<std::string, RGWMetadataLog> md_logs; | |
46 | ||
47 | // use the current period's log for mutating operations | |
48 | RGWMetadataLog* current_log{nullptr}; | |
49 | ||
50 | bool run_sync; | |
51 | ||
52 | // pulls missing periods for period_history | |
53 | std::unique_ptr<RGWPeriodPuller> period_puller; | |
54 | // maintains a connected history of periods | |
55 | std::unique_ptr<RGWPeriodHistory> period_history; | |
56 | ||
57 | public: | |
58 | RGWSI_MDLog(CephContext *cct, bool run_sync); | |
59 | virtual ~RGWSI_MDLog(); | |
60 | ||
61 | struct Svc { | |
62 | RGWSI_RADOS *rados{nullptr}; | |
63 | RGWSI_Zone *zone{nullptr}; | |
64 | RGWSI_SysObj *sysobj{nullptr}; | |
65 | RGWSI_MDLog *mdlog{nullptr}; | |
66 | RGWSI_Cls *cls{nullptr}; | |
67 | } svc; | |
68 | ||
69 | int init(RGWSI_RADOS *_rados_svc, | |
70 | RGWSI_Zone *_zone_svc, | |
71 | RGWSI_SysObj *_sysobj_svc, | |
72 | RGWSI_Cls *_cls_svc); | |
73 | ||
b3b6e05e | 74 | int do_start(optional_yield y, const DoutPrefixProvider *dpp) override; |
9f95a23c TL |
75 | |
76 | // traverse all the way back to the beginning of the period history, and | |
77 | // return a cursor to the first period in a fully attached history | |
b3b6e05e | 78 | RGWPeriodHistory::Cursor find_oldest_period(const DoutPrefixProvider *dpp, optional_yield y); |
9f95a23c TL |
79 | |
80 | /// initialize the oldest log period if it doesn't exist, and attach it to | |
81 | /// our current history | |
b3b6e05e | 82 | RGWPeriodHistory::Cursor init_oldest_log_period(optional_yield y, const DoutPrefixProvider *dpp); |
9f95a23c TL |
83 | |
84 | /// read the oldest log period, and return a cursor to it in our existing | |
85 | /// period history | |
b3b6e05e | 86 | RGWPeriodHistory::Cursor read_oldest_log_period(optional_yield y, const DoutPrefixProvider *dpp) const; |
9f95a23c TL |
87 | |
88 | /// read the oldest log period asynchronously and write its result to the | |
89 | /// given cursor pointer | |
b3b6e05e TL |
90 | RGWCoroutine* read_oldest_log_period_cr(const DoutPrefixProvider *dpp, |
91 | RGWPeriodHistory::Cursor *period, | |
9f95a23c TL |
92 | RGWObjVersionTracker *objv) const; |
93 | ||
94 | /// try to advance the oldest log period when the given period is trimmed, | |
95 | /// using a rados lock to provide atomicity | |
b3b6e05e TL |
96 | RGWCoroutine* trim_log_period_cr(const DoutPrefixProvider *dpp, |
97 | RGWPeriodHistory::Cursor period, | |
9f95a23c | 98 | RGWObjVersionTracker *objv) const; |
b3b6e05e TL |
99 | int read_history(RGWMetadataLogHistory *state, RGWObjVersionTracker *objv_tracker,optional_yield y, const DoutPrefixProvider *dpp) const; |
100 | int write_history(const DoutPrefixProvider *dpp, | |
101 | const RGWMetadataLogHistory& state, | |
9f95a23c | 102 | RGWObjVersionTracker *objv_tracker, |
f67539c2 | 103 | optional_yield y, bool exclusive = false); |
9f95a23c | 104 | |
b3b6e05e | 105 | int add_entry(const DoutPrefixProvider *dpp, const string& hash_key, const string& section, const string& key, bufferlist& bl); |
9f95a23c TL |
106 | |
107 | int get_shard_id(const string& hash_key, int *shard_id); | |
108 | ||
109 | RGWPeriodHistory *get_period_history() { | |
110 | return period_history.get(); | |
111 | } | |
112 | ||
b3b6e05e | 113 | int pull_period(const DoutPrefixProvider *dpp, const std::string& period_id, RGWPeriod& period, optional_yield y); |
9f95a23c TL |
114 | |
115 | /// find or create the metadata log for the given period | |
116 | RGWMetadataLog* get_log(const std::string& period); | |
117 | }; | |
118 |