18 #include "scanner/util/common.h" 19 #include "scanner/util/storehouse.h" 20 #include "storehouse/storage_backend.h" 31 void set_database_path(std::string path);
33 const std::string get_scanner_path();
35 void set_scanner_path(std::string path);
37 inline std::string database_metadata_path() {
41 inline std::string table_megafile_path() {
45 inline std::string table_directory(i32 table_id) {
49 inline std::string table_descriptor_path(i32 table_id) {
50 return table_directory(table_id) +
"/descriptor.bin";
53 inline std::string table_item_output_path(i32 table_id, i32 column_id,
55 return table_directory(table_id) +
"/" + std::to_string(column_id) +
"_" +
56 std::to_string(item_id) +
".bin";
59 inline std::string table_item_video_metadata_path(i32 table_id, i32 column_id,
61 return table_directory(table_id) +
"/" + std::to_string(column_id) +
"_" +
62 std::to_string(item_id) +
"_video_metadata.bin";
65 inline std::string table_item_metadata_path(i32 table_id, i32 column_id,
67 return table_directory(table_id) +
"/" + std::to_string(column_id) +
"_" +
68 std::to_string(item_id) +
"_metadata.bin";
71 inline std::string bulk_job_directory(i32 bulk_job_id) {
75 inline std::string bulk_job_descriptor_path(i32 bulk_job_id) {
76 return bulk_job_directory(bulk_job_id) +
"/descriptor.bin";
79 inline std::string bulk_job_master_profiler_path(i32 bulk_job_id) {
80 return bulk_job_directory(bulk_job_id) +
"/profile_master.bin";
83 inline std::string bulk_job_worker_profiler_path(i32 bulk_job_id, i32 node) {
84 return bulk_job_directory(bulk_job_id) +
"/profile_" + std::to_string(node) +
96 Metadata(
const Descriptor& d) : descriptor_(d) {}
98 Descriptor& get_descriptor()
const {
return descriptor_; }
100 std::string descriptor_path()
const;
103 mutable Descriptor descriptor_;
111 const Descriptor& get_descriptor()
const;
113 static std::string descriptor_path();
115 std::vector<std::string> table_names()
const;
117 bool has_table(
const std::string& table)
const;
118 bool has_table(i32 table_id)
const;
119 i32 get_table_id(
const std::string& table)
const;
120 const std::string& get_table_name(i32 table_id)
const;
121 i32 add_table(
const std::string& table);
122 void commit_table(i32 table_id);
123 bool table_is_committed(i32 table_id)
const;
124 void remove_table(i32 table_id);
126 const std::vector<std::string>& bulk_job_names()
const;
128 bool has_bulk_job(
const std::string& job)
const;
129 bool has_bulk_job(i32 job_id)
const;
130 i32 get_bulk_job_id(
const std::string& job_name)
const;
131 const std::string& get_bulk_job_name(i32 job_id)
const;
132 i32 add_bulk_job(
const std::string& job_name);
133 void commit_bulk_job(i32 job_id);
134 bool bulk_job_is_committed(i32 job_id)
const;
135 void remove_bulk_job(i32 job_id);
139 i32 next_bulk_job_id_;
140 std::unordered_map<i32, std::string> table_id_names_;
141 std::unordered_map<std::string, i32> table_name_ids_;
142 std::unordered_map<i32, bool> table_committed_;
144 std::unordered_map<i32, std::string> bulk_job_id_names_;
145 std::unordered_map<i32, bool> bulk_job_committed_;
153 static std::string descriptor_path(i32 table_id, i32 column_id, i32 item_id);
155 i32 table_id()
const;
156 i32 column_id()
const;
161 i32 channels()
const;
162 proto::FrameType frame_type()
const;
163 proto::VideoDescriptor::VideoCodecType codec_type()
const;
164 i64 num_encoded_videos()
const;
165 std::vector<i64> frames_per_video()
const;
166 std::vector<i64> keyframes_per_video()
const;
167 std::vector<i64> size_per_video()
const;
169 std::vector<u64> keyframe_indices()
const;
170 std::vector<u64> sample_offsets()
const;
171 std::vector<u64> sample_sizes()
const;
172 std::vector<u8> metadata()
const;
173 std::string data_path()
const;
174 bool inplace()
const;
178 :
public Metadata<proto::ImageFormatGroupDescriptor> {
183 i32 num_images()
const;
186 ImageEncodingType encoding_type()
const;
187 ImageColorSpace color_space()
const;
188 std::vector<i64> compressed_sizes()
const;
196 static std::string descriptor_path(i32 job_id);
200 std::string name()
const;
202 i32 io_packet_size()
const;
204 i32 work_packet_size()
const;
206 i32 num_nodes()
const;
208 const std::vector<proto::Column>& columns()
const;
210 i32 column_id(
const std::string& column_name)
const;
217 std::vector<Column> columns_;
218 std::unordered_map<std::string, i32> column_ids_;
219 std::vector<std::string> table_names_;
220 mutable std::unordered_map<std::string, i64> rows_in_table_;
228 static std::string descriptor_path(i32 table_id);
232 std::string name()
const;
234 i64 num_rows()
const;
236 std::vector<i64> end_rows()
const;
238 const std::vector<proto::Column>& columns()
const;
240 bool has_column(
const std::string& name)
const;
242 std::string column_name(i32 column_id)
const;
244 i32 column_id(
const std::string& name)
const;
246 ColumnType column_type(i32 column_id)
const;
249 std::vector<proto::Column> columns_;
257 inline std::string frame_column_name() {
return "frame"; }
259 inline std::string frame_info_column_name() {
return "frame_info"; }
264 template <
typename T>
266 size_t size = descriptor.ByteSizeLong();
267 std::vector<u8> data(size);
268 descriptor.SerializeToArray(data.data(), size);
269 s_write(file, data.data(), size);
272 template <
typename T>
273 T deserialize_db_proto(storehouse::RandomReadFile* file, u64& pos) {
276 BACKOFF_FAIL(file->get_size(size),
277 "while trying to get size for " + file->path());
278 std::vector<u8> data = storehouse::read_entire_file(
279 file, pos, std::max((
size_t)size, (
size_t)1024 * 1024));
280 descriptor.ParseFromArray(data.data(), data.size());
284 template <
typename T>
285 void write_db_proto(storehouse::StorageBackend* storage, T db_proto) {
286 std::unique_ptr<storehouse::WriteFile> output_file;
287 const std::string& desc_path =
288 db_proto.Metadata<typename T::Descriptor>::descriptor_path();
289 BACKOFF_FAIL(make_unique_write_file(storage, desc_path, output_file),
290 "while trying to make write file for " + desc_path);
291 serialize_db_proto<typename T::Descriptor>(output_file.get(),
292 db_proto.get_descriptor());
293 BACKOFF_FAIL(output_file->save(),
294 "while trying to save " + output_file->path());
297 template <
typename T>
298 T read_db_proto(storehouse::StorageBackend* storage,
const std::string& path) {
299 std::unique_ptr<storehouse::RandomReadFile> db_in_file;
300 BACKOFF_FAIL(make_unique_random_read_file(storage, path, db_in_file),
301 "while trying to make read file for " + path);
303 return T(deserialize_db_proto<typename T::Descriptor>(db_in_file.get(), pos));
306 template <
typename T>
307 using WriteFn = void (*)(storehouse::StorageBackend* storage, T db_proto);
309 template <
typename T>
310 using ReadFn = T (*)(storehouse::StorageBackend* storage,
311 const std::string& path);
313 constexpr WriteFn<DatabaseMetadata> write_database_metadata =
314 write_db_proto<DatabaseMetadata>;
315 constexpr ReadFn<DatabaseMetadata> read_database_metadata =
316 read_db_proto<DatabaseMetadata>;
318 void write_table_megafile(
319 storehouse::StorageBackend* storage,
320 const std::unordered_map<i32, TableMetadata>& table_metadata);
322 void read_table_megafile(
323 storehouse::StorageBackend* storage,
324 std::unordered_map<i32, TableMetadata>& table_metadata);
326 constexpr WriteFn<BulkJobMetadata> write_bulk_job_metadata =
327 write_db_proto<BulkJobMetadata>;
328 constexpr ReadFn<BulkJobMetadata> read_bulk_job_metadata =
329 read_db_proto<BulkJobMetadata>;
331 constexpr WriteFn<TableMetadata> write_table_metadata =
332 write_db_proto<TableMetadata>;
333 constexpr ReadFn<TableMetadata> read_table_metadata =
334 read_db_proto<TableMetadata>;
336 constexpr WriteFn<VideoMetadata> write_video_metadata =
337 write_db_proto<VideoMetadata>;
338 constexpr ReadFn<VideoMetadata> read_video_metadata =
339 read_db_proto<VideoMetadata>;
std::string index_column_name()
Constants.
Definition: metadata.h:255
Definition: database.cpp:36
const std::string & get_database_path()
Path functions.
Definition: metadata.cpp:430
void serialize_db_proto(storehouse::WriteFile *file, const T &descriptor)
Helpers.
Definition: metadata.h:265