-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
ReplicatedPG.h
1610 lines (1422 loc) · 49 KB
/
ReplicatedPG.h
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
/*
* Ceph - scalable distributed file system
*
* Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
* Copyright (C) 2013 Cloudwatt <libre.licensing@cloudwatt.com>
*
* Author: Loic Dachary <loic@dachary.org>
*
* 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.
*
*/
#ifndef CEPH_REPLICATEDPG_H
#define CEPH_REPLICATEDPG_H
#include <boost/tuple/tuple.hpp>
#include "include/assert.h"
#include "PG.h"
#include "Watch.h"
#include "TierAgentState.h"
#include "messages/MOSDOpReply.h"
#include "common/sharedptr_registry.hpp"
#include "ReplicatedBackend.h"
class MOSDSubOpReply;
class CopyFromCallback;
class PromoteCallback;
class ReplicatedPG;
class PGLSFilter;
class HitSet;
struct TierAgentState;
class MOSDOp;
class MOSDOpReply;
class MOSDSubOp;
class OSDService;
void intrusive_ptr_add_ref(ReplicatedPG *pg);
void intrusive_ptr_release(ReplicatedPG *pg);
uint64_t get_with_id(ReplicatedPG *pg);
void put_with_id(ReplicatedPG *pg, uint64_t id);
#ifdef PG_DEBUG_REFS
typedef TrackedIntPtr<ReplicatedPG> ReplicatedPGRef;
#else
typedef boost::intrusive_ptr<ReplicatedPG> ReplicatedPGRef;
#endif
struct inconsistent_snapset_wrapper;
class ReplicatedPG : public PG, public PGBackend::Listener {
friend class OSD;
friend class Watch;
public:
/*
* state associated with a copy operation
*/
struct OpContext;
class CopyCallback;
/**
* CopyResults stores the object metadata of interest to a copy initiator.
*/
struct CopyResults {
ceph::real_time mtime; ///< the copy source's mtime
uint64_t object_size; ///< the copied object's size
bool started_temp_obj; ///< true if the callback needs to delete temp object
hobject_t temp_oid; ///< temp object (if any)
/**
* Final transaction; if non-empty the callback must execute it before any
* other accesses to the object (in order to complete the copy).
*/
PGBackend::PGTransaction *final_tx;
version_t user_version; ///< The copy source's user version
bool should_requeue; ///< op should be requeued on cancel
vector<snapid_t> snaps; ///< src's snaps (if clone)
snapid_t snap_seq; ///< src's snap_seq (if head)
librados::snap_set_t snapset; ///< src snapset (if head)
bool mirror_snapset;
map<string, bufferlist> attrs; ///< src user attrs
bool has_omap;
uint32_t flags; // object_copy_data_t::FLAG_*
uint32_t source_data_digest, source_omap_digest;
uint32_t data_digest, omap_digest;
vector<pair<osd_reqid_t, version_t> > reqids; // [(reqid, user_version)]
uint64_t truncate_seq;
uint64_t truncate_size;
bool is_data_digest() {
return flags & object_copy_data_t::FLAG_DATA_DIGEST;
}
bool is_omap_digest() {
return flags & object_copy_data_t::FLAG_OMAP_DIGEST;
}
CopyResults()
: object_size(0), started_temp_obj(false),
final_tx(NULL), user_version(0),
should_requeue(false), mirror_snapset(false),
has_omap(false),
flags(0),
source_data_digest(-1), source_omap_digest(-1),
data_digest(-1), omap_digest(-1),
truncate_seq(0), truncate_size(0)
{}
};
struct CopyOp {
CopyCallback *cb;
ObjectContextRef obc;
hobject_t src;
object_locator_t oloc;
unsigned flags;
bool mirror_snapset;
CopyResults results;
ceph_tid_t objecter_tid;
ceph_tid_t objecter_tid2;
object_copy_cursor_t cursor;
map<string,bufferlist> attrs;
bufferlist data;
bufferlist omap_header;
bufferlist omap_data;
int rval;
object_copy_cursor_t temp_cursor;
/*
* For CopyOp the process is:
* step1: read the data(attr/omap/data) from the source object
* step2: handle those data(w/ those data create a new object)
* src_obj_fadvise_flags used in step1;
* dest_obj_fadvise_flags used in step2
*/
unsigned src_obj_fadvise_flags;
unsigned dest_obj_fadvise_flags;
CopyOp(CopyCallback *cb_, ObjectContextRef _obc, hobject_t s,
object_locator_t l,
version_t v,
unsigned f,
bool ms,
unsigned src_obj_fadvise_flags,
unsigned dest_obj_fadvise_flags)
: cb(cb_), obc(_obc), src(s), oloc(l), flags(f),
mirror_snapset(ms),
objecter_tid(0),
objecter_tid2(0),
rval(-1),
src_obj_fadvise_flags(src_obj_fadvise_flags),
dest_obj_fadvise_flags(dest_obj_fadvise_flags)
{
results.user_version = v;
results.mirror_snapset = mirror_snapset;
}
};
typedef ceph::shared_ptr<CopyOp> CopyOpRef;
/**
* The CopyCallback class defines an interface for completions to the
* copy_start code. Users of the copy infrastructure must implement
* one and give an instance of the class to start_copy.
*
* The implementer is responsible for making sure that the CopyCallback
* can associate itself with the correct copy operation.
*/
typedef boost::tuple<int, CopyResults*> CopyCallbackResults;
friend class CopyFromCallback;
friend class PromoteCallback;
struct ProxyReadOp {
OpRequestRef op;
hobject_t soid;
ceph_tid_t objecter_tid;
vector<OSDOp> &ops;
version_t user_version;
int data_offset;
bool canceled; ///< true if canceled
ProxyReadOp(OpRequestRef _op, hobject_t oid, vector<OSDOp>& _ops)
: op(_op), soid(oid),
objecter_tid(0), ops(_ops),
user_version(0), data_offset(0),
canceled(false) { }
};
typedef ceph::shared_ptr<ProxyReadOp> ProxyReadOpRef;
struct ProxyWriteOp {
OpContext *ctx;
OpRequestRef op;
hobject_t soid;
ceph_tid_t objecter_tid;
vector<OSDOp> &ops;
version_t user_version;
bool sent_disk;
bool sent_ack;
utime_t mtime;
bool canceled;
osd_reqid_t reqid;
ProxyWriteOp(OpRequestRef _op, hobject_t oid, vector<OSDOp>& _ops, osd_reqid_t _reqid)
: ctx(NULL), op(_op), soid(oid),
objecter_tid(0), ops(_ops),
user_version(0), sent_disk(false),
sent_ack(false), canceled(false),
reqid(_reqid) { }
};
typedef ceph::shared_ptr<ProxyWriteOp> ProxyWriteOpRef;
struct FlushOp {
ObjectContextRef obc; ///< obc we are flushing
OpRequestRef op; ///< initiating op
list<OpRequestRef> dup_ops; ///< bandwagon jumpers
version_t flushed_version; ///< user version we are flushing
ceph_tid_t objecter_tid; ///< copy-from request tid
int rval; ///< copy-from result
bool blocking; ///< whether we are blocking updates
bool removal; ///< we are removing the backend object
boost::optional<std::function<void()>> on_flush; ///< callback, may be null
FlushOp()
: flushed_version(0), objecter_tid(0), rval(0),
blocking(false), removal(false) {}
~FlushOp() { assert(!on_flush); }
};
typedef ceph::shared_ptr<FlushOp> FlushOpRef;
boost::scoped_ptr<PGBackend> pgbackend;
PGBackend *get_pgbackend() override {
return pgbackend.get();
}
/// Listener methods
void on_local_recover(
const hobject_t &oid,
const ObjectRecoveryInfo &recovery_info,
ObjectContextRef obc,
ObjectStore::Transaction *t
) override;
void on_peer_recover(
pg_shard_t peer,
const hobject_t &oid,
const ObjectRecoveryInfo &recovery_info,
const object_stat_sum_t &stat
) override;
void begin_peer_recover(
pg_shard_t peer,
const hobject_t oid);
void on_global_recover(
const hobject_t &oid,
const object_stat_sum_t &stat_diff);
void failed_push(pg_shard_t from, const hobject_t &soid);
void cancel_pull(const hobject_t &soid);
template<class T> class BlessedGenContext;
class BlessedContext;
Context *bless_context(Context *c);
GenContext<ThreadPool::TPHandle&> *bless_gencontext(
GenContext<ThreadPool::TPHandle&> *c);
void send_message(int to_osd, Message *m) {
osd->send_message_osd_cluster(to_osd, m, get_osdmap()->get_epoch());
}
void queue_transaction(ObjectStore::Transaction&& t, OpRequestRef op) {
osd->store->queue_transaction(osr.get(), std::move(t), 0, 0, 0, op);
}
void queue_transactions(vector<ObjectStore::Transaction>& tls, OpRequestRef op) {
osd->store->queue_transactions(osr.get(), tls, 0, 0, 0, op, NULL);
}
epoch_t get_epoch() const {
return get_osdmap()->get_epoch();
}
const set<pg_shard_t> &get_actingbackfill_shards() const {
return actingbackfill;
}
const set<pg_shard_t> &get_acting_shards() const {
return actingset;
}
const set<pg_shard_t> &get_backfill_shards() const {
return backfill_targets;
}
std::string gen_dbg_prefix() const { return gen_prefix(); }
const map<hobject_t, set<pg_shard_t>, hobject_t::BitwiseComparator> &get_missing_loc_shards() const {
return missing_loc.get_missing_locs();
}
const map<pg_shard_t, pg_missing_t> &get_shard_missing() const {
return peer_missing;
}
using PGBackend::Listener::get_shard_missing;
const map<pg_shard_t, pg_info_t> &get_shard_info() const {
return peer_info;
}
using PGBackend::Listener::get_shard_info;
const pg_missing_tracker_t &get_local_missing() const {
return pg_log.get_missing();
}
const PGLog &get_log() const {
return pg_log;
}
bool pgb_is_primary() const {
return is_primary();
}
OSDMapRef pgb_get_osdmap() const {
return get_osdmap();
}
const pg_info_t &get_info() const {
return info;
}
const pg_pool_t &get_pool() const {
return pool.info;
}
ObjectContextRef get_obc(
const hobject_t &hoid,
map<string, bufferlist> &attrs) {
return get_object_context(hoid, true, &attrs);
}
void log_operation(
const vector<pg_log_entry_t> &logv,
boost::optional<pg_hit_set_history_t> &hset_history,
const eversion_t &trim_to,
const eversion_t &trim_rollback_to,
bool transaction_applied,
ObjectStore::Transaction &t) {
if (hset_history) {
info.hit_set = *hset_history;
dirty_info = true;
}
append_log(logv, trim_to, trim_rollback_to, t, transaction_applied);
}
struct C_OSD_OnApplied : Context {
ReplicatedPGRef pg;
epoch_t epoch;
eversion_t v;
C_OSD_OnApplied(
ReplicatedPGRef pg,
epoch_t epoch,
eversion_t v)
: pg(pg), epoch(epoch), v(v) {}
void finish(int) override {
pg->lock();
if (!pg->pg_has_reset_since(epoch))
pg->op_applied(v);
pg->unlock();
}
};
void op_applied(
const eversion_t &applied_version);
bool should_send_op(
pg_shard_t peer,
const hobject_t &hoid) {
if (peer == get_primary())
return true;
assert(peer_info.count(peer));
bool should_send =
hoid.pool != (int64_t)info.pgid.pool() ||
cmp(hoid, last_backfill_started, get_sort_bitwise()) <= 0 ||
cmp(hoid, peer_info[peer].last_backfill, get_sort_bitwise()) <= 0;
if (!should_send)
assert(is_backfill_targets(peer));
return should_send;
}
void update_peer_last_complete_ondisk(
pg_shard_t fromosd,
eversion_t lcod) {
peer_last_complete_ondisk[fromosd] = lcod;
}
void update_last_complete_ondisk(
eversion_t lcod) {
last_complete_ondisk = lcod;
}
void update_stats(
const pg_stat_t &stat) {
info.stats = stat;
}
void schedule_recovery_work(
GenContext<ThreadPool::TPHandle&> *c);
pg_shard_t whoami_shard() const {
return pg_whoami;
}
spg_t primary_spg_t() const {
return spg_t(info.pgid.pgid, primary.shard);
}
pg_shard_t primary_shard() const {
return primary;
}
uint64_t min_peer_features() const {
return get_min_peer_features();
}
bool sort_bitwise() const {
return get_sort_bitwise();
}
void send_message_osd_cluster(
int peer, Message *m, epoch_t from_epoch);
void send_message_osd_cluster(
Message *m, Connection *con);
void send_message_osd_cluster(
Message *m, const ConnectionRef& con);
ConnectionRef get_con_osd_cluster(int peer, epoch_t from_epoch);
entity_name_t get_cluster_msgr_name() {
return osd->get_cluster_msgr_name();
}
PerfCounters *get_logger();
ceph_tid_t get_tid() { return osd->get_tid(); }
LogClientTemp clog_error() { return osd->clog->error(); }
struct watch_disconnect_t {
uint64_t cookie;
entity_name_t name;
bool send_disconnect;
watch_disconnect_t(uint64_t c, entity_name_t n, bool sd)
: cookie(c), name(n), send_disconnect(sd) {}
};
void complete_disconnect_watches(
ObjectContextRef obc,
const list<watch_disconnect_t> &to_disconnect);
/*
* Capture all object state associated with an in-progress read or write.
*/
struct OpContext {
OpRequestRef op;
osd_reqid_t reqid;
vector<OSDOp> &ops;
const ObjectState *obs; // Old objectstate
const SnapSet *snapset; // Old snapset
ObjectState new_obs; // resulting ObjectState
SnapSet new_snapset; // resulting SnapSet (in case of a write)
//pg_stat_t new_stats; // resulting Stats
object_stat_sum_t delta_stats;
bool modify; // (force) modification (even if op_t is empty)
bool user_modify; // user-visible modification
bool undirty; // user explicitly un-dirtying this object
bool cache_evict; ///< true if this is a cache eviction
bool ignore_cache; ///< true if IGNORE_CACHE flag is set
bool ignore_log_op_stats; // don't log op stats
bool update_log_only; ///< this is a write that returned an error - just record in pg log for dup detection
// side effects
list<pair<watch_info_t,bool> > watch_connects; ///< new watch + will_ping flag
list<watch_disconnect_t> watch_disconnects; ///< old watch + send_discon
list<notify_info_t> notifies;
struct NotifyAck {
boost::optional<uint64_t> watch_cookie;
uint64_t notify_id;
bufferlist reply_bl;
explicit NotifyAck(uint64_t notify_id) : notify_id(notify_id) {}
NotifyAck(uint64_t notify_id, uint64_t cookie, bufferlist& rbl)
: watch_cookie(cookie), notify_id(notify_id) {
reply_bl.claim(rbl);
}
};
list<NotifyAck> notify_acks;
uint64_t bytes_written, bytes_read;
utime_t mtime;
SnapContext snapc; // writer snap context
eversion_t at_version; // pg's current version pointer
version_t user_at_version; // pg's current user version pointer
int current_osd_subop_num;
PGBackend::PGTransactionUPtr op_t;
vector<pg_log_entry_t> log;
boost::optional<pg_hit_set_history_t> updated_hset_history;
interval_set<uint64_t> modified_ranges;
ObjectContextRef obc;
map<hobject_t,ObjectContextRef, hobject_t::BitwiseComparator> src_obc;
ObjectContextRef clone_obc; // if we created a clone
ObjectContextRef snapset_obc; // if we created/deleted a snapdir
int data_off; // FIXME: we may want to kill this msgr hint off at some point!
MOSDOpReply *reply;
utime_t readable_stamp; // when applied on all replicas
ReplicatedPG *pg;
int num_read; ///< count read ops
int num_write; ///< count update ops
vector<pair<osd_reqid_t, version_t> > extra_reqids;
CopyFromCallback *copy_cb;
hobject_t new_temp_oid, discard_temp_oid; ///< temp objects we should start/stop tracking
// pending xattr updates
map<ObjectContextRef,
map<string, boost::optional<bufferlist> > > pending_attrs;
list<std::function<void()>> on_applied;
list<std::function<void()>> on_committed;
list<std::function<void()>> on_finish;
list<std::function<void()>> on_success;
template <typename F>
void register_on_finish(F &&f) {
on_finish.emplace_back(std::forward<F>(f));
}
template <typename F>
void register_on_success(F &&f) {
on_success.emplace_back(std::forward<F>(f));
}
template <typename F>
void register_on_applied(F &&f) {
on_applied.emplace_back(std::forward<F>(f));
}
template <typename F>
void register_on_commit(F &&f) {
on_committed.emplace_back(std::forward<F>(f));
}
bool sent_ack;
bool sent_disk;
void apply_pending_attrs() {
for (map<ObjectContextRef,
map<string, boost::optional<bufferlist> > >::iterator i =
pending_attrs.begin();
i != pending_attrs.end();
++i) {
if (i->first->obs.exists) {
for (map<string, boost::optional<bufferlist> >::iterator j =
i->second.begin();
j != i->second.end();
++j) {
if (j->second)
i->first->attr_cache[j->first] = j->second.get();
else
i->first->attr_cache.erase(j->first);
}
} else {
i->first->attr_cache.clear();
}
}
pending_attrs.clear();
}
// pending async reads <off, len, op_flags> -> <outbl, outr>
list<pair<boost::tuple<uint64_t, uint64_t, unsigned>,
pair<bufferlist*, Context*> > > pending_async_reads;
int async_read_result;
int inflightreads;
friend struct OnReadComplete;
void start_async_reads(ReplicatedPG *pg);
void finish_read(ReplicatedPG *pg);
bool async_reads_complete() {
return inflightreads == 0;
}
ObjectModDesc mod_desc;
ObjectContext::RWState::State lock_type;
ObcLockManager lock_manager;
OpContext(const OpContext& other);
const OpContext& operator=(const OpContext& other);
OpContext(OpRequestRef _op, osd_reqid_t _reqid, vector<OSDOp>& _ops,
ObjectContextRef& obc,
ReplicatedPG *_pg) :
op(_op), reqid(_reqid), ops(_ops),
obs(&obc->obs),
snapset(0),
new_obs(obs->oi, obs->exists),
modify(false), user_modify(false), undirty(false), cache_evict(false),
ignore_cache(false), ignore_log_op_stats(false), update_log_only(false),
bytes_written(0), bytes_read(0), user_at_version(0),
current_osd_subop_num(0),
obc(obc),
data_off(0), reply(NULL), pg(_pg),
num_read(0),
num_write(0),
copy_cb(NULL),
sent_ack(false), sent_disk(false),
async_read_result(0),
inflightreads(0),
lock_type(ObjectContext::RWState::RWNONE) {
if (obc->ssc) {
new_snapset = obc->ssc->snapset;
snapset = &obc->ssc->snapset;
}
}
OpContext(OpRequestRef _op, osd_reqid_t _reqid,
vector<OSDOp>& _ops, ReplicatedPG *_pg) :
op(_op), reqid(_reqid), ops(_ops), obs(NULL), snapset(0),
modify(false), user_modify(false), undirty(false), cache_evict(false),
ignore_cache(false), ignore_log_op_stats(false), update_log_only(false),
bytes_written(0), bytes_read(0), user_at_version(0),
current_osd_subop_num(0),
data_off(0), reply(NULL), pg(_pg),
num_read(0),
num_write(0),
copy_cb(NULL),
async_read_result(0),
inflightreads(0),
lock_type(ObjectContext::RWState::RWNONE) {}
void reset_obs(ObjectContextRef obc) {
new_obs = ObjectState(obc->obs.oi, obc->obs.exists);
if (obc->ssc) {
new_snapset = obc->ssc->snapset;
snapset = &obc->ssc->snapset;
}
}
~OpContext() {
assert(!op_t);
if (reply)
reply->put();
for (list<pair<boost::tuple<uint64_t, uint64_t, unsigned>,
pair<bufferlist*, Context*> > >::iterator i =
pending_async_reads.begin();
i != pending_async_reads.end();
pending_async_reads.erase(i++)) {
delete i->second.second;
}
}
uint64_t get_features() {
if (op && op->get_req()) {
return op->get_req()->get_connection()->get_features();
}
return -1ull;
}
};
using OpContextUPtr = std::unique_ptr<OpContext>;
friend struct OpContext;
/*
* State on the PG primary associated with the replicated mutation
*/
class RepGather {
public:
hobject_t hoid;
OpRequestRef op;
xlist<RepGather*>::item queue_item;
int nref;
eversion_t v;
ceph_tid_t rep_tid;
bool rep_aborted, rep_done;
bool all_applied;
bool all_committed;
utime_t start;
eversion_t pg_local_last_complete;
ObcLockManager lock_manager;
list<std::function<void()>> on_applied;
list<std::function<void()>> on_committed;
list<std::function<void()>> on_success;
list<std::function<void()>> on_finish;
RepGather(OpContext *c, ceph_tid_t rt,
eversion_t lc) :
hoid(c->obc->obs.oi.soid),
op(c->op),
queue_item(this),
nref(1),
rep_tid(rt),
rep_aborted(false), rep_done(false),
all_applied(false), all_committed(false),
pg_local_last_complete(lc),
lock_manager(std::move(c->lock_manager)),
on_applied(std::move(c->on_applied)),
on_committed(std::move(c->on_committed)),
on_success(std::move(c->on_success)),
on_finish(std::move(c->on_finish)) {}
RepGather(
ObcLockManager &&manager,
boost::optional<std::function<void(void)> > &&on_complete,
ceph_tid_t rt,
eversion_t lc) :
queue_item(this),
nref(1),
rep_tid(rt),
rep_aborted(false), rep_done(false),
all_applied(false), all_committed(false),
pg_local_last_complete(lc),
lock_manager(std::move(manager)) {
if (on_complete) {
on_success.push_back(std::move(*on_complete));
}
}
RepGather *get() {
nref++;
return this;
}
void put() {
assert(nref > 0);
if (--nref == 0) {
assert(on_applied.empty());
delete this;
//generic_dout(0) << "deleting " << this << dendl;
}
}
};
protected:
/**
* Grabs locks for OpContext, should be cleaned up in close_op_ctx
*
* @param ctx [in,out] ctx to get locks for
* @return true on success, false if we are queued
*/
bool get_rw_locks(bool write_ordered, OpContext *ctx) {
/* If snapset_obc, !obc->obs->exists and we will always take the
* snapdir lock *before* the head lock. Since all callers will do
* this (read or write) if we get the first we will be guaranteed
* to get the second.
*/
if (write_ordered && ctx->op->may_read()) {
ctx->lock_type = ObjectContext::RWState::RWEXCL;
} else if (write_ordered) {
ctx->lock_type = ObjectContext::RWState::RWWRITE;
} else {
assert(ctx->op->may_read());
ctx->lock_type = ObjectContext::RWState::RWREAD;
}
if (ctx->snapset_obc) {
assert(!ctx->obc->obs.exists);
if (!ctx->lock_manager.get_lock_type(
ctx->lock_type,
ctx->snapset_obc->obs.oi.soid,
ctx->snapset_obc,
ctx->op)) {
ctx->lock_type = ObjectContext::RWState::RWNONE;
return false;
}
}
if (ctx->lock_manager.get_lock_type(
ctx->lock_type,
ctx->obc->obs.oi.soid,
ctx->obc,
ctx->op)) {
return true;
} else {
assert(!ctx->snapset_obc);
ctx->lock_type = ObjectContext::RWState::RWNONE;
return false;
}
}
/**
* Cleans up OpContext
*
* @param ctx [in] ctx to clean up
*/
void close_op_ctx(OpContext *ctx) {
release_object_locks(ctx->lock_manager);
ctx->op_t.reset();
for (auto p = ctx->on_finish.begin();
p != ctx->on_finish.end();
ctx->on_finish.erase(p++)) {
(*p)();
}
delete ctx;
}
/**
* Releases locks
*
* @param manager [in] manager with locks to release
*/
void release_object_locks(
ObcLockManager &lock_manager) {
list<pair<hobject_t, list<OpRequestRef> > > to_req;
bool requeue_recovery = false;
bool requeue_snaptrim = false;
lock_manager.put_locks(
&to_req,
&requeue_recovery,
&requeue_snaptrim);
if (requeue_recovery)
queue_recovery();
if (requeue_snaptrim)
queue_snap_trim();
if (!to_req.empty()) {
// requeue at front of scrub blocking queue if we are blocked by scrub
for (auto &&p: to_req) {
if (scrubber.write_blocked_by_scrub(
p.first.get_head(),
get_sort_bitwise())) {
waiting_for_active.splice(
waiting_for_active.begin(),
p.second,
p.second.begin(),
p.second.end());
} else {
requeue_ops(p.second);
}
}
}
}
// replica ops
// [primary|tail]
xlist<RepGather*> repop_queue;
friend class C_OSD_RepopApplied;
friend class C_OSD_RepopCommit;
void repop_all_applied(RepGather *repop);
void repop_all_committed(RepGather *repop);
void eval_repop(RepGather*);
void issue_repop(RepGather *repop, OpContext *ctx);
RepGather *new_repop(
OpContext *ctx,
ObjectContextRef obc,
ceph_tid_t rep_tid);
boost::intrusive_ptr<RepGather> new_repop(
ObcLockManager &&manager,
boost::optional<std::function<void(void)> > &&on_complete);
void remove_repop(RepGather *repop);
OpContextUPtr simple_opc_create(ObjectContextRef obc);
void simple_opc_submit(OpContextUPtr ctx);
/**
* Merge entries atomically into all actingbackfill osds
* adjusting missing and recovery state as necessary.
*
* Also used to store error log entries for dup detection.
*/
void submit_log_entries(
const list<pg_log_entry_t> &entries,
ObcLockManager &&manager,
boost::optional<std::function<void(void)> > &&on_complete);
struct LogUpdateCtx {
boost::intrusive_ptr<RepGather> repop;
set<pg_shard_t> waiting_on;
};
void cancel_log_updates();
map<ceph_tid_t, LogUpdateCtx> log_entry_update_waiting_on;
// hot/cold tracking
HitSetRef hit_set; ///< currently accumulating HitSet
utime_t hit_set_start_stamp; ///< time the current HitSet started recording
map<time_t,HitSetRef> hit_set_flushing; ///< currently being written, not yet readable
void hit_set_clear(); ///< discard any HitSet state
void hit_set_setup(); ///< initialize HitSet state
void hit_set_create(); ///< create a new HitSet
void hit_set_persist(); ///< persist hit info
bool hit_set_apply_log(); ///< apply log entries to update in-memory HitSet
void hit_set_trim(OpContextUPtr &ctx, unsigned max); ///< discard old HitSets
void hit_set_in_memory_trim(uint32_t max_in_memory); ///< discard old in memory HitSets
void hit_set_remove_all();
hobject_t get_hit_set_current_object(utime_t stamp);
hobject_t get_hit_set_archive_object(utime_t start,
utime_t end,
bool using_gmt);
// agent
boost::scoped_ptr<TierAgentState> agent_state;
void agent_setup(); ///< initialize agent state
bool agent_work(int max) ///< entry point to do some agent work
{
return agent_work(max, max);
}
bool agent_work(int max, int agent_flush_quota);
bool agent_maybe_flush(ObjectContextRef& obc); ///< maybe flush
bool agent_maybe_evict(ObjectContextRef& obc, bool after_flush); ///< maybe evict
void agent_load_hit_sets(); ///< load HitSets, if needed
/// estimate object atime and temperature
///
/// @param oid [in] object name
/// @param temperature [out] relative temperature (# consider both access time and frequency)
void agent_estimate_temp(const hobject_t& oid, int *temperature);
/// stop the agent
void agent_stop();
void agent_delay();
/// clear agent state
void agent_clear();
/// choose (new) agent mode(s), returns true if op is requeued
bool agent_choose_mode(bool restart = false, OpRequestRef op = OpRequestRef());
void agent_choose_mode_restart();
/// true if we can send an ondisk/commit for v
bool already_complete(eversion_t v) {
for (xlist<RepGather*>::iterator i = repop_queue.begin();
!i.end();
++i) {
// skip copy from temp object ops
if ((*i)->v == eversion_t())
continue;
if ((*i)->v > v)
break;
if (!(*i)->all_committed)
return false;
}
return true;
}
/// true if we can send an ack for v
bool already_ack(eversion_t v) {
for (xlist<RepGather*>::iterator i = repop_queue.begin();
!i.end();
++i) {
// skip copy from temp object ops
if ((*i)->v == eversion_t())
continue;
if ((*i)->v > v)
break;
if (!(*i)->all_applied)
return false;
}
return true;
}
// projected object info
SharedLRU<hobject_t, ObjectContext, hobject_t::ComparatorWithDefault> object_contexts;
// map from oid.snapdir() to SnapSetContext *
map<hobject_t, SnapSetContext*, hobject_t::BitwiseComparator> snapset_contexts;
Mutex snapset_contexts_lock;
// debug order that client ops are applied
map<hobject_t, map<client_t, ceph_tid_t>, hobject_t::BitwiseComparator> debug_op_order;
void populate_obc_watchers(ObjectContextRef obc);
void check_blacklisted_obc_watchers(ObjectContextRef obc);
void check_blacklisted_watchers();
void get_watchers(list<obj_watch_item_t> &pg_watchers);
void get_obc_watchers(ObjectContextRef obc, list<obj_watch_item_t> &pg_watchers);
public:
void handle_watch_timeout(WatchRef watch);
protected:
ObjectContextRef create_object_context(const object_info_t& oi, SnapSetContext *ssc);
ObjectContextRef get_object_context(
const hobject_t& soid,
bool can_create,
map<string, bufferlist> *attrs = 0
);
void context_registry_on_change();
void object_context_destructor_callback(ObjectContext *obc);
class C_PG_ObjectContext;
int find_object_context(const hobject_t& oid,
ObjectContextRef *pobc,
bool can_create,
bool map_snapid_to_clone=false,
hobject_t *missing_oid=NULL);
void add_object_context_to_pg_stat(ObjectContextRef obc, pg_stat_t *stat);
void get_src_oloc(const object_t& oid, const object_locator_t& oloc, object_locator_t& src_oloc);
SnapSetContext *get_snapset_context(
const hobject_t& oid,
bool can_create,
map<string, bufferlist> *attrs = 0,
bool oid_existed = true //indicate this oid whether exsited in backend
);
void register_snapset_context(SnapSetContext *ssc) {
Mutex::Locker l(snapset_contexts_lock);