Skip to content

Commit

Permalink
Add API calls that use default Context
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherHogan committed Apr 7, 2021
1 parent 11e269e commit 6cf9a2f
Show file tree
Hide file tree
Showing 14 changed files with 236 additions and 171 deletions.
73 changes: 58 additions & 15 deletions src/api/bucket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;

Expand All @@ -94,7 +102,14 @@ 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) {
size_t result = Get(name, user_blob, ctx_);

return result;
}

size_t Bucket::Get(const std::string &name, Blob &user_blob,
const Context &ctx) {
(void)ctx;

size_t ret = 0;
Expand Down Expand Up @@ -128,7 +143,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;

Expand All @@ -138,9 +159,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;

Expand Down Expand Up @@ -183,16 +211,13 @@ std::vector<std::string> Bucket::GetBlobNames(Predicate pred,
return std::vector<std::string>();
}

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;

Expand All @@ -209,7 +234,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
Expand All @@ -224,7 +255,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;

Expand All @@ -237,7 +274,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;

Expand Down
47 changes: 24 additions & 23 deletions src/api/bucket.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Bucket {
}

Bucket(const std::string &initial_name, std::shared_ptr<Hermes> const &h,
Context ctx);
Context ctx = Context());

/**
* \brief Releases the Bucket, decrementing its reference count
Expand All @@ -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;
Expand Down Expand Up @@ -96,7 +92,7 @@ class Bucket {
*
*/
Status Put(const std::string &name, const u8 *data, size_t size,
Context &ctx);
const Context &ctx);

/**
*
Expand All @@ -108,7 +104,7 @@ class Bucket {
*/
template<typename T>
Status Put(std::vector<std::string> &names,
std::vector<std::vector<T>> &blobs, Context &ctx);
std::vector<std::vector<T>> &blobs, const Context &ctx);

/**
*
Expand All @@ -123,29 +119,32 @@ class Bucket {
template<typename T>
Status PlaceBlobs(std::vector<PlacementSchema> &schemas,
const std::vector<std::vector<T>> &blobs,
const std::vector<std::string> &names, Context &ctx);
const std::vector<std::string> &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);

/** get blob(s) on this bucket according to predicate */
/** use provides buffer */
template<class Predicate>
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);
Expand All @@ -157,28 +156,29 @@ class Bucket {
template<class Predicate>
std::vector<std::string> 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
*
* 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<typename T>
Expand All @@ -199,7 +199,8 @@ Status Bucket::Put(const std::string &name, const std::vector<T> &data) {
template<typename T>
Status Bucket::PlaceBlobs(std::vector<PlacementSchema> &schemas,
const std::vector<std::vector<T>> &blobs,
const std::vector<std::string> &names, Context &ctx) {
const std::vector<std::string> &names,
const Context &ctx) {
Status result;

for (size_t i = 0; i < schemas.size(); ++i) {
Expand All @@ -226,7 +227,7 @@ Status Bucket::Put(std::vector<std::string> &names,

template<typename T>
Status Bucket::Put(std::vector<std::string> &names,
std::vector<std::vector<T>> &blobs, Context &ctx) {
std::vector<std::vector<T>> &blobs, const Context &ctx) {
Status ret;

for (auto &name : names) {
Expand Down
32 changes: 31 additions & 1 deletion src/api/vbucket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -126,6 +138,12 @@ std::vector<std::string> VBucket::GetLinks(Predicate pred, Context& ctx) {
return std::vector<std::string>();
}

Status VBucket::Attach(Trait* trait) {
Status result = Attach(trait, ctx_);

return result;
}

Status VBucket::Attach(Trait* trait, Context& ctx) {
(void)ctx;
(void)trait;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -214,6 +238,12 @@ std::vector<TraitID> 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;
Expand Down
Loading

0 comments on commit 6cf9a2f

Please sign in to comment.