Skip to content

Commit

Permalink
RPC refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherHogan committed Mar 11, 2021
1 parent 0b6e9d6 commit 8e0dc94
Show file tree
Hide file tree
Showing 7 changed files with 247 additions and 300 deletions.
6 changes: 2 additions & 4 deletions src/api/bucket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,14 @@ Bucket::Bucket(const std::string &initial_name,
std::to_string(kMaxBucketNameSize));
} else {
id_ = GetOrCreateBucketId(&hermes_->context_, &hermes_->rpc_, name_);
if (!Bucket::IsValid()) {
if (!IsValid()) {
throw std::runtime_error("Bucket id is invalid.");
}
}
}

bool Bucket::IsValid() const {
bool result = id_.as_int != 0;

return result;
return !IsNullBucketId(id_);
}

Status Bucket::Put(const std::string &name, const u8 *data, size_t size,
Expand Down
4 changes: 4 additions & 0 deletions src/api/vbucket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ namespace hermes {

namespace api {

bool VBucket::IsValid() const {
return !IsNullVBucketId(id_);
}

Status VBucket::Link(std::string blob_name, std::string bucket_name,
Context& ctx) {
(void)ctx;
Expand Down
9 changes: 8 additions & 1 deletion src/api/vbucket.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ class VBucket {
std::list<Trait *> attached_traits_;
Blob local_blob;
bool persist;
/** internal Hermes object owned by vbucket */
std::shared_ptr<Hermes> hermes_;

public:
/** internal Hermes object owned by vbucket */
VBucket(std::string initial_name, std::shared_ptr<Hermes> const &h,
bool persist, Context ctx)
: name_(initial_name),
Expand All @@ -52,8 +52,13 @@ class VBucket {
(void)ctx;
if (IsVBucketNameTooLong(name_)) {
id_.as_int = 0;
throw std::length_error("VBucket name exceeds maximum size of " +
std::to_string(kMaxVBucketNameSize));
} else {
id_ = GetOrCreateVBucketId(&hermes_->context_, &hermes_->rpc_, name_);
if (!IsValid()) {
throw std::runtime_error("Could not open or create VBucket");
}
}
}

Expand All @@ -62,6 +67,8 @@ class VBucket {
linked_blobs_.clear();
}

bool IsValid() const;

/** get the name of vbucket */
std::string GetName() const { return this->name_; }

Expand Down
Loading

0 comments on commit 8e0dc94

Please sign in to comment.