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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
|
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
* Ceph - scalable distributed file system
*
* Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software
* Foundation. See file COPYING.
*
*/
#include "MDSTable.h"
#include "MDSRank.h"
#include "MDLog.h"
#include "osdc/Filer.h"
#include "include/types.h"
#include "common/config.h"
#include "common/errno.h"
#include "common/Finisher.h"
#include "include/ceph_assert.h"
#define dout_context g_ceph_context
#define dout_subsys ceph_subsys_mds
#undef dout_prefix
#define dout_prefix *_dout << "mds." << rank << "." << table_name << ": "
class MDSTableIOContext : public MDSIOContextBase
{
protected:
MDSTable *ida;
MDSRank *get_mds() override {return ida->mds;}
public:
explicit MDSTableIOContext(MDSTable *ida_) : ida(ida_) {
ceph_assert(ida != NULL);
}
};
class C_IO_MT_Save : public MDSTableIOContext {
version_t version;
public:
C_IO_MT_Save(MDSTable *i, version_t v) : MDSTableIOContext(i), version(v) {}
void finish(int r) override {
ida->save_2(r, version);
}
void print(ostream& out) const override {
out << "table_save(" << ida->table_name << ")";
}
};
void MDSTable::save(MDSContext *onfinish, version_t v)
{
if (v > 0 && v <= committing_version) {
dout(10) << "save v " << version << " - already saving "
<< committing_version << " >= needed " << v << dendl;
if (onfinish)
waitfor_save[v].push_back(onfinish);
return;
}
dout(10) << "save v " << version << dendl;
ceph_assert(is_active());
bufferlist bl;
encode(version, bl);
encode_state(bl);
committing_version = version;
if (onfinish)
waitfor_save[version].push_back(onfinish);
// write (async)
SnapContext snapc;
object_t oid = get_object_name();
object_locator_t oloc(mds->mdsmap->get_metadata_pool());
mds->objecter->write_full(oid, oloc,
snapc,
bl, ceph::real_clock::now(), 0,
new C_OnFinisher(new C_IO_MT_Save(this, version),
mds->finisher));
}
void MDSTable::save_2(int r, version_t v)
{
if (r < 0) {
dout(1) << "save error " << r << " v " << v << dendl;
mds->clog->error() << "failed to store table " << table_name << " object,"
<< " errno " << r;
mds->handle_write_error(r);
return;
}
dout(10) << "save_2 v " << v << dendl;
committed_version = v;
MDSContext::vec ls;
while (!waitfor_save.empty()) {
auto it = waitfor_save.begin();
if (it->first > v) break;
auto& v = it->second;
ls.insert(ls.end(), v.begin(), v.end());
waitfor_save.erase(it);
}
finish_contexts(g_ceph_context, ls, 0);
}
void MDSTable::reset()
{
reset_state();
projected_version = version;
state = STATE_ACTIVE;
}
// -----------------------
class C_IO_MT_Load : public MDSTableIOContext {
public:
Context *onfinish;
bufferlist bl;
C_IO_MT_Load(MDSTable *i, Context *o) : MDSTableIOContext(i), onfinish(o) {}
void finish(int r) override {
ida->load_2(r, bl, onfinish);
}
void print(ostream& out) const override {
out << "table_load(" << ida->table_name << ")";
}
};
object_t MDSTable::get_object_name() const
{
char n[50];
if (per_mds)
snprintf(n, sizeof(n), "mds%d_%s", int(rank), table_name.c_str());
else
snprintf(n, sizeof(n), "mds_%s", table_name.c_str());
return object_t(n);
}
void MDSTable::load(MDSContext *onfinish)
{
dout(10) << "load" << dendl;
ceph_assert(is_undef());
state = STATE_OPENING;
C_IO_MT_Load *c = new C_IO_MT_Load(this, onfinish);
object_t oid = get_object_name();
object_locator_t oloc(mds->mdsmap->get_metadata_pool());
mds->objecter->read_full(oid, oloc, CEPH_NOSNAP, &c->bl, 0,
new C_OnFinisher(c, mds->finisher));
}
void MDSTable::load_2(int r, bufferlist& bl, Context *onfinish)
{
ceph_assert(is_opening());
state = STATE_ACTIVE;
if (r == -EBLACKLISTED) {
mds->respawn();
return;
}
if (r < 0) {
derr << "load_2 could not read table: " << r << dendl;
mds->clog->error() << "error reading table object '" << get_object_name()
<< "' " << r << " (" << cpp_strerror(r) << ")";
mds->damaged();
ceph_assert(r >= 0); // Should be unreachable because damaged() calls respawn()
}
dout(10) << "load_2 got " << bl.length() << " bytes" << dendl;
auto p = bl.cbegin();
try {
decode(version, p);
projected_version = committed_version = version;
dout(10) << "load_2 loaded v" << version << dendl;
decode_state(p);
} catch (buffer::error &e) {
mds->clog->error() << "error decoding table object '" << get_object_name()
<< "': " << e.what();
mds->damaged();
ceph_assert(r >= 0); // Should be unreachable because damaged() calls respawn()
}
if (onfinish) {
onfinish->complete(0);
}
}
|