提交 c266bc52 编写于 作者: W wxyu

Merge remote-tracking branch 'main/branch-0.4.0' into branch-0.4.0


Former-commit-id: 3e09a1fea1621505a5a07920971739f1518e73ff
...@@ -6,10 +6,13 @@ container('milvus-build-env') { ...@@ -6,10 +6,13 @@ container('milvus-build-env') {
def knowhere_build_dir = "${env.WORKSPACE}/milvus_engine/cpp/thirdparty/knowhere/cmake_build" def knowhere_build_dir = "${env.WORKSPACE}/milvus_engine/cpp/thirdparty/knowhere/cmake_build"
checkout([$class: 'GitSCM', branches: [[name: "${SEMVER}"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'SubmoduleOption',disableSubmodules: false,parentCredentials: true,recursiveSubmodules: true,reference: '',trackingSubmodules: false]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: "${params.GIT_USER}", url: "git@192.168.1.105:megasearch/milvus.git", name: 'origin', refspec: "+refs/heads/${SEMVER}:refs/remotes/origin/${SEMVER}"]]]) checkout([$class: 'GitSCM', branches: [[name: "${SEMVER}"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'SubmoduleOption',disableSubmodules: false,parentCredentials: true,recursiveSubmodules: true,reference: '',trackingSubmodules: false]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: "${params.GIT_USER}", url: "git@192.168.1.105:megasearch/milvus.git", name: 'origin', refspec: "+refs/heads/${SEMVER}:refs/remotes/origin/${SEMVER}"]]])
/*
dir ("cpp/thirdparty/knowhere") { dir ("cpp/thirdparty/knowhere") {
checkout([$class: 'GitSCM', branches: [[name: "${SEMVER}"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'SubmoduleOption',disableSubmodules: false,parentCredentials: true,recursiveSubmodules: true,reference: '',trackingSubmodules: false]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: "${params.GIT_USER}", url: "git@192.168.1.105:megasearch/knowhere.git", name: 'origin', refspec: "+refs/heads/${SEMVER}:refs/remotes/origin/${SEMVER}"]]]) checkout([$class: 'GitSCM', branches: [[name: "${SEMVER}"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'SubmoduleOption',disableSubmodules: false,parentCredentials: true,recursiveSubmodules: true,reference: '',trackingSubmodules: false]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: "${params.GIT_USER}", url: "git@192.168.1.105:megasearch/knowhere.git", name: 'origin', refspec: "+refs/heads/${SEMVER}:refs/remotes/origin/${SEMVER}"]]])
sh "./build.sh -t ${params.BUILD_TYPE} -p ${knowhere_build_dir} -j" sh "./build.sh -t ${params.BUILD_TYPE} -p ${knowhere_build_dir} -j"
} }
*/
dir ("cpp") { dir ("cpp") {
sh "git config --global user.email \"test@zilliz.com\"" sh "git config --global user.email \"test@zilliz.com\""
......
...@@ -7,10 +7,12 @@ container('milvus-build-env') { ...@@ -7,10 +7,12 @@ container('milvus-build-env') {
checkout([$class: 'GitSCM', branches: [[name: "${SEMVER}"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'SubmoduleOption',disableSubmodules: false,parentCredentials: true,recursiveSubmodules: true,reference: '',trackingSubmodules: false]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: "${params.GIT_USER}", url: "git@192.168.1.105:megasearch/milvus.git", name: 'origin', refspec: "+refs/heads/${SEMVER}:refs/remotes/origin/${SEMVER}"]]]) checkout([$class: 'GitSCM', branches: [[name: "${SEMVER}"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'SubmoduleOption',disableSubmodules: false,parentCredentials: true,recursiveSubmodules: true,reference: '',trackingSubmodules: false]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: "${params.GIT_USER}", url: "git@192.168.1.105:megasearch/milvus.git", name: 'origin', refspec: "+refs/heads/${SEMVER}:refs/remotes/origin/${SEMVER}"]]])
/*
dir ("cpp/thirdparty/knowhere") { dir ("cpp/thirdparty/knowhere") {
checkout([$class: 'GitSCM', branches: [[name: "${SEMVER}"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'SubmoduleOption',disableSubmodules: false,parentCredentials: true,recursiveSubmodules: true,reference: '',trackingSubmodules: false]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: "${params.GIT_USER}", url: "git@192.168.1.105:megasearch/knowhere.git", name: 'origin', refspec: "+refs/heads/${SEMVER}:refs/remotes/origin/${SEMVER}"]]]) checkout([$class: 'GitSCM', branches: [[name: "${SEMVER}"]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'SubmoduleOption',disableSubmodules: false,parentCredentials: true,recursiveSubmodules: true,reference: '',trackingSubmodules: false]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: "${params.GIT_USER}", url: "git@192.168.1.105:megasearch/knowhere.git", name: 'origin', refspec: "+refs/heads/${SEMVER}:refs/remotes/origin/${SEMVER}"]]])
sh "./build.sh -t ${params.BUILD_TYPE} -p ${knowhere_build_dir} -j" sh "./build.sh -t ${params.BUILD_TYPE} -p ${knowhere_build_dir} -j"
} }
*/
dir ("cpp") { dir ("cpp") {
sh "git config --global user.email \"test@zilliz.com\"" sh "git config --global user.email \"test@zilliz.com\""
......
...@@ -16,6 +16,7 @@ Please mark all change in change log and use the ticket from JIRA. ...@@ -16,6 +16,7 @@ Please mark all change in change log and use the ticket from JIRA.
- MS-331 - Crate Table : when table exists, error code is META_FAILED(code=15) rather than ILLEGAL TABLE NAME(code=9)) - MS-331 - Crate Table : when table exists, error code is META_FAILED(code=15) rather than ILLEGAL TABLE NAME(code=9))
- MS-430 - Search no result if index created with FLAT - MS-430 - Search no result if index created with FLAT
- MS-443 - Create index hang again - MS-443 - Create index hang again
- MS-436 - Delete vectors failed if index created with index_type: IVF_FLAT/IVF_SQ8
## Improvement ## Improvement
- MS-327 - Clean code for milvus - MS-327 - Clean code for milvus
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
BUILD_TYPE="Debug" BUILD_TYPE="Debug"
BUILD_UNITTEST="OFF" BUILD_UNITTEST="OFF"
LICENSE_CHECK="OFF"
INSTALL_PREFIX=$(pwd)/milvus INSTALL_PREFIX=$(pwd)/milvus
MAKE_CLEAN="OFF" MAKE_CLEAN="OFF"
BUILD_COVERAGE="OFF" BUILD_COVERAGE="OFF"
...@@ -12,7 +11,7 @@ BUILD_FAISS_WITH_MKL="OFF" ...@@ -12,7 +11,7 @@ BUILD_FAISS_WITH_MKL="OFF"
USE_JFROG_CACHE="OFF" USE_JFROG_CACHE="OFF"
KNOWHERE_BUILD_DIR="`pwd`/src/core/cmake_build" KNOWHERE_BUILD_DIR="`pwd`/src/core/cmake_build"
while getopts "p:d:t:k:uhlrcgmj" arg while getopts "p:d:t:k:uhrcgmj" arg
do do
case $arg in case $arg in
t) t)
...@@ -28,9 +27,6 @@ do ...@@ -28,9 +27,6 @@ do
d) d)
DB_PATH=$OPTARG DB_PATH=$OPTARG
;; ;;
l)
LICENSE_CHECK="ON"
;;
r) r)
if [[ -d cmake_build ]]; then if [[ -d cmake_build ]]; then
rm ./cmake_build -r rm ./cmake_build -r
...@@ -60,7 +56,6 @@ parameter: ...@@ -60,7 +56,6 @@ parameter:
-u: building unit test options(default: OFF) -u: building unit test options(default: OFF)
-p: install prefix(default: $(pwd)/milvus) -p: install prefix(default: $(pwd)/milvus)
-d: db path(default: /opt/milvus) -d: db path(default: /opt/milvus)
-l: build license version(default: OFF)
-r: remove previous build directory(default: OFF) -r: remove previous build directory(default: OFF)
-c: code coverage(default: OFF) -c: code coverage(default: OFF)
-g: profiling(default: OFF) -g: profiling(default: OFF)
...@@ -94,7 +89,6 @@ if [[ ${MAKE_CLEAN} == "ON" ]]; then ...@@ -94,7 +89,6 @@ if [[ ${MAKE_CLEAN} == "ON" ]]; then
-DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX}
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \ -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DCMAKE_CUDA_COMPILER=${CUDA_COMPILER} \ -DCMAKE_CUDA_COMPILER=${CUDA_COMPILER} \
-DCMAKE_LICENSE_CHECK=${LICENSE_CHECK} \
-DBUILD_COVERAGE=${BUILD_COVERAGE} \ -DBUILD_COVERAGE=${BUILD_COVERAGE} \
-DMILVUS_DB_PATH=${DB_PATH} \ -DMILVUS_DB_PATH=${DB_PATH} \
-DMILVUS_ENABLE_PROFILING=${PROFILING} \ -DMILVUS_ENABLE_PROFILING=${PROFILING} \
......
...@@ -162,7 +162,7 @@ Status DBImpl::Query(const std::string &table_id, uint64_t k, uint64_t nq, uint6 ...@@ -162,7 +162,7 @@ Status DBImpl::Query(const std::string &table_id, uint64_t k, uint64_t nq, uint6
const float *vectors, QueryResults &results) { const float *vectors, QueryResults &results) {
server::CollectQueryMetrics metrics(nq); server::CollectQueryMetrics metrics(nq);
meta::DatesT dates = {meta::Meta::GetDate()}; meta::DatesT dates = {utils::GetDate()};
Status result = Query(table_id, k, nq, nprobe, vectors, dates, results); Status result = Query(table_id, k, nq, nprobe, vectors, dates, results);
return result; return result;
......
...@@ -156,6 +156,35 @@ bool UserDefinedId(int64_t flag) { ...@@ -156,6 +156,35 @@ bool UserDefinedId(int64_t flag) {
return flag & meta::FLAG_MASK_USERID; return flag & meta::FLAG_MASK_USERID;
} }
meta::DateT GetDate(const std::time_t& t, int day_delta) {
struct tm ltm;
localtime_r(&t, &ltm);
if (day_delta > 0) {
do {
++ltm.tm_mday;
--day_delta;
} while(day_delta > 0);
mktime(&ltm);
} else if (day_delta < 0) {
do {
--ltm.tm_mday;
++day_delta;
} while(day_delta < 0);
mktime(&ltm);
} else {
ltm.tm_mday;
}
return ltm.tm_year*10000 + ltm.tm_mon*100 + ltm.tm_mday;
}
meta::DateT GetDateWithDelta(int day_delta) {
return GetDate(std::time(nullptr), day_delta);
}
meta::DateT GetDate() {
return GetDate(std::time(nullptr), 0);
}
} // namespace utils } // namespace utils
} // namespace engine } // namespace engine
} // namespace milvus } // namespace milvus
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "db/Types.h" #include "db/Types.h"
#include <string> #include <string>
#include <ctime>
namespace zilliz { namespace zilliz {
namespace milvus { namespace milvus {
...@@ -29,6 +30,10 @@ bool IsSameIndex(const TableIndex& index1, const TableIndex& index2); ...@@ -29,6 +30,10 @@ bool IsSameIndex(const TableIndex& index1, const TableIndex& index2);
bool UserDefinedId(int64_t flag); bool UserDefinedId(int64_t flag);
meta::DateT GetDate(const std::time_t &t, int day_delta = 0);
meta::DateT GetDate();
meta::DateT GetDateWithDelta(int day_delta);
} // namespace utils } // namespace utils
} // namespace engine } // namespace engine
} // namespace milvus } // namespace milvus
......
/*******************************************************************************
* Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited.
* Proprietary and confidential.
******************************************************************************/
#include "Meta.h"
#include <ctime>
#include <stdio.h>
namespace zilliz {
namespace milvus {
namespace engine {
namespace meta {
Meta::~Meta() = default;
DateT Meta::GetDate(const std::time_t& t, int day_delta) {
struct tm ltm;
localtime_r(&t, &ltm);
if (day_delta > 0) {
do {
++ltm.tm_mday;
--day_delta;
} while(day_delta > 0);
mktime(&ltm);
} else if (day_delta < 0) {
do {
--ltm.tm_mday;
++day_delta;
} while(day_delta < 0);
mktime(&ltm);
} else {
ltm.tm_mday;
}
return ltm.tm_year*10000 + ltm.tm_mon*100 + ltm.tm_mday;
}
DateT Meta::GetDateWithDelta(int day_delta) {
return GetDate(std::time(nullptr), day_delta);
}
DateT Meta::GetDate() {
return GetDate(std::time(nullptr), 0);
}
} // namespace meta
} // namespace engine
} // namespace milvus
} // namespace zilliz
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "db/Types.h" #include "db/Types.h"
#include <cstddef> #include <cstddef>
#include <ctime>
#include <memory> #include <memory>
namespace zilliz { namespace zilliz {
...@@ -19,105 +18,70 @@ namespace milvus { ...@@ -19,105 +18,70 @@ namespace milvus {
namespace engine { namespace engine {
namespace meta { namespace meta {
class Meta { class Meta {
public: public:
using Ptr = std::shared_ptr<Meta>; using Ptr = std::shared_ptr<Meta>;
virtual virtual ~Meta() = default;
~Meta() = 0;
virtual Status
CreateTable(TableSchema &table_schema) = 0;
virtual Status
DescribeTable(TableSchema &table_schema) = 0;
virtual Status
HasTable(const std::string &table_id, bool &has_or_not) = 0;
virtual Status virtual Status CreateTable(TableSchema &table_schema) = 0;
AllTables(std::vector<TableSchema> &table_schema_array) = 0;
virtual Status virtual Status DescribeTable(TableSchema &table_schema) = 0;
UpdateTableIndexParam(const std::string &table_id, const TableIndex& index) = 0;
virtual Status virtual Status HasTable(const std::string &table_id, bool &has_or_not) = 0;
UpdateTableFlag(const std::string &table_id, int64_t flag) = 0;
virtual Status virtual Status AllTables(std::vector<TableSchema> &table_schema_array) = 0;
DeleteTable(const std::string &table_id) = 0;
virtual Status virtual Status UpdateTableIndexParam(const std::string &table_id, const TableIndex& index) = 0;
DeleteTableFiles(const std::string &table_id) = 0;
virtual Status virtual Status UpdateTableFlag(const std::string &table_id, int64_t flag) = 0;
CreateTableFile(TableFileSchema &file_schema) = 0;
virtual Status virtual Status DeleteTable(const std::string &table_id) = 0;
DropPartitionsByDates(const std::string &table_id, const DatesT &dates) = 0;
virtual Status virtual Status DeleteTableFiles(const std::string &table_id) = 0;
GetTableFiles(const std::string &table_id, const std::vector<size_t> &ids, TableFilesSchema &table_files) = 0;
virtual Status virtual Status CreateTableFile(TableFileSchema &file_schema) = 0;
UpdateTableFilesToIndex(const std::string &table_id) = 0;
virtual Status virtual Status DropPartitionsByDates(const std::string &table_id, const DatesT &dates) = 0;
UpdateTableFile(TableFileSchema &file_schema) = 0;
virtual Status virtual Status GetTableFiles(const std::string &table_id,
UpdateTableFiles(TableFilesSchema &files) = 0; const std::vector<size_t> &ids,
TableFilesSchema &table_files) = 0;
virtual Status virtual Status UpdateTableFilesToIndex(const std::string &table_id) = 0;
FilesToSearch(const std::string &table_id,
const std::vector<size_t> &ids,
const DatesT &partition,
DatePartionedTableFilesSchema &files) = 0;
virtual Status virtual Status UpdateTableFile(TableFileSchema &file_schema) = 0;
FilesToMerge(const std::string &table_id, DatePartionedTableFilesSchema &files) = 0;
virtual Status virtual Status UpdateTableFiles(TableFilesSchema &files) = 0;
Size(uint64_t &result) = 0;
virtual Status virtual Status FilesToSearch(const std::string &table_id,
Archive() = 0; const std::vector<size_t> &ids,
const DatesT &partition,
DatePartionedTableFilesSchema &files) = 0;
virtual Status virtual Status FilesToMerge(const std::string &table_id, DatePartionedTableFilesSchema &files) = 0;
FilesToIndex(TableFilesSchema &) = 0;
virtual Status virtual Status Size(uint64_t &result) = 0;
FilesByType(const std::string &table_id,
const std::vector<int> &file_types,
std::vector<std::string>& file_ids) = 0;
virtual Status virtual Status Archive() = 0;
DescribeTableIndex(const std::string &table_id, TableIndex& index) = 0;
virtual Status virtual Status FilesToIndex(TableFilesSchema &) = 0;
DropTableIndex(const std::string &table_id) = 0;
virtual Status virtual Status FilesByType(const std::string &table_id,
CleanUp() = 0; const std::vector<int> &file_types,
std::vector<std::string>& file_ids) = 0;
virtual Status virtual Status DescribeTableIndex(const std::string &table_id, TableIndex& index) = 0;
CleanUpFilesWithTTL(uint16_t) = 0;
virtual Status virtual Status DropTableIndex(const std::string &table_id) = 0;
DropAll() = 0;
virtual Status virtual Status CleanUp() = 0;
Count(const std::string &table_id, uint64_t &result) = 0;
static DateT virtual Status CleanUpFilesWithTTL(uint16_t) = 0;
GetDate(const std::time_t &t, int day_delta = 0);
static DateT virtual Status DropAll() = 0;
GetDate();
static DateT virtual Status Count(const std::string &table_id, uint64_t &result) = 0;
GetDateWithDelta(int day_delta);
}; // MetaData }; // MetaData
......
...@@ -41,6 +41,18 @@ Status HandleException(const std::string &desc, std::exception &e) { ...@@ -41,6 +41,18 @@ Status HandleException(const std::string &desc, std::exception &e) {
} }
MySQLMetaImpl::MySQLMetaImpl(const DBMetaOptions &options_, const int &mode)
: options_(options_),
mode_(mode) {
Initialize();
}
MySQLMetaImpl::~MySQLMetaImpl() {
if (mode_ != Options::MODE::READ_ONLY) {
CleanUp();
}
}
Status MySQLMetaImpl::NextTableId(std::string &table_id) { Status MySQLMetaImpl::NextTableId(std::string &table_id) {
std::stringstream ss; std::stringstream ss;
SimpleIDGenerator g; SimpleIDGenerator g;
...@@ -57,12 +69,6 @@ Status MySQLMetaImpl::NextFileId(std::string &file_id) { ...@@ -57,12 +69,6 @@ Status MySQLMetaImpl::NextFileId(std::string &file_id) {
return Status::OK(); return Status::OK();
} }
MySQLMetaImpl::MySQLMetaImpl(const DBMetaOptions &options_, const int &mode)
: options_(options_),
mode_(mode) {
Initialize();
}
Status MySQLMetaImpl::Initialize() { Status MySQLMetaImpl::Initialize() {
if (!boost::filesystem::is_directory(options_.path)) { if (!boost::filesystem::is_directory(options_.path)) {
auto ret = boost::filesystem::create_directory(options_.path); auto ret = boost::filesystem::create_directory(options_.path);
...@@ -202,15 +208,6 @@ Status MySQLMetaImpl::DropPartitionsByDates(const std::string &table_id, ...@@ -202,15 +208,6 @@ Status MySQLMetaImpl::DropPartitionsByDates(const std::string &table_id,
} }
try { try {
auto yesterday = GetDateWithDelta(-1);
for (auto &date : dates) {
if (date >= yesterday) {
return Status::Error("Could not delete partitions within 2 days");
}
}
std::stringstream dateListSS; std::stringstream dateListSS;
for (auto &date : dates) { for (auto &date : dates) {
dateListSS << std::to_string(date) << ", "; dateListSS << std::to_string(date) << ", ";
...@@ -229,7 +226,8 @@ Status MySQLMetaImpl::DropPartitionsByDates(const std::string &table_id, ...@@ -229,7 +226,8 @@ Status MySQLMetaImpl::DropPartitionsByDates(const std::string &table_id,
Query dropPartitionsByDatesQuery = connectionPtr->query(); Query dropPartitionsByDatesQuery = connectionPtr->query();
dropPartitionsByDatesQuery << "UPDATE TableFiles " << dropPartitionsByDatesQuery << "UPDATE TableFiles " <<
"SET file_type = " << std::to_string(TableFileSchema::TO_DELETE) << " " << "SET file_type = " << std::to_string(TableFileSchema::TO_DELETE) << "," <<
"updated_time = " << utils::GetMicroSecTimeStamp() << " " <<
"WHERE table_id = " << quote << table_id << " AND " << "WHERE table_id = " << quote << table_id << " AND " <<
"date in (" << dateListStr << ");"; "date in (" << dateListStr << ");";
...@@ -877,7 +875,7 @@ Status MySQLMetaImpl::AllTables(std::vector<TableSchema> &table_schema_array) { ...@@ -877,7 +875,7 @@ Status MySQLMetaImpl::AllTables(std::vector<TableSchema> &table_schema_array) {
Status MySQLMetaImpl::CreateTableFile(TableFileSchema &file_schema) { Status MySQLMetaImpl::CreateTableFile(TableFileSchema &file_schema) {
if (file_schema.date_ == EmptyDate) { if (file_schema.date_ == EmptyDate) {
file_schema.date_ = Meta::GetDate(); file_schema.date_ = utils::GetDate();
} }
TableSchema table_schema; TableSchema table_schema;
table_schema.table_id_ = file_schema.table_id_; table_schema.table_id_ = file_schema.table_id_;
...@@ -2031,12 +2029,6 @@ Status MySQLMetaImpl::DropAll() { ...@@ -2031,12 +2029,6 @@ Status MySQLMetaImpl::DropAll() {
return Status::OK(); return Status::OK();
} }
MySQLMetaImpl::~MySQLMetaImpl() {
if (mode_ != Options::MODE::READ_ONLY) {
CleanUp();
}
}
} // namespace meta } // namespace meta
} // namespace engine } // namespace engine
} // namespace milvus } // namespace milvus
......
...@@ -24,6 +24,7 @@ using namespace mysqlpp; ...@@ -24,6 +24,7 @@ using namespace mysqlpp;
class MySQLMetaImpl : public Meta { class MySQLMetaImpl : public Meta {
public: public:
MySQLMetaImpl(const DBMetaOptions &options_, const int &mode); MySQLMetaImpl(const DBMetaOptions &options_, const int &mode);
~MySQLMetaImpl();
Status CreateTable(TableSchema &table_schema) override; Status CreateTable(TableSchema &table_schema) override;
...@@ -86,8 +87,6 @@ class MySQLMetaImpl : public Meta { ...@@ -86,8 +87,6 @@ class MySQLMetaImpl : public Meta {
Status Count(const std::string &table_id, uint64_t &result) override; Status Count(const std::string &table_id, uint64_t &result) override;
virtual ~MySQLMetaImpl();
private: private:
Status NextFileId(std::string &file_id); Status NextFileId(std::string &file_id);
Status NextTableId(std::string &table_id); Status NextTableId(std::string &table_id);
......
...@@ -68,6 +68,15 @@ using ConnectorT = decltype(StoragePrototype("")); ...@@ -68,6 +68,15 @@ using ConnectorT = decltype(StoragePrototype(""));
static std::unique_ptr<ConnectorT> ConnectorPtr; static std::unique_ptr<ConnectorT> ConnectorPtr;
using ConditionT = decltype(c(&TableFileSchema::id_) == 1UL); using ConditionT = decltype(c(&TableFileSchema::id_) == 1UL);
SqliteMetaImpl::SqliteMetaImpl(const DBMetaOptions &options_)
: options_(options_) {
Initialize();
}
SqliteMetaImpl::~SqliteMetaImpl() {
CleanUp();
}
Status SqliteMetaImpl::NextTableId(std::string &table_id) { Status SqliteMetaImpl::NextTableId(std::string &table_id) {
std::stringstream ss; std::stringstream ss;
SimpleIDGenerator g; SimpleIDGenerator g;
...@@ -84,11 +93,6 @@ Status SqliteMetaImpl::NextFileId(std::string &file_id) { ...@@ -84,11 +93,6 @@ Status SqliteMetaImpl::NextFileId(std::string &file_id) {
return Status::OK(); return Status::OK();
} }
SqliteMetaImpl::SqliteMetaImpl(const DBMetaOptions &options_)
: options_(options_) {
Initialize();
}
Status SqliteMetaImpl::Initialize() { Status SqliteMetaImpl::Initialize() {
if (!boost::filesystem::is_directory(options_.path)) { if (!boost::filesystem::is_directory(options_.path)) {
auto ret = boost::filesystem::create_directory(options_.path); auto ret = boost::filesystem::create_directory(options_.path);
...@@ -111,7 +115,7 @@ Status SqliteMetaImpl::Initialize() { ...@@ -111,7 +115,7 @@ Status SqliteMetaImpl::Initialize() {
// PXU TODO: Temp solution. Will fix later // PXU TODO: Temp solution. Will fix later
Status SqliteMetaImpl::DropPartitionsByDates(const std::string &table_id, Status SqliteMetaImpl::DropPartitionsByDates(const std::string &table_id,
const DatesT &dates) { const DatesT &dates) {
if (dates.size() == 0) { if (dates.size() == 0) {
return Status::OK(); return Status::OK();
} }
...@@ -124,20 +128,13 @@ Status SqliteMetaImpl::DropPartitionsByDates(const std::string &table_id, ...@@ -124,20 +128,13 @@ Status SqliteMetaImpl::DropPartitionsByDates(const std::string &table_id,
} }
try { try {
auto yesterday = GetDateWithDelta(-1);
for (auto &date : dates) {
if (date >= yesterday) {
return Status::Error("Could not delete partitions with 2 days");
}
}
//multi-threads call sqlite update may get exception('bad logic', etc), so we add a lock here //multi-threads call sqlite update may get exception('bad logic', etc), so we add a lock here
std::lock_guard<std::mutex> meta_lock(meta_mutex_); std::lock_guard<std::mutex> meta_lock(meta_mutex_);
ConnectorPtr->update_all( ConnectorPtr->update_all(
set( set(
c(&TableFileSchema::file_type_) = (int) TableFileSchema::TO_DELETE c(&TableFileSchema::file_type_) = (int) TableFileSchema::TO_DELETE,
c(&TableFileSchema::updated_time_) = utils::GetMicroSecTimeStamp()
), ),
where( where(
c(&TableFileSchema::table_id_) == table_id and c(&TableFileSchema::table_id_) == table_id and
...@@ -543,7 +540,7 @@ Status SqliteMetaImpl::AllTables(std::vector<TableSchema>& table_schema_array) { ...@@ -543,7 +540,7 @@ Status SqliteMetaImpl::AllTables(std::vector<TableSchema>& table_schema_array) {
Status SqliteMetaImpl::CreateTableFile(TableFileSchema &file_schema) { Status SqliteMetaImpl::CreateTableFile(TableFileSchema &file_schema) {
if (file_schema.date_ == EmptyDate) { if (file_schema.date_ == EmptyDate) {
file_schema.date_ = Meta::GetDate(); file_schema.date_ = utils::GetDate();
} }
TableSchema table_schema; TableSchema table_schema;
table_schema.table_id_ = file_schema.table_id_; table_schema.table_id_ = file_schema.table_id_;
...@@ -1214,10 +1211,6 @@ Status SqliteMetaImpl::DropAll() { ...@@ -1214,10 +1211,6 @@ Status SqliteMetaImpl::DropAll() {
return Status::OK(); return Status::OK();
} }
SqliteMetaImpl::~SqliteMetaImpl() {
CleanUp();
}
} // namespace meta } // namespace meta
} // namespace engine } // namespace engine
} // namespace milvus } // namespace milvus
......
...@@ -20,6 +20,7 @@ auto StoragePrototype(const std::string &path); ...@@ -20,6 +20,7 @@ auto StoragePrototype(const std::string &path);
class SqliteMetaImpl : public Meta { class SqliteMetaImpl : public Meta {
public: public:
explicit SqliteMetaImpl(const DBMetaOptions &options_); explicit SqliteMetaImpl(const DBMetaOptions &options_);
~SqliteMetaImpl();
Status CreateTable(TableSchema &table_schema) override; Status CreateTable(TableSchema &table_schema) override;
...@@ -80,8 +81,6 @@ class SqliteMetaImpl : public Meta { ...@@ -80,8 +81,6 @@ class SqliteMetaImpl : public Meta {
Status Count(const std::string &table_id, uint64_t &result) override; Status Count(const std::string &table_id, uint64_t &result) override;
~SqliteMetaImpl() override;
private: private:
Status NextFileId(std::string &file_id); Status NextFileId(std::string &file_id);
Status NextTableId(std::string &table_id); Status NextTableId(std::string &table_id);
......
...@@ -93,6 +93,7 @@ namespace { ...@@ -93,6 +93,7 @@ namespace {
return; return;
} }
//range: [start_day, end_day)
for (long i = 0; i < days; i++) { for (long i = 0; i < days; i++) {
time_t tt_day = tt_start + DAY_SECONDS * i; time_t tt_day = tt_start + DAY_SECONDS * i;
tm tm_day; tm tm_day;
......
...@@ -293,18 +293,15 @@ TEST_F(DBTest, PRELOADTABLE_TEST) { ...@@ -293,18 +293,15 @@ TEST_F(DBTest, PRELOADTABLE_TEST) {
ASSERT_STATS(stat); ASSERT_STATS(stat);
ASSERT_EQ(table_info_get.dimension_, TABLE_DIM); ASSERT_EQ(table_info_get.dimension_, TABLE_DIM);
engine::IDNumbers vector_ids; int64_t nb = VECTOR_COUNT;
engine::IDNumbers target_ids;
int64_t nb = 100000;
std::vector<float> xb; std::vector<float> xb;
BuildVectors(nb, xb); BuildVectors(nb, xb);
int loop = 5; int loop = 5;
for (auto i=0; i<loop; ++i) { for (auto i=0; i<loop; ++i) {
db_->InsertVectors(TABLE_NAME, nb, xb.data(), target_ids); engine::IDNumbers vector_ids;
ASSERT_EQ(target_ids.size(), nb); db_->InsertVectors(TABLE_NAME, nb, xb.data(), vector_ids);
ASSERT_EQ(vector_ids.size(), nb);
} }
engine::TableIndex index; engine::TableIndex index;
...@@ -342,9 +339,6 @@ TEST_F(DBTest2, ARHIVE_DISK_CHECK) { ...@@ -342,9 +339,6 @@ TEST_F(DBTest2, ARHIVE_DISK_CHECK) {
ASSERT_STATS(stat); ASSERT_STATS(stat);
ASSERT_EQ(table_info_get.dimension_, TABLE_DIM); ASSERT_EQ(table_info_get.dimension_, TABLE_DIM);
engine::IDNumbers vector_ids;
engine::IDNumbers target_ids;
uint64_t size; uint64_t size;
db_->Size(size); db_->Size(size);
...@@ -354,6 +348,7 @@ TEST_F(DBTest2, ARHIVE_DISK_CHECK) { ...@@ -354,6 +348,7 @@ TEST_F(DBTest2, ARHIVE_DISK_CHECK) {
int loop = INSERT_LOOP; int loop = INSERT_LOOP;
for (auto i=0; i<loop; ++i) { for (auto i=0; i<loop; ++i) {
engine::IDNumbers vector_ids;
db_->InsertVectors(TABLE_NAME, nb, xb.data(), vector_ids); db_->InsertVectors(TABLE_NAME, nb, xb.data(), vector_ids);
std::this_thread::sleep_for(std::chrono::microseconds(1)); std::this_thread::sleep_for(std::chrono::microseconds(1));
} }
...@@ -378,20 +373,17 @@ TEST_F(DBTest2, DELETE_TEST) { ...@@ -378,20 +373,17 @@ TEST_F(DBTest2, DELETE_TEST) {
db_->HasTable(TABLE_NAME, has_table); db_->HasTable(TABLE_NAME, has_table);
ASSERT_TRUE(has_table); ASSERT_TRUE(has_table);
engine::IDNumbers vector_ids;
uint64_t size; uint64_t size;
db_->Size(size); db_->Size(size);
int64_t nb = INSERT_LOOP; int64_t nb = VECTOR_COUNT;
std::vector<float> xb; std::vector<float> xb;
BuildVectors(nb, xb); BuildVectors(nb, xb);
int loop = 20; engine::IDNumbers vector_ids;
for (auto i=0; i<loop; ++i) { stat = db_->InsertVectors(TABLE_NAME, nb, xb.data(), vector_ids);
db_->InsertVectors(TABLE_NAME, nb, xb.data(), vector_ids); engine::TableIndex index;
std::this_thread::sleep_for(std::chrono::microseconds(1)); stat = db_->CreateIndex(TABLE_NAME, index);
}
std::vector<engine::meta::DateT> dates; std::vector<engine::meta::DateT> dates;
stat = db_->DeleteTable(TABLE_NAME, dates); stat = db_->DeleteTable(TABLE_NAME, dates);
...@@ -420,25 +412,31 @@ TEST_F(DBTest2, DELETE_BY_RANGE_TEST) { ...@@ -420,25 +412,31 @@ TEST_F(DBTest2, DELETE_BY_RANGE_TEST) {
db_->HasTable(TABLE_NAME, has_table); db_->HasTable(TABLE_NAME, has_table);
ASSERT_TRUE(has_table); ASSERT_TRUE(has_table);
engine::IDNumbers vector_ids;
uint64_t size; uint64_t size;
db_->Size(size); db_->Size(size);
ASSERT_EQ(size, 0UL);
int64_t nb = INSERT_LOOP; int64_t nb = VECTOR_COUNT;
std::vector<float> xb; std::vector<float> xb;
BuildVectors(nb, xb); BuildVectors(nb, xb);
int loop = 20; engine::IDNumbers vector_ids;
for (auto i=0; i<loop; ++i) { stat = db_->InsertVectors(TABLE_NAME, nb, xb.data(), vector_ids);
db_->InsertVectors(TABLE_NAME, nb, xb.data(), vector_ids); engine::TableIndex index;
std::this_thread::sleep_for(std::chrono::microseconds(1)); stat = db_->CreateIndex(TABLE_NAME, index);
}
db_->Size(size);
ASSERT_NE(size, 0UL);
std::vector<engine::meta::DateT> dates; std::vector<engine::meta::DateT> dates;
std::string start_value = CurrentTmDate(-3); std::string start_value = CurrentTmDate();
std::string end_value = CurrentTmDate(-2); std::string end_value = CurrentTmDate(1);
ConvertTimeRangeToDBDates(start_value, end_value, dates); ConvertTimeRangeToDBDates(start_value, end_value, dates);
db_->DeleteTable(TABLE_NAME, dates); stat = db_->DeleteTable(TABLE_NAME, dates);
ASSERT_STATS(stat);
uint64_t row_count = 0;
db_->GetTableRowCount(TABLE_NAME, row_count);
ASSERT_EQ(row_count, 0UL);
} }
\ No newline at end of file
...@@ -74,21 +74,21 @@ TEST_F(MetaTest, TABLE_FILE_TEST) { ...@@ -74,21 +74,21 @@ TEST_F(MetaTest, TABLE_FILE_TEST) {
ASSERT_EQ(table_file.file_type_, new_file_type); ASSERT_EQ(table_file.file_type_, new_file_type);
meta::DatesT dates; meta::DatesT dates;
dates.push_back(meta::Meta::GetDate()); dates.push_back(utils::GetDate());
status = impl_->DropPartitionsByDates(table_file.table_id_, dates); status = impl_->DropPartitionsByDates(table_file.table_id_, dates);
ASSERT_FALSE(status.ok()); ASSERT_TRUE(status.ok());
dates.clear(); dates.clear();
for (auto i=2; i < 10; ++i) { for (auto i=2; i < 10; ++i) {
dates.push_back(meta::Meta::GetDateWithDelta(-1*i)); dates.push_back(utils::GetDateWithDelta(-1*i));
} }
status = impl_->DropPartitionsByDates(table_file.table_id_, dates); status = impl_->DropPartitionsByDates(table_file.table_id_, dates);
ASSERT_TRUE(status.ok()); ASSERT_TRUE(status.ok());
table_file.date_ = meta::Meta::GetDateWithDelta(-2); table_file.date_ = utils::GetDateWithDelta(-2);
status = impl_->UpdateTableFile(table_file); status = impl_->UpdateTableFile(table_file);
ASSERT_TRUE(status.ok()); ASSERT_TRUE(status.ok());
ASSERT_EQ(table_file.date_, meta::Meta::GetDateWithDelta(-2)); ASSERT_EQ(table_file.date_, utils::GetDateWithDelta(-2));
ASSERT_FALSE(table_file.file_type_ == meta::TableFileSchema::TO_DELETE); ASSERT_FALSE(table_file.file_type_ == meta::TableFileSchema::TO_DELETE);
dates.clear(); dates.clear();
......
...@@ -105,7 +105,7 @@ TEST(DBMiscTest, META_TEST) { ...@@ -105,7 +105,7 @@ TEST(DBMiscTest, META_TEST) {
time_t tt; time_t tt;
time( &tt ); time( &tt );
int delta = 10; int delta = 10;
engine::meta::DateT dt = impl.GetDate(tt, delta); engine::meta::DateT dt = engine::utils::GetDate(tt, delta);
ASSERT_GT(dt, 0); ASSERT_GT(dt, 0);
} }
......
...@@ -90,7 +90,7 @@ TEST_F(DISABLED_MySQLTest, TABLE_FILE_TEST) { ...@@ -90,7 +90,7 @@ TEST_F(DISABLED_MySQLTest, TABLE_FILE_TEST) {
ASSERT_EQ(table_file.file_type_, meta::TableFileSchema::NEW); ASSERT_EQ(table_file.file_type_, meta::TableFileSchema::NEW);
meta::DatesT dates; meta::DatesT dates;
dates.push_back(meta::Meta::GetDate()); dates.push_back(utils::GetDate());
status = impl.DropPartitionsByDates(table_file.table_id_, dates); status = impl.DropPartitionsByDates(table_file.table_id_, dates);
ASSERT_FALSE(status.ok()); ASSERT_FALSE(status.ok());
...@@ -110,15 +110,15 @@ TEST_F(DISABLED_MySQLTest, TABLE_FILE_TEST) { ...@@ -110,15 +110,15 @@ TEST_F(DISABLED_MySQLTest, TABLE_FILE_TEST) {
dates.clear(); dates.clear();
for (auto i=2; i < 10; ++i) { for (auto i=2; i < 10; ++i) {
dates.push_back(meta::Meta::GetDateWithDelta(-1*i)); dates.push_back(utils::GetDateWithDelta(-1*i));
} }
status = impl.DropPartitionsByDates(table_file.table_id_, dates); status = impl.DropPartitionsByDates(table_file.table_id_, dates);
ASSERT_TRUE(status.ok()); ASSERT_TRUE(status.ok());
table_file.date_ = meta::Meta::GetDateWithDelta(-2); table_file.date_ = utils::GetDateWithDelta(-2);
status = impl.UpdateTableFile(table_file); status = impl.UpdateTableFile(table_file);
ASSERT_TRUE(status.ok()); ASSERT_TRUE(status.ok());
ASSERT_EQ(table_file.date_, meta::Meta::GetDateWithDelta(-2)); ASSERT_EQ(table_file.date_, utils::GetDateWithDelta(-2));
ASSERT_FALSE(table_file.file_type_ == meta::TableFileSchema::TO_DELETE); ASSERT_FALSE(table_file.file_type_ == meta::TableFileSchema::TO_DELETE);
dates.clear(); dates.clear();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册