15 #ifndef STORAGES_RT_MUTABLE_GRAPH_FILE_NAMES_H_
16 #define STORAGES_RT_MUTABLE_GRAPH_FILE_NAMES_H_
23 #include <sys/types.h>
27 #include "glog/logging.h"
80 inline void copy_file(
const std::string& src,
const std::string& dst) {
81 if (!std::filesystem::exists(src)) {
82 LOG(ERROR) <<
"file not exists: " << src;
85 #if USE_COPY_FILE_RANGE
86 size_t len = std::filesystem::file_size(src);
87 int src_fd = open(src.c_str(), O_RDONLY, 0777);
89 if (!std::filesystem::exists(dst)) {
92 int dst_fd = open(dst.c_str(), O_WRONLY | O_CREAT, 0777);
94 std::filesystem::perms readWritePermission =
95 std::filesystem::perms::owner_read |
96 std::filesystem::perms::owner_write;
97 std::error_code errorCode;
98 std::filesystem::permissions(dst, readWritePermission,
99 std::filesystem::perm_options::add, errorCode);
101 LOG(ERROR) <<
"Failed to set read/write permission for file: " << dst
102 <<
" " << errorCode.message() << std::endl;
110 dst_fd = open(dst.c_str(), O_WRONLY, 0777);
114 ret = copy_file_range(src_fd, NULL, dst_fd, NULL, len, 0);
116 perror(
"copy_file_range");
120 }
while (len > 0 && ret > 0);
125 if (!std::filesystem::exists(dst)) {
128 std::error_code errorCode;
130 src, dst, std::filesystem::copy_options::overwrite_existing, errorCode);
132 LOG(ERROR) <<
"Failed to copy file from " << src <<
" to " << dst <<
" "
133 << errorCode.message() << std::endl;
136 std::filesystem::perms readWritePermission =
137 std::filesystem::perms::owner_read |
138 std::filesystem::perms::owner_write;
139 std::error_code errorCode;
140 std::filesystem::permissions(dst, readWritePermission,
141 std::filesystem::perm_options::add, errorCode);
143 LOG(INFO) <<
"Failed to set read/write permission for file: " << dst
144 <<
" " << errorCode.message() << std::endl;
152 return work_dir +
"/schema";
156 return work_dir +
"/snapshots/";
167 FILE* fin = fopen((
snapshots_dir +
"/VERSION").c_str(),
"r");
168 CHECK_EQ(fread(&version,
sizeof(uint32_t), 1, fin), 1);
176 FILE* version_file = fopen(version_path.c_str(),
"rb");
177 uint32_t version = 0;
178 CHECK_EQ(fread(&version,
sizeof(uint32_t), 1, version_file), 1);
179 fclose(version_file);
186 FILE* version_file = fopen(version_path.c_str(),
"wb");
187 CHECK_EQ(fwrite(&version,
sizeof(uint32_t), 1, version_file), 1);
188 fflush(version_file);
189 fclose(version_file);
192 inline std::string
snapshot_dir(
const std::string& work_dir, uint32_t version) {
196 inline std::string
wal_dir(
const std::string& work_dir) {
197 return work_dir +
"/wal/";
201 return work_dir +
"/runtime/";
213 inline std::string
tmp_dir(
const std::string& work_dir) {
218 return tmp_dir(work_dir) +
"bulk_load_progress.log";
222 std::string tmp_dir_str =
tmp_dir(work_dir);
223 if (std::filesystem::exists(tmp_dir_str)) {
224 assert(std::filesystem::is_directory(tmp_dir_str));
225 if (std::filesystem::directory_iterator(tmp_dir_str) !=
226 std::filesystem::directory_iterator()) {
227 for (
const auto& entry :
228 std::filesystem::directory_iterator(tmp_dir_str)) {
229 std::filesystem::remove_all(entry.path());
236 return "vertex_map_" + label;
239 inline std::string
ie_prefix(
const std::string& src_label,
240 const std::string& dst_label,
241 const std::string edge_label) {
242 return "ie_" + src_label +
"_" + edge_label +
"_" + dst_label;
245 inline std::string
oe_prefix(
const std::string& src_label,
246 const std::string& dst_label,
247 const std::string edge_label) {
248 return "oe_" + src_label +
"_" + edge_label +
"_" + dst_label;
252 const std::string& dst_label,
253 const std::string& edge_label) {
254 return "e_" + src_label +
"_" + edge_label +
"_" + dst_label +
"_data";
257 return "vertex_table_" + label;
268 #endif // STORAGES_RT_MUTABLE_GRAPH_FILE_NAMES_H_