 |
SWC-DB
v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
|
Go to the documentation of this file.
14 namespace SWC {
namespace FS {
18 config->
settings->file_desc.add_options()
20 "Ceph FileSystem's base root path")
25 "This ceph Client Id(name)")
28 "CephFs Permission Group")
30 "CephFs Permission User")
33 "The ceph configuration file 'ceph.conf'")
35 "The ceph config value for 'mon_addr'")
38 "Enable or Disable Metrics Tracking")
41 "CephFs default replication")
44 "Max Open Fds for opt. without closing")
47 "Size of ceph stripe unit")
49 "Count of ceph stripes")
51 "Size of ceph object")
55 config->
settings->get_str(
"swc.fs.ceph.cfg",
""),
60 "swc.fs.ceph.path.root");
64 "swc.fs.ceph.metrics.enabled");
74 settings->get<Config::Property::Value_int32_g>(
75 "swc.fs.ceph.stripe.unit")),
77 settings->get<Config::Property::Value_int32_g>(
78 "swc.fs.ceph.stripe.count")),
80 settings->get<Config::Property::Value_int32_g>(
81 "swc.fs.ceph.object.size")),
82 m_filesystem(nullptr), m_perm(nullptr) {
91 "FS-Ceph, unable to initialize connection to Ceph, try=%u",
93 std::this_thread::sleep_for(std::chrono::milliseconds(1000));
101 "FS-Ceph, ceph_cwd='%s' != path_root='%s' changing",
117 if(
settings->has(
"swc.fs.ceph.replication"))
118 ceph_set_default_file_replication(
144 std::string client_id;
145 if(
settings->has(
"swc.fs.ceph.client.id"))
146 client_id =
settings->get_str(
"swc.fs.ceph.client.id");
149 &
m_filesystem, client_id.empty() ?
nullptr : client_id.c_str());
150 if(err < 0 || errno) {
151 err = err ? -err : errno;
158 if((ceph_conf =
settings->has(
"swc.fs.ceph.configuration.file"))) {
159 const std::string conf_file =
settings->get_str(
160 "swc.fs.ceph.configuration.file");
163 err = ceph_conf_read_file(
m_filesystem, conf_file.c_str());
164 if(err < 0 || errno) {
165 err = err ? -err : errno;
174 if(!ceph_conf &&
settings->has(
"swc.fs.ceph.mon.addr")) {
175 const std::string mon_host =
settings->get_str(
"swc.fs.ceph.mon.addr");
176 err = ceph_conf_set(
m_filesystem,
"mon_host", mon_host.c_str());
177 if(err < 0 || errno) {
178 err = err ? -err : errno;
187 std::string mon_host;
188 mon_host.resize(4096);
189 int sz = ceph_conf_get(
m_filesystem,
"mon_host", mon_host.data(), 4096);
190 mon_host = std::string(mon_host.data(), sz);
192 mon_host.c_str(), sz);
198 if(err < 0 || errno) {
199 err = err ? -err : errno;
216 ceph_userperm_destroy(
m_perm);
236 "(type=CEPH path_root=%s path_data=%s)",
250 struct ceph_statx stx;
252 CEPH_STATX_CTIME, AT_SYMLINK_NOFOLLOW);
287 struct ceph_statx stx;
290 CEPH_STATX_SIZE, AT_SYMLINK_NOFOLLOW);
295 size_t len = err ? 0 : stx.stx_size;
323 struct ceph_dir_result* dirp =
nullptr;
324 err = ceph_opendir(
m_filesystem, abspath.c_str(), &dirp);
333 struct ceph_statx stx;
335 while((err = ceph_readdirplus_r(
337 &stx, CEPH_STATX_INO, AT_NO_ATTR_SYNC,
nullptr)) == 1) {
338 if(de.d_name[0] ==
'.' || !de.d_name[0])
342 entry.name.reserve(abspath.length() + 1 + strlen(de.d_name));
343 entry.name.append(abspath);
344 entry.name.append(
"/");
345 entry.name.append(de.d_name);
346 entry.is_dir = S_ISDIR(stx.stx_mode) || de.d_type == DT_DIR;
348 entry.length = stx.stx_size;
349 entry.last_modification_time = stx.stx_mtime.tv_sec;
369 struct ceph_dir_result* dirp =
nullptr;
370 err = ceph_opendir(
m_filesystem, abspath.c_str(), &dirp);
379 struct ceph_statx stx;
381 while((err = ceph_readdirplus_r(
383 &stx, CEPH_STATX_INO, AT_NO_ATTR_SYNC,
nullptr)) == 1) {
384 if(de.d_name[0] ==
'.' || !de.d_name[0])
387 if(S_ISDIR(stx.stx_mode) || de.d_type == DT_DIR) {
388 rmdir(err, name +
"/" + de.d_name);
410 const std::string& to) {
413 std::string abspath_from;
415 std::string abspath_to;
419 err = ceph_rename(
m_filesystem, abspath_from.c_str(), abspath_to.c_str());
429 uint8_t replication) {
432 int oflags = O_WRONLY | O_CREAT;
443 int tmperr = ceph_open_layout(
450 }
else if(tmperr > 0) {
459 if(tmperr == EACCES || tmperr == ENOENT)
461 else if (tmperr == EPERM)
475 int oflags = O_RDONLY;
477 int tmperr = ceph_open(
m_filesystem, abspath.c_str(), oflags, 0);
480 }
else if(tmperr > 0) {
490 if(tmperr == EACCES || tmperr == ENOENT)
492 else if (tmperr == EPERM)
501 void *dst,
size_t amount) {
508 static_cast<char*
>(dst), amount, smartfd->pos());
520 if((ret = nread) != amount)
522 smartfd->forward(nread);
530 uint64_t offset,
void *dst,
size_t amount) {
537 static_cast<char*
>(dst), amount, offset);
548 }
else if((ret = nread) != amount) {
560 ssize_t nwritten = 0;
564 reinterpret_cast<const char*
>(buffer.
base),
565 buffer.
size, smartfd->pos());
570 else if(nwritten != ssize_t(buffer.
size))
584 smartfd->forward(nwritten);
595 err = ceph_lseek(
m_filesystem, smartfd->fd(), offset, SEEK_SET);
601 smartfd->pos(offset);
636 int32_t fd = smartfd->invalidate();
#define SWC_FS_FLUSH_FINISH(_error, _smartfd, _tracker)
Property::Value_int32::Ptr i32(const int32_t &v)
#define SWC_FS_APPEND_START(_smartfd, _amount, _flags)
Property::Value_int32_g::Ptr g_i32(const int32_t &v)
FileSystemCeph(Configurables *config)
SWC::FS::FileSystem * fs_make_new_ceph(SWC::FS::Configurables *config)
#define SWC_LOGF(priority, fmt,...)
const Config::Property::Value_int32_g::Ptr cfg_stripe_unit
#define SWC_FS_FLUSH_START(_smartfd)
const char * get_text(const int err) noexcept
#define SWC_FS_RMDIR_FINISH(_error, _path, _tracker)
Configurables * apply_ceph(Configurables *config)
#define SWC_FS_RENAME_FINISH(_error, _from, _to, _tracker)
SWC_CAN_INLINE Metric::Tracker tracker(Command cmd) noexcept
void sync(int &err, SmartFd::Ptr &smartfd) override
void seek(int &err, SmartFd::Ptr &smartfd, size_t offset) override
Property::Value_bool::Ptr boo(const bool &v)
SWC_CAN_INLINE int32_t get() const noexcept
#define SWC_FS_PREAD_START(_smartfd, _offset, _amount)
#define SWC_FS_MKDIRS_FINISH(_error, _path, _tracker)
void rmdir(int &err, const std::string &name) override
void open(int &err, SmartFd::Ptr &smartfd) override
#define SWC_FS_READDIR_FINISH(_error, _path, _sz, _tracker)
#define SWC_FS_CLOSE_START(_smartfd)
#define SWC_FS_OPEN_FINISH(_error, _smartfd, _open_fds, _tracker)
bool str_eq(const char *s1, const char *s2) noexcept SWC_ATTRIBS((SWC_ATTRIB_O3))
constexpr SWC_CAN_INLINE void store(T v) noexcept
#define SWC_FS_RENAME_START(_from, _to)
#define SWC_FS_MKDIRS_START(_path)
#define SWC_FS_LENGTH_FINISH(_error, _path, _len, _tracker)
#define SWC_FS_CREATE_FINISH(_error, _smartfd, _open_fds, _tracker)
#define SWC_FS_SYNC_START(_smartfd)
The SWC-DB C++ namespace 'SWC'.
#define SWC_FS_APPEND_FINISH(_error, _smartfd, _amount, _tracker)
void remove(int &err, const std::string &name) override
Config::Settings::Ptr settings
size_t pread(int &err, SmartFd::Ptr &smartfd, uint64_t offset, void *dst, size_t amount) override
#define SWC_FS_CREATE_START(_smartfd, _replication)
Property::Value_strings::Ptr strs(Strings &&v)
std::string to_string() const override
Config::Property::Value_int32_g::Ptr cfg_fds_max
#define SWC_FS_OPEN_START(_smartfd)
Property::Value_string::Ptr str(std::string &&v)
#define SWC_FS_READ_FINISH(_error, _smartfd, _amount, _tracker)
struct ceph_mount_info * m_filesystem
void fd_open_incr() noexcept
const Config::Settings::Ptr settings
size_t append(int &err, SmartFd::Ptr &smartfd, StaticBuffer &buffer, Flags flags) override
size_t length(int &err, const std::string &name) override
std::string format(const char *fmt,...) __attribute__((format(printf
void create(int &err, SmartFd::Ptr &smartfd, uint8_t replication) override
Comp from(const char **buf, uint32_t *remainp, uint8_t extended=0x00) noexcept
std::shared_ptr< SmartFd > Ptr
#define SWC_FS_READDIR_START(_path)
#define SWC_FS_PREAD_FINISH(_error, _smartfd, _amount, _tracker)
void rename(int &err, const std::string &from, const std::string &to) override
void fd_open_decr() noexcept
void readdir(int &err, const std::string &name, DirentList &results) override
void read(int &err, const std::string &name, StaticBuffer *dst) override
void mkdirs(int &err, const std::string &name) override
const std::string path_root
#define SWC_FS_READ_START(_smartfd, _amount)
#define SWC_FS_SEEK_FINISH(_error, _smartfd, _tracker)
size_t fds_open() const noexcept
const std::string path_data
#define SWC_FS_EXISTS_START(_path)
bool exists(int &err, const std::string &name) override
const Config::Property::Value_int32_g::Ptr cfg_object_size
#define SWC_FS_RMDIR_START(_path)
const Config::Property::Value_int32_g::Ptr cfg_stripe_count
#define SWC_FS_SEEK_START(_smartfd, _offset)
#define SWC_FS_LENGTH_START(_path)
void flush(int &err, SmartFd::Ptr &smartfd) override
virtual ~FileSystemCeph() noexcept
#define SWC_FS_CLOSE_FINISH(_error, _smartfd, _tracker)
#define SWC_FS_REMOVE_FINISH(_error, _path, _tracker)
virtual void get_abspath(const std::string &name, std::string &abspath, size_t reserve=0)
void close(int &err, SmartFd::Ptr &smartfd) override
constexpr SWC_CAN_INLINE size_type size() const noexcept
SWC_CAN_INLINE reference emplace_back(ArgsT &&... args)
#define SWC_FS_SYNC_FINISH(_error, _smartfd, _tracker)
#define SWC_FS_REMOVE_START(_path)
Type SWC_CONST_FUNC get_type() const noexcept override
#define SWC_FS_EXISTS_FINISH(_error, _path, _state, _tracker)