From: lixiaoy1 Date: Thu, 7 Nov 2019 11:02:15 +0000 (-0500) Subject: librbd: add sync point class X-Git-Tag: v15.1.1~300^2~4 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=6845340a5f54c411f5b95894c4c394d4f3eae5bf;p=ceph-ci.git librbd: add sync point class This class is to identify the check point of a customer request. Signed-off-by: Peterson, Scott Signed-off-by: Li, Xiaoyan Signed-off-by: Lu, Yuan Signed-off-by: Chamarthy, Mahati --- diff --git a/src/librbd/CMakeLists.txt b/src/librbd/CMakeLists.txt index 693b15e7cef..7d2870627f8 100644 --- a/src/librbd/CMakeLists.txt +++ b/src/librbd/CMakeLists.txt @@ -165,6 +165,7 @@ if(WITH_RBD_RWL) ${librbd_internal_srcs} cache/rwl/ImageCacheState.cc cache/rwl/LogEntry.cc + cache/rwl/SyncPoint.cc cache/rwl/Types.cc cache/ReplicatedWriteLog.cc) endif() diff --git a/src/librbd/cache/rwl/SyncPoint.cc b/src/librbd/cache/rwl/SyncPoint.cc new file mode 100644 index 00000000000..a135c6c3d5b --- /dev/null +++ b/src/librbd/cache/rwl/SyncPoint.cc @@ -0,0 +1,51 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include "SyncPoint.h" + +#define dout_subsys ceph_subsys_rbd +#undef dout_prefix +#define dout_prefix *_dout << "librbd::cache::rwl::SyncPoint: " << this << " " \ + << __func__ << ": " + +namespace librbd { +namespace cache { +namespace rwl { + +template +SyncPoint::SyncPoint(T &rwl, const uint64_t sync_gen_num) + : rwl(rwl), log_entry(std::make_shared(sync_gen_num)) { + prior_log_entries_persisted = new C_Gather(rwl.m_image_ctx.cct, nullptr); + sync_point_persist = new C_Gather(rwl.m_image_ctx.cct, nullptr); + on_sync_point_appending.reserve(MAX_WRITES_PER_SYNC_POINT + 2); + on_sync_point_persisted.reserve(MAX_WRITES_PER_SYNC_POINT + 2); + if (RWL_VERBOSE_LOGGING) { + ldout(rwl.m_image_ctx.cct, 20) << "sync point " << sync_gen_num << dendl; + } +} + +template +SyncPoint::~SyncPoint() { + assert(on_sync_point_appending.empty()); + assert(on_sync_point_persisted.empty()); + assert(!earlier_sync_point); +} + +template +std::ostream &SyncPoint::format(std::ostream &os) const { + os << "log_entry=[" << *log_entry << "], " + << "earlier_sync_point=" << earlier_sync_point << ", " + << "later_sync_point=" << later_sync_point << ", " + << "final_op_sequence_num=" << final_op_sequence_num << ", " + << "prior_log_entries_persisted=" << prior_log_entries_persisted << ", " + << "prior_log_entries_persisted_complete=" << prior_log_entries_persisted_complete << ", " + << "append_scheduled=" << append_scheduled << ", " + << "appending=" << appending << ", " + << "on_sync_point_appending=" << on_sync_point_appending.size() << ", " + << "on_sync_point_persisted=" << on_sync_point_persisted.size() << ""; + return os; +}; + +} // namespace rwl +} // namespace cache +} // namespace librbd diff --git a/src/librbd/cache/rwl/SyncPoint.h b/src/librbd/cache/rwl/SyncPoint.h new file mode 100644 index 00000000000..7dad7204623 --- /dev/null +++ b/src/librbd/cache/rwl/SyncPoint.h @@ -0,0 +1,64 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#ifndef CEPH_LIBRBD_CACHE_RWL_SYNC_POINT_H +#define CEPH_LIBRBD_CACHE_RWL_SYNC_POINT_H + +#include "librbd/ImageCtx.h" +#include "librbd/cache/rwl/LogEntry.h" +#include "librbd/cache/rwl/Types.h" + +namespace librbd { +namespace cache { +namespace rwl { +/* Limit work between sync points */ +static const uint64_t MAX_WRITES_PER_SYNC_POINT = 256; + +template +class SyncPoint { +public: + T &rwl; + std::shared_ptr log_entry; + /* Use m_lock for earlier/later links */ + std::shared_ptr> earlier_sync_point; /* NULL if earlier has completed */ + std::shared_ptr> later_sync_point; + uint64_t final_op_sequence_num = 0; + /* A sync point can't appear in the log until all the writes bearing + * it and all the prior sync points have been appended and + * persisted. + * + * Writes bearing this sync gen number and the prior sync point will be + * sub-ops of this Gather. This sync point will not be appended until all + * these complete to the point where their persist order is guaranteed. */ + C_Gather *prior_log_entries_persisted; + int prior_log_entries_persisted_result = 0; + int prior_log_entries_persisted_complete = false; + /* The finisher for this will append the sync point to the log. The finisher + * for m_prior_log_entries_persisted will be a sub-op of this. */ + C_Gather *sync_point_persist; + bool append_scheduled = false; + bool appending = false; + /* Signal these when this sync point is appending to the log, and its order + * of appearance is guaranteed. One of these is is a sub-operation of the + * next sync point's m_prior_log_entries_persisted Gather. */ + std::vector on_sync_point_appending; + /* Signal these when this sync point is appended and persisted. User + * aio_flush() calls are added to this. */ + std::vector on_sync_point_persisted; + + SyncPoint(T &rwl, const uint64_t sync_gen_num); + ~SyncPoint(); + SyncPoint(const SyncPoint&) = delete; + SyncPoint &operator=(const SyncPoint&) = delete; + std::ostream &format(std::ostream &os) const; + friend std::ostream &operator<<(std::ostream &os, + const SyncPoint &p) { + return p.format(os); + } +}; + +} // namespace rwl +} // namespace cache +} // namespace librbd + +#endif // CEPH_LIBRBD_CACHE_RWL_SYNC_POINT_H diff --git a/src/librbd/cache/rwl/Types.h b/src/librbd/cache/rwl/Types.h index b134beda05e..b02b2fdda36 100644 --- a/src/librbd/cache/rwl/Types.h +++ b/src/librbd/cache/rwl/Types.h @@ -140,6 +140,8 @@ namespace librbd { namespace cache { namespace rwl { +static const bool RWL_VERBOSE_LOGGING = false; + /* Defer a set of Contexts until destruct/exit. Used for deferring * work on a given thread until a required lock is dropped. */ class DeferredContexts {