});
}
-seastar::future<std::vector<coll_t>> AlienStore::list_collections()
+seastar::future<std::vector<coll_core_t>> AlienStore::list_collections()
{
logger().debug("{}", __func__);
assert(tp);
return do_with_op_gate(std::vector<coll_t>{}, [this] (auto &ls) {
return tp->submit([this, &ls] {
return store->list_collections(ls);
- }).then([&ls] (int r) {
+ }).then([&ls] (int r) -> seastar::future<std::vector<coll_core_t>> {
assert(r == 0);
- return seastar::make_ready_future<std::vector<coll_t>>(std::move(ls));
+ std::vector<coll_core_t> ret;
+ ret.resize(ls.size());
+ std::transform(
+ ls.begin(), ls.end(), ret.begin(),
+ [](auto p) { return std::make_pair(p, NULL_CORE); });
+ return seastar::make_ready_future<std::vector<coll_core_t>>(std::move(ret));
});
});
}
}
namespace crimson::os {
+using coll_core_t = FuturizedStore::coll_core_t;
class AlienStore final : public FuturizedStore {
public:
AlienStore(const std::string& type,
seastar::future<CollectionRef> create_new_collection(const coll_t& cid) final;
seastar::future<CollectionRef> open_collection(const coll_t& cid) final;
- seastar::future<std::vector<coll_t>> list_collections() final;
+ seastar::future<std::vector<coll_core_t>> list_collections() final;
seastar::future<> do_transaction_no_callbacks(
CollectionRef c,
return crimson::write_file(std::move(bl), fn);
}
-seastar::future<std::vector<coll_t>>
+seastar::future<std::vector<coll_core_t>>
CyanStore::list_collections()
{
- return seastar::do_with(std::vector<coll_t>{}, [this](auto &collections) {
+ return seastar::do_with(std::vector<coll_core_t>{}, [this](auto &collections) {
return shard_stores.map([](auto &local_store) {
return local_store.list_collections();
- }).then([&collections](std::vector<std::vector<coll_t>> results) {
+ }).then([&collections](std::vector<std::vector<coll_core_t>> results) {
for (auto& colls : results) {
collections.insert(collections.end(), colls.begin(), colls.end());
}
- return seastar::make_ready_future<std::vector<coll_t>>(
+ return seastar::make_ready_future<std::vector<coll_core_t>>(
std::move(collections));
});
});
return seastar::make_ready_future<CollectionRef>(_get_collection(cid));
}
-seastar::future<std::vector<coll_t>>
+seastar::future<std::vector<coll_core_t>>
CyanStore::ShardStores::list_collections()
{
- std::vector<coll_t> collections;
+ std::vector<coll_core_t> collections;
for (auto& coll : coll_map) {
- collections.push_back(coll.first);
+ collections.push_back(std::make_pair(coll.first, seastar::this_shard_id()));
}
- return seastar::make_ready_future<std::vector<coll_t>>(std::move(collections));
+ return seastar::make_ready_future<std::vector<coll_core_t>>(std::move(collections));
}
CyanStore::read_errorator::future<ceph::bufferlist>
}
namespace crimson::os {
-
+using coll_core_t = FuturizedStore::coll_core_t;
class CyanStore final : public FuturizedStore {
class ShardStores {
public:
seastar::future<CollectionRef> open_collection(const coll_t& cid);
- seastar::future<std::vector<coll_t>> list_collections();
+ seastar::future<std::vector<coll_core_t>> list_collections();
seastar::future<> do_transaction_no_callbacks(
CollectionRef ch,
});
}
- seastar::future<std::vector<coll_t>> list_collections() final;
+ seastar::future<std::vector<coll_core_t>> list_collections() final;
// public interfaces called by each shard osd
public:
#include "os/Transaction.h"
#include "crimson/common/smp_helpers.h"
+#include "crimson/common/smp_helpers.h"
#include "crimson/osd/exceptions.h"
#include "include/buffer_fwd.h"
#include "include/uuid.h"
virtual seastar::future<CollectionRef> create_new_collection(const coll_t& cid) = 0;
virtual seastar::future<CollectionRef> open_collection(const coll_t& cid) = 0;
- virtual seastar::future<std::vector<coll_t>> list_collections() = 0;
+ using coll_core_t = std::pair<coll_t, core_id_t>;
+ virtual seastar::future<std::vector<coll_core_t>> list_collections() = 0;
protected:
virtual seastar::future<> do_transaction_no_callbacks(
seastar::future<CollectionRef> open_collection(const coll_t &cid) final {
return proxy(&T::open_collection, cid);
}
- seastar::future<std::vector<coll_t>> list_collections() final {
+ seastar::future<std::vector<coll_core_t>> list_collections() final {
return proxy(&T::list_collections);
}
seastar::future<> do_transaction_no_callbacks(
{
LOG_PREFIX(SeaStore::open_collection);
DEBUG("{}", cid);
- return list_collections().then([cid, this] (auto colls) {
- if (auto found = std::find(colls.begin(), colls.end(), cid);
- found != colls.end()) {
+ return list_collections().then([cid, this] (auto colls_cores) {
+ if (auto found = std::find(colls_cores.begin(), colls_cores.end(),
+ std::make_pair(cid, NULL_CORE));
+ found != colls_cores.end()) {
return seastar::make_ready_future<CollectionRef>(_get_collection(cid));
} else {
return seastar::make_ready_future<CollectionRef>();
});
}
-seastar::future<std::vector<coll_t>> SeaStore::list_collections()
+seastar::future<std::vector<coll_core_t>> SeaStore::list_collections()
{
return seastar::do_with(
- std::vector<coll_t>(),
+ std::vector<coll_core_t>(),
[this](auto &ret) {
return repeat_eagain([this, &ret] {
return transaction_manager->with_transaction_intr(
ret.resize(colls.size());
std::transform(
colls.begin(), colls.end(), ret.begin(),
- [](auto p) { return p.first; });
+ [](auto p) { return std::make_pair(p.first, NULL_CORE); });
});
});
}).safe_then([&ret] {
- return seastar::make_ready_future<std::vector<coll_t>>(ret);
+ return seastar::make_ready_future<std::vector<coll_core_t>>(ret);
});
}
).handle_error(
ghobject_t obj_end;
};
+using coll_core_t = FuturizedStore::coll_core_t;
class SeaStore final : public FuturizedStore {
public:
class MDStore {
seastar::future<CollectionRef> create_new_collection(const coll_t& cid) final;
seastar::future<CollectionRef> open_collection(const coll_t& cid) final;
- seastar::future<std::vector<coll_t>> list_collections() final;
+ seastar::future<std::vector<coll_core_t>> list_collections() final;
seastar::future<> do_transaction_no_callbacks(
CollectionRef ch,
}
/// Returns mapping for pgid, creates new one if it doesn't already exist
- core_id_t maybe_create_pg(spg_t pgid) {
- auto [insert_iter, inserted] = pg_to_core.emplace(pgid, NULL_CORE);
+ core_id_t maybe_create_pg(spg_t pgid, core_id_t core = NULL_CORE) {
+ auto [insert_iter, inserted] = pg_to_core.emplace(pgid, core);
if (!inserted) {
ceph_assert_always(insert_iter->second != NULL_CORE);
+ if (core != NULL_CORE) {
+ ceph_assert_always(insert_iter->second == core);
+ }
return insert_iter->second;
} else {
ceph_assert_always(core_to_num_pgs.size() > 0);
- auto core_iter = std::min_element(
- core_to_num_pgs.begin(),
- core_to_num_pgs.end(),
- [](const auto &left, const auto &right) {
- return left.second < right.second;
- });
+ std::map<core_id_t, unsigned>::iterator core_iter;
+ if (core == NULL_CORE) {
+ core_iter = std::min_element(
+ core_to_num_pgs.begin(),
+ core_to_num_pgs.end(),
+ [](const auto &left, const auto &right) {
+ return left.second < right.second;
+ });
+ } else {
+ core_iter = core_to_num_pgs.find(core);
+ }
ceph_assert_always(core_to_num_pgs.end() != core_iter);
insert_iter->second = core_iter->first;
core_iter->second++;
{
ceph_assert(seastar::this_shard_id() == PRIMARY_CORE);
return get_local_state().store.list_collections(
- ).then([this](auto colls) {
+ ).then([this](auto colls_cores) {
return seastar::parallel_for_each(
- colls,
- [this](auto coll) {
+ colls_cores,
+ [this](auto coll_core) {
+ auto[coll, shard_core] = coll_core;
spg_t pgid;
if (coll.is_pg(&pgid)) {
auto core = get_osd_singleton_state(
).pg_to_shard_mapping.maybe_create_pg(
- pgid);
+ pgid, shard_core);
return with_remote_shard_state(
core,
[pgid](
t.create_collection(test_coll, 4);
do_transaction(std::move(t));
}
- auto collections = seastore->list_collections().get0();
- EXPECT_EQ(collections.size(), 2);
- EXPECT_TRUE(contains(collections, coll_name));
- EXPECT_TRUE(contains(collections, test_coll));
+ auto colls_cores = seastore->list_collections().get0();
+ std::vector<coll_t> colls;
+ colls.resize(colls_cores.size());
+ std::transform(
+ colls_cores.begin(), colls_cores.end(), colls.begin(),
+ [](auto p) { return p.first; });
+ EXPECT_EQ(colls.size(), 2);
+ EXPECT_TRUE(contains(colls, coll_name));
+ EXPECT_TRUE(contains(colls, test_coll));
}
{
t.remove_collection(test_coll);
do_transaction(std::move(t));
}
- auto collections = seastore->list_collections().get0();
- EXPECT_EQ(collections.size(), 1);
- EXPECT_TRUE(contains(collections, coll_name));
+ auto colls_cores = seastore->list_collections().get0();
+ std::vector<coll_t> colls;
+ colls.resize(colls_cores.size());
+ std::transform(
+ colls_cores.begin(), colls_cores.end(), colls.begin(),
+ [](auto p) { return p.first; });
+ EXPECT_EQ(colls.size(), 1);
+ EXPECT_TRUE(contains(colls, coll_name));
}
});
}