From: tridao Date: Sun, 18 Jun 2023 03:09:40 +0000 (-0300) Subject: Passed compilation with simple test X-Git-Tag: v19.0.0~874^2~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6f6bc8cc96347665127c7384cdf10f7e4123bb5c;p=ceph.git Passed compilation with simple test Still needs more testing Signed-off-by: Tri Dao --- diff --git a/src/test/objectstore/CMakeLists.txt b/src/test/objectstore/CMakeLists.txt index a012264e8d37..99a88a654b6b 100644 --- a/src/test/objectstore/CMakeLists.txt +++ b/src/test/objectstore/CMakeLists.txt @@ -138,3 +138,11 @@ if(WITH_BLUESTORE) install(TARGETS ceph_test_alloc_replay DESTINATION bin) endif() + +add_library(ObjectStoreImitator OBJECT ObjectStoreImitator.cc) + +add_executable(ceph_test_fragmentation_sim + Fragmentation_simulator.cc + $) +add_ceph_unittest(ceph_test_fragmentation_sim) +target_link_libraries(ceph_test_fragmentation_sim os global) diff --git a/src/test/objectstore/Fragmentation_simulator.cc b/src/test/objectstore/Fragmentation_simulator.cc index 10bd5232f386..a1fa64c299b6 100644 --- a/src/test/objectstore/Fragmentation_simulator.cc +++ b/src/test/objectstore/Fragmentation_simulator.cc @@ -2,11 +2,18 @@ // vim: ts=8 sw=2 smarttab /* * Fragmentation Simulator - * Author: Tri Dao, tri.dao@uwaterloo.ca + * Author: Tri Dao, daominhtri0503@gmail.com */ +#include "common/ceph_argparse.h" +#include "common/common_init.h" #include "common/hobject.h" +#include "global/global_init.h" #include "os/ObjectStore.h" #include "test/objectstore/ObjectStoreImitator.h" +#include +#include + +#define dout_context g_ceph_context class FragmentationSimulator { public: @@ -15,11 +22,15 @@ public: ObjectStoreImitator *os) = 0; virtual std::string name() = 0; - WorkloadGenerator(); - virtual ~WorkloadGenerator(); + WorkloadGenerator() {} + virtual ~WorkloadGenerator() {} }; - using WorkloadGeneratorRef = std::unique_ptr; + using WorkloadGeneratorRef = std::shared_ptr; std::vector generators; + void add_generator(WorkloadGeneratorRef gen) { + std::cout << "Generator: " << gen->name() << " added\n"; + generators.push_back(gen); + } int begin_simulation_with_generators() { for (auto &g : generators) { @@ -37,6 +48,13 @@ public: return 0; } + FragmentationSimulator() { + std::cout << "Initializing simulator\n" << std::endl; + os = new ObjectStoreImitator(g_ceph_context, "", 4096); + os->init_alloc("btree", 1024 * 1024 * 1024, 4096); + } + ~FragmentationSimulator() { delete os; } + private: ObjectStoreImitator *os; }; @@ -57,3 +75,20 @@ struct SimpleCWGenerator : public FragmentationSimulator::WorkloadGenerator { return 0; } }; + +TEST(FragmentationSimulator, simple) { + auto sim = FragmentationSimulator(); + sim.add_generator(std::make_shared()); + sim.begin_simulation_with_generators(); +} + +int main(int argc, char **argv) { + auto args = argv_to_vec(argc, argv); + auto cct = + global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, + CINIT_FLAG_NO_DEFAULT_CONFIG_FILE); + common_init_finish(g_ceph_context); + + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/src/test/objectstore/ObjectStoreImitator.cc b/src/test/objectstore/ObjectStoreImitator.cc index 795723f87b14..5959293504d4 100644 --- a/src/test/objectstore/ObjectStoreImitator.cc +++ b/src/test/objectstore/ObjectStoreImitator.cc @@ -1,3 +1,9 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Fragmentation Simulator + * Author: Tri Dao, daominhtri0503@gmail.com + */ #include "test/objectstore/ObjectStoreImitator.h" #include "common/errno.h" @@ -253,6 +259,34 @@ void ObjectStoreImitator::_add_transaction(Transaction *t) { } } +int ObjectStoreImitator::read(CollectionHandle &c_, const ghobject_t &oid, + uint64_t offset, size_t length, bufferlist &bl, + uint32_t op_flags) { + + Collection *c = static_cast(c_.get()); + if (!c->exists) + return -ENOENT; + + bl.clear(); + int r; + { + std::shared_lock l(c->lock); + ObjectRef o = c->get_obj(oid, false); + if (!o || !o->exists) { + r = -ENOENT; + goto out; + } + + if (offset == length && offset == 0) + length = o->size; + + r = _do_read(c, o, offset, length, bl, op_flags); + } + +out: + return r; +} + // ------- Helpers ------- void ObjectStoreImitator::_assign_nid(ObjectRef &o) { diff --git a/src/test/objectstore/ObjectStoreImitator.h b/src/test/objectstore/ObjectStoreImitator.h index 54f72e64a8a9..cfe7658f98f6 100644 --- a/src/test/objectstore/ObjectStoreImitator.h +++ b/src/test/objectstore/ObjectStoreImitator.h @@ -1,8 +1,16 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Fragmentation Simulator + * Author: Tri Dao, daominhtri0503@gmail.com + */ #pragma once +#include "include/common_fwd.h" #include "os/ObjectStore.h" #include "os/bluestore/Allocator.h" #include "os/bluestore/bluestore_types.h" +#include /** * ObjectStoreImitator will simulate how BlueStore does IO (as of the time @@ -22,7 +30,7 @@ private: class Collection; typedef boost::intrusive_ptr CollectionRef; - struct Object { + struct Object : public RefCountedObject { Collection *c; ghobject_t oid; bool exists; @@ -113,11 +121,13 @@ private: } auto o = objects.find(oid); - if (o->second) + if (o != objects.end()) return o->second; - auto on = new Object(this, oid); - return objects[oid] = on; + if (!create) + return nullptr; + + return objects[oid] = new Object(this, oid); } bool flush_commit(Context *c) override { return false; } @@ -174,6 +184,8 @@ private: int _clone(CollectionRef &c, ObjectRef &oldo, ObjectRef &newo); int _clone_range(CollectionRef &c, ObjectRef &oldo, ObjectRef &newo, uint64_t srcoff, uint64_t length, uint64_t dstoff); + int read(CollectionHandle &c, const ghobject_t &oid, uint64_t offset, + size_t len, ceph::buffer::list &bl, uint32_t op_flags = 0) override; // Helpers @@ -228,6 +240,8 @@ public: void set_collection_commit_queue(const coll_t &cid, ContextQueue *commit_queue) override; bool exists(CollectionHandle &c, const ghobject_t &old) override; + int set_collection_opts(CollectionHandle &c, + const pool_opts_t &opts) override; int list_collections(std::vector &ls) override; bool collection_exists(const coll_t &c) override; @@ -257,8 +271,6 @@ public: bool *per_pool_omap) override { return 0; } - int set_collection_opts(CollectionHandle &c, - const pool_opts_t &opts) override; int stat(CollectionHandle &c, const ghobject_t &oid, struct stat *st, bool allow_eio = false) override { return 0; @@ -325,7 +337,9 @@ public: } void set_fsid(uuid_d u) override {} uuid_d get_fsid() override { return {}; } - uint64_t estimate_objects_overhead(uint64_t num_objects) override; + uint64_t estimate_objects_overhead(uint64_t num_objects) override { + return num_objects * 300; + } objectstore_perf_stat_t get_cur_stats() override { return {}; } const PerfCounters *get_perf_counters() const override { return nullptr; }; };