diff --git a/src/api/bucket.cc b/src/api/bucket.cc index 03addea3f..7170ccab4 100644 --- a/src/api/bucket.cc +++ b/src/api/bucket.cc @@ -45,12 +45,20 @@ Bucket::~Bucket() { } } +std::string Bucket::GetName() const { + return name_; +} + +u64 Bucket::GetId() const { + return id_.as_int; +} + bool Bucket::IsValid() const { return !IsNullBucketId(id_); } Status Bucket::Put(const std::string &name, const u8 *data, size_t size, - Context &ctx) { + const Context &ctx) { Status result; if (size > 0 && nullptr == data) { @@ -76,7 +84,7 @@ Status Bucket::Put(const std::string &name, const u8 *data, size_t size) { } size_t Bucket::GetBlobSize(Arena *arena, const std::string &name, - Context &ctx) { + const Context &ctx) { (void)ctx; size_t result = 0; @@ -94,14 +102,21 @@ size_t Bucket::GetBlobSize(Arena *arena, const std::string &name, return result; } -size_t Bucket::Get(const std::string &name, Blob &user_blob, Context &ctx) { +size_t Bucket::Get(const std::string &name, Blob &user_blob, + const Context &ctx) { size_t ret = Get(name, user_blob.data(), user_blob.size(), ctx); return ret; } +size_t Bucket::Get(const std::string &name, Blob &user_blob) { + size_t result = Get(name, user_blob, ctx_); + + return result; +} + size_t Bucket::Get(const std::string &name, void *user_blob, size_t blob_size, - Context &ctx) { + const Context &ctx) { (void)ctx; size_t ret = 0; @@ -128,7 +143,7 @@ size_t Bucket::Get(const std::string &name, void *user_blob, size_t blob_size, } std::vector Bucket::Get(const std::vector &names, - std::vector &blobs, Context &ctx) { + std::vector &blobs, const Context &ctx) { std::vector result(names.size(), 0); if (names.size() == blobs.size()) { for (size_t i = 0; i < result.size(); ++i) { @@ -154,7 +169,13 @@ Status Bucket::GetV(void *user_blob, Predicate pred, Context &ctx) { return ret; } -Status Bucket::DeleteBlob(const std::string &name, Context &ctx) { +Status Bucket::DeleteBlob(const std::string &name) { + Status result = DeleteBlob(name, ctx_); + + return result; +} + +Status Bucket::DeleteBlob(const std::string &name, const Context &ctx) { (void)ctx; Status ret; @@ -164,9 +185,16 @@ Status Bucket::DeleteBlob(const std::string &name, Context &ctx) { return ret; } +Status Bucket::RenameBlob(const std::string &old_name, + const std::string &new_name) { + Status result = RenameBlob(old_name, new_name, ctx_); + + return result; +} + Status Bucket::RenameBlob(const std::string &old_name, const std::string &new_name, - Context &ctx) { + const Context &ctx) { (void)ctx; Status ret; @@ -209,16 +237,13 @@ std::vector Bucket::GetBlobNames(Predicate pred, return std::vector(); } -struct bkt_info * Bucket::GetInfo(Context &ctx) { - (void)ctx; - struct bkt_info *ret = nullptr; - - LOG(INFO) << "Getting bucket information from bucket " << name_ << '\n'; +Status Bucket::Rename(const std::string &new_name) { + Status result = Rename(new_name, ctx_); - return ret; + return result; } -Status Bucket::Rename(const std::string &new_name, Context &ctx) { +Status Bucket::Rename(const std::string &new_name, const Context &ctx) { (void)ctx; Status ret; @@ -235,7 +260,13 @@ Status Bucket::Rename(const std::string &new_name, Context &ctx) { return ret; } -Status Bucket::Persist(const std::string &file_name, Context &ctx) { +Status Bucket::Persist(const std::string &file_name) { + Status result = Persist(file_name, ctx_); + + return result; +} + +Status Bucket::Persist(const std::string &file_name, const Context &ctx) { (void)ctx; // TODO(chogan): Once we have Traits, we need to let users control the mode // when we're, for example, updating an existing file. For now we just assume @@ -250,7 +281,13 @@ Status Bucket::Persist(const std::string &file_name, Context &ctx) { return result; } -Status Bucket::Release(Context &ctx) { +Status Bucket::Release() { + Status result = Release(ctx_); + + return result; +} + +Status Bucket::Release(const Context &ctx) { (void)ctx; Status ret; @@ -263,7 +300,13 @@ Status Bucket::Release(Context &ctx) { return ret; } -Status Bucket::Destroy(Context &ctx) { +Status Bucket::Destroy() { + Status result = Destroy(ctx_); + + return result; +} + +Status Bucket::Destroy(const Context &ctx) { (void)ctx; Status result; diff --git a/src/api/bucket.h b/src/api/bucket.h index 37f16f179..1c54f9926 100644 --- a/src/api/bucket.h +++ b/src/api/bucket.h @@ -46,7 +46,7 @@ class Bucket { } Bucket(const std::string &initial_name, std::shared_ptr const &h, - Context ctx); + Context ctx = Context()); /** * \brief Releases the Bucket, decrementing its reference count @@ -57,14 +57,10 @@ class Bucket { ~Bucket(); /** get the name of bucket */ - std::string GetName() const { - return this->name_; - } + std::string GetName() const; /** get the internal ID of the bucket */ - u64 GetId() const { - return id_.as_int; - } + u64 GetId() const; /** returns true if this Bucket has been created but not yet destroyed */ bool IsValid() const; @@ -96,7 +92,7 @@ class Bucket { * */ Status Put(const std::string &name, const u8 *data, size_t size, - Context &ctx); + const Context &ctx); /** * @@ -108,7 +104,7 @@ class Bucket { */ template Status Put(std::vector &names, - std::vector> &blobs, Context &ctx); + std::vector> &blobs, const Context &ctx); /** * @@ -123,29 +119,30 @@ class Bucket { template Status PlaceBlobs(std::vector &schemas, const std::vector> &blobs, - const std::vector &names, Context &ctx); + const std::vector &names, const Context &ctx); /** Get the size in bytes of the Blob referred to by `name` */ - size_t GetBlobSize(Arena *arena, const std::string &name, Context &ctx); + size_t GetBlobSize(Arena *arena, const std::string &name, const Context &ctx); /** get a blob on this bucket */ /** - if user_blob.size() == 0 => return the minimum buffer size needed */ /** - if user_blob.size() > 0 => copy user_blob.size() bytes */ /** to user_blob and return user_blob.size() */ /** use provides buffer */ - size_t Get(const std::string &name, Blob& user_blob, Context &ctx); + size_t Get(const std::string &name, Blob& user_blob, const Context &ctx); + size_t Get(const std::string &name, Blob& user_blob); /** * \brief Retrieve multiple Blobs in one call. */ std::vector Get(const std::vector &names, - std::vector &blobs, Context &ctx); + std::vector &blobs, const Context &ctx); /** * \brief Retrieve a Blob into a user buffer. */ size_t Get(const std::string &name, void *user_blob, size_t blob_size, - Context &ctx); + const Context &ctx); /** get blob(s) on this bucket according to predicate */ /** use provides buffer */ @@ -153,11 +150,13 @@ class Bucket { Status GetV(void *user_blob, Predicate pred, Context &ctx); /** delete a blob from this bucket */ - Status DeleteBlob(const std::string &name, Context &ctx); + Status DeleteBlob(const std::string &name, const Context &ctx); + Status DeleteBlob(const std::string &name); /** rename a blob on this bucket */ Status RenameBlob(const std::string &old_name, const std::string &new_name, - Context &ctx); + const Context &ctx); + Status RenameBlob(const std::string &old_name, const std::string &new_name); /** Returns true if the Bucket contains a Blob called `name` */ bool ContainsBlob(const std::string &name); @@ -169,16 +168,15 @@ class Bucket { template std::vector GetBlobNames(Predicate pred, Context &ctx); - /** get information from the bucket at level-of-detail */ - struct bkt_info * GetInfo(Context &ctx); - /** rename this bucket */ - Status Rename(const std::string& new_name, Context &ctx); + Status Rename(const std::string& new_name, const Context &ctx); + Status Rename(const std::string& new_name); /** Save this bucket's blobs to persistent storage. * * The blobs are written in the same order in which they are `Put`. */ - Status Persist(const std::string &file_name, Context &ctx); + Status Persist(const std::string &file_name, const Context &ctx); + Status Persist(const std::string &file_name); /** * \brief Release this Bucket @@ -186,11 +184,13 @@ class Bucket { * This simpley decrements the refcount to this Bucket in the Hermes metadata. * To free resources associated with this Bucket, call Bucket::Destroy. */ - Status Release(Context &ctx); + Status Release(const Context &ctx); + Status Release(); /** destroy this bucket */ /** ctx controls "aggressiveness */ - Status Destroy(Context &ctx); + Status Destroy(const Context &ctx); + Status Destroy(); }; template @@ -211,7 +211,8 @@ Status Bucket::Put(const std::string &name, const std::vector &data) { template Status Bucket::PlaceBlobs(std::vector &schemas, const std::vector> &blobs, - const std::vector &names, Context &ctx) { + const std::vector &names, + const Context &ctx) { Status result; for (size_t i = 0; i < schemas.size(); ++i) { @@ -238,7 +239,7 @@ Status Bucket::Put(std::vector &names, template Status Bucket::Put(std::vector &names, - std::vector> &blobs, Context &ctx) { + std::vector> &blobs, const Context &ctx) { Status ret; for (auto &name : names) { diff --git a/src/api/vbucket.cc b/src/api/vbucket.cc index 8affcdd75..ac8b2c53c 100644 --- a/src/api/vbucket.cc +++ b/src/api/vbucket.cc @@ -27,6 +27,12 @@ bool VBucket::IsValid() const { return !IsNullVBucketId(id_); } +Status VBucket::Link(std::string blob_name, std::string bucket_name) { + Status result = Link(blob_name, bucket_name, ctx_); + + return result; +} + Status VBucket::Link(std::string blob_name, std::string bucket_name, Context& ctx) { (void)ctx; @@ -57,6 +63,12 @@ Status VBucket::Link(std::string blob_name, std::string bucket_name, return ret; } +Status VBucket::Unlink(std::string blob_name, std::string bucket_name) { + Status result = Unlink(blob_name, bucket_name, ctx_); + + return result; +} + Status VBucket::Unlink(std::string blob_name, std::string bucket_name, Context& ctx) { (void)ctx; @@ -90,7 +102,7 @@ Status VBucket::Unlink(std::string blob_name, std::string bucket_name, return ret; } -bool VBucket::Contain_blob(std::string blob_name, std::string bucket_name) { +bool VBucket::ContainsBlob(std::string blob_name, std::string bucket_name) { bool ret = false; std::string bk_tmp, blob_tmp; @@ -126,6 +138,12 @@ std::vector VBucket::GetLinks(Predicate pred, Context& ctx) { return std::vector(); } +Status VBucket::Attach(Trait* trait) { + Status result = Attach(trait, ctx_); + + return result; +} + Status VBucket::Attach(Trait* trait, Context& ctx) { (void)ctx; (void)trait; @@ -160,6 +178,12 @@ Status VBucket::Attach(Trait* trait, Context& ctx) { return ret; } +Status VBucket::Detach(Trait* trait) { + Status result = Detach(trait, ctx_); + + return result; +} + Status VBucket::Detach(Trait* trait, Context& ctx) { (void)ctx; (void)trait; @@ -214,6 +238,12 @@ std::vector VBucket::GetTraits(Predicate pred, Context& ctx) { return attached_traits; } +Status VBucket::Delete() { + Status result = Delete(ctx_); + + return result; +} + Status VBucket::Delete(Context& ctx) { (void)ctx; Status ret; diff --git a/src/api/vbucket.h b/src/api/vbucket.h index eb40217a0..8370f9c73 100644 --- a/src/api/vbucket.h +++ b/src/api/vbucket.h @@ -37,19 +37,21 @@ class VBucket { bool persist; /** internal Hermes object owned by vbucket */ std::shared_ptr hermes_; + /** The Context for this VBucket. */ + Context ctx_; public: VBucket(std::string initial_name, std::shared_ptr const &h, - bool persist, Context ctx) + bool persist, Context ctx = Context()) : name_(initial_name), id_({0, 0}), linked_blobs_(), attached_traits_(), local_blob(), persist(persist), - hermes_(h) { + hermes_(h), + ctx_(ctx) { LOG(INFO) << "Create VBucket " << initial_name << std::endl; - (void)ctx; if (IsVBucketNameTooLong(name_)) { id_.as_int = 0; throw std::length_error("VBucket name exceeds maximum size of " + @@ -74,12 +76,14 @@ class VBucket { /** link a blob to this vbucket */ Status Link(std::string blob_name, std::string bucket_name, Context &ctx); + Status Link(std::string blob_name, std::string bucket_name); /** unlink a blob from this vbucket */ Status Unlink(std::string blob_name, std::string bucket_name, Context &ctx); + Status Unlink(std::string blob_name, std::string bucket_name); /** check if blob is in this vbucket */ - bool Contain_blob(std::string blob_name, std::string bucket_name); + bool ContainsBlob(std::string blob_name, std::string bucket_name); /** get a blob linked to this vbucket */ Blob &GetBlob(std::string blob_name, std::string bucket_name); @@ -91,9 +95,11 @@ class VBucket { /** attach a trait to this vbucket */ Status Attach(Trait *trait, Context &ctx); + Status Attach(Trait *trait); /** detach a trait to this vbucket */ Status Detach(Trait *trait, Context &ctx); + Status Detach(Trait *trait); /** retrieves the subset of attached traits satisfying pred */ template @@ -102,6 +108,7 @@ class VBucket { /** delete a vBucket */ /** decrements the links counts of blobs in buckets */ Status Delete(Context &ctx); + Status Delete(); }; // class VBucket } // namespace api diff --git a/src/buffer_organizer.cc b/src/buffer_organizer.cc index a27fa095b..d77bd1b75 100644 --- a/src/buffer_organizer.cc +++ b/src/buffer_organizer.cc @@ -17,7 +17,7 @@ namespace hermes { Status PlaceInHierarchy(SharedMemoryContext *context, RpcContext *rpc, SwapBlob swap_blob, const std::string &name, - api::Context &ctx) { + const api::Context &ctx) { std::vector schemas; std::vector sizes(1, swap_blob.size); Status result = CalculatePlacement(context, rpc, sizes, schemas, ctx); diff --git a/src/buffer_pool.cc b/src/buffer_pool.cc index 3e3f4b1f6..16e0352a2 100644 --- a/src/buffer_pool.cc +++ b/src/buffer_pool.cc @@ -1654,7 +1654,8 @@ size_t ReadFromSwap(SharedMemoryContext *context, Blob blob, api::Status PlaceBlob(SharedMemoryContext *context, RpcContext *rpc, PlacementSchema &schema, Blob blob, const std::string &name, BucketID bucket_id, - api::Context &ctx, bool called_from_buffer_organizer) { + const api::Context &ctx, + bool called_from_buffer_organizer) { api::Status result; if (ContainsBlob(context, rpc, bucket_id, name) diff --git a/src/buffer_pool.h b/src/buffer_pool.h index ed9dd30d9..7254054fa 100644 --- a/src/buffer_pool.h +++ b/src/buffer_pool.h @@ -489,11 +489,11 @@ u32 GetBufferSize(SharedMemoryContext *context, RpcContext *rpc, BufferID id); bool BufferIsByteAddressable(SharedMemoryContext *context, BufferID id); api::Status PlaceInHierarchy(SharedMemoryContext *context, RpcContext *rpc, SwapBlob swap_blob, const std::string &blob_name, - api::Context &ctx); + const api::Context &ctx); api::Status PlaceBlob(SharedMemoryContext *context, RpcContext *rpc, PlacementSchema &schema, Blob blob, const std::string &name, BucketID bucket_id, - api::Context &ctx, + const api::Context &ctx, bool called_from_buffer_organizer = false); api::Status StdIoPersistBucket(SharedMemoryContext *context, RpcContext *rpc, Arena *arena, BucketID bucket_id, diff --git a/src/rpc_thallium.cc b/src/rpc_thallium.cc index aeca5dac3..7c08b7e65 100644 --- a/src/rpc_thallium.cc +++ b/src/rpc_thallium.cc @@ -446,7 +446,7 @@ void StartBufferOrganizer(SharedMemoryContext *context, RpcContext *rpc, void TriggerBufferOrganizer(RpcContext *rpc, const char *func_name, const std::string &blob_name, SwapBlob swap_blob, - api::Context &ctx) { + const api::Context &ctx) { std::string server_name = GetServerName(rpc, rpc->node_id, true); std::string protocol = GetProtocol(rpc); tl::engine engine(protocol, THALLIUM_CLIENT_MODE, true); diff --git a/test/bucket_test.cc b/test/bucket_test.cc index 158bcc5c4..e027aedb4 100644 --- a/test/bucket_test.cc +++ b/test/bucket_test.cc @@ -50,12 +50,11 @@ void add_buffer_to_vector(hermes::api::Blob &vector, const char *buffer, int compress_blob(hermes::api::TraitInput &input, hermes::api::Trait *trait) { MyTrait *my_trait = (MyTrait *)trait; - hapi::Context ctx; - hapi::Bucket bkt(input.bucket_name, hermes_app, ctx); + hapi::Bucket bkt(input.bucket_name, hermes_app); hapi::Blob blob = {}; - size_t blob_size = bkt.Get(input.blob_name, blob, ctx); + size_t blob_size = bkt.Get(input.blob_name, blob); blob.resize(blob_size); - bkt.Get(input.blob_name, blob, ctx); + bkt.Get(input.blob_name, blob); // If Hermes is already linked with a compression library, you can call the // function directly here. If not, the symbol will have to be dynamically // loaded and probably stored as a pointer in the Trait. @@ -85,22 +84,21 @@ void TestBucketPersist(std::shared_ptr hermes) { constexpr int num_blobs = 3; constexpr int total_bytes = num_blobs * bytes_per_blob; - hapi::Context ctx; hapi::Status status; hapi::Blob blobx(bytes_per_blob, 'x'); hapi::Blob bloby(bytes_per_blob, 'y'); hapi::Blob blobz(bytes_per_blob, 'z'); - hapi::Bucket bkt("persistent_bucket", hermes, ctx); - status = bkt.Put("blobx", blobx, ctx); + hapi::Bucket bkt("persistent_bucket", hermes); + status = bkt.Put("blobx", blobx); Assert(status.Succeeded()); - status = bkt.Put("bloby", bloby, ctx); + status = bkt.Put("bloby", bloby); Assert(status.Succeeded()); - status = bkt.Put("blobz", blobz, ctx); + status = bkt.Put("blobz", blobz); Assert(status.Succeeded()); std::string saved_file("blobsxyz.txt"); - bkt.Persist(saved_file, ctx); - bkt.Destroy(ctx); + bkt.Persist(saved_file); + bkt.Destroy(); Assert(!bkt.IsValid()); FILE *bkt_file = fopen(saved_file.c_str(), "r"); @@ -139,13 +137,12 @@ void TestBucketPersist(std::shared_ptr hermes) { } void TestPutOverwrite(std::shared_ptr hermes) { - hapi::Context ctx; - hapi::Bucket bucket("overwrite", hermes, ctx); + hapi::Bucket bucket("overwrite", hermes); std::string blob_name("1"); size_t blob_size = KILOBYTES(6); hapi::Blob blob(blob_size, 'x'); - hapi::Status status = bucket.Put(blob_name, blob, ctx); + hapi::Status status = bucket.Put(blob_name, blob); Assert(status.Succeeded()); hermes::testing::GetAndVerifyBlob(bucket, blob_name, blob); @@ -153,49 +150,48 @@ void TestPutOverwrite(std::shared_ptr hermes) { // NOTE(chogan): Overwrite the data size_t new_size = KILOBYTES(9); hapi::Blob new_blob(new_size, 'z'); - status = bucket.Put(blob_name, new_blob, ctx); + status = bucket.Put(blob_name, new_blob); Assert(status.Succeeded()); hermes::testing::GetAndVerifyBlob(bucket, blob_name, new_blob); - bucket.Destroy(ctx); + bucket.Destroy(); } void TestCompressionTrait(std::shared_ptr hermes) { - hermes::api::Context ctx; hermes::api::Status status; const std::string bucket_name = "compression"; - hermes::api::Bucket my_bucket(bucket_name, hermes, ctx); + hermes::api::Bucket my_bucket(bucket_name, hermes); hermes::api::Blob p1(1024*1024*1, 255); hermes::api::Blob p2(p1); const std::string blob1_name = "Blob1"; const std::string blob2_name = "Blob2"; - Assert(my_bucket.Put(blob1_name, p1, ctx).Succeeded()); - Assert(my_bucket.Put(blob2_name, p2, ctx).Succeeded()); + Assert(my_bucket.Put(blob1_name, p1).Succeeded()); + Assert(my_bucket.Put(blob2_name, p2).Succeeded()); Assert(my_bucket.ContainsBlob(blob1_name)); Assert(my_bucket.ContainsBlob(blob2_name)); const std::string vbucket_name = "VB1"; - hermes::api::VBucket my_vb(vbucket_name, hermes, false, ctx); - my_vb.Link(blob1_name, bucket_name, ctx); - my_vb.Link(blob2_name, bucket_name, ctx); + hermes::api::VBucket my_vb(vbucket_name, hermes, false); + my_vb.Link(blob1_name, bucket_name); + my_vb.Link(blob2_name, bucket_name); - Assert(my_vb.Contain_blob(blob1_name, bucket_name) == 1); - Assert(my_vb.Contain_blob(blob2_name, bucket_name) == 1); + Assert(my_vb.ContainsBlob(blob1_name, bucket_name) == 1); + Assert(my_vb.ContainsBlob(blob2_name, bucket_name) == 1); MyTrait trait; trait.compress_level = 6; // Compression Trait compresses all blobs on Attach - Assert(my_vb.Attach(&trait, ctx).Succeeded()); + Assert(my_vb.Attach(&trait).Succeeded()); - Assert(my_vb.Unlink(blob1_name, bucket_name, ctx).Succeeded()); - Assert(my_vb.Detach(&trait, ctx).Succeeded()); + Assert(my_vb.Unlink(blob1_name, bucket_name).Succeeded()); + Assert(my_vb.Detach(&trait).Succeeded()); - Assert(my_vb.Delete(ctx).Succeeded()); - Assert(my_bucket.Destroy(ctx).Succeeded()); + Assert(my_vb.Delete().Succeeded()); + Assert(my_bucket.Destroy().Succeeded()); } void TestMultiGet(std::shared_ptr hermes) { diff --git a/test/buffer_pool_test.cc b/test/buffer_pool_test.cc index e1cde36c7..0315f20a8 100644 --- a/test/buffer_pool_test.cc +++ b/test/buffer_pool_test.cc @@ -115,7 +115,7 @@ static void TestGetBandwidths() { static hapi::Status ForceBlobToSwap(hapi::Hermes *hermes, hermes::u64 id, hapi::Blob &blob, const char *blob_name, - hapi::Context ctx) { + hapi::Context &ctx) { using namespace hermes; // NOLINT(*) PlacementSchema schema; schema.push_back({blob.size(), testing::DefaultRamTargetId()}); @@ -165,18 +165,18 @@ static void TestBlobOverwrite() { std::string blob_name("1"); size_t blob_size = KILOBYTES(2); hapi::Blob blob(blob_size, '1'); - hapi::Status status = bucket.Put(blob_name, blob, ctx); + hapi::Status status = bucket.Put(blob_name, blob); Assert(status.Succeeded()); Assert(buffers_available[slab_index] == 1); // NOTE(chogan): Overwrite the data hapi::Blob new_blob(blob_size, '2'); - Assert(bucket.Put(blob_name, new_blob, ctx).Succeeded()); + Assert(bucket.Put(blob_name, new_blob).Succeeded()); Assert(buffers_available[slab_index] == 1); - bucket.Destroy(ctx); + bucket.Destroy(); hermes->Finalize(true); } @@ -199,13 +199,13 @@ static void TestSwap() { Assert(bucket.ContainsBlob(blob_name)); hapi::Blob get_result; - size_t blob_size = bucket.Get(blob_name, get_result, ctx); + size_t blob_size = bucket.Get(blob_name, get_result); get_result.resize(blob_size); - blob_size = bucket.Get(blob_name, get_result, ctx); + blob_size = bucket.Get(blob_name, get_result); Assert(get_result == data); - bucket.Destroy(ctx); + bucket.Destroy(); hermes->Finalize(true); } @@ -222,7 +222,7 @@ static void TestBufferOrganizer() { // NOTE(chogan): Fill our single buffer with a blob. hapi::Blob data1(KILOBYTES(4), 'x'); std::string blob1_name("bo_blob1"); - hapi::Status status = bucket.Put(blob1_name, data1, ctx); + hapi::Status status = bucket.Put(blob1_name, data1); Assert(status.Succeeded()); Assert(bucket.ContainsBlob(blob1_name)); @@ -236,7 +236,7 @@ static void TestBufferOrganizer() { // NOTE(chogan): Delete the first blob, which will make room for the second, // and the buffer organizer should move it from swap space to the hierarchy. - bucket.DeleteBlob(blob1_name, ctx); + bucket.DeleteBlob(blob1_name); // NOTE(chogan): Give the BufferOrganizer time to finish. std::this_thread::sleep_for(std::chrono::seconds(3)); @@ -245,13 +245,13 @@ static void TestBufferOrganizer() { Assert(!bucket.BlobIsInSwap(blob2_name)); hapi::Blob get_result; - size_t blob_size = bucket.Get(blob2_name, get_result, ctx); + size_t blob_size = bucket.Get(blob2_name, get_result); get_result.resize(blob_size); - blob_size = bucket.Get(blob2_name, get_result, ctx); + blob_size = bucket.Get(blob2_name, get_result); Assert(get_result == data2); - bucket.Destroy(ctx); + bucket.Destroy(); hermes->Finalize(true); } diff --git a/test/end_to_end_test.cc b/test/end_to_end_test.cc index 05365f8ca..3bc9c6036 100644 --- a/test/end_to_end_test.cc +++ b/test/end_to_end_test.cc @@ -34,15 +34,14 @@ void TestPutGetBucket(hapi::Bucket &bucket, int app_rank, int app_size) { hapi::Blob put_data(bytes_per_rank, rand() % 255); - hapi::Context ctx; std::string blob_name = "test_blob" + std::to_string(app_rank); - hermes::api::Status status = bucket.Put(blob_name, put_data, ctx); + hermes::api::Status status = bucket.Put(blob_name, put_data); Assert(status.Succeeded()); hapi::Blob get_result; - size_t blob_size = bucket.Get(blob_name, get_result, ctx); + size_t blob_size = bucket.Get(blob_name, get_result); get_result.resize(blob_size); - blob_size = bucket.Get(blob_name, get_result, ctx); + blob_size = bucket.Get(blob_name, get_result); Assert(put_data == get_result); } @@ -50,14 +49,13 @@ void TestPutGetBucket(hapi::Bucket &bucket, int app_rank, int app_size) { void TestBulkTransfer(std::shared_ptr hermes, int app_rank) { size_t transfer_size = KILOBYTES(8); - hapi::Context ctx; - hapi::Bucket bucket(std::string("bulk_bucket"), hermes, ctx); + hapi::Bucket bucket(std::string("bulk_bucket"), hermes); std::string blob_name = "1"; hapi::Blob put_data(transfer_size, 'x'); if (app_rank == 0) { - hermes::api::Status status = bucket.Put(blob_name, put_data, ctx); + hermes::api::Status status = bucket.Put(blob_name, put_data); Assert(status.Succeeded()); } @@ -65,19 +63,19 @@ void TestBulkTransfer(std::shared_ptr hermes, int app_rank) { if (app_rank != 0) { hapi::Blob get_result; - size_t blob_size = bucket.Get(blob_name, get_result, ctx); + size_t blob_size = bucket.Get(blob_name, get_result); get_result.resize(blob_size); - blob_size = bucket.Get(blob_name, get_result, ctx); + blob_size = bucket.Get(blob_name, get_result); Assert(get_result == put_data); - bucket.Release(ctx); + bucket.Release(); } hermes->AppBarrier(); if (app_rank == 0) { - bucket.Destroy(ctx); + bucket.Destroy(); } } @@ -100,29 +98,27 @@ int main(int argc, char **argv) { int app_rank = hermes->GetProcessRank(); int app_size = hermes->GetNumProcesses(); - hapi::Context ctx; - // Each rank puts and gets its portion of a blob to a shared bucket - hapi::Bucket shared_bucket(std::string("test_bucket"), hermes, ctx); + hapi::Bucket shared_bucket(std::string("test_bucket"), hermes); TestPutGetBucket(shared_bucket, app_rank, app_size); if (app_rank != 0) { - shared_bucket.Release(ctx); + shared_bucket.Release(); } hermes->AppBarrier(); if (app_rank == 0) { - shared_bucket.Destroy(ctx); + shared_bucket.Destroy(); } hermes->AppBarrier(); // Each rank puts a whole blob to its own bucket hapi::Bucket own_bucket(std::string("test_bucket_") + - std::to_string(app_rank), hermes, ctx); + std::to_string(app_rank), hermes); TestPutGetBucket(own_bucket, app_rank, 0); - own_bucket.Destroy(ctx); + own_bucket.Destroy(); TestBulkTransfer(hermes, app_rank); } else { diff --git a/test/mdm_test.cc b/test/mdm_test.cc index 7fe402a3e..db8489e6f 100644 --- a/test/mdm_test.cc +++ b/test/mdm_test.cc @@ -46,18 +46,17 @@ static void TestLocalGetNextFreeBucketId(HermesPtr hermes) { // NOTE(chogan): Test that the app doesn't fail when creating more buckets // than the maximum allowed by the configuration. - hapi::Context ctx; MetadataManager *mdm = GetMetadataManagerFromContext(&hermes->context_); for (u32 i = 0; i < mdm->max_buckets; ++i) { std::string bucket_name = "bucket" + std::to_string(i); - hapi::Bucket bucket(bucket_name, hermes, ctx); + hapi::Bucket bucket(bucket_name, hermes); } std::string fail_name = "this_should_fail"; bool threw_runtime_error = false; try { - hapi::Bucket bucket(fail_name, hermes, ctx); + hapi::Bucket bucket(fail_name, hermes); } catch (const std::runtime_error& e) { threw_runtime_error = true; @@ -66,98 +65,96 @@ static void TestLocalGetNextFreeBucketId(HermesPtr hermes) { for (u32 i = 0; i < mdm->max_buckets; ++i) { std::string name = "bucket" + std::to_string(i); - hapi::Bucket bucket(name, hermes, ctx); - bucket.Destroy(ctx); + hapi::Bucket bucket(name, hermes); + bucket.Destroy(); } } static void TestGetOrCreateBucketId(HermesPtr hermes) { // NOTE(chogan): Create a bucket, close it, then open it again and ensure the // IDs are the same. - hapi::Context ctx; std::string bucket_name = "bucket"; - hapi::Bucket new_bucket(bucket_name, hermes, ctx); + hapi::Bucket new_bucket(bucket_name, hermes); u64 id = new_bucket.GetId(); - new_bucket.Release(ctx); + new_bucket.Release(); - hapi::Bucket existing_bucket(bucket_name, hermes, ctx); + hapi::Bucket existing_bucket(bucket_name, hermes); Assert(existing_bucket.GetId() == id); - existing_bucket.Destroy(ctx); + existing_bucket.Destroy(); } static void TestRenameBlob(HermesPtr hermes) { - hapi::Context ctx; std::string bucket_name = "rename_blob_test"; - hapi::Bucket bucket(bucket_name, hermes, ctx); + hapi::Bucket bucket(bucket_name, hermes); u8 data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; static_assert(sizeof(data[0]) == sizeof(u8)); std::string old_blob_name = "old_blob_name"; - Assert(bucket.Put(old_blob_name, data, sizeof(data), ctx).Succeeded()); + Assert(bucket.Put(old_blob_name, data, sizeof(data)).Succeeded()); std::string new_blob_name = "new_blob_name"; - bucket.RenameBlob(old_blob_name, new_blob_name, ctx); + bucket.RenameBlob(old_blob_name, new_blob_name); Assert(!bucket.ContainsBlob(old_blob_name)); + hapi::Context ctx; size_t blob_size = bucket.GetBlobSize(&hermes->trans_arena_, new_blob_name, ctx); Assert(blob_size == sizeof(data)); hapi::Blob retrieved_data(blob_size); - bucket.Get(new_blob_name, retrieved_data, ctx); + bucket.Get(new_blob_name, retrieved_data); for (size_t i = 0; i < retrieved_data.size(); ++i) { Assert(retrieved_data[i] == data[i]); } - bucket.Destroy(ctx); + bucket.Destroy(); } static void TestRenameBucket(HermesPtr hermes) { - hapi::Context ctx; std::string old_bucket_name = "old_bucket"; - hapi::Bucket bucket(old_bucket_name, hermes, ctx); + hapi::Bucket bucket(old_bucket_name, hermes); u8 data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; static_assert(sizeof(data[0]) == sizeof(u8)); std::string blob_name = "renamed_bucket_blob"; - Assert(bucket.Put(blob_name, data, sizeof(data), ctx).Succeeded()); + Assert(bucket.Put(blob_name, data, sizeof(data)).Succeeded()); std::string new_bucket_name = "new_bucket"; - bucket.Rename(new_bucket_name, ctx); - bucket.Release(ctx); + bucket.Rename(new_bucket_name); + bucket.Release(); - hapi::Bucket renamed_bucket(new_bucket_name, hermes, ctx); + hapi::Bucket renamed_bucket(new_bucket_name, hermes); + hapi::Context ctx; size_t blob_size = renamed_bucket.GetBlobSize(&hermes->trans_arena_, blob_name, ctx); Assert(blob_size == sizeof(data)); hapi::Blob retrieved_data(blob_size); - renamed_bucket.Get(blob_name, retrieved_data, ctx); + renamed_bucket.Get(blob_name, retrieved_data); for (size_t i = 0; i < retrieved_data.size(); ++i) { Assert(retrieved_data[i] == data[i]); } - renamed_bucket.Destroy(ctx); + renamed_bucket.Destroy(); } static void TestBucketRefCounting(HermesPtr hermes) { - hapi::Context ctx; std::string name = "refcounted_bucket"; - hapi::Bucket bucket1(name, hermes, ctx); - hapi::Bucket bucket2(name, hermes, ctx); + hapi::Bucket bucket1(name, hermes); + hapi::Bucket bucket2(name, hermes); // Refcount of "refcounted_bucket" is 2 - bucket1.Destroy(ctx); + bucket1.Destroy(); // Bucket should not have been destroyed Assert(bucket1.IsValid()); - bucket1.Release(ctx); + bucket1.Release(); // Refcount is 1 - bucket2.Destroy(ctx); + bucket2.Destroy(); Assert(!bucket2.IsValid()); Assert(!bucket1.IsValid()); @@ -165,11 +162,10 @@ static void TestBucketRefCounting(HermesPtr hermes) { static void TestMaxNameLength(HermesPtr hermes) { // Bucket with a name that's too large is invalid. - hapi::Context ctx; std::string long_bucket_name(kMaxBucketNameSize + 1, 'x'); bool threw_length_error = false; try { - hapi::Bucket invalid_bucket(long_bucket_name, hermes, ctx); + hapi::Bucket invalid_bucket(long_bucket_name, hermes); } catch (const std::length_error& e) { threw_length_error = true; @@ -179,9 +175,9 @@ static void TestMaxNameLength(HermesPtr hermes) { // Put fails when a blob name is too long std::string name = "b1"; std::string long_blob_name(kMaxBlobNameSize + 1, 'x'); - hapi::Bucket bucket(name, hermes, ctx); + hapi::Bucket bucket(name, hermes); hapi::Blob blob('x'); - Status status = bucket.Put(long_blob_name, blob, ctx); + Status status = bucket.Put(long_blob_name, blob); Assert(status.Failed()); Assert(!bucket.ContainsBlob(long_blob_name)); @@ -191,14 +187,14 @@ static void TestMaxNameLength(HermesPtr hermes) { std::string c = "c"; std::vector blob_names = {a, b, long_blob_name, c}; std::vector blobs = {blob, blob, blob, blob}; - status = bucket.Put(blob_names, blobs, ctx); + status = bucket.Put(blob_names, blobs); Assert(status.Failed()); Assert(!bucket.ContainsBlob(long_blob_name)); Assert(!bucket.ContainsBlob(a)); Assert(!bucket.ContainsBlob(b)); Assert(!bucket.ContainsBlob(c)); - bucket.Destroy(ctx); + bucket.Destroy(); } static void TestGetRelativeNodeId() { @@ -215,39 +211,37 @@ static void TestGetRelativeNodeId() { } static void TestDuplicateBlobNames(HermesPtr hermes) { - hapi::Context ctx; const size_t blob_size = 8; - hapi::Bucket b1("b1", hermes, ctx); - hapi::Bucket b2("b2", hermes, ctx); + hapi::Bucket b1("b1", hermes); + hapi::Bucket b2("b2", hermes); std::string blob_name("duplicate"); hapi::Blob blob1(blob_size, 'x'); hapi::Blob blob2(blob_size, 'z'); - Assert(b1.Put(blob_name, blob1, ctx).Succeeded()); + Assert(b1.Put(blob_name, blob1).Succeeded()); Assert(!b2.ContainsBlob(blob_name)); - Assert(b2.Put(blob_name, blob2, ctx).Succeeded()); + Assert(b2.Put(blob_name, blob2).Succeeded()); Assert(b1.ContainsBlob(blob_name)); Assert(b2.ContainsBlob(blob_name)); hapi::Blob result(blob_size, '0'); - Assert(b1.Get(blob_name, result, ctx) == blob_size); + Assert(b1.Get(blob_name, result) == blob_size); Assert(result == blob1); - Assert(b2.Get(blob_name, result, ctx) == blob_size); + Assert(b2.Get(blob_name, result) == blob_size); Assert(result == blob2); - Assert(b1.Destroy(ctx).Succeeded()); - Assert(b2.Destroy(ctx).Succeeded()); + Assert(b1.Destroy().Succeeded()); + Assert(b2.Destroy().Succeeded()); } static void TestGetBucketIdFromBlobId(HermesPtr hermes) { - hapi::Context ctx; const size_t blob_size = 8; - hapi::Bucket b1("b1", hermes, ctx); + hapi::Bucket b1("b1", hermes); std::string blob_name("blob1"); hapi::Blob blob1(blob_size, 'x'); - Assert(b1.Put(blob_name, blob1, ctx).Succeeded()); + Assert(b1.Put(blob_name, blob1).Succeeded()); BucketID b1_id = {}; b1_id.as_int = b1.GetId(); @@ -258,7 +252,7 @@ static void TestGetBucketIdFromBlobId(HermesPtr hermes) { hermes::GetBucketIdFromBlobId(&hermes->context_, &hermes->rpc_, blob_id); Assert(bucket_id.as_int == b1.GetId()); - Assert(b1.Destroy(ctx).Succeeded()); + Assert(b1.Destroy().Succeeded()); } static void TestHexStringToU64() { @@ -301,13 +295,12 @@ void TestSwapBlobsExistInBucket() { } std::shared_ptr hermes = hermes::InitHermes(&config, true); - hapi::Context ctx; - hermes::api::Bucket swap_bucket("swap_test", hermes, ctx); + hermes::api::Bucket swap_bucket("swap_test", hermes); hermes::api::Blob blob(128*1024, 255); auto success_blob_names = std::vector(); for (int i = 0; i < 32; i++) { std::string blob_name = "Blob" + std::to_string(i); - hapi::Status status = swap_bucket.Put(blob_name, blob, ctx); + hapi::Status status = swap_bucket.Put(blob_name, blob); if (!status.Failed()) { success_blob_names.push_back(blob_name); } diff --git a/test/test_utils.h b/test/test_utils.h index 8ebc85ffc..906a508db 100644 --- a/test/test_utils.h +++ b/test/test_utils.h @@ -78,13 +78,12 @@ TargetID DefaultFileTargetId() { void GetAndVerifyBlob(api::Bucket &bucket, const std::string &blob_name, const api::Blob &expected) { - api::Context ctx; api::Blob retrieved_blob; size_t expected_size = expected.size(); - size_t retrieved_size = bucket.Get(blob_name, retrieved_blob, ctx); + size_t retrieved_size = bucket.Get(blob_name, retrieved_blob); Assert(expected_size == retrieved_size); retrieved_blob.resize(retrieved_size); - retrieved_size = bucket.Get(blob_name, retrieved_blob, ctx); + retrieved_size = bucket.Get(blob_name, retrieved_blob); Assert(expected_size == retrieved_size); Assert(retrieved_blob == expected); } diff --git a/test/trait_test.cc b/test/trait_test.cc index da22264d2..eaf508518 100644 --- a/test/trait_test.cc +++ b/test/trait_test.cc @@ -93,13 +93,12 @@ TEST_CASE("CustomTrait", // REQUIRE(info.comm_size > 1); std::shared_ptr hermes_app = hermes::api::InitHermes(args.config.c_str(), true); - hermes::api::Context ctx; fs::path fullpath = args.directory; fullpath /= args.filename; std::string fullpath_str = fullpath.string(); SECTION("Basic") { - hermes::api::Bucket file_bucket(args.filename, hermes_app, ctx); - hermes::api::VBucket file_vbucket(args.filename, hermes_app, true, ctx); + hermes::api::Bucket file_bucket(args.filename, hermes_app); + hermes::api::VBucket file_vbucket(args.filename, hermes_app, true); auto offset_map = std::unordered_map(); auto blob_cmp = [](std::string a, std::string b) { return std::stol(a) < std::stol(b); @@ -108,21 +107,21 @@ TEST_CASE("CustomTrait", auto check_write = hermes::api::Blob(); for (size_t i = 0; i < args.iterations; ++i) { hermes::api::Status status = - file_bucket.Put(std::to_string(i), info.write_blob, ctx); + file_bucket.Put(std::to_string(i), info.write_blob); Assert(status.Succeeded()); blob_names.insert(std::to_string(i)); check_write.insert(check_write.end(), info.write_blob.begin(), info.write_blob.end()); } for (const auto& blob_name : blob_names) { - file_vbucket.Link(blob_name, args.filename, ctx); + file_vbucket.Link(blob_name, args.filename); offset_map.emplace(blob_name, std::stol(blob_name) * info.FILE_PAGE); } auto trait = hermes::api::FileMappingTrait(fullpath_str, offset_map, nullptr, NULL, NULL); - file_vbucket.Attach(&trait, ctx); - file_vbucket.Delete(ctx); - file_bucket.Destroy(ctx); + file_vbucket.Attach(&trait); + file_vbucket.Delete(); + file_bucket.Destroy(); REQUIRE(fs::exists(fullpath_str)); REQUIRE(fs::file_size(fullpath_str) == args.iterations * args.request_size); auto read_blob =