From 7b2a0504d4e9ac67f7de268a94d9b486885db076 Mon Sep 17 00:00:00 2001 From: Tom Coldrick Date: Wed, 16 Nov 2022 02:51:41 -0500 Subject: [PATCH] rgw: Add log types to dencoder When debugging an issue in RGW multisite replication, we discovered that we had no way to deserialise data stored in the logs (in particular the datalog) when attempting to look inside the RADOS objects and work out what's going on. This commit adds the types to ceph-dencoder, to facilitate future efforts at debugging. As a bonus, this also allows serialisation for these types to be tested. Adds the following types to ceph-dencoder: - RGWMetadataLogData - rgw_data_change - cls_log_entry Signed-off-by: Tom Coldrick --- src/cls/log/cls_log_types.h | 32 +++++++++++++++++++++++++++++ src/rgw/driver/rados/rgw_datalog.cc | 9 ++++++++ src/rgw/driver/rados/rgw_datalog.h | 1 + src/rgw/rgw_mdlog.h | 1 + src/rgw/rgw_metadata.cc | 10 +++++++++ src/tools/ceph-dencoder/rgw_types.h | 9 ++++++++ 6 files changed, 62 insertions(+) diff --git a/src/cls/log/cls_log_types.h b/src/cls/log/cls_log_types.h index 1746d243e5a..33b8cce51e5 100644 --- a/src/cls/log/cls_log_types.h +++ b/src/cls/log/cls_log_types.h @@ -8,7 +8,11 @@ #include "include/utime.h" +#include "common/ceph_json.h" +#include "common/Formatter.h" + class JSONObj; +class JSONDecoder; struct cls_log_entry { @@ -40,6 +44,34 @@ struct cls_log_entry { decode(id, bl); DECODE_FINISH(bl); } + + void dump(ceph::Formatter* f) const { + encode_json("section", section, f); + encode_json("name", name, f); + encode_json("timestamp", timestamp, f); + encode_json("data", data, f); + encode_json("id", id, f); + } + + void decode_json(JSONObj* obj) { + JSONDecoder::decode_json("section", section, obj); + JSONDecoder::decode_json("name", name, obj); + JSONDecoder::decode_json("timestamp", timestamp, obj); + JSONDecoder::decode_json("data", data, obj); + JSONDecoder::decode_json("id", id, obj); + } + + static void generate_test_instances(std::list& l) { + l.push_back(new cls_log_entry{}); + l.push_back(new cls_log_entry); + l.back()->id = "test_id"; + l.back()->section = "test_section"; + l.back()->name = "test_name"; + l.back()->timestamp = utime_t(); + ceph::buffer::list bl; + ceph::encode(std::string("Test"), bl, 0); + l.back()->data = bl; + } }; WRITE_CLASS_ENCODER(cls_log_entry) diff --git a/src/rgw/driver/rados/rgw_datalog.cc b/src/rgw/driver/rados/rgw_datalog.cc index 7ca37abf684..c7c3233cf67 100644 --- a/src/rgw/driver/rados/rgw_datalog.cc +++ b/src/rgw/driver/rados/rgw_datalog.cc @@ -61,6 +61,15 @@ void rgw_data_change::decode_json(JSONObj *obj) { JSONDecoder::decode_json("gen", gen, obj); } +void rgw_data_change::generate_test_instances(std::list& l) { + l.push_back(new rgw_data_change{}); + l.push_back(new rgw_data_change); + l.back()->entity_type = ENTITY_TYPE_BUCKET; + l.back()->key = "bucket_name"; + l.back()->timestamp = ceph::real_clock::zero(); + l.back()->gen = 0; +} + void rgw_data_change_log_entry::dump(Formatter *f) const { encode_json("log_id", log_id, f); diff --git a/src/rgw/driver/rados/rgw_datalog.h b/src/rgw/driver/rados/rgw_datalog.h index 174cf86ded1..58042df2c62 100644 --- a/src/rgw/driver/rados/rgw_datalog.h +++ b/src/rgw/driver/rados/rgw_datalog.h @@ -82,6 +82,7 @@ struct rgw_data_change { void dump(ceph::Formatter* f) const; void decode_json(JSONObj* obj); + static void generate_test_instances(std::list& l); }; WRITE_CLASS_ENCODER(rgw_data_change) diff --git a/src/rgw/rgw_mdlog.h b/src/rgw/rgw_mdlog.h index 179cc2aca44..6a6fb67d17a 100644 --- a/src/rgw/rgw_mdlog.h +++ b/src/rgw/rgw_mdlog.h @@ -159,6 +159,7 @@ struct RGWMetadataLogData { void decode(bufferlist::const_iterator& bl); void dump(Formatter *f) const; void decode_json(JSONObj *obj); + static void generate_test_instances(std::list& l); }; WRITE_CLASS_ENCODER(RGWMetadataLogData) diff --git a/src/rgw/rgw_metadata.cc b/src/rgw/rgw_metadata.cc index 7fd25ae7587..a6d75de0eba 100644 --- a/src/rgw/rgw_metadata.cc +++ b/src/rgw/rgw_metadata.cc @@ -101,6 +101,16 @@ void RGWMetadataLogData::decode_json(JSONObj *obj) { JSONDecoder::decode_json("status", status, obj); } +void RGWMetadataLogData::generate_test_instances(std::list& l) { + l.push_back(new RGWMetadataLogData{}); + l.push_back(new RGWMetadataLogData); + l.back()->read_version = obj_version(); + l.back()->read_version.tag = "read_tag"; + l.back()->write_version = obj_version(); + l.back()->write_version.tag = "write_tag"; + l.back()->status = MDLOG_STATUS_WRITE; +} + RGWMetadataHandler_GenericMetaBE::Put::Put(RGWMetadataHandler_GenericMetaBE *_handler, RGWSI_MetaBackend_Handler::Op *_op, string& _entry, RGWMetadataObject *_obj, diff --git a/src/tools/ceph-dencoder/rgw_types.h b/src/tools/ceph-dencoder/rgw_types.h index dd5c3a8cb7f..7a5f544eca2 100644 --- a/src/tools/ceph-dencoder/rgw_types.h +++ b/src/tools/ceph-dencoder/rgw_types.h @@ -30,6 +30,9 @@ TYPE(RGWCacheNotifyInfo) #include "rgw_lc.h" TYPE(RGWLifecycleConfiguration) +#include "cls/log/cls_log_types.h" +TYPE(cls_log_entry) + #include "cls/rgw/cls_rgw_types.h" TYPE(rgw_bucket_pending_info) TYPE(rgw_bucket_dir_entry_meta) @@ -122,6 +125,12 @@ TYPE(rgw_obj) #include "rgw_log.h" TYPE(rgw_log_entry) +#include "rgw_datalog.h" +TYPE(rgw_data_change) + +#include "rgw_mdlog.h" +TYPE(RGWMetadataLogData) + #include "rgw_meta_sync_status.h" TYPE(rgw_meta_sync_info) TYPE(rgw_meta_sync_marker) -- 2.39.5