Skip to content

Commit

Permalink
Merge pull request #64 from hariharan-devarajan/hariharan/vbucket_trait
Browse files Browse the repository at this point in the history
Hariharan/vbucket trait
  • Loading branch information
ChristopherHogan committed Jan 14, 2021
2 parents b4c03d5 + 0f00327 commit 71ccd1b
Show file tree
Hide file tree
Showing 22 changed files with 763 additions and 123 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ GTAGS

/cmake-build-debug/
/.idea/
/.clang-format
__pycache__/
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ endif()

if(NOT CMAKE_CXX_FLAGS)
#TODO: add -Werror
set (CMAKE_CXX_FLAGS "-Wall -Wextra ${CMAKE_CXX_FLAGS}")
set (CMAKE_CXX_FLAGS "-Wall -Wextra ${CMAKE_CXX_FLAGS} -DCATCH_CONFIG_FAST_COMPILE")
message (STATUS "Warnings Configuration: default: ${CMAKE_CXX_FLAGS}")
endif()

Expand Down
3 changes: 1 addition & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ set(HERMES_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/api/hermes.cc
${CMAKE_CURRENT_SOURCE_DIR}/api/vbucket.cc
${CMAKE_CURRENT_SOURCE_DIR}/buffer_pool.cc
${CMAKE_CURRENT_SOURCE_DIR}/data_placement_engine.cc
)
${CMAKE_CURRENT_SOURCE_DIR}/data_placement_engine.cc)

#------------------------------------------------------------------------------
# Libraries
Expand Down
8 changes: 8 additions & 0 deletions src/api/hermes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ void Hermes::AppBarrier() {
hermes::SubBarrier(&comm_);
}

bool Hermes::BucketContainsBlob(const std::string &bucket_name,
const std::string &blob_name) {
BucketID bucket_id = GetBucketIdByName(&context_, &rpc_, bucket_name.c_str());
bool result = hermes::ContainsBlob(&context_, &rpc_, bucket_id, blob_name);

return result;
}

int Hermes::GetProcessRank() {
int result = comm_.sub_proc_id;

Expand Down
4 changes: 4 additions & 0 deletions src/api/hermes.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "hermes_types.h"
#include "buffer_pool.h"
#include "metadata_management.h"
#include "rpc.h"
#include "id.h"

Expand Down Expand Up @@ -58,6 +59,9 @@ class Hermes {
void *GetAppCommunicator();
void Finalize(bool force_rpc_shutdown = false);

bool BucketContainsBlob(const std::string &bucket_name,
const std::string &blob_name);

// MPI comms.
// proxy/reference to Hermes core
};
Expand Down
52 changes: 52 additions & 0 deletions src/api/traits.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "traits.h"

#include <functional>

namespace hermes {
namespace api {
Trait::Trait(TraitID id, TraitIdArray conflict_traits, TraitType type)
: id(id),
conflict_traits(conflict_traits),
type(type),
onAttachFn(nullptr),
onDetachFn(nullptr),
onLinkFn(nullptr),
onUnlinkFn(nullptr) {}

FileMappingTrait::FileMappingTrait(
std::string &filename, std::unordered_map<std::string, u64> &offset_map,
TraitCallback flush_cb, TraitCallback load_cb)
: Trait(HERMES_FILE_TRAIT, TraitIdArray(), TraitType::FILE_MAPPING),
flush_cb(flush_cb),
load_cb(load_cb),
filename(filename),
offset_map(offset_map) {
this->onAttachFn = std::bind(&FileMappingTrait::onAttach, this,
std::placeholders::_1, std::placeholders::_2);
this->onDetachFn = std::bind(&FileMappingTrait::onDetach, this,
std::placeholders::_1, std::placeholders::_2);
this->onLinkFn = std::bind(&FileMappingTrait::onLink, this,
std::placeholders::_1, std::placeholders::_2);
this->onUnlinkFn = std::bind(&FileMappingTrait::onUnlink, this,
std::placeholders::_1, std::placeholders::_2);
}
void FileMappingTrait::onAttach(TraitInput &input, Trait *trait) {
if (load_cb) {
load_cb(input, trait);
// TODO(hari): @errorhandling Check if load was successful
}
}
void FileMappingTrait::onDetach(TraitInput &input, Trait *trait) {
if (flush_cb) {
flush_cb(input, trait);
// TODO(hari): @errorhandling Check if flush was successful
}
}
void FileMappingTrait::onLink(TraitInput &input, Trait *trait) {
onAttach(input, trait);
}
void FileMappingTrait::onUnlink(TraitInput &input, Trait *trait) {
onDetach(input, trait);
}
} // namespace api
} // namespace hermes
50 changes: 50 additions & 0 deletions src/api/traits.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#ifndef HERMES_TRAITS_H
#define HERMES_TRAITS_H

#include <unordered_map>

#include "hermes_types.h"

namespace hermes {
namespace api {

struct BlobInfo {
std::string bucket_name;
std::string blob_name;
};

typedef BlobInfo TraitInput;
struct Trait;
typedef std::function<void(TraitInput &, Trait *)> TraitCallback;

struct Trait {
TraitID id;
TraitIdArray conflict_traits;
TraitType type;
TraitCallback onAttachFn;
TraitCallback onDetachFn;
TraitCallback onLinkFn;
TraitCallback onUnlinkFn;
Trait(TraitID id, TraitIdArray conflict_traits, TraitType type);
};

#define HERMES_FILE_TRAIT 10

struct FileMappingTrait : public Trait {
public:
TraitCallback flush_cb;
TraitCallback load_cb;
std::string filename;
std::unordered_map<std::string, u64> offset_map;
FileMappingTrait(std::string &filename,
std::unordered_map<std::string, u64> &offset_map,
TraitCallback flush_cb, TraitCallback load_cb);
void onAttach(TraitInput &blob, Trait *trait);
void onDetach(TraitInput &blob, Trait *trait);
void onLink(TraitInput &blob, Trait *trait);
void onUnlink(TraitInput &blob, Trait *trait);
};
} // namespace api
} // namespace hermes

#endif // HERMES_TRAITS_H
Loading

0 comments on commit 71ccd1b

Please sign in to comment.