From d79effe2b3cf2e3d9918df554bcb56e63689545a Mon Sep 17 00:00:00 2001 From: groot Date: Fri, 30 Aug 2019 16:39:26 +0800 Subject: [PATCH] MS-436 Delete vectors failed if index created with index_type: IVF_FLAT/IVF_SQ8 Former-commit-id: 23f864e471339f4878f43c8512930d752ddd189c --- cpp/CHANGELOG.md | 1 + cpp/build.sh | 8 +- cpp/src/db/DBImpl.cpp | 2 +- cpp/src/db/Utils.cpp | 29 ++++++ cpp/src/db/Utils.h | 5 + cpp/src/db/meta/Meta.cpp | 50 --------- cpp/src/db/meta/Meta.h | 104 ++++++------------- cpp/src/db/meta/MySQLMetaImpl.cpp | 38 +++---- cpp/src/db/meta/MySQLMetaImpl.h | 3 +- cpp/src/db/meta/SqliteMetaImpl.cpp | 33 +++--- cpp/src/db/meta/SqliteMetaImpl.h | 3 +- cpp/src/server/grpc_impl/GrpcRequestTask.cpp | 1 + cpp/unittest/db/db_tests.cpp | 56 +++++----- cpp/unittest/db/meta_tests.cpp | 10 +- cpp/unittest/db/misc_test.cpp | 2 +- cpp/unittest/db/mysql_meta_test.cpp | 8 +- 16 files changed, 139 insertions(+), 214 deletions(-) delete mode 100644 cpp/src/db/meta/Meta.cpp diff --git a/cpp/CHANGELOG.md b/cpp/CHANGELOG.md index bf3a13da..1d367916 100644 --- a/cpp/CHANGELOG.md +++ b/cpp/CHANGELOG.md @@ -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-430 - Search no result if index created with FLAT - MS-443 - Create index hang again +- MS-436 - Delete vectors failed if index created with index_type: IVF_FLAT/IVF_SQ8 ## Improvement - MS-327 - Clean code for milvus diff --git a/cpp/build.sh b/cpp/build.sh index f61a5ea2..be236e19 100755 --- a/cpp/build.sh +++ b/cpp/build.sh @@ -2,7 +2,6 @@ BUILD_TYPE="Debug" BUILD_UNITTEST="OFF" -LICENSE_CHECK="OFF" INSTALL_PREFIX=$(pwd)/milvus MAKE_CLEAN="OFF" BUILD_COVERAGE="OFF" @@ -12,7 +11,7 @@ BUILD_FAISS_WITH_MKL="OFF" USE_JFROG_CACHE="OFF" 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 case $arg in t) @@ -28,9 +27,6 @@ do d) DB_PATH=$OPTARG ;; - l) - LICENSE_CHECK="ON" - ;; r) if [[ -d cmake_build ]]; then rm ./cmake_build -r @@ -60,7 +56,6 @@ parameter: -u: building unit test options(default: OFF) -p: install prefix(default: $(pwd)/milvus) -d: db path(default: /opt/milvus) --l: build license version(default: OFF) -r: remove previous build directory(default: OFF) -c: code coverage(default: OFF) -g: profiling(default: OFF) @@ -94,7 +89,6 @@ if [[ ${MAKE_CLEAN} == "ON" ]]; then -DCMAKE_INSTALL_PREFIX=${INSTALL_PREFIX} -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \ -DCMAKE_CUDA_COMPILER=${CUDA_COMPILER} \ - -DCMAKE_LICENSE_CHECK=${LICENSE_CHECK} \ -DBUILD_COVERAGE=${BUILD_COVERAGE} \ -DMILVUS_DB_PATH=${DB_PATH} \ -DMILVUS_ENABLE_PROFILING=${PROFILING} \ diff --git a/cpp/src/db/DBImpl.cpp b/cpp/src/db/DBImpl.cpp index 4f9cd1e7..36580dce 100644 --- a/cpp/src/db/DBImpl.cpp +++ b/cpp/src/db/DBImpl.cpp @@ -162,7 +162,7 @@ Status DBImpl::Query(const std::string &table_id, uint64_t k, uint64_t nq, uint6 const float *vectors, QueryResults &results) { 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); return result; diff --git a/cpp/src/db/Utils.cpp b/cpp/src/db/Utils.cpp index 4eec3346..61675b9d 100644 --- a/cpp/src/db/Utils.cpp +++ b/cpp/src/db/Utils.cpp @@ -156,6 +156,35 @@ bool UserDefinedId(int64_t flag) { return flag & meta::FLAG_MASK_USERID; } +meta::DateT GetDate(const std::time_t& t, int day_delta) { + struct tm ltm; + localtime_r(&t, <m); + if (day_delta > 0) { + do { + ++ltm.tm_mday; + --day_delta; + } while(day_delta > 0); + mktime(<m); + } else if (day_delta < 0) { + do { + --ltm.tm_mday; + ++day_delta; + } while(day_delta < 0); + mktime(<m); + } 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 engine } // namespace milvus diff --git a/cpp/src/db/Utils.h b/cpp/src/db/Utils.h index d6244ebc..d2b8a751 100644 --- a/cpp/src/db/Utils.h +++ b/cpp/src/db/Utils.h @@ -10,6 +10,7 @@ #include "db/Types.h" #include +#include namespace zilliz { namespace milvus { @@ -29,6 +30,10 @@ bool IsSameIndex(const TableIndex& index1, const TableIndex& index2); 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 engine } // namespace milvus diff --git a/cpp/src/db/meta/Meta.cpp b/cpp/src/db/meta/Meta.cpp deleted file mode 100644 index a86051a1..00000000 --- a/cpp/src/db/meta/Meta.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved - * Unauthorized copying of this file, via any medium is strictly prohibited. - * Proprietary and confidential. - ******************************************************************************/ -#include "Meta.h" - -#include -#include - -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, <m); - if (day_delta > 0) { - do { - ++ltm.tm_mday; - --day_delta; - } while(day_delta > 0); - mktime(<m); - } else if (day_delta < 0) { - do { - --ltm.tm_mday; - ++day_delta; - } while(day_delta < 0); - mktime(<m); - } 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 diff --git a/cpp/src/db/meta/Meta.h b/cpp/src/db/meta/Meta.h index b7210815..8d5dd63a 100644 --- a/cpp/src/db/meta/Meta.h +++ b/cpp/src/db/meta/Meta.h @@ -11,7 +11,6 @@ #include "db/Types.h" #include -#include #include namespace zilliz { @@ -19,105 +18,70 @@ namespace milvus { namespace engine { namespace meta { - class Meta { public: using Ptr = std::shared_ptr; - virtual - ~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 ~Meta() = default; - virtual Status - AllTables(std::vector &table_schema_array) = 0; + virtual Status CreateTable(TableSchema &table_schema) = 0; - virtual Status - UpdateTableIndexParam(const std::string &table_id, const TableIndex& index) = 0; + virtual Status DescribeTable(TableSchema &table_schema) = 0; - virtual Status - UpdateTableFlag(const std::string &table_id, int64_t flag) = 0; + virtual Status HasTable(const std::string &table_id, bool &has_or_not) = 0; - virtual Status - DeleteTable(const std::string &table_id) = 0; + virtual Status AllTables(std::vector &table_schema_array) = 0; - virtual Status - DeleteTableFiles(const std::string &table_id) = 0; + virtual Status UpdateTableIndexParam(const std::string &table_id, const TableIndex& index) = 0; - virtual Status - CreateTableFile(TableFileSchema &file_schema) = 0; + virtual Status UpdateTableFlag(const std::string &table_id, int64_t flag) = 0; - virtual Status - DropPartitionsByDates(const std::string &table_id, const DatesT &dates) = 0; + virtual Status DeleteTable(const std::string &table_id) = 0; - virtual Status - GetTableFiles(const std::string &table_id, const std::vector &ids, TableFilesSchema &table_files) = 0; + virtual Status DeleteTableFiles(const std::string &table_id) = 0; - virtual Status - UpdateTableFilesToIndex(const std::string &table_id) = 0; + virtual Status CreateTableFile(TableFileSchema &file_schema) = 0; - virtual Status - UpdateTableFile(TableFileSchema &file_schema) = 0; + virtual Status DropPartitionsByDates(const std::string &table_id, const DatesT &dates) = 0; - virtual Status - UpdateTableFiles(TableFilesSchema &files) = 0; + virtual Status GetTableFiles(const std::string &table_id, + const std::vector &ids, + TableFilesSchema &table_files) = 0; - virtual Status - FilesToSearch(const std::string &table_id, - const std::vector &ids, - const DatesT &partition, - DatePartionedTableFilesSchema &files) = 0; + virtual Status UpdateTableFilesToIndex(const std::string &table_id) = 0; - virtual Status - FilesToMerge(const std::string &table_id, DatePartionedTableFilesSchema &files) = 0; + virtual Status UpdateTableFile(TableFileSchema &file_schema) = 0; - virtual Status - Size(uint64_t &result) = 0; + virtual Status UpdateTableFiles(TableFilesSchema &files) = 0; - virtual Status - Archive() = 0; + virtual Status FilesToSearch(const std::string &table_id, + const std::vector &ids, + const DatesT &partition, + DatePartionedTableFilesSchema &files) = 0; - virtual Status - FilesToIndex(TableFilesSchema &) = 0; + virtual Status FilesToMerge(const std::string &table_id, DatePartionedTableFilesSchema &files) = 0; - virtual Status - FilesByType(const std::string &table_id, - const std::vector &file_types, - std::vector& file_ids) = 0; + virtual Status Size(uint64_t &result) = 0; - virtual Status - DescribeTableIndex(const std::string &table_id, TableIndex& index) = 0; + virtual Status Archive() = 0; - virtual Status - DropTableIndex(const std::string &table_id) = 0; + virtual Status FilesToIndex(TableFilesSchema &) = 0; - virtual Status - CleanUp() = 0; + virtual Status FilesByType(const std::string &table_id, + const std::vector &file_types, + std::vector& file_ids) = 0; - virtual Status - CleanUpFilesWithTTL(uint16_t) = 0; + virtual Status DescribeTableIndex(const std::string &table_id, TableIndex& index) = 0; - virtual Status - DropAll() = 0; + virtual Status DropTableIndex(const std::string &table_id) = 0; - virtual Status - Count(const std::string &table_id, uint64_t &result) = 0; + virtual Status CleanUp() = 0; - static DateT - GetDate(const std::time_t &t, int day_delta = 0); + virtual Status CleanUpFilesWithTTL(uint16_t) = 0; - static DateT - GetDate(); + virtual Status DropAll() = 0; - static DateT - GetDateWithDelta(int day_delta); + virtual Status Count(const std::string &table_id, uint64_t &result) = 0; }; // MetaData diff --git a/cpp/src/db/meta/MySQLMetaImpl.cpp b/cpp/src/db/meta/MySQLMetaImpl.cpp index b14ac115..beae3fa1 100644 --- a/cpp/src/db/meta/MySQLMetaImpl.cpp +++ b/cpp/src/db/meta/MySQLMetaImpl.cpp @@ -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) { std::stringstream ss; SimpleIDGenerator g; @@ -57,12 +69,6 @@ Status MySQLMetaImpl::NextFileId(std::string &file_id) { return Status::OK(); } -MySQLMetaImpl::MySQLMetaImpl(const DBMetaOptions &options_, const int &mode) - : options_(options_), - mode_(mode) { - Initialize(); -} - Status MySQLMetaImpl::Initialize() { if (!boost::filesystem::is_directory(options_.path)) { auto ret = boost::filesystem::create_directory(options_.path); @@ -202,15 +208,6 @@ Status MySQLMetaImpl::DropPartitionsByDates(const std::string &table_id, } 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; for (auto &date : dates) { dateListSS << std::to_string(date) << ", "; @@ -229,7 +226,8 @@ Status MySQLMetaImpl::DropPartitionsByDates(const std::string &table_id, Query dropPartitionsByDatesQuery = connectionPtr->query(); 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 " << "date in (" << dateListStr << ");"; @@ -877,7 +875,7 @@ Status MySQLMetaImpl::AllTables(std::vector &table_schema_array) { Status MySQLMetaImpl::CreateTableFile(TableFileSchema &file_schema) { if (file_schema.date_ == EmptyDate) { - file_schema.date_ = Meta::GetDate(); + file_schema.date_ = utils::GetDate(); } TableSchema table_schema; table_schema.table_id_ = file_schema.table_id_; @@ -2031,12 +2029,6 @@ Status MySQLMetaImpl::DropAll() { return Status::OK(); } -MySQLMetaImpl::~MySQLMetaImpl() { - if (mode_ != Options::MODE::READ_ONLY) { - CleanUp(); - } -} - } // namespace meta } // namespace engine } // namespace milvus diff --git a/cpp/src/db/meta/MySQLMetaImpl.h b/cpp/src/db/meta/MySQLMetaImpl.h index f5454d2f..08897cbe 100644 --- a/cpp/src/db/meta/MySQLMetaImpl.h +++ b/cpp/src/db/meta/MySQLMetaImpl.h @@ -24,6 +24,7 @@ using namespace mysqlpp; class MySQLMetaImpl : public Meta { public: MySQLMetaImpl(const DBMetaOptions &options_, const int &mode); + ~MySQLMetaImpl(); Status CreateTable(TableSchema &table_schema) override; @@ -86,8 +87,6 @@ class MySQLMetaImpl : public Meta { Status Count(const std::string &table_id, uint64_t &result) override; - virtual ~MySQLMetaImpl(); - private: Status NextFileId(std::string &file_id); Status NextTableId(std::string &table_id); diff --git a/cpp/src/db/meta/SqliteMetaImpl.cpp b/cpp/src/db/meta/SqliteMetaImpl.cpp index 0b111b25..73b4501a 100644 --- a/cpp/src/db/meta/SqliteMetaImpl.cpp +++ b/cpp/src/db/meta/SqliteMetaImpl.cpp @@ -68,6 +68,15 @@ using ConnectorT = decltype(StoragePrototype("")); static std::unique_ptr ConnectorPtr; 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) { std::stringstream ss; SimpleIDGenerator g; @@ -84,11 +93,6 @@ Status SqliteMetaImpl::NextFileId(std::string &file_id) { return Status::OK(); } -SqliteMetaImpl::SqliteMetaImpl(const DBMetaOptions &options_) - : options_(options_) { - Initialize(); -} - Status SqliteMetaImpl::Initialize() { if (!boost::filesystem::is_directory(options_.path)) { auto ret = boost::filesystem::create_directory(options_.path); @@ -111,7 +115,7 @@ Status SqliteMetaImpl::Initialize() { // PXU TODO: Temp solution. Will fix later Status SqliteMetaImpl::DropPartitionsByDates(const std::string &table_id, - const DatesT &dates) { + const DatesT &dates) { if (dates.size() == 0) { return Status::OK(); } @@ -124,20 +128,13 @@ Status SqliteMetaImpl::DropPartitionsByDates(const std::string &table_id, } 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 std::lock_guard meta_lock(meta_mutex_); ConnectorPtr->update_all( set( - c(&TableFileSchema::file_type_) = (int) TableFileSchema::TO_DELETE + c(&TableFileSchema::file_type_) = (int) TableFileSchema::TO_DELETE, + c(&TableFileSchema::updated_time_) = utils::GetMicroSecTimeStamp() ), where( c(&TableFileSchema::table_id_) == table_id and @@ -543,7 +540,7 @@ Status SqliteMetaImpl::AllTables(std::vector& table_schema_array) { Status SqliteMetaImpl::CreateTableFile(TableFileSchema &file_schema) { if (file_schema.date_ == EmptyDate) { - file_schema.date_ = Meta::GetDate(); + file_schema.date_ = utils::GetDate(); } TableSchema table_schema; table_schema.table_id_ = file_schema.table_id_; @@ -1214,10 +1211,6 @@ Status SqliteMetaImpl::DropAll() { return Status::OK(); } -SqliteMetaImpl::~SqliteMetaImpl() { - CleanUp(); -} - } // namespace meta } // namespace engine } // namespace milvus diff --git a/cpp/src/db/meta/SqliteMetaImpl.h b/cpp/src/db/meta/SqliteMetaImpl.h index 4a780d90..ad0d21f5 100644 --- a/cpp/src/db/meta/SqliteMetaImpl.h +++ b/cpp/src/db/meta/SqliteMetaImpl.h @@ -20,6 +20,7 @@ auto StoragePrototype(const std::string &path); class SqliteMetaImpl : public Meta { public: explicit SqliteMetaImpl(const DBMetaOptions &options_); + ~SqliteMetaImpl(); Status CreateTable(TableSchema &table_schema) override; @@ -80,8 +81,6 @@ class SqliteMetaImpl : public Meta { Status Count(const std::string &table_id, uint64_t &result) override; - ~SqliteMetaImpl() override; - private: Status NextFileId(std::string &file_id); Status NextTableId(std::string &table_id); diff --git a/cpp/src/server/grpc_impl/GrpcRequestTask.cpp b/cpp/src/server/grpc_impl/GrpcRequestTask.cpp index c277f11a..12390256 100644 --- a/cpp/src/server/grpc_impl/GrpcRequestTask.cpp +++ b/cpp/src/server/grpc_impl/GrpcRequestTask.cpp @@ -93,6 +93,7 @@ namespace { return; } + //range: [start_day, end_day) for (long i = 0; i < days; i++) { time_t tt_day = tt_start + DAY_SECONDS * i; tm tm_day; diff --git a/cpp/unittest/db/db_tests.cpp b/cpp/unittest/db/db_tests.cpp index 500186a0..f37896df 100644 --- a/cpp/unittest/db/db_tests.cpp +++ b/cpp/unittest/db/db_tests.cpp @@ -293,18 +293,15 @@ TEST_F(DBTest, PRELOADTABLE_TEST) { ASSERT_STATS(stat); ASSERT_EQ(table_info_get.dimension_, TABLE_DIM); - engine::IDNumbers vector_ids; - engine::IDNumbers target_ids; - - int64_t nb = 100000; + int64_t nb = VECTOR_COUNT; std::vector xb; BuildVectors(nb, xb); int loop = 5; - for (auto i=0; iInsertVectors(TABLE_NAME, nb, xb.data(), target_ids); - ASSERT_EQ(target_ids.size(), nb); + engine::IDNumbers vector_ids; + db_->InsertVectors(TABLE_NAME, nb, xb.data(), vector_ids); + ASSERT_EQ(vector_ids.size(), nb); } engine::TableIndex index; @@ -342,9 +339,6 @@ TEST_F(DBTest2, ARHIVE_DISK_CHECK) { ASSERT_STATS(stat); ASSERT_EQ(table_info_get.dimension_, TABLE_DIM); - engine::IDNumbers vector_ids; - engine::IDNumbers target_ids; - uint64_t size; db_->Size(size); @@ -354,6 +348,7 @@ TEST_F(DBTest2, ARHIVE_DISK_CHECK) { int loop = INSERT_LOOP; for (auto i=0; iInsertVectors(TABLE_NAME, nb, xb.data(), vector_ids); std::this_thread::sleep_for(std::chrono::microseconds(1)); } @@ -378,20 +373,17 @@ TEST_F(DBTest2, DELETE_TEST) { db_->HasTable(TABLE_NAME, has_table); ASSERT_TRUE(has_table); - engine::IDNumbers vector_ids; - uint64_t size; db_->Size(size); - int64_t nb = INSERT_LOOP; + int64_t nb = VECTOR_COUNT; std::vector xb; BuildVectors(nb, xb); - int loop = 20; - for (auto i=0; iInsertVectors(TABLE_NAME, nb, xb.data(), vector_ids); - std::this_thread::sleep_for(std::chrono::microseconds(1)); - } + engine::IDNumbers vector_ids; + stat = db_->InsertVectors(TABLE_NAME, nb, xb.data(), vector_ids); + engine::TableIndex index; + stat = db_->CreateIndex(TABLE_NAME, index); std::vector dates; stat = db_->DeleteTable(TABLE_NAME, dates); @@ -420,25 +412,31 @@ TEST_F(DBTest2, DELETE_BY_RANGE_TEST) { db_->HasTable(TABLE_NAME, has_table); ASSERT_TRUE(has_table); - engine::IDNumbers vector_ids; - uint64_t size; db_->Size(size); + ASSERT_EQ(size, 0UL); - int64_t nb = INSERT_LOOP; + int64_t nb = VECTOR_COUNT; std::vector xb; BuildVectors(nb, xb); - int loop = 20; - for (auto i=0; iInsertVectors(TABLE_NAME, nb, xb.data(), vector_ids); - std::this_thread::sleep_for(std::chrono::microseconds(1)); - } + engine::IDNumbers vector_ids; + stat = db_->InsertVectors(TABLE_NAME, nb, xb.data(), vector_ids); + engine::TableIndex index; + stat = db_->CreateIndex(TABLE_NAME, index); + + db_->Size(size); + ASSERT_NE(size, 0UL); std::vector dates; - std::string start_value = CurrentTmDate(-3); - std::string end_value = CurrentTmDate(-2); + std::string start_value = CurrentTmDate(); + std::string end_value = CurrentTmDate(1); 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 diff --git a/cpp/unittest/db/meta_tests.cpp b/cpp/unittest/db/meta_tests.cpp index fa28a74e..2baad61c 100644 --- a/cpp/unittest/db/meta_tests.cpp +++ b/cpp/unittest/db/meta_tests.cpp @@ -74,21 +74,21 @@ TEST_F(MetaTest, TABLE_FILE_TEST) { ASSERT_EQ(table_file.file_type_, new_file_type); meta::DatesT dates; - dates.push_back(meta::Meta::GetDate()); + dates.push_back(utils::GetDate()); status = impl_->DropPartitionsByDates(table_file.table_id_, dates); - ASSERT_FALSE(status.ok()); + ASSERT_TRUE(status.ok()); dates.clear(); 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); ASSERT_TRUE(status.ok()); - table_file.date_ = meta::Meta::GetDateWithDelta(-2); + table_file.date_ = utils::GetDateWithDelta(-2); status = impl_->UpdateTableFile(table_file); 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); dates.clear(); diff --git a/cpp/unittest/db/misc_test.cpp b/cpp/unittest/db/misc_test.cpp index 608a5ca1..a948d1f4 100644 --- a/cpp/unittest/db/misc_test.cpp +++ b/cpp/unittest/db/misc_test.cpp @@ -105,7 +105,7 @@ TEST(DBMiscTest, META_TEST) { time_t tt; time( &tt ); int delta = 10; - engine::meta::DateT dt = impl.GetDate(tt, delta); + engine::meta::DateT dt = engine::utils::GetDate(tt, delta); ASSERT_GT(dt, 0); } diff --git a/cpp/unittest/db/mysql_meta_test.cpp b/cpp/unittest/db/mysql_meta_test.cpp index 46b831d3..2ad842a2 100644 --- a/cpp/unittest/db/mysql_meta_test.cpp +++ b/cpp/unittest/db/mysql_meta_test.cpp @@ -90,7 +90,7 @@ TEST_F(DISABLED_MySQLTest, TABLE_FILE_TEST) { ASSERT_EQ(table_file.file_type_, meta::TableFileSchema::NEW); meta::DatesT dates; - dates.push_back(meta::Meta::GetDate()); + dates.push_back(utils::GetDate()); status = impl.DropPartitionsByDates(table_file.table_id_, dates); ASSERT_FALSE(status.ok()); @@ -110,15 +110,15 @@ TEST_F(DISABLED_MySQLTest, TABLE_FILE_TEST) { dates.clear(); 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); ASSERT_TRUE(status.ok()); - table_file.date_ = meta::Meta::GetDateWithDelta(-2); + table_file.date_ = utils::GetDateWithDelta(-2); status = impl.UpdateTableFile(table_file); 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); dates.clear(); -- GitLab