]>
git.proxmox.com Git - ceph.git/blob - ceph/src/mds/MDSTable.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
20 #include "osdc/Filer.h"
22 #include "include/types.h"
24 #include "common/config.h"
25 #include "common/errno.h"
26 #include "common/Finisher.h"
28 #include "include/ceph_assert.h"
31 #define dout_context g_ceph_context
32 #define dout_subsys ceph_subsys_mds
34 #define dout_prefix *_dout << "mds." << rank << "." << table_name << ": "
37 class MDSTableIOContext
: public MDSIOContextBase
41 MDSRank
*get_mds() override
{return ida
->mds
;}
43 explicit MDSTableIOContext(MDSTable
*ida_
) : ida(ida_
) {
44 ceph_assert(ida
!= NULL
);
49 class C_IO_MT_Save
: public MDSTableIOContext
{
52 C_IO_MT_Save(MDSTable
*i
, version_t v
) : MDSTableIOContext(i
), version(v
) {}
53 void finish(int r
) override
{
54 ida
->save_2(r
, version
);
56 void print(ostream
& out
) const override
{
57 out
<< "table_save(" << ida
->table_name
<< ")";
61 void MDSTable::save(MDSContext
*onfinish
, version_t v
)
63 if (v
> 0 && v
<= committing_version
) {
64 dout(10) << "save v " << version
<< " - already saving "
65 << committing_version
<< " >= needed " << v
<< dendl
;
67 waitfor_save
[v
].push_back(onfinish
);
71 dout(10) << "save v " << version
<< dendl
;
72 ceph_assert(is_active());
78 committing_version
= version
;
81 waitfor_save
[version
].push_back(onfinish
);
85 object_t oid
= get_object_name();
86 object_locator_t
oloc(mds
->mdsmap
->get_metadata_pool());
87 mds
->objecter
->write_full(oid
, oloc
,
89 bl
, ceph::real_clock::now(), 0,
90 new C_OnFinisher(new C_IO_MT_Save(this, version
),
94 void MDSTable::save_2(int r
, version_t v
)
97 dout(1) << "save error " << r
<< " v " << v
<< dendl
;
98 mds
->clog
->error() << "failed to store table " << table_name
<< " object,"
100 mds
->handle_write_error(r
);
104 dout(10) << "save_2 v " << v
<< dendl
;
105 committed_version
= v
;
108 while (!waitfor_save
.empty()) {
109 auto it
= waitfor_save
.begin();
110 if (it
->first
> v
) break;
111 auto& v
= it
->second
;
112 ls
.insert(ls
.end(), v
.begin(), v
.end());
113 waitfor_save
.erase(it
);
115 finish_contexts(g_ceph_context
, ls
, 0);
119 void MDSTable::reset()
122 projected_version
= version
;
123 state
= STATE_ACTIVE
;
128 // -----------------------
130 class C_IO_MT_Load
: public MDSTableIOContext
{
134 C_IO_MT_Load(MDSTable
*i
, Context
*o
) : MDSTableIOContext(i
), onfinish(o
) {}
135 void finish(int r
) override
{
136 ida
->load_2(r
, bl
, onfinish
);
138 void print(ostream
& out
) const override
{
139 out
<< "table_load(" << ida
->table_name
<< ")";
143 object_t
MDSTable::get_object_name() const
147 snprintf(n
, sizeof(n
), "mds%d_%s", int(rank
), table_name
.c_str());
149 snprintf(n
, sizeof(n
), "mds_%s", table_name
.c_str());
153 void MDSTable::load(MDSContext
*onfinish
)
155 dout(10) << "load" << dendl
;
157 ceph_assert(is_undef());
158 state
= STATE_OPENING
;
160 C_IO_MT_Load
*c
= new C_IO_MT_Load(this, onfinish
);
161 object_t oid
= get_object_name();
162 object_locator_t
oloc(mds
->mdsmap
->get_metadata_pool());
163 mds
->objecter
->read_full(oid
, oloc
, CEPH_NOSNAP
, &c
->bl
, 0,
164 new C_OnFinisher(c
, mds
->finisher
));
167 void MDSTable::load_2(int r
, bufferlist
& bl
, Context
*onfinish
)
169 ceph_assert(is_opening());
170 state
= STATE_ACTIVE
;
171 if (r
== -EBLACKLISTED
) {
176 derr
<< "load_2 could not read table: " << r
<< dendl
;
177 mds
->clog
->error() << "error reading table object '" << get_object_name()
178 << "' " << r
<< " (" << cpp_strerror(r
) << ")";
180 ceph_assert(r
>= 0); // Should be unreachable because damaged() calls respawn()
183 dout(10) << "load_2 got " << bl
.length() << " bytes" << dendl
;
184 auto p
= bl
.cbegin();
188 projected_version
= committed_version
= version
;
189 dout(10) << "load_2 loaded v" << version
<< dendl
;
191 } catch (buffer::error
&e
) {
192 mds
->clog
->error() << "error decoding table object '" << get_object_name()
193 << "': " << e
.what();
195 ceph_assert(r
>= 0); // Should be unreachable because damaged() calls respawn()
199 onfinish
->complete(0);