Skip to content

Commit

Permalink
crimson: add FuturizedCollection
Browse files Browse the repository at this point in the history
we will need to talk to BlueStore, and currently `ceph::os::Collection`
only works with `CyanStore`, so a wrapper around `ceph::os::Collection`
is added. we can subclass it to adapt to CyanStore and to BlueStore.

the underlying concrete `FuturizedStore` classes are responsible to
cast `FuturizedCollection` to their own `Collection` type if they
want to access the interface not exposed by `FuturizedCollection`.

Signed-off-by: chunmei Liu <[email protected]>
  • Loading branch information
chunmei Liu authored and tchaikov committed Aug 27, 2019
1 parent 6188e31 commit 0fbedd5
Show file tree
Hide file tree
Showing 18 changed files with 72 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/crimson/os/cyan_collection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace ceph::os
{

Collection::Collection(const coll_t& c)
: cid{c}
: FuturizedCollection{c}
{}

Collection::~Collection() = default;
Expand Down
17 changes: 4 additions & 13 deletions src/crimson/os/cyan_collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "include/buffer.h"
#include "osd/osd_types.h"

#include "futurized_collection.h"

namespace ceph::os {

class Object;
Expand All @@ -24,10 +26,7 @@ class Object;
* ObjectStore users may get collection handles with open_collection() (or,
* for bootstrapping a new collection, create_new_collection()).
*/
struct Collection : public boost::intrusive_ref_counter<
Collection,
boost::thread_unsafe_counter>
{
struct Collection final : public FuturizedCollection {
using ObjectRef = boost::intrusive_ptr<Object>;
int bits = 0;
// always use bufferlist object for testing
Expand All @@ -38,23 +37,15 @@ struct Collection : public boost::intrusive_ref_counter<
bool exists = true;

Collection(const coll_t& c);
~Collection();
~Collection() final;

ObjectRef create_object() const;
ObjectRef get_object(ghobject_t oid);
ObjectRef get_or_create_object(ghobject_t oid);
uint64_t used_bytes() const;

const coll_t &get_cid() const {
return cid;
}

void encode(bufferlist& bl) const;
void decode(bufferlist::const_iterator& p);
private:
const coll_t cid;
};

using CollectionRef = boost::intrusive_ptr<Collection>;

}
22 changes: 14 additions & 8 deletions src/crimson/os/cyan_store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ seastar::future<> CyanStore::mount()
if (int r = cbl.read_file(fn.c_str(), &err); r < 0) {
throw std::runtime_error("read_file");
}
CollectionRef c{new Collection{coll}};
boost::intrusive_ptr<Collection> c{new Collection{coll}};
auto p = cbl.cbegin();
c->decode(p);
coll_map[coll] = c;
Expand Down Expand Up @@ -125,11 +125,12 @@ store_statfs_t CyanStore::stat() const
}

seastar::future<std::vector<ghobject_t>, ghobject_t>
CyanStore::list_objects(CollectionRef c,
CyanStore::list_objects(CollectionRef ch,
const ghobject_t& start,
const ghobject_t& end,
uint64_t limit) const
{
auto c = static_cast<Collection*>(ch.get());
logger().debug("{} {} {} {} {}",
__func__, c->get_cid(), start, end, limit);
std::vector<ghobject_t> objects;
Expand Down Expand Up @@ -170,12 +171,13 @@ seastar::future<std::vector<coll_t>> CyanStore::list_collections()
return seastar::make_ready_future<std::vector<coll_t>>(std::move(collections));
}

seastar::future<ceph::bufferlist> CyanStore::read(CollectionRef c,
seastar::future<ceph::bufferlist> CyanStore::read(CollectionRef ch,
const ghobject_t& oid,
uint64_t offset,
size_t len,
uint32_t op_flags)
{
auto c = static_cast<Collection*>(ch.get());
logger().debug("{} {} {} {}~{}",
__func__, c->get_cid(), oid, offset, len);
if (!c->exists) {
Expand All @@ -200,10 +202,11 @@ seastar::future<ceph::bufferlist> CyanStore::read(CollectionRef c,
return seastar::make_ready_future<ceph::bufferlist>(std::move(bl));
}

seastar::future<ceph::bufferptr> CyanStore::get_attr(CollectionRef c,
seastar::future<ceph::bufferptr> CyanStore::get_attr(CollectionRef ch,
const ghobject_t& oid,
std::string_view name) const
{
auto c = static_cast<Collection*>(ch.get());
logger().debug("{} {} {}",
__func__, c->get_cid(), oid);
auto o = c->get_object(oid);
Expand All @@ -219,9 +222,10 @@ seastar::future<ceph::bufferptr> CyanStore::get_attr(CollectionRef c,
}
}

seastar::future<CyanStore::attrs_t> CyanStore::get_attrs(CollectionRef c,
seastar::future<CyanStore::attrs_t> CyanStore::get_attrs(CollectionRef ch,
const ghobject_t& oid)
{
auto c = static_cast<Collection*>(ch.get());
logger().debug("{} {} {}",
__func__, c->get_cid(), oid);
auto o = c->get_object(oid);
Expand All @@ -232,10 +236,11 @@ seastar::future<CyanStore::attrs_t> CyanStore::get_attrs(CollectionRef c,
}

seastar::future<CyanStore::omap_values_t>
CyanStore::omap_get_values(CollectionRef c,
CyanStore::omap_get_values(CollectionRef ch,
const ghobject_t& oid,
const omap_keys_t& keys)
{
auto c = static_cast<Collection*>(ch.get());
logger().debug("{} {} {}",
__func__, c->get_cid(), oid);
auto o = c->get_object(oid);
Expand All @@ -253,10 +258,11 @@ CyanStore::omap_get_values(CollectionRef c,

seastar::future<bool, CyanStore::omap_values_t>
CyanStore::omap_get_values(
CollectionRef c,
CollectionRef ch,
const ghobject_t &oid,
const std::optional<string> &start
) {
auto c = static_cast<Collection*>(ch.get());
logger().debug(
"{} {} {}",
__func__, c->get_cid(), oid);
Expand Down Expand Up @@ -599,7 +605,7 @@ int CyanStore::_create_collection(const coll_t& cid, int bits)
return 0;
}

CollectionRef CyanStore::_get_collection(const coll_t& cid)
boost::intrusive_ptr<Collection> CyanStore::_get_collection(const coll_t& cid)
{
auto cp = coll_map.find(cid);
if (cp == coll_map.end())
Expand Down
7 changes: 3 additions & 4 deletions src/crimson/os/cyan_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <optional>
#include <seastar/core/future.hh>

#include "crimson/os/cyan_collection.h"
#include "osd/osd_types.h"
#include "include/uuid.h"

Expand All @@ -28,8 +27,8 @@ class CyanStore final : public FuturizedStore {
constexpr static unsigned MAX_KEYS_PER_OMAP_GET_CALL = 32;

const std::string path;
std::unordered_map<coll_t, CollectionRef> coll_map;
std::map<coll_t,CollectionRef> new_coll_map;
std::unordered_map<coll_t, boost::intrusive_ptr<Collection>> coll_map;
std::map<coll_t, boost::intrusive_ptr<Collection>> new_coll_map;
uint64_t used_bytes = 0;
uuid_d osd_fsid;

Expand Down Expand Up @@ -113,7 +112,7 @@ class CyanStore final : public FuturizedStore {
int _setattrs(const coll_t& cid, const ghobject_t& oid,
std::map<std::string,bufferptr>& aset);
int _create_collection(const coll_t& cid, int bits);
CollectionRef _get_collection(const coll_t& cid);
boost::intrusive_ptr<Collection> _get_collection(const coll_t& cid);
};

}
36 changes: 36 additions & 0 deletions src/crimson/os/futurized_collection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#pragma once

#include <boost/intrusive_ptr.hpp>
#include <boost/smart_ptr/intrusive_ref_counter.hpp>
#include <seastar/core/future.hh>

#include "osd/osd_types.h"

namespace ceph::os {

class FuturizedCollection
: public boost::intrusive_ref_counter<FuturizedCollection,
boost::thread_unsafe_counter>
{
public:
FuturizedCollection(const coll_t& cid)
: cid{cid} {}
virtual ~FuturizedCollection() {}
virtual seastar::future<> flush() {
return seastar::now();
}
virtual seastar::future<bool> flush_commit() {
return seastar::make_ready_future<bool>(true);
}
const coll_t& get_cid() const {
return cid;
}
private:
const coll_t cid;
};

using CollectionRef = boost::intrusive_ptr<FuturizedCollection>;
}
4 changes: 2 additions & 2 deletions src/crimson/os/futurized_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace ceph::os {

class Collection;
class FuturizedCollection;
class Transaction;

class FuturizedStore {
Expand Down Expand Up @@ -64,7 +64,7 @@ class FuturizedStore {
virtual seastar::future<> mkfs(uuid_d new_osd_fsid) = 0;
virtual store_statfs_t stat() const = 0;

using CollectionRef = boost::intrusive_ptr<Collection>;
using CollectionRef = boost::intrusive_ptr<FuturizedCollection>;
virtual seastar::future<ceph::bufferlist> read(CollectionRef c,
const ghobject_t& oid,
uint64_t offset,
Expand Down
1 change: 0 additions & 1 deletion src/crimson/osd/ec_backend.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "ec_backend.h"

#include "crimson/os/cyan_collection.h"
#include "crimson/osd/shard_services.h"

ECBackend::ECBackend(shard_id_t shard,
Expand Down
2 changes: 1 addition & 1 deletion src/crimson/osd/osd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "crimson/mon/MonClient.h"
#include "crimson/net/Connection.h"
#include "crimson/net/Messenger.h"
#include "crimson/os/cyan_collection.h"
#include "crimson/os/futurized_collection.h"
#include "crimson/os/cyan_object.h"
#include "crimson/os/futurized_store.h"
#include "crimson/osd/heartbeat.h"
Expand Down
1 change: 0 additions & 1 deletion src/crimson/osd/osd.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ namespace ceph::net {

namespace ceph::os {
class FuturizedStore;
struct Collection;
class Transaction;
}

Expand Down
2 changes: 1 addition & 1 deletion src/crimson/osd/osd_meta.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <fmt/format.h>

#include "crimson/os/cyan_collection.h"
#include "crimson/os/futurized_collection.h"
#include "crimson/os/futurized_store.h"
#include "os/Transaction.h"

Expand Down
6 changes: 3 additions & 3 deletions src/crimson/osd/osd_meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include "osd/osd_types.h"

namespace ceph::os {
class FuturizedCollection;
class FuturizedStore;
class Collection;
class Transaction;
}

Expand All @@ -20,10 +20,10 @@ class OSDMeta {
template<typename T> using Ref = boost::intrusive_ptr<T>;

ceph::os::FuturizedStore* store;
Ref<ceph::os::Collection> coll;
Ref<ceph::os::FuturizedCollection> coll;

public:
OSDMeta(Ref<ceph::os::Collection> coll,
OSDMeta(Ref<ceph::os::FuturizedCollection> coll,
ceph::os::FuturizedStore* store)
: store{store}, coll{coll}
{}
Expand Down
2 changes: 1 addition & 1 deletion src/crimson/osd/pg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#include "crimson/net/Connection.h"
#include "crimson/net/Messenger.h"
#include "crimson/os/cyan_collection.h"
#include "crimson/os/futurized_collection.h"
#include "os/Transaction.h"
#include "crimson/os/cyan_store.h"

Expand Down
1 change: 1 addition & 0 deletions src/crimson/osd/pg.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "osd/PeeringState.h"

#include "crimson/common/type_helpers.h"
#include "crimson/os/futurized_collection.h"
#include "crimson/osd/osd_operations/client_request.h"
#include "crimson/osd/osd_operations/peering_event.h"
#include "crimson/osd/osd_operations/replicated_request.h"
Expand Down
2 changes: 1 addition & 1 deletion src/crimson/osd/pg_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include "messages/MOSDOp.h"

#include "crimson/os/cyan_collection.h"
#include "crimson/os/futurized_collection.h"
#include "crimson/os/cyan_object.h"
#include "crimson/os/futurized_store.h"
#include "replicated_backend.h"
Expand Down
4 changes: 2 additions & 2 deletions src/crimson/osd/pg_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <boost/smart_ptr/local_shared_ptr.hpp>

#include "crimson/os/futurized_store.h"
#include "crimson/os/cyan_collection.h"
#include "crimson/os/futurized_collection.h"
#include "crimson/osd/acked_peers.h"
#include "crimson/common/shared_lru.h"
#include "os/Transaction.h"
Expand All @@ -26,7 +26,7 @@ namespace ceph::osd {
class PGBackend
{
protected:
using CollectionRef = boost::intrusive_ptr<ceph::os::Collection>;
using CollectionRef = ceph::os::CollectionRef;
using ec_profile_t = std::map<std::string, std::string>;

public:
Expand Down
2 changes: 1 addition & 1 deletion src/crimson/osd/pg_meta.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <string_view>

#include "crimson/os/cyan_collection.h"
#include "crimson/os/futurized_collection.h"
#include "crimson/os/futurized_store.h"

// prefix pgmeta_oid keys with _ so that PGLog::read_log_and_missing() can
Expand Down
1 change: 0 additions & 1 deletion src/crimson/osd/replicated_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "messages/MOSDRepOpReply.h"

#include "crimson/common/log.h"
#include "crimson/os/cyan_collection.h"
#include "crimson/os/cyan_object.h"
#include "crimson/os/futurized_store.h"
#include "crimson/osd/shard_services.h"
Expand Down
2 changes: 1 addition & 1 deletion src/crimson/osd/shard_services.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "osd_operation.h"
#include "msg/MessageRef.h"
#include "crimson/os/cyan_collection.h"
#include "crimson/os/futurized_collection.h"
#include "osd/PeeringState.h"
#include "crimson/osd/osdmap_service.h"

Expand Down

0 comments on commit 0fbedd5

Please sign in to comment.