16 #include <glog/logging.h>
20 #include <unordered_map>
23 #include "dpe/round_robin.h"
25 #include "metadata_management.h"
57 LOG(INFO) <<
"Create NULL Bucket " << std::endl;
69 Bucket(
const std::string &initial_name, std::shared_ptr<Hermes>
const &h,
118 template <
typename T>
119 Status Put(
const std::string &name,
const std::vector<T> &data);
127 template <
typename T>
128 Status Put(
const std::string &name,
const std::vector<T> &data,
Context &ctx);
146 Status Put(
const std::string &name,
const u8 *data,
size_t size);
155 Status Put(
const std::string &name,
const u8 *data,
size_t size,
168 template <
typename T>
169 Status Put(
const std::vector<std::string> &names,
170 const std::vector<std::vector<T>> &blobs);
178 template <
typename T>
179 Status Put(
const std::vector<std::string> &names,
180 const std::vector<std::vector<T>> &blobs,
const Context &ctx);
208 size_t Get(
const std::string &name,
Blob &user_blob);
216 size_t Get(
const std::string &name,
Blob &user_blob,
const Context &ctx);
227 std::vector<size_t>
Get(
const std::vector<std::string> &names,
228 std::vector<Blob> &blobs,
const Context &ctx);
233 size_t Get(
const std::string &name,
void *user_blob,
size_t blob_size,
266 size_t GetNext(
u64 blob_index,
void *user_blob,
size_t blob_size,
275 std::vector<Blob> &blobs,
const Context &ctx);
283 template <
class Predicate>
310 Status RenameBlob(
const std::string &old_name,
const std::string &new_name);
341 template <
class Predicate>
394 f32 custom_importance = -1.f);
434 template <
typename T>
436 const std::vector<size_t> &sizes,
437 const std::vector<std::vector<T>> &blobs,
443 template <
typename T>
445 const std::vector<std::vector<T>> &blobs,
446 const std::vector<std::string> &names,
const Context &ctx);
449 template <
typename T>
452 Status result =
Put(name, (
u8 *)data.data(), data.size() *
sizeof(T), ctx);
457 template <
typename T>
464 template <
typename T>
466 const std::vector<std::vector<T>> &blobs,
467 const std::vector<std::string> &names,
471 for (
size_t i = 0; i < schemas.size(); ++i) {
474 blob.
data = (
u8 *)blobs[i].data();
475 blob.
size = blobs[i].size() *
sizeof(T);
476 LOG(INFO) <<
"Attaching blob '" << names[i] <<
"' to Bucket '" <<
name_
489 template <
typename T>
491 const std::vector<std::vector<T>> &blobs) {
497 template <
typename T>
499 const std::vector<size_t> &sizes,
500 const std::vector<std::vector<T>> &blobs,
502 std::vector<PlacementSchema> schemas;
509 result =
PlaceBlobs(schemas, blobs, names, ctx);
511 LOG(ERROR) << result.
Msg();
517 template <
typename T>
519 const std::vector<std::vector<T>> &blobs,
523 for (
auto &name : names) {
525 ret = BLOB_NAME_TOO_LONG;
526 LOG(ERROR) << ret.
Msg();
531 if (blobs.size() == 0) {
533 LOG(ERROR) << ret.
Msg();
538 size_t num_blobs = blobs.size();
539 std::vector<size_t> sizes_in_bytes(num_blobs);
540 for (
size_t i = 0; i < num_blobs; ++i) {
541 sizes_in_bytes[i] = blobs[i].size() *
sizeof(T);
548 for (
int i = 0; i < num_devices; ++i) {
549 ret =
PutInternal(names, sizes_in_bytes, blobs, ctx);
560 ret =
PutInternal(names, sizes_in_bytes, blobs, ctx);
563 ret = INVALID_BUCKET;
564 LOG(ERROR) << ret.
Msg();
Definition: hermes_status.h:80
bool Succeeded() const
Definition: hermes_status.h:86
bool Failed() const
Definition: hermes_status.h:94
std::string Msg() const
Definition: hermes_status.h:108
Definition: round_robin.h:25
int GetCurrentDeviceIndex() const
Definition: round_robin.cc:51
void SetCurrentDeviceIndex(int new_device_index)
Definition: round_robin.cc:55
A container for Blobs.
Definition: bucket.h:37
Status Put(const std::string &name, const std::vector< T > &data)
Put a Blob in this Bucket.
Definition: bucket.h:458
size_t GetBlobSize(const std::string &name, const Context &ctx)
Get the size in bytes of the Blob referred to by name.
Definition: bucket.cc:100
Status GetV(void *user_blob, Predicate pred, Context &ctx)
Get Blob%(s) from this Bucket according to a predicate.
Definition: bucket.cc:251
bool BlobIsInSwap(const std::string &name)
Return true if the Blob name is in swap space.
Definition: bucket.cc:312
void OrganizeBlob(const std::string &blob_name, f32 epsilon, f32 custom_importance=-1.f)
Allign blob_name's access speed to its importance.
Definition: bucket.cc:375
u64 GetId() const
Get the internal ID of the bucket.
Definition: bucket.cc:52
bool ContainsBlob(const std::string &name)
Returns true if the Bucket contains a Blob called name.
Definition: bucket.cc:305
Status Rename(const std::string &new_name)
Rename this Bucket.
Definition: bucket.cc:332
~Bucket()
Releases the Bucket, decrementing its reference count.
Definition: bucket.cc:41
size_t GetTotalBlobSize()
Return the total size in bytes of all Blobs in this Bucket.
Definition: bucket.cc:86
Status PutInternal(const std::vector< std::string > &names, const std::vector< size_t > &sizes, const std::vector< std::vector< T >> &blobs, const Context &ctx)
Internal version of Put, called by all overloads.
Definition: bucket.h:498
std::shared_ptr< Hermes > hermes_
Definition: bucket.h:46
std::string GetName() const
Get the user-facing name of the Bucket.
Definition: bucket.cc:48
std::string name_
Definition: bucket.h:40
Status Release()
Release this Bucket.
Definition: bucket.cc:381
Status Persist(const std::string &file_name)
Save this Bucket's Blobs to persistent storage.
Definition: bucket.cc:354
Status PlaceBlobs(std::vector< PlacementSchema > &schemas, const std::vector< std::vector< T >> &blobs, const std::vector< std::string > &names, const Context &ctx)
Low-level version of Put.
Definition: bucket.h:465
hermes::BucketID id_
Definition: bucket.h:42
bool IsValid() const
Return true if the Bucket is valid.
Definition: bucket.cc:56
Bucket()
Default constructor.
Definition: bucket.h:56
Context ctx_
Definition: bucket.h:48
std::vector< std::string > GetBlobNames(Predicate pred, Context &ctx)
Get a list of blob names filtered by pred.
Definition: bucket.cc:321
Status Destroy()
Destroy this Bucket.
Definition: bucket.cc:400
Status RenameBlob(const std::string &old_name, const std::string &new_name)
Rename a Blob in this Bucket.
Definition: bucket.cc:279
Status DeleteBlob(const std::string &name)
Delete a Blob from this Bucket.
Definition: bucket.cc:263
size_t Get(const std::string &name, Blob &user_blob)
Get a blob from this Bucket.
Definition: bucket.cc:133
size_t GetNext(u64 blob_index, Blob &user_blob)
Given an ordering of Blobs, retrieves the Blob at index blob_index + 1.
Definition: bucket.cc:189
std::vector< unsigned char > Blob
Definition: hermes_types.h:70
Definition: adapter_utils.cc:35
SystemViewState * GetLocalSystemViewState(MetadataManager *mdm)
Definition: metadata_management.cc:1018
api::Status PlaceBlob(SharedMemoryContext *context, RpcContext *rpc, PlacementSchema &schema, Blob blob, const std::string &name, BucketID bucket_id, const api::Context &ctx, bool called_from_buffer_organizer)
Definition: buffer_pool.cc:1898
float f32
Definition: hermes_types.h:48
uint8_t u8
Definition: hermes_types.h:40
bool IsBlobNameTooLong(const std::string &name)
Definition: metadata_management.cc:48
std::vector< std::pair< size_t, TargetID > > PlacementSchema
Definition: hermes_types.h:226
Status CalculatePlacement(SharedMemoryContext *context, RpcContext *rpc, const std::vector< size_t > &blob_sizes, std::vector< PlacementSchema > &output, const api::Context &api_context)
Definition: data_placement_engine.cc:111
uint64_t u64
Definition: hermes_types.h:43
Definition: memory_management.h:84
Definition: buffer_pool.h:427
u64 size
Definition: buffer_pool.h:431
u8 * data
Definition: buffer_pool.h:429
int num_devices
Definition: metadata_management.h:172
Definition: hermes_types.h:137
bool rr_retry
Definition: hermes_types.h:162
Definition: hermes_types.h:358
#define HERMES_BEGIN_TIMED_BLOCK(func_name)
Definition: utils.h:46
#define HERMES_END_TIMED_BLOCK()
Definition: utils.h:47