FlashGraph-ng
A new frontier in large-scale graph analysis and data mining
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
safs_file.h
1 #ifndef __SAFS_FILE_H__
2 #define __SAFS_FILE_H__
3 
4 /*
5  * Copyright 2014 Open Connectome Project (http://openconnecto.me)
6  * Written by Da Zheng (zhengda1936@gmail.com)
7  *
8  * This file is part of SAFSlib.
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22 
23 #include <stdlib.h>
24 
25 #include <string>
26 #include <vector>
27 #include <set>
28 
29 #include "common.h"
30 #include "native_file.h"
31 #include "safs_header.h"
32 #include "parameters.h"
33 
34 namespace safs
35 {
36 
37 /*
38  * This stores the local filesystem file information that stores
39  * each partition of SAFS files.
40  */
41 class part_file_info
42 {
43  // The file name in the local filesystem.
44  std::string name;
45  // The disk ID where the block is stored.
46  int disk_id;
47  // The NUMA node id where the disk is connected to.
48  int node_id;
49 public:
50  part_file_info() {
51  disk_id = 0;
52  node_id = 0;
53  }
54 
55  part_file_info(const std::string &name, int disk_id, int node_id) {
56  this->name = name;
57  this->disk_id = disk_id;
58  this->node_id = node_id;
59  }
60 
61  std::string get_file_name() const {
62  return name;
63  }
64 
65  int get_disk_id() const {
66  return disk_id;
67  }
68 
69  int get_node_id() const {
70  return node_id;
71  }
72 };
73 
74 class RAID_config;
75 class safs_file_group;
76 
77 class safs_file
78 {
79  // The collection of native files.
80  std::vector<part_file_info> native_dirs;
81  // The path of the header file in the local Linux filesystem.
82  std::string header_file;
83  std::string name;
84 
85  std::string get_header_file() const;
86 public:
87  static std::vector<std::string> erase_header_file(
88  const std::vector<std::string> &files);
89 
90  safs_file(const RAID_config &conf, const std::string &file_name);
91 
92  safs_header get_header() const;
93 
94  /*
95  * An SAFS file allows a user to store user-defined metadata along with
96  * the data in the file.
97  */
98  bool set_user_metadata(const std::vector<char> &data);
99  std::vector<char> get_user_metadata() const;
100 
101  const std::string &get_name() const {
102  return name;
103  }
104 
105  bool exist() const;
106  ssize_t get_size() const;
107  bool create_file(size_t file_size,
108  int block_size = params.get_RAID_block_size(),
109  int mapping_option = params.get_RAID_mapping_option(),
110  std::shared_ptr<safs_file_group> group = NULL);
111  bool delete_file();
112  bool rename(const std::string &new_name);
113 };
114 
115 class safs_file_group
116 {
117 public:
118  enum group_t {
119  NAIVE,
120  ROTATE,
121  RAND_ROTATE,
122  };
123  typedef std::shared_ptr<safs_file_group> ptr;
124 
125  static ptr create(const RAID_config &conf, group_t type);
126  virtual std::vector<int> add_file(safs_file &file) = 0;
127  virtual std::string get_name() const = 0;
128 };
129 
130 size_t get_all_safs_files(std::set<std::string> &files);
131 
132 bool exist_safs_file(const std::string &name);
133 ssize_t get_safs_size(const std::string &name);
134 
135 }
136 
137 #endif