SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
FileSystem.cc
Go to the documentation of this file.
1 /*
2  * SWC-DB© Copyright since 2019 Alex Kashirin <kashirin.alex@gmail.com>
3  * License details at <https://github.com/kashirin-alex/swc-db/#license>
4  */
5 
6 
8 #include <filesystem>
9 #include <fcntl.h>
10 #include <dirent.h>
11 
12 #if defined(SWC_FS_LOCAL_USE_IO_URING)
13 #include <asio/stream_file.hpp>
14 #endif
15 
16 
17 #if defined(__MINGW64__) || defined(_WIN32)
18  #include <Windows.h>
19  #include <io.h>
20  #include <fileapi.h>
21 
22  namespace {
24  ssize_t __pread(int fd, uint8_t* ptr, size_t n, off_t offset) noexcept {
25  long unsigned int read_bytes = 0;
26  OVERLAPPED overlapped;
27  memset(&overlapped, 0, sizeof(OVERLAPPED));
28  overlapped.OffsetHigh = offset >> 32;
29  overlapped.Offset = ((offset << 32) >> 32);
30  SetLastError(0);
31  if(!ReadFile(HANDLE(_get_osfhandle(fd)), ptr, n, &read_bytes, &overlapped)) {
32  errno = GetLastError();
33  return -1;
34  }
35  return read_bytes;
36  }
37  }
38  #define SWC_MKDIR(path, perms) ::mkdir(path)
39  #define SWC_FSYNC(fd) ::_commit(fd)
40  #define SWC_PREAD(fd, ptr, nleft, offset) __pread(fd, ptr, nleft, offset)
41 
42 #else
43  #define SWC_MKDIR(path, perms) ::mkdir(path, perms)
44  #define SWC_FSYNC(fd) ::fsync(fd)
45  #define SWC_PREAD(fd, ptr, nleft, offset) ::pread(fd, ptr, nleft, offset)
46 #endif
47 
48 
49 
50 namespace SWC { namespace FS {
51 
52 
54  config->settings->file_desc.add_options()
55  ("swc.fs.local.path.root", Config::str(""),
56  "Local FileSystem's base root path")
57  ("swc.fs.local.cfg.dyn", Config::strs(),
58  "Dyn-config file")
59 
60  ("swc.fs.local.metrics.enabled", Config::boo(true),
61  "Enable or Disable Metrics Tracking")
62 
63  #if defined(SWC_FS_LOCAL_USE_IO_URING)
64  ("swc.fs.local.handlers", Config::i32(12),
65  "Handlers for async filesystem")
66  #endif
67 
68  ("swc.fs.local.fds.max", Config::g_i32(512),
69  "Max Open Fds for opt. without closing")
70  ;
71  config->settings->parse_file(
72  config->settings->get_str("swc.fs.local.cfg", ""),
73  "swc.fs.local.cfg.dyn"
74  );
75 
76  config->path_root = config->settings->get_str(
77  "swc.fs.local.path.root");
78  config->cfg_fds_max = config->settings
79  ->get<Config::Property::Value_int32_g>("swc.fs.local.fds.max");
80  config->stats_enabled = config->settings->get_bool(
81  "swc.fs.local.metrics.enabled");
82  return config;
83 }
84 
85 
87  : FileSystem(
88  apply_local(config),
89  ImplOptions()
90  #if defined(SWC_FS_LOCAL_USE_IO_URING)
91  .add_async_readall()
92  #endif
93  ),
94  m_directio(settings->get_bool(
95  "swc.fs.local.DirectIO", false))
96  #if defined(SWC_FS_LOCAL_USE_IO_URING)
97  ,
98  m_io(new Comm::IoContext(
99  "FsLocal", settings->get_i32("swc.fs.local.handlers")))
100  #endif
101  {
102 }
103 
105 
106 #if defined(SWC_FS_LOCAL_USE_IO_URING)
107 void FileSystemLocal::stop() {
108  m_io->stop();
110 }
111 #endif
112 
113 Type FileSystemLocal::get_type() const noexcept {
114  return Type::LOCAL;
115 }
116 
117 std::string FileSystemLocal::to_string() const {
118  return format(
119  "(type=LOCAL path_root=%s path_data=%s)",
120  path_root.c_str(),
121  path_data.c_str()
122  );
123 }
124 
125 
126 
127 bool FileSystemLocal::exists(int& err, const std::string& name) {
129  SWC_FS_EXISTS_START(name);
130  std::string abspath;
131  get_abspath(name, abspath);
132  struct stat statbuf;
133  errno = 0;
134  bool state = !::stat(abspath.c_str(), &statbuf);
135  err = errno == ENOENT ? Error::OK : errno;
136  SWC_FS_EXISTS_FINISH(err, abspath, state, tracker);
137  return state;
138 }
139 
140 void FileSystemLocal::remove(int& err, const std::string& name) {
142  SWC_FS_REMOVE_START(name);
143  std::string abspath;
144  get_abspath(name, abspath);
145  errno = 0;
146  err = ::unlink(abspath.c_str())==-1 && errno != ENOENT ? errno : Error::OK;
147  SWC_FS_REMOVE_FINISH(err, abspath, tracker);
148 }
149 
150 size_t FileSystemLocal::length(int& err, const std::string& name) {
152  SWC_FS_LENGTH_START(name);
153  std::string abspath;
154  get_abspath(name, abspath);
155 
156  struct stat statbuf;
157  errno = 0;
158  size_t len = stat(abspath.c_str(), &statbuf) ? 0 : statbuf.st_size;
159  err = errno;
160  SWC_FS_LENGTH_FINISH(err, abspath, len, tracker);
161  return len;
162 }
163 
164 
165 namespace {
167 int _mkdirs(std::string& dirname) {
168  dirname.append("/");
169  struct stat statbuf;
170  errno = 0;
171  for(auto it = dirname.begin(); ++it != dirname.cend(); ) {
172  if(*it != '/')
173  continue;
174  *it = 0;
175  if(stat(dirname.c_str(), &statbuf)) {
176  if(errno != ENOENT)
177  break;
178  errno = 0;
179  if(SWC_MKDIR(dirname.c_str(), 0755)) {
180  if(errno != EEXIST)
181  break;
182  }
183  errno = 0;
184  }
185  *it = '/';
186  }
187  return errno;
188 }
189 }
190 
191 void FileSystemLocal::mkdirs(int& err, const std::string& name) {
193  SWC_FS_MKDIRS_START(name);
194  std::string abspath;
195  get_abspath(name, abspath, 1);
196  err = _mkdirs(abspath);
197  SWC_FS_MKDIRS_FINISH(err, abspath, tracker);
198 }
199 
200 void FileSystemLocal::readdir(int& err, const std::string& name,
201  DirentList& results) {
203  SWC_FS_READDIR_START(name);
204  std::string abspath;
205  get_abspath(name, abspath);
206 
207  #if defined(__MINGW64__) || defined(_WIN32)
208  const std::filesystem::path _dir_path(std::move(abspath));
209  std::error_code ec;
210  _do:
211  for(auto const& de : std::filesystem::directory_iterator(_dir_path, ec)) {
212  bool is_dir = de.is_directory(ec);
213  size_t sz;
214  if(!ec) {
215  sz = is_dir ? 0 : de.file_size(ec);
216  // auto t = de.last_write_time(ec); ? no-reason
217  }
218  if(ec) {
219  if(ec.value() == ENOENT) {
220  results.clear();
221  ec.clear();
222  goto _do; // and do all again directory changed
223  }
224  break;
225  }
226  results.emplace_back(
227  de.path().filename().string().c_str(), 0, is_dir, sz);
228  }
229  err = ec.value();
230 
231  #else
232  DIR* dirp;
233  std::string full_entry_path;
234  struct stat statbuf;
235 
236  _do:
237  errno = 0;
238  dirp = ::opendir(abspath.c_str());
239  if(!dirp || errno) {
240  err = errno;
241  goto _finish;
242  }
243 
244  for(struct dirent* dep; (dep = ::readdir(dirp)); ) {
245  if(!dep->d_name[0] || dep->d_name[0] == '.')
246  continue;
247  full_entry_path.clear();
248  full_entry_path.reserve(abspath.length() + 1 + strlen(dep->d_name));
249  full_entry_path.append(abspath);
250  full_entry_path.append("/");
251  full_entry_path.append(dep->d_name);
252  if(::stat(full_entry_path.c_str(), &statbuf) == -1) {
253  if(errno == ENOENT) {
254  results.clear();
255  goto _do; // and do all again directory changed
256  }
257  err = errno;
258  goto _finish;
259  }
260  results.emplace_back(
261  dep->d_name, statbuf.st_mtime, dep->d_type == DT_DIR, statbuf.st_size);
262  }
263  err = errno;
264 
265  _finish:
266  if(dirp)
267  closedir(dirp);
268  #endif
269 
270  SWC_FS_READDIR_FINISH(err, abspath, results.size(), tracker);
271 }
272 
273 void FileSystemLocal::rmdir(int& err, const std::string& name) {
274  auto tracker = statistics.tracker(Statistics::RMDIR_SYNC);
275  SWC_FS_RMDIR_START(name);
276  std::string abspath;
277  get_abspath(name, abspath);
278  std::error_code ec;
279  std::filesystem::remove_all(abspath, ec);
280  err = ec.value();
281  SWC_FS_RMDIR_FINISH(err, abspath, tracker);
282 }
283 
284 void FileSystemLocal::rename(int& err, const std::string& from,
285  const std::string& to) {
288  std::string abspath_from;
289  get_abspath(from, abspath_from);
290  std::string abspath_to;
291  get_abspath(to, abspath_to);
292  std::error_code ec;
293  std::filesystem::rename(abspath_from, abspath_to, ec);
294  err = ec.value();
295  SWC_FS_RENAME_FINISH(err, abspath_from, abspath_to, tracker);
296 }
297 
298 #if defined(SWC_FS_LOCAL_USE_IO_URING)
299 /*
300 void FileSystemLocal::read(Callback::ReadAllCb_t&& cb,
301  const std::string& name) {
302  SWC_FS_READALL_START(name);
303 
304  struct HandlerReadAll {
305  FS::SmartFd::Ptr smartfd;
306  Callback::ReadAllCb_t cb;
307  StaticBuffer::Ptr buffer;
308  asio::stream_file sf;
309  size_t recved;
310  FS::Statistics::Metric::Tracker tracker;
311 
312  HandlerReadAll(Callback::ReadAllCb_t&& a_cb,
313  const Comm::IoContextPtr& io, FS::Statistics& stats)
314  : cb(std::move(a_cb)), sf(io->executor()), recved(0),
315  tracker(stats.tracker(Statistics::READ_ALL_SYNC)) {
316  }
317  void run(size_t sz) {
318  sf.assign(smartfd->fd());
319  buffer.reset(new StaticBuffer(sz));
320  operator()(asio::error_code(), 0);
321  }
322  void operator()(const asio::error_code& ec, size_t bytes) {
323  SWC_PRINT << "HandlerReadAll() ec=" << ec << " is_open=" << sf.is_open() << " bytes=" << bytes << " left=" << (buffer->size - bytes) << SWC_PRINT_CLOSE;
324  if(!ec && (recved += bytes) < buffer->size) {
325  sf.async_read_some(
326  asio::buffer(buffer->base + bytes, buffer->size - bytes),
327  std::move(*this)
328  );
329  } else {
330  callback(ec.value());
331  }
332  }
333  void callback(int err) {
334  SWC_PRINT << "HandlerReadAll callback() err=" << err << " recved=" << recved << SWC_PRINT_CLOSE;
335  if(sf.is_open()) {
336  asio::error_code tmp;
337  sf.close(tmp);
338  }
339  SWC_FS_READALL_FINISH(err, smartfd->filepath(), recved, tracker);
340  cb(
341  err
342  ? (err == ENOENT ? Error::FS_PATH_NOT_FOUND : err)
343  : (recved != buffer->size ? Error::FS_EOF : err),
344  buffer
345  );
346  }
347  };
348 
349  HandlerReadAll hdlr(std::move(cb), m_io, statistics);
350 
351  int err = Error::OK;
352  size_t len;
353  if(!exists(err, name)) {
354  if(!err)
355  err = Error::FS_PATH_NOT_FOUND;
356  len = 0;
357  goto finish;
358  }
359  len = length(err, name);
360  if(err)
361  goto finish;
362 
363  hdlr.smartfd = FS::SmartFd::make_ptr(name, 0);
364 
365  open(err, hdlr.smartfd);
366  if(!err && !hdlr.smartfd->valid())
367  err = EBADR;
368  finish:
369  err ? hdlr.callback(err) : hdlr.run(len);
370 }
371 */
372 
374  const std::string& name) {
375  SWC_FS_READALL_START(name);
376 
377  struct HandlerReadAll {
378  std::string name;
380  StaticBuffer::Ptr buffer;
381  asio::stream_file sf;
382  size_t recved;
384 
385  HandlerReadAll(FileSystemLocal* fs,
386  const std::string& a_name, Callback::ReadAllCb_t&& a_cb,
387  const Comm::IoContextPtr& io, FS::Statistics& stats)
388  : name(a_name), cb(std::move(a_cb)),
389  sf(io->executor()), recved(0),
390  tracker(stats.tracker(Statistics::READ_ALL_SYNC)) {
391  std::string abspath;
392  fs->get_abspath(name, abspath);
393 
394  asio::error_code ec;
395  sf.open(abspath, asio::stream_file::read_only, ec);
396  SWC_PRINT << "HandlerReadAll() open ec=" << ec << SWC_PRINT_CLOSE;
397  if(!ec) {
398  size_t sz = sf.size(ec);
399  //if(!ec)
400  // sf.seek(0, asio::stream_file::seek_set);
401  SWC_PRINT << "HandlerReadAll() ec=" << ec << " sz=" << sz << SWC_PRINT_CLOSE;
402  if(!ec) {
403  buffer.reset(new StaticBuffer(sz));
404  operator()(ec, 0);
405  return;
406  }
407  }
408  callback(ec.value());
409  }
410  void operator()(const asio::error_code& ec, size_t bytes) {
411  SWC_PRINT << "HandlerReadAll() ec=" << ec << " is_open=" << sf.is_open() << " bytes=" << bytes << " left=" << (buffer->size - bytes) << SWC_PRINT_CLOSE;
412  if(!ec && (recved += bytes) < buffer->size) {
413  sf.async_read_some(
414  asio::buffer(buffer->base + bytes, buffer->size - bytes),
415  std::move(*this)
416  );
417  } else {
418  callback(ec.value());
419  }
420  }
421  void callback(int err) {
422  SWC_PRINT << "HandlerReadAll callback() err=" << err << " recved=" << recved << SWC_PRINT_CLOSE;
423  if(sf.is_open()) {
424  asio::error_code tmp;
425  sf.close(tmp);
426  }
427  SWC_FS_READALL_FINISH(err, name, recved, tracker);
428  cb(
429  err
430  ? (err == ENOENT ? Error::FS_PATH_NOT_FOUND : err)
431  : (recved != buffer->size ? Error::FS_EOF : err),
432  std::move(*buffer.get())
433  );
434  }
435  };
436 
437  SWC_PRINT << "HandlerReadAll 1 " << SWC_PRINT_CLOSE;
438  HandlerReadAll(this, name, std::move(cb), m_io, statistics);
439  SWC_PRINT << "HandlerReadAll 2 " << SWC_PRINT_CLOSE;
440 }
441 #endif
442 
443 void FileSystemLocal::create(int& err, SmartFd::Ptr& smartfd,
444  uint8_t replication) {
446  SWC_FS_CREATE_START(smartfd, replication);
447  std::string abspath;
448  get_abspath(smartfd->filepath(), abspath);
449 
450  int oflags = O_WRONLY | O_CREAT
451  | (smartfd->flags() & OpenFlags::OPEN_FLAG_OVERWRITE ? O_TRUNC : O_APPEND);
452 
453  #ifdef O_DIRECT
454  if (m_directio && smartfd->flags() & OpenFlags::OPEN_FLAG_DIRECTIO)
455  oflags |= O_DIRECT;
456  #endif
457 
458  /* Open the file */
459  int tmperr;
460  errno = 0;
461  smartfd->fd(::open(abspath.c_str(), oflags, 0644));
462  if (!smartfd->valid()) {
463  tmperr = errno;
464  if(tmperr == EACCES || tmperr == ENOENT)
466  else if (tmperr == EPERM)
468  else
469  err = tmperr;
470  } else {
471  err = tmperr = Error::OK;
472  fd_open_incr();
473  #if defined(__APPLE__)
474  #ifdef F_NOCACHE
475  fcntl(smartfd->fd(), F_NOCACHE, 1);
476  #endif
477  #elif defined(__sun__)
478  if (m_directio)
479  directio(smartfd->fd(), DIRECTIO_ON);
480  #endif
481  }
482  SWC_FS_CREATE_FINISH(tmperr, smartfd, fds_open(), tracker);
483 }
484 
485 void FileSystemLocal::open(int& err, SmartFd::Ptr& smartfd) {
486  auto tracker = statistics.tracker(Statistics::OPEN_SYNC);
487  SWC_FS_OPEN_START(smartfd);
488  std::string abspath;
489  get_abspath(smartfd->filepath(), abspath);
490 
491  int oflags = O_RDONLY;
492  #ifdef O_DIRECT
493  if(m_directio && smartfd->flags() & OpenFlags::OPEN_FLAG_DIRECTIO)
494  oflags |= O_DIRECT;
495  #endif
496 
497  /* Open the file */
498  int tmperr;
499  errno = 0;
500  smartfd->fd(::open(abspath.c_str(), oflags));
501  if (!smartfd->valid()) {
502  tmperr = errno;
503  if(tmperr == EACCES || tmperr == ENOENT)
505  else if (tmperr == EPERM)
507  else
508  err = tmperr;
509  } else {
510  err = tmperr = Error::OK;
511  fd_open_incr();
512 
513  #if defined(__sun__)
514  if(m_directio)
515  directio(smartfd->fd(), DIRECTIO_ON);
516  #endif
517  }
518  SWC_FS_OPEN_FINISH(tmperr, smartfd, fds_open(), tracker);
519 }
520 
521 
522 namespace {
524 ssize_t _read(int fd, uint8_t* ptr, size_t n) noexcept {
525  size_t nleft = n;
526  for(ssize_t nread; nleft; nleft -= nread, ptr += nread) {
527  if ((nread = ::read(fd, ptr, nleft)) < 0) {
528  if (errno == EINTR)
529  nread = 0;/* and call read() again */
530  else if (errno == EAGAIN)
531  break;
532  else
533  return -1;
534  } else if (!nread) {
535  break; /* EOF */
536  }
537  }
538  return n - nleft;
539 }
540 }
541 
542 size_t FileSystemLocal::read(int& err, SmartFd::Ptr& smartfd,
543  void *dst, size_t amount) {
544  auto tracker = statistics.tracker(Statistics::READ_SYNC);
545  SWC_FS_READ_START(smartfd, amount);
546  size_t ret;
547  errno = 0;
548  ssize_t nread = _read(smartfd->fd(), static_cast<uint8_t*>(dst), amount);
549  if (nread == -1) {
550  ret = 0;
551  nread = 0;
552  err = errno;
553  } else {
554  err = (ret = nread) == amount ? Error::OK : Error::FS_EOF;
555  smartfd->forward(ret);
556  }
557  SWC_FS_READ_FINISH(err, smartfd, ret, tracker);
558  return ret;
559 }
560 
561 
562 namespace {
564 ssize_t _pread(int fd, off_t offset, uint8_t* ptr, size_t n) noexcept {
565  ssize_t nleft = n;
566  for(ssize_t nread; nleft; nleft -= nread, ptr += nread, offset += nread) {
567  if((nread = SWC_PREAD(fd, ptr, nleft, offset)) < 0) {
568  if(errno == EINTR)
569  nread = 0;/* and call read() again */
570  else if(errno == EAGAIN)
571  break;
572  else
573  return -1;
574  } else if (!nread) {
575  break; /* EOF */
576  }
577  }
578  return n - nleft;
579 }
580 }
581 
582 size_t FileSystemLocal::pread(int& err, SmartFd::Ptr& smartfd,
583  uint64_t offset, void* dst,
584  size_t amount) {
585  auto tracker = statistics.tracker(Statistics::PREAD_SYNC);
586  SWC_FS_PREAD_START(smartfd, offset, amount);
587 
588  size_t ret;
589  errno = 0;
590  ssize_t nread = _pread(
591  smartfd->fd(), off_t(offset), static_cast<uint8_t*>(dst), amount);
592  if (nread == -1) {
593  ret = 0;
594  nread = 0;
595  err = errno;
596  } else {
597  err = (ret = nread) == amount ? Error::OK : Error::FS_EOF;
598  smartfd->pos(offset + ret);
599  }
600  SWC_FS_PREAD_FINISH(err, smartfd, ret, tracker);
601  return ret;
602 }
603 
604 
605 namespace {
607 bool _write(int fd, const uint8_t* ptr, size_t nleft) noexcept {
608  for(ssize_t nwritten; nleft; nleft -= nwritten, ptr += nwritten) {
609  if((nwritten = ::write(fd, ptr, nleft)) <= 0) {
610  if(errno != EINTR)
611  return false; /* error */
612  nwritten = 0; /* again */
613  }
614  }
615  return true;
616 }
617 }
618 
619 size_t FileSystemLocal::append(int& err, SmartFd::Ptr& smartfd,
620  StaticBuffer& buffer, Flags flags) {
622  SWC_FS_APPEND_START(smartfd, buffer.size, flags);
623 
624  errno = 0;
625  if(!_write(smartfd->fd(), buffer.base, buffer.size)) {
626  err = errno ? errno : ECANCELED;
627  } else {
628  smartfd->forward(buffer.size);
629  if((flags == Flags::FLUSH || flags == Flags::SYNC) &&
630  SWC_FSYNC(smartfd->fd())) {
631  err = errno;
632  } else {
633  err = Error::OK;
634  }
635  }
636  SWC_FS_APPEND_FINISH(err, smartfd, buffer.size, tracker);
637  return buffer.size;
638 }
639 
640 void FileSystemLocal::seek(int& err, SmartFd::Ptr& smartfd, size_t offset) {
641  auto tracker = statistics.tracker(Statistics::SEEK_SYNC);
642  SWC_FS_SEEK_START(smartfd, offset);
643 
644  errno = 0;
645  uint64_t at = ::lseek(smartfd->fd(), offset, SEEK_SET);
646  err = errno;
647  if (at == uint64_t(-1) || at != offset || err) {
648  if(!err)
649  smartfd->pos(at);
650  } else {
651  smartfd->pos(offset);
652  }
653  SWC_FS_SEEK_FINISH(err, smartfd, tracker);
654 }
655 
656 void FileSystemLocal::flush(int& err, SmartFd::Ptr& smartfd) {
657  sync(err, smartfd);
658 }
659 
660 void FileSystemLocal::sync(int& err, SmartFd::Ptr& smartfd) {
661  auto tracker = statistics.tracker(Statistics::SYNC_SYNC);
662  SWC_FS_SYNC_START(smartfd);
663 
664  err = SWC_FSYNC(smartfd->fd()) ? errno : Error::OK;
665  SWC_FS_SYNC_FINISH(err, smartfd, tracker);
666 }
667 
668 void FileSystemLocal::close(int& err, SmartFd::Ptr& smartfd) {
669  auto tracker = statistics.tracker(Statistics::CLOSE_SYNC);
670  SWC_FS_CLOSE_START(smartfd);
671 
672  int32_t fd = smartfd->invalidate();
673  if(fd != -1) {
674  errno = 0;
675  ::close(fd);
676  fd_open_decr();
677  err = errno;
678  } else {
679  err = EBADR;
680  }
681  SWC_FS_CLOSE_FINISH(err, smartfd, tracker);
682 }
683 
684 
685 
686 }} // namespace SWC
687 
688 
689 
690 #undef SWC_MKDIR
691 #undef SWC_FSYNC
692 #undef SWC_PREAD
693 
694 
695 extern "C" {
697  return static_cast<SWC::FS::FileSystem*>(
698  new SWC::FS::FileSystemLocal(config));
699 }
700 }
SWC::Config::i32
Property::Value_int32::Ptr i32(const int32_t &v)
Definition: PropertiesParser.cc:33
SWC_FS_APPEND_START
#define SWC_FS_APPEND_START(_smartfd, _amount, _flags)
Definition: Logger.h:217
SWC::FS::FileSystemLocal::~FileSystemLocal
virtual ~FileSystemLocal() noexcept
Definition: FileSystem.cc:104
SWC_FSYNC
#define SWC_FSYNC(fd)
Definition: FileSystem.cc:44
SWC::FS::FileSystemLocal::open
void open(int &err, SmartFd::Ptr &smartfd) override
Definition: FileSystem.cc:485
SWC::Config::g_i32
Property::Value_int32_g::Ptr g_i32(const int32_t &v)
Definition: PropertiesParser.cc:77
SWC::FS::Statistics::REMOVE_SYNC
@ REMOVE_SYNC
Definition: Statistics.h:34
SWC::FS::FileSystemLocal::flush
void flush(int &err, SmartFd::Ptr &smartfd) override
Definition: FileSystem.cc:656
SWC::FS::FileSystemLocal::seek
void seek(int &err, SmartFd::Ptr &smartfd, size_t offset) override
Definition: FileSystem.cc:640
SWC::FS::LOCAL
@ LOCAL
Definition: FileSystem.h:23
SWC::FS::Statistics::READDIR_SYNC
@ READDIR_SYNC
Definition: Statistics.h:46
SWC::FS::FileSystemLocal::length
size_t length(int &err, const std::string &name) override
Definition: FileSystem.cc:150
SWC::Core::Vector::clear
SWC_CAN_INLINE void clear() noexcept(_NoExceptDestructor)
Definition: Vector.h:120
SWC::FS::Type
Type
Definition: FileSystem.h:20
SWC::FS::Statistics::CLOSE_SYNC
@ CLOSE_SYNC
Definition: Statistics.h:26
SWC::FS::Statistics::RENAME_SYNC
@ RENAME_SYNC
Definition: Statistics.h:50
SWC::FS::Statistics::RMDIR_SYNC
@ RMDIR_SYNC
Definition: Statistics.h:44
SWC::Error::FS_PERMISSION_DENIED
@ FS_PERMISSION_DENIED
Definition: Error.h:95
SWC::FS::FileSystemLocal::to_string
std::string to_string() const override
Definition: FileSystem.cc:117
SWC_FS_RMDIR_FINISH
#define SWC_FS_RMDIR_FINISH(_error, _path, _tracker)
Definition: Logger.h:96
SWC_PREAD
#define SWC_PREAD(fd, ptr, nleft, offset)
Definition: FileSystem.cc:45
SWC_FS_RENAME_FINISH
#define SWC_FS_RENAME_FINISH(_error, _from, _to, _tracker)
Definition: Logger.h:108
fs_make_new_local
SWC::FS::FileSystem * fs_make_new_local(SWC::FS::Configurables *config)
Definition: FileSystem.cc:696
SWC::FS::Flags
Flags
Definition: FileSystem.h:41
SWC::FS::Statistics::tracker
SWC_CAN_INLINE Metric::Tracker tracker(Command cmd) noexcept
Definition: Statistics.h:119
SWC::Comm::IoContextPtr
std::shared_ptr< IoContext > IoContextPtr
Definition: IoContext.h:16
SWC::Error::FS_PATH_NOT_FOUND
@ FS_PATH_NOT_FOUND
Definition: Error.h:97
SWC::FS::FileSystem
Definition: FileSystem.h:101
SWC::FS::Statistics::SYNC_SYNC
@ SYNC_SYNC
Definition: Statistics.h:52
SWC_PRINT
#define SWC_PRINT
Definition: Logger.h:167
SWC::Config::boo
Property::Value_bool::Ptr boo(const bool &v)
Definition: PropertiesParser.cc:21
SWC::Common::Files::RgrData::read
static void read(DB::RgrData &data, int &err, const std::string &filepath)
Definition: RgrData.h:27
SWC_PRINT_CLOSE
#define SWC_PRINT_CLOSE
Definition: Logger.h:171
SWC::FS::Statistics::SEEK_SYNC
@ SEEK_SYNC
Definition: Statistics.h:32
SWC::FS::FileSystemLocal
Definition: FileSystem.h:22
SWC::FS::Statistics::CREATE_SYNC
@ CREATE_SYNC
Definition: Statistics.h:24
SWC_FS_PREAD_START
#define SWC_FS_PREAD_START(_smartfd, _offset, _amount)
Definition: Logger.h:185
SWC_FS_MKDIRS_FINISH
#define SWC_FS_MKDIRS_FINISH(_error, _path, _tracker)
Definition: Logger.h:72
SWC::FS::Configurables
Definition: FileSystem.h:48
SWC::FS::Statistics::MKDIRS_SYNC
@ MKDIRS_SYNC
Definition: Statistics.h:40
SWC::FS::Statistics::EXISTS_SYNC
@ EXISTS_SYNC
Definition: Statistics.h:48
SWC_FS_READDIR_FINISH
#define SWC_FS_READDIR_FINISH(_error, _path, _sz, _tracker)
Definition: Logger.h:84
SWC_FS_CLOSE_START
#define SWC_FS_CLOSE_START(_smartfd)
Definition: Logger.h:263
SWC::FS::ImplOptions
Definition: FileSystem.h:66
SWC_FS_OPEN_FINISH
#define SWC_FS_OPEN_FINISH(_error, _smartfd, _open_fds, _tracker)
Definition: Logger.h:149
SWC::FS::FileSystemLocal::FileSystemLocal
FileSystemLocal(Configurables *config)
Definition: FileSystem.cc:86
SWC::FS::Configurables::path_root
std::string path_root
Definition: FileSystem.h:51
SWC::Error::OK
@ OK
Definition: Error.h:45
SWC::FS::Statistics::READ_SYNC
@ READ_SYNC
Definition: Statistics.h:28
SWC::FS::FileSystemLocal::m_directio
bool m_directio
Definition: FileSystem.h:110
SWC_CAN_INLINE
#define SWC_CAN_INLINE
Definition: Compat.h:102
SWC_FS_RENAME_START
#define SWC_FS_RENAME_START(_from, _to)
Definition: Logger.h:103
SWC::Error::FS_EOF
@ FS_EOF
Definition: Error.h:96
SWC_FS_MKDIRS_START
#define SWC_FS_MKDIRS_START(_path)
Definition: Logger.h:67
SWC_FS_LENGTH_FINISH
#define SWC_FS_LENGTH_FINISH(_error, _path, _len, _tracker)
Definition: Logger.h:60
SWC_FS_CREATE_FINISH
#define SWC_FS_CREATE_FINISH(_error, _smartfd, _open_fds, _tracker)
Definition: Logger.h:137
SWC_FS_SYNC_START
#define SWC_FS_SYNC_START(_smartfd)
Definition: Logger.h:252
SWC::FS::FileSystemLocal::remove
void remove(int &err, const std::string &name) override
Definition: FileSystem.cc:140
SWC::Core::Buffer::base
value_type * base
Definition: Buffer.h:131
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC_FS_APPEND_FINISH
#define SWC_FS_APPEND_FINISH(_error, _smartfd, _amount, _tracker)
Definition: Logger.h:223
SWC::FS::OPEN_FLAG_OVERWRITE
@ OPEN_FLAG_OVERWRITE
Definition: FileSystem.h:35
SWC::FS::Statistics::LENGTH_SYNC
@ LENGTH_SYNC
Definition: Statistics.h:36
SWC::FS::Configurables::settings
Config::Settings::Ptr settings
Definition: FileSystem.h:49
SWC::Core::Buffer
Definition: Buffer.h:18
SWC::Core::Buffer::size
size_t size
Definition: Buffer.h:130
SWC::FS::FileSystemLocal::rmdir
void rmdir(int &err, const std::string &name) override
Definition: FileSystem.cc:273
SWC::FS::FileSystemLocal::sync
void sync(int &err, SmartFd::Ptr &smartfd) override
Definition: FileSystem.cc:660
SWC::FS::FileSystemLocal::mkdirs
void mkdirs(int &err, const std::string &name) override
Definition: FileSystem.cc:191
SWC::FS::Callback::ReadAllCb_t
std::function< void(int, StaticBuffer &&)> ReadAllCb_t
Definition: Callbacks.h:30
SWC_FS_READALL_FINISH
#define SWC_FS_READALL_FINISH(_error, _name, _amount, _tracker)
Definition: Logger.h:120
SWC_FS_CREATE_START
#define SWC_FS_CREATE_START(_smartfd, _replication)
Definition: Logger.h:131
SWC::Config::strs
Property::Value_strings::Ptr strs(Strings &&v)
Definition: PropertiesParser.cc:49
SWC::FS::FileSystemLocal::append
size_t append(int &err, SmartFd::Ptr &smartfd, StaticBuffer &buffer, Flags flags) override
Definition: FileSystem.cc:619
SWC::FS::Configurables::cfg_fds_max
Config::Property::Value_int32_g::Ptr cfg_fds_max
Definition: FileSystem.h:50
SWC_FS_OPEN_START
#define SWC_FS_OPEN_START(_smartfd)
Definition: Logger.h:144
SWC::FS::FileSystemLocal::get_type
Type SWC_CONST_FUNC get_type() const noexcept override
Definition: FileSystem.cc:113
SWC::Config::str
Property::Value_string::Ptr str(std::string &&v)
Definition: PropertiesParser.cc:45
SWC_FS_READ_FINISH
#define SWC_FS_READ_FINISH(_error, _smartfd, _amount, _tracker)
Definition: Logger.h:175
SWC::FS::Statistics::APPEND_SYNC
@ APPEND_SYNC
Definition: Statistics.h:30
SWC::FS::apply_local
Configurables * apply_local()
SWC::FS::Statistics::OPEN_SYNC
@ OPEN_SYNC
Definition: Statistics.h:22
SWC_MKDIR
#define SWC_MKDIR(path, perms)
Definition: FileSystem.cc:43
SWC::FS::FileSystem::fd_open_incr
void fd_open_incr() noexcept
Definition: FileSystem.cc:155
SWC::FS::FileSystemLocal::create
void create(int &err, SmartFd::Ptr &smartfd, uint8_t replication) override
Definition: FileSystem.cc:443
SWC::format
std::string format(const char *fmt,...) __attribute__((format(printf
Definition: String.cc:17
SWC::Core::Vector< Dirent >
SWC::FS::Statistics::PREAD_SYNC
@ PREAD_SYNC
Definition: Statistics.h:38
SWC::Condition::from
Comp from(const char **buf, uint32_t *remainp, uint8_t extended=0x00) noexcept
Definition: Comparators.cc:15
SWC::FS::SmartFd::Ptr
std::shared_ptr< SmartFd > Ptr
Definition: SmartFd.h:37
SWC_FS_READDIR_START
#define SWC_FS_READDIR_START(_path)
Definition: Logger.h:79
SWC::FS::FileSystemLocal::pread
size_t pread(int &err, SmartFd::Ptr &smartfd, uint64_t offset, void *dst, size_t amount) override
Definition: FileSystem.cc:582
SWC::FS::FileSystemLocal::readdir
void readdir(int &err, const std::string &name, DirentList &results) override
Definition: FileSystem.cc:200
SWC::StaticBuffer
Core::StaticBuffer StaticBuffer
Definition: Buffer.h:340
SWC::FS::FileSystem::stop
virtual void stop()
Definition: FileSystem.cc:115
SWC_FS_PREAD_FINISH
#define SWC_FS_PREAD_FINISH(_error, _smartfd, _amount, _tracker)
Definition: Logger.h:191
SWC::FS::FileSystemLocal::rename
void rename(int &err, const std::string &from, const std::string &to) override
Definition: FileSystem.cc:284
SWC::FS::FileSystem::fd_open_decr
void fd_open_decr() noexcept
Definition: FileSystem.cc:159
SWC::Comm::Protocol::FsBroker::Handler::rename
void rename(const ConnHandlerPtr &conn, const Event::Ptr &ev)
Definition: Rename.h:17
SWC::FS::Configurables::stats_enabled
bool stats_enabled
Definition: FileSystem.h:52
SWC::Common::Files::Schema::write
void write(SWC::DynamicBuffer &dst_buf, const DB::Schema::Ptr &schema)
Definition: Schema.h:50
SWC::FS::FLUSH
@ FLUSH
Definition: FileSystem.h:43
SWC::FS::FileSystem::path_root
const std::string path_root
Definition: FileSystem.h:107
SWC_FS_READ_START
#define SWC_FS_READ_START(_smartfd, _amount)
Definition: Logger.h:170
SWC_FS_SEEK_FINISH
#define SWC_FS_SEEK_FINISH(_error, _smartfd, _tracker)
Definition: Logger.h:235
SWC::FS::FileSystemLocal::close
void close(int &err, SmartFd::Ptr &smartfd) override
Definition: FileSystem.cc:668
SWC::FS::FileSystemLocal::exists
bool exists(int &err, const std::string &name) override
Definition: FileSystem.cc:127
SWC::FS::FileSystem::fds_open
size_t fds_open() const noexcept
Definition: FileSystem.cc:167
SWC::FS::Statistics::Metric::Tracker
Definition: Statistics.h:69
SWC::FS::Statistics
Definition: Statistics.h:18
SWC::FS::FileSystem::path_data
const std::string path_data
Definition: FileSystem.h:108
SWC_FS_EXISTS_START
#define SWC_FS_EXISTS_START(_path)
Definition: Logger.h:31
SWC::FS::FileSystemLocal::read
void read(int &err, const std::string &name, StaticBuffer *dst) override
Definition: FileSystem.h:64
FileSystem.h
SWC_FS_RMDIR_START
#define SWC_FS_RMDIR_START(_path)
Definition: Logger.h:91
flags
uint8_t flags
Flags.
Definition: Header.h:55
SWC::FS::SYNC
@ SYNC
Definition: FileSystem.h:44
SWC_FS_SEEK_START
#define SWC_FS_SEEK_START(_smartfd, _offset)
Definition: Logger.h:230
SWC::Core::Buffer::Ptr
std::shared_ptr< BufferT > Ptr
Definition: Buffer.h:22
SWC_FS_LENGTH_START
#define SWC_FS_LENGTH_START(_path)
Definition: Logger.h:55
SWC_FS_CLOSE_FINISH
#define SWC_FS_CLOSE_FINISH(_error, _smartfd, _tracker)
Definition: Logger.h:268
SWC_FS_REMOVE_FINISH
#define SWC_FS_REMOVE_FINISH(_error, _path, _tracker)
Definition: Logger.h:48
SWC::FS::FileSystem::get_abspath
virtual void get_abspath(const std::string &name, std::string &abspath, size_t reserve=0)
Definition: FileSystem.cc:138
SWC::Core::Vector::size
constexpr SWC_CAN_INLINE size_type size() const noexcept
Definition: Vector.h:189
SWC::FS::OPEN_FLAG_DIRECTIO
@ OPEN_FLAG_DIRECTIO
Definition: FileSystem.h:34
SWC_FS_READALL_START
#define SWC_FS_READALL_START(_name)
Definition: Logger.h:115
SWC::Core::Vector::emplace_back
SWC_CAN_INLINE reference emplace_back(ArgsT &&... args)
Definition: Vector.h:349
SWC::FS::FileSystem::statistics
Statistics statistics
Definition: FileSystem.h:114
SWC_FS_SYNC_FINISH
#define SWC_FS_SYNC_FINISH(_error, _smartfd, _tracker)
Definition: Logger.h:257
SWC_FS_REMOVE_START
#define SWC_FS_REMOVE_START(_path)
Definition: Logger.h:43
SWC::Config::Property::Value_int32_g
Definition: Property.h:586
SWC_FS_EXISTS_FINISH
#define SWC_FS_EXISTS_FINISH(_error, _path, _state, _tracker)
Definition: Logger.h:36