Hermes  0.9.5-beta
Hierarchical Distributed I/O Buffering System
metadata_management.h
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * Distributed under BSD 3-Clause license. *
3  * Copyright by The HDF Group. *
4  * Copyright by the Illinois Institute of Technology. *
5  * All rights reserved. *
6  * *
7  * This file is part of Hermes. The full Hermes copyright notice, including *
8  * terms governing use, modification, and redistribution, is contained in *
9  * the COPYING file, which can be found at the top directory. If you do not *
10  * have access to the file, you may request a copy from help@hdfgroup.org. *
11  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12 
13 #ifndef HERMES_METADATA_MANAGEMENT_H_
14 #define HERMES_METADATA_MANAGEMENT_H_
15 
16 #include <string.h>
17 
18 #include <atomic>
19 #include <string>
20 
21 #include "buffer_pool.h"
22 #include "memory_management.h"
23 
24 namespace hermes {
25 
26 static const u32 kGlobalMutexNodeId = 1;
28 struct RpcContext;
29 
45 struct ShmemString {
50 
51  ShmemString(const ShmemString &) = delete;
52  ShmemString(const ShmemString &&) = delete;
53  ShmemString &operator=(const ShmemString &) = delete;
54  ShmemString &operator=(const ShmemString &&) = delete;
55 };
56 
58 enum MapType {
59  kMapType_Bucket,
60  kMapType_VBucket,
61  kMapType_BlobId,
62  kMapType_BlobInfo,
63  kMapType_Count
64 };
65 
67 enum class ThresholdViolation { kMin, kMax };
68 
72 struct ViolationInfo {
75  size_t violation_size;
76 };
77 
81 struct Stats {
84 };
85 
86 const int kIdListChunkSize = 10;
90 struct IdList {
93 };
94 
98 struct BufferIdArray {
101 };
102 
106 struct BlobInfo {
111  bool stop;
113  BlobInfo() : last(0), stop(false) {
114  stats.recency = 0;
115  stats.frequency = 0;
116  lock.ticket.store(0);
117  lock.serving.store(0);
119  }
120 
122  BlobInfo &operator=(const BlobInfo &other) {
123  stats = other.stats;
124  lock.ticket.store(other.lock.ticket.load());
125  lock.serving.store(other.lock.serving.load());
127  last = other.last;
128  stop = other.stop;
129 
130  return *this;
131  }
132 };
133 
137 struct BucketInfo {
140  std::atomic<int> ref_count;
141  bool active;
142 };
143 
145 static constexpr int kMaxTraitsPerVBucket = 8;
146 
150 struct VBucketInfo {
153  std::atomic<int> ref_count;
154  std::atomic<int> async_flush_count;
157  bool active;
158 };
159 
167  std::atomic<u64> bytes_available[kMaxDevices];
173 };
174 
175 // TODO(chogan):
197  std::atomic<u64> *bytes_available;
201 };
202 
207  // All offsets are relative to the beginning of the MDM
208  ptrdiff_t bucket_info_offset;
214  ptrdiff_t rpc_state_offset;
215  ptrdiff_t host_names_offset;
220  ptrdiff_t id_heap_offset;
221  ptrdiff_t map_heap_offset;
223  ptrdiff_t bucket_map_offset;
224  ptrdiff_t vbucket_map_offset;
225  ptrdiff_t blob_id_map_offset;
231  // TODO(chogan): @optimization Should the TicketMutexes here be reader/writer
232  // locks?
233 
242 
253 
254  size_t map_seed;
265  std::atomic<u32> clock;
266 };
267 
268 struct RpcContext;
269 
273 void InitMetadataManager(MetadataManager *mdm, RpcContext *rpc, Arena *arena,
274  Config *config);
275 
280 
284 bool DestroyBucket(SharedMemoryContext *context, RpcContext *rpc,
285  const char *name, BucketID bucket_id);
286 
290 bool DestroyVBucket(SharedMemoryContext *context, RpcContext *rpc,
291  const char *name, VBucketID vbucket_id);
292 
297  BucketID bucket_id, const std::string &blob_name);
298 
302 void RenameBlob(SharedMemoryContext *context, RpcContext *rpc,
303  const std::string &old_name, const std::string &new_name,
304  BucketID bucket_id);
305 
309 void RenameBucket(SharedMemoryContext *context, RpcContext *rpc, BucketID id,
310  const std::string &old_name, const std::string &new_name);
311 
315 bool ContainsBlob(SharedMemoryContext *context, RpcContext *rpc,
316  BucketID bucket_id, const std::string &blob_name);
317 
322  RpcContext *rpc, BlobID blob_id,
323  u32 **sizes);
324 
329  const std::string &name, BucketID bucket_id,
330  bool track_stats = true);
331 
335 std::string GetBlobNameFromId(SharedMemoryContext *context, RpcContext *rpc,
336  BlobID blob_id);
337 
341 bool BlobIsInSwap(BlobID id);
342 
347  const std::string &name);
348 
353  const std::string &name);
354 
359  const char *blob_name, BucketID bucket_id,
360  const std::vector<BufferID> &buffer_ids,
361  TargetID effective_target, bool is_swap_blob = false,
362  bool called_from_buffer_organizer = false);
363 
368  BucketID id);
369 
373 std::vector<BufferID> SwapBlobToVec(SwapBlob swap_blob);
374 
378 SwapBlob VecToSwapBlob(std::vector<BufferID> &vec);
379 
384 
388 bool IsBlobNameTooLong(const std::string &name);
389 
393 bool IsBucketNameTooLong(const std::string &name);
394 
398 bool IsVBucketNameTooLong(const std::string &name);
399 
403 TargetID FindTargetIdFromDeviceId(const std::vector<TargetID> &targets,
404  DeviceID device_id);
405 
409 std::vector<TargetID> GetNeighborhoodTargets(SharedMemoryContext *context,
410  RpcContext *rpc);
414 std::vector<u64> GetRemainingTargetCapacities(
415  SharedMemoryContext *context, RpcContext *rpc,
416  const std::vector<TargetID> &targets);
420 std::vector<BlobID> GetBlobIds(SharedMemoryContext *context, RpcContext *rpc,
421  BucketID bucket_id);
422 
427  const char *name);
428 
433  BlobID blob_id);
434 
439  VBucketID id);
443 bool IsNullBucketId(BucketID id);
444 
448 bool IsNullVBucketId(VBucketID id);
449 
453 bool IsNullBlobId(BlobID id);
454 
459 
464 
469 
474 
479  const char *blob_name, const char *bucket_name,
480  VBucketID vbucket_id);
481 
486  BucketID bucket_id, BlobID blob_id);
487 
492  VBucketID vbucket_id, const char *blob_name,
493  const char *bucket_name);
494 
498 std::vector<BlobID> GetBlobsFromVBucketInfo(SharedMemoryContext *context,
499  RpcContext *rpc,
500  VBucketID vbucket_id);
501 
505 std::string GetBucketNameById(SharedMemoryContext *context, RpcContext *rpc,
506  BucketID id);
511  BlobID blob_id);
512 
517 
521 bool LockBlob(SharedMemoryContext *context, RpcContext *rpc, BlobID blob_id);
522 
526 bool UnlockBlob(SharedMemoryContext *context, RpcContext *rpc, BlobID blob_id);
527 
531 bool LocalLockBlob(SharedMemoryContext *context, BlobID blob_id);
532 
536 bool LocalUnlockBlob(SharedMemoryContext *context, BlobID blob_id);
537 
542 
547  BucketID bucket_id, BlobID old_blob_id,
548  BlobID new_blob_id);
554  BucketID bucket_id, BlobID old_blob_id,
555  BlobID new_blob_id);
556 
567 void MakeShmemString(ShmemString *sms, u8 *memory, const std::string &val);
568 
577 std::string GetShmemString(ShmemString *sms);
578 
579 } // namespace hermes
580 
581 #endif // HERMES_METADATA_MANAGEMENT_H_
Definition: adapter_utils.cc:35
BufferIdArray GetBufferIdsFromBlobId(Arena *arena, SharedMemoryContext *context, RpcContext *rpc, BlobID blob_id, u32 **sizes)
Definition: metadata_management.cc:696
bool LocalUnlockBlob(SharedMemoryContext *context, BlobID blob_id)
Definition: metadata_management.cc:1656
constexpr int kMaxDevices
Definition: hermes_types.h:184
void LocalBeginGlobalTicketMutex(MetadataManager *mdm)
MapType
Definition: metadata_management.h:58
SystemViewState * GetLocalSystemViewState(MetadataManager *mdm)
Definition: metadata_management.cc:1018
SwapBlob VecToSwapBlob(std::vector< BufferID > &vec)
Definition: metadata_management.cc:1255
void DecrementRefcount(SharedMemoryContext *context, RpcContext *rpc, BucketID id)
Definition: metadata_management.cc:999
ThresholdViolation
Definition: metadata_management.h:67
bool LockBlob(SharedMemoryContext *context, RpcContext *rpc, BlobID blob_id)
Definition: metadata_management.cc:1680
void BeginGlobalTicketMutex(SharedMemoryContext *context, RpcContext *rpc)
bool IsBucketNameTooLong(const std::string &name)
Definition: metadata_management.cc:55
bool IsNullVBucketId(VBucketID id)
Definition: metadata_management.cc:80
SwapBlob IdArrayToSwapBlob(BufferIdArray ids)
Definition: metadata_management.cc:1272
BucketID GetBucketId(SharedMemoryContext *context, RpcContext *rpc, const char *name)
Definition: metadata_management.cc:170
bool UnlockBlob(SharedMemoryContext *context, RpcContext *rpc, BlobID blob_id)
Definition: metadata_management.cc:1691
std::vector< BlobID > GetBlobIds(SharedMemoryContext *context, RpcContext *rpc, BucketID bucket_id)
Definition: metadata_management.cc:424
const int kIdListChunkSize
Definition: metadata_management.h:86
void RenameBucket(SharedMemoryContext *context, RpcContext *rpc, BucketID id, const std::string &old_name, const std::string &new_name)
Definition: metadata_management.cc:972
TargetID FindTargetIdFromDeviceId(const std::vector< TargetID > &targets, DeviceID device_id)
Definition: metadata_management.cc:1163
bool IsNullBucketId(BucketID id)
Definition: metadata_management.cc:75
static constexpr int kMaxTraitsPerVBucket
Definition: metadata_management.h:145
VBucketID GetOrCreateVBucketId(SharedMemoryContext *context, RpcContext *rpc, const std::string &name)
Definition: metadata_management.cc:573
void RemoveBlobFromBucketInfo(SharedMemoryContext *context, RpcContext *rpc, BucketID bucket_id, BlobID blob_id)
Definition: metadata_management.cc:859
void IncrementBlobStats(SharedMemoryContext *context, RpcContext *rpc, BlobID blob_id)
Definition: metadata_storage_stb_ds.cc:448
void AttachBlobToVBucket(SharedMemoryContext *context, RpcContext *rpc, const char *blob_name, const char *bucket_name, VBucketID vbucket_id)
Definition: metadata_management.cc:1513
void ReplaceBlobIdInBucket(SharedMemoryContext *context, RpcContext *rpc, BucketID bucket_id, BlobID old_blob_id, BlobID new_blob_id)
Definition: metadata_management.cc:596
void EndGlobalTicketMutex(SharedMemoryContext *context, RpcContext *rpc)
uint8_t u8
Definition: hermes_types.h:40
bool IsBlobNameTooLong(const std::string &name)
Definition: metadata_management.cc:48
void LocalIncrementBlobStats(MetadataManager *mdm, BlobID blob_id)
Definition: metadata_storage_stb_ds.cc:439
BlobID GetBlobId(SharedMemoryContext *context, RpcContext *rpc, const std::string &name, BucketID bucket_id, bool track_stats)
Definition: metadata_management.cc:227
void InitNeighborhoodTargets(SharedMemoryContext *context, RpcContext *rpc)
Definition: metadata_storage_stb_ds.cc:952
u16 DeviceID
Definition: hermes_types.h:51
void InitMetadataManager(MetadataManager *mdm, RpcContext *rpc, Arena *arena, Config *config)
Definition: metadata_management.cc:1289
BucketID GetOrCreateBucketId(SharedMemoryContext *context, RpcContext *rpc, const std::string &name)
Definition: metadata_management.cc:502
std::string GetBucketNameById(SharedMemoryContext *context, RpcContext *rpc, BucketID id)
Definition: metadata_management.cc:1557
void RenameBlob(SharedMemoryContext *context, RpcContext *rpc, const std::string &old_name, const std::string &new_name, BucketID bucket_id)
Definition: metadata_management.cc:889
bool IsNullBlobId(BlobID id)
Definition: metadata_management.cc:85
BucketID GetBucketIdFromBlobId(SharedMemoryContext *context, RpcContext *rpc, BlobID id)
Definition: metadata_management.cc:402
bool LocalLockBlob(SharedMemoryContext *context, BlobID blob_id)
Definition: metadata_management.cc:1617
bool BlobIsInSwap(BlobID id)
Definition: metadata_management.cc:652
bool DestroyBucket(SharedMemoryContext *context, RpcContext *rpc, const char *name, BucketID bucket_id)
Definition: metadata_management.cc:933
void LocalEndGlobalTicketMutex(MetadataManager *mdm)
uint32_t u32
Definition: hermes_types.h:42
std::string GetBlobNameFromId(SharedMemoryContext *context, RpcContext *rpc, BlobID blob_id)
Definition: metadata_management.cc:349
std::vector< BufferID > SwapBlobToVec(SwapBlob swap_blob)
Definition: metadata_management.cc:1240
std::vector< TargetID > GetNeighborhoodTargets(SharedMemoryContext *context, RpcContext *rpc)
Definition: metadata_management.cc:1448
void DestroyBlobByName(SharedMemoryContext *context, RpcContext *rpc, BucketID bucket_id, const std::string &blob_name)
Definition: metadata_management.cc:871
std::vector< BlobID > GetBlobsFromVBucketInfo(SharedMemoryContext *context, RpcContext *rpc, VBucketID vbucket_id)
Definition: metadata_management.cc:1531
void RemoveBlobFromVBucketInfo(SharedMemoryContext *context, RpcContext *rpc, VBucketID vbucket_id, const char *blob_name, const char *bucket_name)
Definition: metadata_management.cc:1543
static const u32 kGlobalMutexNodeId
Definition: metadata_management.h:26
u64 TraitID
Definition: hermes_types.h:421
bool ContainsBlob(SharedMemoryContext *context, RpcContext *rpc, BucketID bucket_id, const std::string &blob_name)
Definition: metadata_management.cc:903
bool DestroyVBucket(SharedMemoryContext *context, RpcContext *rpc, const char *name, VBucketID vbucket_id)
Definition: metadata_management.cc:948
uint64_t u64
Definition: hermes_types.h:43
std::string GetShmemString(ShmemString *sms)
Definition: metadata_management.cc:1718
bool IsVBucketNameTooLong(const std::string &name)
Definition: metadata_management.cc:62
void AttachBlobToBucket(SharedMemoryContext *context, RpcContext *rpc, const char *blob_name, BucketID bucket_id, const std::vector< BufferID > &buffer_ids, TargetID effective_target, bool is_swap_blob, bool called_from_buffer_organizer)
Definition: metadata_management.cc:750
void LocalReplaceBlobIdInBucket(SharedMemoryContext *context, BucketID bucket_id, BlobID old_blob_id, BlobID new_blob_id)
Definition: metadata_storage_stb_ds.cc:475
void MakeShmemString(ShmemString *sms, u8 *memory, const char *val, u32 size)
Definition: metadata_management.cc:1704
std::vector< u64 > GetRemainingTargetCapacities(SharedMemoryContext *context, RpcContext *rpc, const std::vector< TargetID > &targets)
Definition: metadata_management.cc:1502
Definition: memory_management.h:84
Definition: metadata_management.h:106
bool stop
Definition: metadata_management.h:111
u32 last
Definition: metadata_management.h:110
BlobInfo & operator=(const BlobInfo &other)
Definition: metadata_management.h:122
TicketMutex lock
Definition: metadata_management.h:108
Stats stats
Definition: metadata_management.h:107
TargetID effective_target
Definition: metadata_management.h:109
Definition: metadata_management.h:137
std::atomic< int > ref_count
Definition: metadata_management.h:140
ChunkedIdList blobs
Definition: metadata_management.h:139
BucketID next_free
Definition: metadata_management.h:138
bool active
Definition: metadata_management.h:141
Definition: metadata_management.h:98
BufferID * ids
Definition: metadata_management.h:99
u32 length
Definition: metadata_management.h:100
Definition: hermes_types.h:56
Definition: hermes_types.h:258
Definition: metadata_management.h:190
Thresholds bo_capacity_thresholds[kMaxDevices]
Definition: metadata_management.h:200
int num_devices
Definition: metadata_management.h:194
std::atomic< u64 > * bytes_available
Definition: metadata_management.h:197
u64 num_targets
Definition: metadata_management.h:192
u64 capacities[kMaxDevices]
Definition: metadata_management.h:195
Definition: metadata_management.h:90
u32 head_offset
Definition: metadata_management.h:91
u32 length
Definition: metadata_management.h:92
Definition: metadata_management.h:206
u32 global_system_view_state_node_id
Definition: metadata_management.h:260
ptrdiff_t global_system_view_state_offset
Definition: metadata_management.h:218
ptrdiff_t blob_id_map_offset
Definition: metadata_management.h:225
TicketMutex bucket_mutex
Definition: metadata_management.h:236
ptrdiff_t blob_info_map_offset
Definition: metadata_management.h:226
size_t map_seed
Definition: metadata_management.h:254
VBucketID first_free_vbucket
Definition: metadata_management.h:212
RwLock bucket_delete_lock
Definition: metadata_management.h:237
ptrdiff_t bucket_map_offset
Definition: metadata_management.h:223
std::atomic< u32 > clock
Definition: metadata_management.h:265
TicketMutex blob_id_map_mutex
Definition: metadata_management.h:248
ptrdiff_t vbucket_map_offset
Definition: metadata_management.h:224
IdList neighborhood_targets
Definition: metadata_management.h:257
u32 max_vbuckets
Definition: metadata_management.h:264
ptrdiff_t vbucket_info_offset
Definition: metadata_management.h:211
ptrdiff_t bucket_info_offset
Definition: metadata_management.h:208
ptrdiff_t host_names_offset
Definition: metadata_management.h:215
ptrdiff_t system_view_state_offset
Definition: metadata_management.h:217
ptrdiff_t host_numbers_offset
Definition: metadata_management.h:216
u32 num_buckets
Definition: metadata_management.h:261
TicketMutex id_mutex
Definition: metadata_management.h:252
ptrdiff_t rpc_state_offset
Definition: metadata_management.h:214
ptrdiff_t id_heap_offset
Definition: metadata_management.h:220
TicketMutex bucket_map_mutex
Definition: metadata_management.h:244
BucketID first_free_bucket
Definition: metadata_management.h:209
IdList node_targets
Definition: metadata_management.h:256
TicketMutex blob_info_map_mutex
Definition: metadata_management.h:250
u32 num_vbuckets
Definition: metadata_management.h:263
TicketMutex vbucket_map_mutex
Definition: metadata_management.h:246
ptrdiff_t map_heap_offset
Definition: metadata_management.h:221
TicketMutex vbucket_mutex
Definition: metadata_management.h:241
ptrdiff_t swap_filename_suffix_offset
Definition: metadata_management.h:229
u32 system_view_state_update_interval_ms
Definition: metadata_management.h:259
ptrdiff_t swap_filename_prefix_offset
Definition: metadata_management.h:228
u32 max_buckets
Definition: metadata_management.h:262
Definition: rpc.h:43
Definition: memory_management.h:53
Definition: buffer_pool.h:273
Definition: metadata_management.h:45
u32 offset
Definition: metadata_management.h:47
u32 size
Definition: metadata_management.h:49
Definition: metadata_management.h:81
u32 recency
Definition: metadata_management.h:82
u32 frequency
Definition: metadata_management.h:83
Definition: buffer_pool.h:440
Definition: metadata_management.h:163
int num_devices
Definition: metadata_management.h:172
u64 capacities[kMaxDevices]
Definition: metadata_management.h:165
std::atomic< u64 > bytes_available[kMaxDevices]
Definition: metadata_management.h:167
Thresholds bo_capacity_thresholds[kMaxDevices]
Definition: metadata_management.h:170
Definition: hermes_types.h:250
Definition: memory_management.h:36
std::atomic< u32 > serving
Definition: memory_management.h:38
std::atomic< u32 > ticket
Definition: memory_management.h:37
Definition: metadata_management.h:150
std::atomic< int > ref_count
Definition: metadata_management.h:153
TraitID traits[kMaxTraitsPerVBucket]
Definition: metadata_management.h:156
bool active
Definition: metadata_management.h:157
VBucketID next_free
Definition: metadata_management.h:151
ChunkedIdList blobs
Definition: metadata_management.h:152
std::atomic< int > async_flush_count
Definition: metadata_management.h:154
Definition: metadata_management.h:72
ThresholdViolation violation
Definition: metadata_management.h:74
size_t violation_size
Definition: metadata_management.h:75
TargetID target_id
Definition: metadata_management.h:73
Definition: hermes_types.h:405
Definition: hermes_types.h:358
Definition: buffer_pool.h:93
Definition: hermes_types.h:198
u64 as_int
Definition: hermes_types.h:213
Definition: hermes_types.h:388