-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathRDG.h
More file actions
301 lines (238 loc) · 10.8 KB
/
RDG.h
File metadata and controls
301 lines (238 loc) · 10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
#ifndef KATANA_LIBTSUBA_TSUBA_RDG_H_
#define KATANA_LIBTSUBA_TSUBA_RDG_H_
#include <cstdint>
#include <memory>
#include <optional>
#include <string>
#include <arrow/api.h>
#include <arrow/chunked_array.h>
#include <nlohmann/json.hpp>
#include "katana/Result.h"
#include "katana/URI.h"
#include "katana/config.h"
#include "tsuba/Errors.h"
#include "tsuba/FileFrame.h"
#include "tsuba/FileView.h"
#include "tsuba/PartitionMetadata.h"
#include "tsuba/RDGLineage.h"
#include "tsuba/ReadGroup.h"
#include "tsuba/WriteGroup.h"
#include "tsuba/tsuba.h"
namespace tsuba {
class RDGManifest;
class RDGCore;
class PropStorageInfo;
struct KATANA_EXPORT RDGLoadOptions {
/// Which partition of the RDG on storage should be loaded
/// nullopt means the partition associated with the current host's ID will be
/// loaded
std::optional<uint32_t> partition_id_to_load;
/// List of node properties that should be loaded
/// nullptr means all node properties will be loaded
std::optional<std::vector<std::string>> node_properties{std::nullopt};
/// List of edge properties that should be loaded
/// nullptr means all edge properties will be loaded
std::optional<std::vector<std::string>> edge_properties{std::nullopt};
};
class KATANA_EXPORT RDG {
public:
enum RDGVersioningPolicy { RetainVersion = 0, IncrementVersion };
RDG(const RDG& no_copy) = delete;
RDG& operator=(const RDG& no_dopy) = delete;
RDG();
~RDG();
RDG(RDG&& other) noexcept;
RDG& operator=(RDG&& other) noexcept;
/// Perform some checks on assumed invariants
katana::Result<void> Validate() const;
/// Determine if two RDGs are Equal //TODO (yasser): verify that this now works with
//views
bool Equals(const RDG& other) const;
/// @brief Store RDG with lineage based on command line and update version based on the versioning policy.
/// @param handle :: handle indicating where to store RDG
/// @param command_line :: added to metadata to track lineage of RDG
/// @param versioning_action :: can be set to 'RDG::RDGVersioningPolicy::IncrementVersion' or
/// @param ff :: if ff is not nullptr, it is persisted as the topology for this RDG.
/// 'RDG::RDGVersioningPolicy::RetainVersion' to indicate whether RDG version is
katana::Result<void> Store(
RDGHandle handle, const std::string& command_line,
RDGVersioningPolicy versioning_action, std::unique_ptr<FileFrame> ff);
/// @brief Store new version of the RDG with lineage based on command line.
/// @param handle :: handle indicating where to store RDG
/// @param command_line :: added to metadata to track lineage of RDG
/// @param ff :: FileFrame for topology information, can be nullptr. If set, topology
/// information will be persisted to ff.
katana::Result<void> Store(
RDGHandle handle, const std::string& command_line,
std::unique_ptr<FileFrame> ff) {
return Store(handle, command_line, IncrementVersion, std::move(ff));
}
/// @brief Store new version of RDG with lineage based on command line.
/// @param handle :: handle indicating where to store RDG
/// @param command_line :: added to metadata to track lineage of RDG
katana::Result<void> Store(
RDGHandle handle, const std::string& command_line) {
return Store(handle, command_line, IncrementVersion, nullptr);
}
/// @brief Store RDG with lineage based on command line and update version based on the versioning policy.
/// @param handle :: handle indicating where to store RDG
/// @param command_line :: added to metadata to track lineage of RDG
/// @param versioning_action :: can be set to 'RDG::RDGVersioningPolicy::IncrementVersion' or
/// 'RDG::RDGVersioningPolicy::RetainVersion' to indicate whether RDG version is
/// changing with this store.
katana::Result<void> Store(
RDGHandle handle, const std::string& command_line,
RDGVersioningPolicy versioning_action) {
return Store(handle, command_line, versioning_action, nullptr);
}
katana::Result<void> AddNodeProperties(
const std::shared_ptr<arrow::Table>& props);
katana::Result<void> AddEdgeProperties(
const std::shared_ptr<arrow::Table>& props);
katana::Result<void> UpsertNodeProperties(
const std::shared_ptr<arrow::Table>& props);
katana::Result<void> UpsertEdgeProperties(
const std::shared_ptr<arrow::Table>& props);
katana::Result<void> RemoveNodeProperty(int i);
katana::Result<void> RemoveEdgeProperty(int i);
/// Ensure the node property at index `i` was written back to storage
/// then free its memory
katana::Result<void> UnloadNodeProperty(int i);
/// Ensure the edge property at index `i` was written back to storage
/// then free its memory
katana::Result<void> UnloadEdgeProperty(int i);
/// Load node property with a particular name and insert it into the
/// property table at index. If index is invalid, the property is put
/// in the last slot. A given property cannot be loaded more than once
katana::Result<void> LoadNodeProperty(const std::string& name, int i = -1);
/// Load edge property with a particular name and insert it into the
/// property table at index. If index is greater than the last column
/// index in the table, it is put in the last slot. A given property
/// cannot be loaded more than once
katana::Result<void> LoadEdgeProperty(const std::string& name, int i = -1);
std::vector<std::string> ListNodeProperties() const;
std::vector<std::string> ListEdgeProperties() const;
/// Explain to graph how it is derived from previous version
void AddLineage(const std::string& command_line);
/// Load the RDG described by the metadata in handle into memory.
static katana::Result<RDG> Make(RDGHandle handle, const RDGLoadOptions& opts);
katana::Result<void> UnbindTopologyFileStorage();
/// Inform this RDG that it's topology is in storage at this location
/// without loading it into memory. \param new_top must exist and be in
/// the correct directory for this RDG
katana::Result<void> SetTopologyFile(const katana::Uri& new_top);
void AddMirrorNodes(std::shared_ptr<arrow::ChunkedArray>&& a) {
mirror_nodes_.emplace_back(std::move(a));
}
void AddMasterNodes(std::shared_ptr<arrow::ChunkedArray>&& a) {
master_nodes_.emplace_back(std::move(a));
}
//
// accessors and mutators
//
const katana::Uri& rdg_dir() const { return rdg_dir_; }
void set_rdg_dir(const katana::Uri& rdg_dir) { rdg_dir_ = rdg_dir; }
uint32_t partition_id() const { return partition_id_; }
void set_partition_id(uint32_t partition_id) { partition_id_ = partition_id; }
/// The node properties
const std::shared_ptr<arrow::Table>& node_properties() const;
/// The edge properties
const std::shared_ptr<arrow::Table>& edge_properties() const;
/// Remove all node properties
void DropNodeProperties();
/// Remove all edge properties
void DropEdgeProperties();
//write the list of node and edge column names persisted to json, private as it is called only when the node and edge property index vectors are pushed back
void set_node_property_indexes_column_name(
std::vector<std::string>& node_property_indexes_column_name);
void set_edge_property_indexes_column_name(
std::vector<std::string>& edge_property_indexes_column_name);
// read the same as above and recreate indexes
std::vector<std::string>& get_node_property_indexes_column_name();
std::vector<std::string>& get_edge_property_indexes_column_name();
std::shared_ptr<arrow::Schema> full_node_schema() const;
std::shared_ptr<arrow::Schema> full_edge_schema() const;
const std::vector<std::shared_ptr<arrow::ChunkedArray>>& master_nodes()
const {
return master_nodes_;
}
void set_master_nodes(std::vector<std::shared_ptr<arrow::ChunkedArray>>&& a) {
master_nodes_ = std::move(a);
}
const std::vector<std::shared_ptr<arrow::ChunkedArray>>& mirror_nodes()
const {
return mirror_nodes_;
}
void set_mirror_nodes(std::vector<std::shared_ptr<arrow::ChunkedArray>>&& a) {
mirror_nodes_ = std::move(a);
}
const std::shared_ptr<arrow::ChunkedArray>& host_to_owned_global_node_ids()
const {
return host_to_owned_global_node_ids_;
}
void set_host_to_owned_global_node_ids(
std::shared_ptr<arrow::ChunkedArray>&& a) {
host_to_owned_global_node_ids_ = std::move(a);
}
const std::shared_ptr<arrow::ChunkedArray>& host_to_owned_global_edge_ids()
const {
return host_to_owned_global_edge_ids_;
}
void set_host_to_owned_global_edge_ids(
std::shared_ptr<arrow::ChunkedArray>&& a) {
host_to_owned_global_edge_ids_ = std::move(a);
}
const std::shared_ptr<arrow::ChunkedArray>& local_to_user_id() const {
return local_to_user_id_;
}
void set_local_to_user_id(std::shared_ptr<arrow::ChunkedArray>&& a) {
local_to_user_id_ = std::move(a);
}
const std::shared_ptr<arrow::ChunkedArray>& local_to_global_id() const {
return local_to_global_id_;
}
void set_local_to_global_id(std::shared_ptr<arrow::ChunkedArray>&& a) {
local_to_global_id_ = std::move(a);
}
const PartitionMetadata& part_metadata() const;
void set_part_metadata(const PartitionMetadata& metadata);
const FileView& topology_file_storage() const;
void set_view_name(const std::string& v) { view_type_ = v; }
private:
std::string view_type_;
RDG(std::unique_ptr<RDGCore>&& core);
void InitEmptyTables();
katana::Result<void> DoMake(
const std::vector<PropStorageInfo*>& node_props_to_be_loaded,
const std::vector<PropStorageInfo*>& edge_props_to_be_loaded,
const katana::Uri& metadata_dir);
static katana::Result<RDG> Make(
const RDGManifest& manifest, const RDGLoadOptions& opts);
katana::Result<void> AddPartitionMetadataArray(
const std::shared_ptr<arrow::Table>& props);
katana::Result<std::vector<tsuba::PropStorageInfo>> WritePartArrays(
const katana::Uri& dir, tsuba::WriteGroup* desc);
katana::Result<void> DoStore(
RDGHandle handle, const std::string& command_line,
RDGVersioningPolicy versioning_action, std::unique_ptr<WriteGroup> desc);
//
// Data
//
std::unique_ptr<RDGCore> core_;
std::vector<std::shared_ptr<arrow::ChunkedArray>> mirror_nodes_;
std::vector<std::shared_ptr<arrow::ChunkedArray>> master_nodes_;
// Called while constructing to put these arrays into a usable state for Distribution
void InitArrowVectors();
std::shared_ptr<arrow::ChunkedArray> host_to_owned_global_node_ids_;
std::shared_ptr<arrow::ChunkedArray> host_to_owned_global_edge_ids_;
std::shared_ptr<arrow::ChunkedArray> local_to_user_id_;
std::shared_ptr<arrow::ChunkedArray> local_to_global_id_;
/// name of the graph that was used to load this RDG
katana::Uri rdg_dir_;
/// which partition of the graph was loaded
uint32_t partition_id_{std::numeric_limits<uint32_t>::max()};
// How this graph was derived from the previous version
RDGLineage lineage_;
};
} // namespace tsuba
#endif