From 6000732706890fa5d276d22972d1d83be32bb5c8 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Sun, 3 Dec 2023 14:10:30 -0500 Subject: [PATCH] rgw/metadata: add RGWMetadataLister abstraction Signed-off-by: Casey Bodley --- src/rgw/driver/rados/rgw_metadata_lister.h | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/rgw/driver/rados/rgw_metadata_lister.h diff --git a/src/rgw/driver/rados/rgw_metadata_lister.h b/src/rgw/driver/rados/rgw_metadata_lister.h new file mode 100644 index 0000000000000..9fbb21ac3b402 --- /dev/null +++ b/src/rgw/driver/rados/rgw_metadata_lister.h @@ -0,0 +1,73 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab ft=cpp + +/* + * Ceph - scalable distributed file system + * + * Copyright contributors to the Ceph project + * + * 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. + * + */ + +#pragma once + +#include +#include +#include +#include +#include +#include "services/svc_sys_obj.h" + +class DoutPrefixProvider; + +class RGWMetadataLister { + RGWSI_SysObj::Pool pool; + RGWSI_SysObj::Pool::Op listing; + + virtual void filter_transform(std::vector& oids, + std::list& keys) { + // use all oids as keys + std::move(oids.begin(), oids.end(), std::back_inserter(keys)); + } + + public: + explicit RGWMetadataLister(RGWSI_SysObj::Pool pool) + : pool(pool), listing(this->pool) {} + virtual ~RGWMetadataLister() {} + + int init(const DoutPrefixProvider* dpp, + const std::string& marker, + const std::string& prefix) + { + return listing.init(dpp, marker, prefix); + } + + int get_next(const DoutPrefixProvider* dpp, int max, + std::list& keys, bool* truncated) + { + std::vector oids; + int r = listing.get_next(dpp, max, &oids, truncated); + if (r == -ENOENT) { + if (truncated) { + *truncated = false; + } + return 0; + } + if (r < 0) { + return r; + } + filter_transform(oids, keys); + return 0; + } + + std::string get_marker() + { + std::string marker; + listing.get_marker(&marker); + return marker; + } +}; -- 2.39.5