diff --git a/cpp/src/db.h b/cpp/src/db.h index 5d8c0cf791dcf1353a15e0df506006e6e4bf2316..1840450502a1519a43e75d73eb5dac56e3b37491 100644 --- a/cpp/src/db.h +++ b/cpp/src/db.h @@ -1,6 +1,7 @@ #ifndef VECENGINE_DB_H_ #define VECENGINE_DB_H_ +#include #include "options.h" namespace vecengine { @@ -11,6 +12,9 @@ class DB { public: static DB* Open(const Options& options_, const std::string& name_); + virtual std::string add_group(GroupOptions options_, + const std::string& group_id_) = 0; + DB() = default; DB(const DB&) = delete; DB& operator=(const DB&) = delete; diff --git a/cpp/src/db_impl.cpp b/cpp/src/db_impl.cpp index 66ee9633ee49eb59a6c26f9741b0162e5907e0d2..3d030d9e2aedcad95c21543bb1afc61d2086ba60 100644 --- a/cpp/src/db_impl.cpp +++ b/cpp/src/db_impl.cpp @@ -1,11 +1,31 @@ -include "db_impl.h" +#include +#include "db_impl.h" namespace vecengine { -DB::DB(const Options& options_, const std::string& name_) +DBImpl::DBImpl(const Options& options_, const std::string& name_) : _dbname(name_), _env(options_.env), _options(options_) { } +Status DBImpl::add_group(const GroupOptions& options_, + const std::string& group_id_, + std::string& gid_) { + assert((!options_.has_id) || + (options_.has_id && ("" != group_id_))); + +} + +/* + * DB + */ + +DB::~DB() {} + +DB* DB::Open(const Options& options_, const std::string& name_) { + DBImpl* impl = new DBImpl(options_, name_); + return impl; +} + } // namespace vecengine diff --git a/cpp/src/db_impl.h b/cpp/src/db_impl.h index 7dc55273f111c36559f8bb4479477f53abdeebf8..0d7d2a3f10a7567a43d9b965456cd123459e2fa9 100644 --- a/cpp/src/db_impl.h +++ b/cpp/src/db_impl.h @@ -11,8 +11,16 @@ class DBImpl : public DB { public: DBImpl(const Options& options_, const std::string& name_); + virtual Status add_group(GroupOptions options_, + const std::string& group_id_, + std::string& gid_) override; + virtual ~DBImpl(); private: + + Status meta_add_group(const std::string& group_id_); + Status meta_add_group_file(const std::string& group_id_); + const _dbname; Env* const _env; const Options _options; diff --git a/cpp/src/db_meta.cpp b/cpp/src/db_meta.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c1fc0f75f25342880ebeeda79c36d19ef29f563f --- /dev/null +++ b/cpp/src/db_meta.cpp @@ -0,0 +1,14 @@ +#include "db_meta.h" + +namespace zilliz { +namespace vecwise { +namespace engine { + +Meta* Meta::Default() { + static DefaultMeta meta; + return *meta; +} + +} // namespace engine +} // namespace vecwise +} // namespace zilliz diff --git a/cpp/src/db_meta.h b/cpp/src/db_meta.h new file mode 100644 index 0000000000000000000000000000000000000000..e84d97051fef123b8265115565deab95fcf8214d --- /dev/null +++ b/cpp/src/db_meta.h @@ -0,0 +1,60 @@ +#ifndef VECENGINE_DB_META_H_ +#define VECENGINE_DB_META_H_ + +namespace zilliz { +namespace vecwise { +namespace engine { + +struct GroupSchema { + size_t id; + std::string group_id; + size_t files_cnt = 0; + uint16_t dimension; + std::string location = ""; +}; // GroupSchema + + +struct GroupFileSchema { + typedef enum { + RAW, + INDEX + } FILE_TYPE; + + size_t id; + std::string group_id; + std::string file_id; + int files_type = RAW; + size_t rows; + std::string location = ""; +}; // GroupFileSchema + +typedef std::vector GroupFilesSchema; + + +class Meta { +public: + virtual Status add_group(const std::string& group_id_, GroupSchema& group_info) = 0; + virtual Status get_group(const std::string& group_id_, GroupSchema& group_info) = 0; + virtual Status has_group(const std::string& group_id_, bool& has_or_not) = 0; + + virtual Status add_group_file(const std::string& group_id, + GroupFileSchema& group_file_info) = 0; + virtual Status has_group_file(const std::string& group_id, + const std::string& file_id, + bool& has_or_not) = 0; + virtual Status get_group_file(const std::string& group_id, + const std::string& file_id, + GroupFileSchema& group_file_info) = 0; + virtual Status mark_group_file_as_index(const std::string& group_id, + const std::string& file_id) = 0; + + virtual Status get_group_files(const std::string& group_id, + GroupFilesSchema& group_files_info) = 0; + +}; // MetaData + +} // namespace engine +} // namespace vecwise +} // namespace zilliz + +#endif // VECENGINE_DB_META_H_ diff --git a/cpp/src/db_meta_impl.cpp b/cpp/src/db_meta_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a6754a817dc7925ff1e3a278a8291b5a47461445 --- /dev/null +++ b/cpp/src/db_meta_impl.cpp @@ -0,0 +1,66 @@ +#include "db_meta_impl.h" + +namespace zilliz { +namespace vecwise { +namespace engine { + +Status DBMetaImpl::DBMetaImpl(DBMetaOptions options_) + : _options(options_) { + initialize(); +} + +Status DBMetaImpl::initialize() { + // PXU TODO: Create DB Connection + return Status.OK(); +} + +Status DBMetaImpl::add_group(const std::string& group_id_, GroupSchema& group_info) { + //PXU TODO + return Status.OK(); +} + +Status DBMetaImpl::get_group(const std::string& group_id_, GroupSchema& group_info) { + //PXU TODO + return Status.OK(); +} + +Status DBMetaImpl::has_group(const std::string& group_id_, bool& has_or_not) { + //PXU TODO + return Status.OK(); +} + +Status DBMetaImpl::add_group_file(const std::string& group_id, + GroupFileSchema& group_file_info) { + //PXU TODO + return Status.OK(); +} + +Status DBMetaImpl::has_group_file(const std::string& group_id, + const std::string& file_id, + bool& has_or_not) { + //PXU TODO + return Status.OK(); +} + +Status DBMetaImpl::get_group_file(const std::string& group_id, + const std::string& file_id, + GroupFileSchema& group_file_info) { + //PXU TODO + return Status.OK(); +} + +Status DBMetaImpl::get_group_files(const std::string& group_id, + GroupFilesSchema& group_files_info) { + // PXU TODO + return Status.OK(); +} + +Status DBMetaImpl::mark_group_file_as_index(const std::string& group_id, + const std::string& file_id) { + //PXU TODO + return Status.OK(); +} + +} // namespace engine +} // namespace vecwise +} // namespace zilliz diff --git a/cpp/src/db_meta_impl.h b/cpp/src/db_meta_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..d3aa5e19d634fd57fa310a9c6aa7a103ceee093a --- /dev/null +++ b/cpp/src/db_meta_impl.h @@ -0,0 +1,45 @@ +#ifndef VECENGINE_DB_META_IMPL_H_ +#define VECENGINE_DB_META_IMPL_H_ + +#include "db_meta.h" +#include "options.h" + +namespace zilliz { +namespace vecwise { +namespace engine { + +class DBMetaImpl : public Meta { +public: + DBMetaImpl(DBMetaOptions& options_); + + virtual Status add_group(const std::string& group_id_, GroupSchema& group_info) override; + virtual Status get_group(const std::string& group_id_, GroupSchema& group_info) override; + virtual Status has_group(const std::string& group_id_, bool& has_or_not) override; + + virtual Status add_group_file(const std::string& group_id, + GroupFileSchema& group_file_info) override; + virtual Status has_group_file(const std::string& group_id, + const std::string& file_id, + bool& has_or_not) override; + virtual Status get_group_file(const std::string& group_id, + const std::string& file_id, + GroupFileSchema& group_file_info) override; + virtual Status mark_group_file_as_index(const std::string& group_id, + const std::string& file_id) override; + + virtual Status get_group_files(const std::string& group_id, + GroupFilesSchema& group_files_info) override; + +private: + + Status initialize(); + + const DBMetaOptions _options; + +}; // DBMetaImpl + +} // namespace engine +} // namespace vecwise +} // namespace zilliz + +#endif // VECENGINE_DB_META_IMPL_H_ diff --git a/cpp/src/options.h b/cpp/src/options.h index 114861104ddd99aceee36b429ff71b01ec896288..f07f10cd39438c78dc1fd6fa650750e5ce7e63fc 100644 --- a/cpp/src/options.h +++ b/cpp/src/options.h @@ -1,12 +1,30 @@ #ifndef VECENGINE_OPTIONS_H_ #define VECENGINE_OPTIONS_H_ +#include + namespace vecengine { struct Options { }; // Options + +struct GroupOptions { + size_t dimension; + bool has_id = false; +}; // GroupOptions + + +struct MetaOptions { +}; // MetaOptions + + +struct DBMetaOptions : public MetaOptions { + std::string db_uri; +}; // DBMetaOptions + + } // namespace vecengine #endif // VECENGINE_OPTIONS_H_ diff --git a/cpp/src/status.cpp b/cpp/src/status.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8c547d5abec0be84885e33c6cdfb88a5b96f81d6 --- /dev/null +++ b/cpp/src/status.cpp @@ -0,0 +1,52 @@ +#include "status.h" + +namespace vecengine { + +const char* Status::CopyState(const char* state_) { + uint32_t size; + memcpy(&size, state_, sizeof(size)); + char result = new char[size+5]; + memcpy(result, state_, size+5); + return result; +} + +Status::Status(Code code_, const std::string& msg_, const std::string& msg2_) { + assert(code_ != kOK); + const uint32_t len1 = msg_.size(); + const uint32_t len2 = msg2_.size(); + const uint32_t size = len1 + (len2 ? (2+len2) : 0); + char* result = new char[size+5]; + memcpy(result, &size, sizeof(size)); + result[4] = static_cast(code); + memcpy(result+5, msg_.data(), len1); + if (len2) { + result[5 + len1] = ':'; + result[6 + len1] = ' '; + memcpy(result + 7 + len1, msg2_.data(), len2); + } + _state = result; +} + +std::string Status::ToString() const { + if (_state == nullptr) return "OK"; + char tmp[30]; + const char* type; + switch (code()) { + case kOK: + type = "OK"; + break; + default: + snprintf(tmp, sizeof(tmp), "Unkown code(%d): ", + static_cast(code())); + type = tmp; + break; + } + + std::string result(type); + uint32_t length; + memcpy(&length, state_, sizeof(length)); + result.append(state_ + 5, length); + return result; +} + +} // namespace vecengine diff --git a/cpp/src/status.h b/cpp/src/status.h new file mode 100644 index 0000000000000000000000000000000000000000..01e3a4ce5dc1da6619e441ac81e71ab9e135e6c9 --- /dev/null +++ b/cpp/src/status.h @@ -0,0 +1,55 @@ +#ifndef VECENGINE_STATUS_H_ +#define VECENGINE_STATUS_H_ + +namespace vecengine { + +class Status { +public: + Status() noexcept : _state(nullptr) {} + ~Status() { delete[] _state; } + + Status(const Status& rhs_); + Status& operator=(const Status& rhs_); + + Status(const Status&& rhs_) noexcept : _state(rhs_._state) { rhs_._state = nullptr; } + Status& operator=(const Status& rhs_) noexcept; + + static Status OK() { return Status(); } + + bool ok() const { return _state == nullptr; } + +private: + const char* _state; + + enum Code { + kOK = 0, + }; + + Code code() const { + return (_state == nullptr) ? kOK : static_cast(_state[4]) + } + + static const char* CopyState(const char* s); + +}; // Status + +inline Status::Status(const Status* rhs_) { + _state = (rhs_._state == nullptr) ? nullptr : CopyState(rhs_._state); +} + +inline Status& Status::operator=(const Status& rhs_) { + if (_state != rhs_._state) { + delete[] state_; + _state = (rhs_._state == nullptr) ? nullptr : CopyState(rhs_._state); + } + return *this; +} + +inline Status& Status::operator=(Status&& rhs_) noexcept { + std::swap(_state, rhs_._state); + return *this; +} + +} // namespace vecengine + +#endif // VECENGINE_STATUS_H_