Hermes  0.9.5-beta
Hierarchical Distributed I/O Buffering System
traits.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_TRAITS_H
14 #define HERMES_TRAITS_H
15 
16 #include <unordered_map>
17 
18 #include "hermes.h"
19 #include "hermes_types.h"
20 
21 namespace hermes {
22 namespace api {
23 
24 #define HERMES_PERSIST_TRAIT 11
25 #define HERMES_WRITE_ONLY_TRAIT 12
26 
28 struct BlobInfo {
30  std::string bucket_name;
32  std::string blob_name;
33 };
34 
35 typedef BlobInfo TraitInput;
36 struct Trait;
37 using HermesPtr = std::shared_ptr<Hermes>;
38 
39 // TODO(chogan): I don't think we need to pass a Trait* to these callbacks
40 // anymore. That is a relic of an old implementation.
41 
43 typedef std::function<void(HermesPtr, TraitInput &, Trait *)> OnLinkCallback;
45 typedef std::function<void(HermesPtr, VBucketID, Trait *)> OnAttachCallback;
46 
52 struct Trait {
56  std::vector<TraitID> conflict_traits;
60  OnAttachCallback onAttachFn;
62  OnAttachCallback onDetachFn;
64  OnLinkCallback onLinkFn;
66  OnLinkCallback onUnlinkFn;
68  OnLinkCallback onGetFn;
69 
73  Trait() {}
74 
81  Trait(TraitID id, const std::vector<TraitID> &conflict_traits,
82  TraitType type);
83 };
84 
89 struct PersistTrait : public Trait {
91  std::string filename;
93  std::unordered_map<std::string, u64> offset_map;
96 
98  using OffsetMap = std::unordered_map<std::string, u64>;
99 
101  explicit PersistTrait(bool synchronous);
102 
104  explicit PersistTrait(const std::string &filename,
105  const OffsetMap &offset_map, bool synchronous = false);
106 
110  void onAttach(HermesPtr hermes, VBucketID id, Trait *trait);
111 
113  void onDetach(HermesPtr hermes, VBucketID id, Trait *trait);
114 
118  void onLink(HermesPtr hermes, TraitInput &input, Trait *trait);
119 
121  void onUnlink(HermesPtr hermes, TraitInput &input, Trait *trait);
122 };
123 
130 struct WriteOnlyTrait : public Trait {
132  WriteOnlyTrait();
133 
135  void onAttach(HermesPtr hermes, VBucketID id, Trait *trait);
136 
138  void onDetach(HermesPtr hermes, VBucketID id, Trait *trait);
139 
143  void onLink(HermesPtr hermes, TraitInput &input, Trait *trait);
144 
146  void onUnlink(HermesPtr hermes, TraitInput &input, Trait *trait);
147 };
148 
149 } // namespace api
150 } // namespace hermes
151 
152 #endif // HERMES_TRAITS_H
TraitType
Trait types.
Definition: hermes_types.h:428
Definition: adapter_utils.cc:35
u64 TraitID
Definition: hermes_types.h:421
Definition: traits.h:28
std::string bucket_name
Definition: traits.h:30
std::string blob_name
Definition: traits.h:32
Engable persisting a VBucket's linked Blobs to permanent storage.
Definition: traits.h:89
std::string filename
Definition: traits.h:91
void onUnlink(HermesPtr hermes, TraitInput &input, Trait *trait)
Currently a no-op.
Definition: traits.cc:92
bool synchronous
Definition: traits.h:95
PersistTrait(bool synchronous)
void onAttach(HermesPtr hermes, VBucketID id, Trait *trait)
Definition: traits.cc:51
std::unordered_map< std::string, u64 > offset_map
Definition: traits.h:93
std::unordered_map< std::string, u64 > OffsetMap
Definition: traits.h:98
void onDetach(HermesPtr hermes, VBucketID id, Trait *trait)
Currently a no-op.
Definition: traits.cc:66
void onLink(HermesPtr hermes, TraitInput &input, Trait *trait)
Definition: traits.cc:72
Base class for Traits, which can attach functionality to VBuckets.
Definition: traits.h:52
OnLinkCallback onUnlinkFn
Definition: traits.h:66
OnAttachCallback onDetachFn
Definition: traits.h:62
OnLinkCallback onGetFn
Definition: traits.h:68
OnAttachCallback onAttachFn
Definition: traits.h:60
TraitType type
Definition: traits.h:58
TraitID id
Definition: traits.h:54
OnLinkCallback onLinkFn
Definition: traits.h:64
Trait()
Default constructor.
Definition: traits.h:73
std::vector< TraitID > conflict_traits
Definition: traits.h:56
Marks the Blobs in a VBucket as write-only.
Definition: traits.h:130
void onAttach(HermesPtr hermes, VBucketID id, Trait *trait)
Currently a no-op.
Definition: traits.cc:114
void onDetach(HermesPtr hermes, VBucketID id, Trait *trait)
Currently a no-op.
Definition: traits.cc:120
void onUnlink(HermesPtr hermes, TraitInput &input, Trait *trait)
Currently a no-op.
Definition: traits.cc:138
void onLink(HermesPtr hermes, TraitInput &input, Trait *trait)
Definition: traits.cc:126
Definition: hermes_types.h:388