]>
git.proxmox.com Git - ceph.git/blob - ceph/src/osd/PGBackend.h
b50f0d8c78cbdab2db7bbaa835b13fd13571b6cf
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) 2013,2014 Inktank Storage, Inc.
7 * Copyright (C) 2013,2014 Cloudwatt <libre.licensing@cloudwatt.com>
9 * Author: Loic Dachary <loic@dachary.org>
11 * This is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License version 2.1, as published by the Free Software
14 * Foundation. See file COPYING.
21 #include "osd_types.h"
22 #include "common/WorkQueue.h"
23 #include "include/Context.h"
24 #include "os/ObjectStore.h"
25 #include "common/LogClient.h"
27 #include "PGTransaction.h"
32 struct shard_info_wrapper
;
33 struct inconsistent_obj_wrapper
;
38 typedef ceph::shared_ptr
<const OSDMap
> OSDMapRef
;
43 * PGBackend defines an interface for logic handling IO and
44 * replication on RADOS objects. The PGBackend implementation
47 * 1) Handling client operations
48 * 2) Handling object recovery
49 * 3) Handling object access
50 * 4) Handling scrub, deep-scrub, repair
58 ObjectStore::CollectionHandle
&ch
;
61 * Provides interfaces for PGBackend callbacks
63 * The intention is that the parent calls into the PGBackend
64 * implementation holding a lock and that the callbacks are
65 * called under the same locks.
70 virtual DoutPrefixProvider
*get_dpp() = 0;
75 * Called with the transaction recovering oid
77 virtual void on_local_recover(
79 const ObjectRecoveryInfo
&recovery_info
,
81 ObjectStore::Transaction
*t
85 * Called when transaction recovering oid is durable and
86 * applied on all replicas
88 virtual void on_global_recover(
90 const object_stat_sum_t
&stat_diff
94 * Called when peer is recovered
96 virtual void on_peer_recover(
99 const ObjectRecoveryInfo
&recovery_info
102 virtual void begin_peer_recover(
104 const hobject_t oid
) = 0;
106 virtual void failed_push(const list
<pg_shard_t
> &from
, const hobject_t
&soid
) = 0;
108 virtual void cancel_pull(const hobject_t
&soid
) = 0;
110 virtual void apply_stats(
111 const hobject_t
&soid
,
112 const object_stat_sum_t
&delta_stats
) = 0;
118 * Wraps a context in whatever outer layers the parent usually
119 * uses to call into the PGBackend
121 virtual Context
*bless_context(Context
*c
) = 0;
122 virtual GenContext
<ThreadPool::TPHandle
&> *bless_gencontext(
123 GenContext
<ThreadPool::TPHandle
&> *c
) = 0;
125 virtual void send_message(int to_osd
, Message
*m
) = 0;
126 virtual void queue_transaction(
127 ObjectStore::Transaction
&& t
,
128 OpRequestRef op
= OpRequestRef()
130 virtual void queue_transactions(
131 vector
<ObjectStore::Transaction
>& tls
,
132 OpRequestRef op
= OpRequestRef()
134 virtual epoch_t
get_epoch() const = 0;
135 virtual epoch_t
get_interval_start_epoch() const = 0;
136 virtual epoch_t
get_last_peering_reset_epoch() const = 0;
138 virtual const set
<pg_shard_t
> &get_actingbackfill_shards() const = 0;
139 virtual const set
<pg_shard_t
> &get_acting_shards() const = 0;
140 virtual const set
<pg_shard_t
> &get_backfill_shards() const = 0;
142 virtual std::string
gen_dbg_prefix() const = 0;
144 virtual const map
<hobject_t
, set
<pg_shard_t
>> &get_missing_loc_shards()
147 virtual const pg_missing_tracker_t
&get_local_missing() const = 0;
148 virtual const map
<pg_shard_t
, pg_missing_t
> &get_shard_missing()
150 virtual boost::optional
<const pg_missing_const_i
&> maybe_get_shard_missing(
151 pg_shard_t peer
) const {
152 if (peer
== primary_shard()) {
153 return get_local_missing();
155 map
<pg_shard_t
, pg_missing_t
>::const_iterator i
=
156 get_shard_missing().find(peer
);
157 if (i
== get_shard_missing().end()) {
158 return boost::optional
<const pg_missing_const_i
&>();
164 virtual const pg_missing_const_i
&get_shard_missing(pg_shard_t peer
) const {
165 auto m
= maybe_get_shard_missing(peer
);
170 virtual const map
<pg_shard_t
, pg_info_t
> &get_shard_info() const = 0;
171 virtual const pg_info_t
&get_shard_info(pg_shard_t peer
) const {
172 if (peer
== primary_shard()) {
175 map
<pg_shard_t
, pg_info_t
>::const_iterator i
=
176 get_shard_info().find(peer
);
177 assert(i
!= get_shard_info().end());
182 virtual const PGLog
&get_log() const = 0;
183 virtual bool pgb_is_primary() const = 0;
184 virtual OSDMapRef
pgb_get_osdmap() const = 0;
185 virtual const pg_info_t
&get_info() const = 0;
186 virtual const pg_pool_t
&get_pool() const = 0;
188 virtual ObjectContextRef
get_obc(
189 const hobject_t
&hoid
,
190 const map
<string
, bufferlist
> &attrs
) = 0;
192 virtual bool try_lock_for_read(
193 const hobject_t
&hoid
,
194 ObcLockManager
&manager
) = 0;
196 virtual void release_locks(ObcLockManager
&manager
) = 0;
198 virtual void op_applied(
199 const eversion_t
&applied_version
) = 0;
201 virtual bool should_send_op(
203 const hobject_t
&hoid
) = 0;
205 virtual void log_operation(
206 const vector
<pg_log_entry_t
> &logv
,
207 const boost::optional
<pg_hit_set_history_t
> &hset_history
,
208 const eversion_t
&trim_to
,
209 const eversion_t
&roll_forward_to
,
210 bool transaction_applied
,
211 ObjectStore::Transaction
&t
) = 0;
213 virtual void pgb_set_object_snap_mapping(
214 const hobject_t
&soid
,
215 const set
<snapid_t
> &snaps
,
216 ObjectStore::Transaction
*t
) = 0;
218 virtual void pgb_clear_object_snap_mapping(
219 const hobject_t
&soid
,
220 ObjectStore::Transaction
*t
) = 0;
222 virtual void update_peer_last_complete_ondisk(
224 eversion_t lcod
) = 0;
226 virtual void update_last_complete_ondisk(
227 eversion_t lcod
) = 0;
229 virtual void update_stats(
230 const pg_stat_t
&stat
) = 0;
232 virtual void schedule_recovery_work(
233 GenContext
<ThreadPool::TPHandle
&> *c
) = 0;
235 virtual pg_shard_t
whoami_shard() const = 0;
237 return whoami_shard().osd
;
239 spg_t
whoami_spg_t() const {
240 return get_info().pgid
;
243 virtual spg_t
primary_spg_t() const = 0;
244 virtual pg_shard_t
primary_shard() const = 0;
246 virtual uint64_t min_peer_features() const = 0;
248 virtual hobject_t
get_temp_recovery_object(const hobject_t
& target
,
249 eversion_t version
) = 0;
251 virtual void send_message_osd_cluster(
252 int peer
, Message
*m
, epoch_t from_epoch
) = 0;
253 virtual void send_message_osd_cluster(
254 Message
*m
, Connection
*con
) = 0;
255 virtual void send_message_osd_cluster(
256 Message
*m
, const ConnectionRef
& con
) = 0;
257 virtual ConnectionRef
get_con_osd_cluster(int peer
, epoch_t from_epoch
) = 0;
258 virtual entity_name_t
get_cluster_msgr_name() = 0;
260 virtual PerfCounters
*get_logger() = 0;
262 virtual ceph_tid_t
get_tid() = 0;
264 virtual LogClientTemp
clog_error() = 0;
266 virtual bool check_failsafe_full(ostream
&ss
) = 0;
268 virtual bool check_osdmap_full(const set
<pg_shard_t
> &missing_on
) = 0;
270 virtual ~Listener() {}
273 Listener
*get_parent() const { return parent
; }
274 PGBackend(CephContext
* cct
, Listener
*l
, ObjectStore
*store
, coll_t coll
,
275 ObjectStore::CollectionHandle
&ch
) :
281 bool is_primary() const { return get_parent()->pgb_is_primary(); }
282 OSDMapRef
get_osdmap() const { return get_parent()->pgb_get_osdmap(); }
283 const pg_info_t
&get_info() { return get_parent()->get_info(); }
285 std::string
gen_prefix() const {
286 return parent
->gen_dbg_prefix();
292 * We may want to recover multiple objects in the same set of
293 * messages. RecoveryHandle is an interface for the opaque
294 * object used by the implementation to store the details of
295 * the pending recovery operations.
297 struct RecoveryHandle
{
298 bool cache_dont_need
;
300 RecoveryHandle(): cache_dont_need(false) {}
301 virtual ~RecoveryHandle() {}
304 /// Get a fresh recovery operation
305 virtual RecoveryHandle
*open_recovery_op() = 0;
307 /// run_recovery_op: finish the operation represented by h
308 virtual void run_recovery_op(
309 RecoveryHandle
*h
, ///< [in] op to finish
310 int priority
///< [in] msg priority
316 * Triggers a recovery operation on the specified hobject_t
317 * onreadable must be called before onwriteable
319 * On each replica (primary included), get_parent()->on_not_missing()
320 * must be called when the transaction finalizing the recovery
321 * is queued. Similarly, get_parent()->on_readable() must be called
322 * when the transaction is applied in the backing store.
324 * get_parent()->on_not_degraded() should be called on the primary
325 * when writes can resume on the object.
327 * obc may be NULL if the primary lacks the object.
329 * head may be NULL only if the head/snapdir is missing
331 * @param missing [in] set of info, missing pairs for queried nodes
332 * @param overlaps [in] mapping of object to file offset overlaps
334 virtual void recover_object(
335 const hobject_t
&hoid
, ///< [in] object to recover
336 eversion_t v
, ///< [in] version to recover
337 ObjectContextRef head
, ///< [in] context of the head/snapdir object
338 ObjectContextRef obc
, ///< [in] context of the object
339 RecoveryHandle
*h
///< [in,out] handle to attach recovery op to
343 * true if PGBackend can handle this message while inactive
345 * If it returns true, handle_message *must* also return true
347 virtual bool can_handle_while_inactive(OpRequestRef op
) = 0;
349 /// gives PGBackend a crack at an incoming message
350 virtual bool handle_message(
351 OpRequestRef op
///< [in] message received
352 ) = 0; ///< @return true if the message was handled
354 virtual void check_recovery_sources(const OSDMapRef
& osdmap
) = 0;
358 * clean up any temporary on-disk state due to a pg interval change
360 void on_change_cleanup(ObjectStore::Transaction
*t
);
362 * implementation should clear itself, contexts blessed prior to on_change
363 * won't be called after on_change()
365 virtual void on_change() = 0;
366 virtual void clear_recovery_state() = 0;
368 virtual void on_flushed() = 0;
370 virtual IsPGRecoverablePredicate
*get_is_recoverable_predicate() = 0;
371 virtual IsPGReadablePredicate
*get_is_readable_predicate() = 0;
373 virtual void dump_recovery_info(Formatter
*f
) const = 0;
376 set
<hobject_t
> temp_contents
;
378 // Track contents of temp collection, clear on reset
379 void add_temp_obj(const hobject_t
&oid
) {
380 temp_contents
.insert(oid
);
382 void add_temp_objs(const set
<hobject_t
> &oids
) {
383 temp_contents
.insert(oids
.begin(), oids
.end());
385 void clear_temp_obj(const hobject_t
&oid
) {
386 temp_contents
.erase(oid
);
388 void clear_temp_objs(const set
<hobject_t
> &oids
) {
389 for (set
<hobject_t
>::const_iterator i
= oids
.begin();
392 temp_contents
.erase(*i
);
396 virtual ~PGBackend() {}
398 /// execute implementation specific transaction
399 virtual void submit_transaction(
400 const hobject_t
&hoid
, ///< [in] object
401 const object_stat_sum_t
&delta_stats
,///< [in] stat change
402 const eversion_t
&at_version
, ///< [in] version
403 PGTransactionUPtr
&&t
, ///< [in] trans to execute (move)
404 const eversion_t
&trim_to
, ///< [in] trim log to here
405 const eversion_t
&roll_forward_to
, ///< [in] trim rollback info to here
406 const vector
<pg_log_entry_t
> &log_entries
, ///< [in] log entries for t
407 /// [in] hitset history (if updated with this transaction)
408 boost::optional
<pg_hit_set_history_t
> &hset_history
,
409 Context
*on_local_applied_sync
, ///< [in] called when applied locally
410 Context
*on_all_applied
, ///< [in] called when all acked
411 Context
*on_all_commit
, ///< [in] called when all commit
412 ceph_tid_t tid
, ///< [in] tid
413 osd_reqid_t reqid
, ///< [in] reqid
414 OpRequestRef op
///< [in] op
417 /// submit callback to be called in order with pending writes
418 virtual void call_write_ordered(std::function
<void(void)> &&cb
) = 0;
421 const hobject_t
&hoid
,
423 ObjectStore::Transaction
*t
);
426 const pg_log_entry_t
&entry
,
427 ObjectStore::Transaction
*t
);
429 friend class LRBTrimmer
;
431 const pg_log_entry_t
&entry
,
432 ObjectStore::Transaction
*t
);
435 const pg_log_entry_t
&entry
,
436 ObjectStore::Transaction
*t
);
439 const hobject_t
&hoid
,
440 ObjectStore::Transaction
*t
);
443 /// Reapply old attributes
444 void rollback_setattrs(
445 const hobject_t
&hoid
,
446 map
<string
, boost::optional
<bufferlist
> > &old_attrs
,
447 ObjectStore::Transaction
*t
);
449 /// Truncate object to rollback append
450 virtual void rollback_append(
451 const hobject_t
&hoid
,
453 ObjectStore::Transaction
*t
);
455 /// Unstash object to rollback stash
457 const hobject_t
&hoid
,
458 version_t old_version
,
459 ObjectStore::Transaction
*t
);
461 /// Unstash object to rollback stash
462 void rollback_try_stash(
463 const hobject_t
&hoid
,
464 version_t old_version
,
465 ObjectStore::Transaction
*t
);
467 /// Delete object to rollback create
468 void rollback_create(
469 const hobject_t
&hoid
,
470 ObjectStore::Transaction
*t
) {
474 /// Clone the extents back into place
475 void rollback_extents(
477 const vector
<pair
<uint64_t, uint64_t> > &extents
,
478 const hobject_t
&hoid
,
479 ObjectStore::Transaction
*t
);
482 /// Trim object stashed at version
483 void trim_rollback_object(
484 const hobject_t
&hoid
,
486 ObjectStore::Transaction
*t
);
488 /// List objects in collection
489 int objects_list_partial(
490 const hobject_t
&begin
,
493 vector
<hobject_t
> *ls
,
496 int objects_list_range(
497 const hobject_t
&start
,
498 const hobject_t
&end
,
500 vector
<hobject_t
> *ls
,
501 vector
<ghobject_t
> *gen_obs
=0);
503 int objects_get_attr(
504 const hobject_t
&hoid
,
508 virtual int objects_get_attrs(
509 const hobject_t
&hoid
,
510 map
<string
, bufferlist
> *out
);
512 virtual int objects_read_sync(
513 const hobject_t
&hoid
,
519 virtual void objects_read_async(
520 const hobject_t
&hoid
,
521 const list
<pair
<boost::tuple
<uint64_t, uint64_t, uint32_t>,
522 pair
<bufferlist
*, Context
*> > > &to_read
,
523 Context
*on_complete
, bool fast_read
= false) = 0;
525 virtual bool scrub_supported() = 0;
526 virtual bool auto_repair_supported() const = 0;
528 ScrubMap
&map
, const vector
<hobject_t
> &ls
, bool deep
, uint32_t seed
,
529 ThreadPool::TPHandle
&handle
);
530 bool be_compare_scrub_objects(
531 pg_shard_t auth_shard
,
532 const ScrubMap::object
&auth
,
533 const object_info_t
& auth_oi
,
534 const ScrubMap::object
&candidate
,
535 shard_info_wrapper
& shard_error
,
536 inconsistent_obj_wrapper
&result
,
537 ostream
&errorstream
);
538 map
<pg_shard_t
, ScrubMap
*>::const_iterator
be_select_auth_object(
539 const hobject_t
&obj
,
540 const map
<pg_shard_t
,ScrubMap
*> &maps
,
541 object_info_t
*auth_oi
,
542 map
<pg_shard_t
, shard_info_wrapper
> &shard_map
,
543 inconsistent_obj_wrapper
&object_error
);
544 void be_compare_scrubmaps(
545 const map
<pg_shard_t
,ScrubMap
*> &maps
,
547 map
<hobject_t
, set
<pg_shard_t
>> &missing
,
548 map
<hobject_t
, set
<pg_shard_t
>> &inconsistent
,
549 map
<hobject_t
, list
<pg_shard_t
>> &authoritative
,
550 map
<hobject_t
, pair
<uint32_t,uint32_t>> &missing_digest
,
551 int &shallow_errors
, int &deep_errors
,
554 const vector
<int> &acting
,
555 ostream
&errorstream
);
556 virtual uint64_t be_get_ondisk_size(
557 uint64_t logical_size
) = 0;
558 virtual void be_deep_scrub(
559 const hobject_t
&poid
,
562 ThreadPool::TPHandle
&handle
) = 0;
564 static PGBackend
*build_pg_backend(
565 const pg_pool_t
&pool
,
566 const OSDMapRef curmap
,
569 ObjectStore::CollectionHandle
&ch
,