提交 43905fe0 编写于 作者: J jinhai

MS-176 Add create table parameter check


Former-commit-id: 28500a443d0a55339ac987f1f13417d23a2edf46
上级 2ad68565
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "utils/CommonUtil.h" #include "utils/CommonUtil.h"
#include "utils/Log.h" #include "utils/Log.h"
#include "utils/TimeRecorder.h" #include "utils/TimeRecorder.h"
#include "utils/ValidationUtil.h"
#include "DBWrapper.h" #include "DBWrapper.h"
#include "version.h" #include "version.h"
...@@ -133,19 +134,23 @@ BaseTaskPtr CreateTableTask::Create(const thrift::TableSchema& schema) { ...@@ -133,19 +134,23 @@ BaseTaskPtr CreateTableTask::Create(const thrift::TableSchema& schema) {
ServerError CreateTableTask::OnExecute() { ServerError CreateTableTask::OnExecute() {
TimeRecorder rc("CreateTableTask"); TimeRecorder rc("CreateTableTask");
try { try {
//step 1: check arguments //step 1: check arguments
if(schema_.table_name.empty()) { ServerError res = SERVER_SUCCESS;
return SetError(SERVER_INVALID_TABLE_NAME, "Empty table name"); res = ValidateTableName(schema_.table_name);
if(res != SERVER_SUCCESS) {
return res;
} }
if(schema_.dimension <= 0) {
return SetError(SERVER_INVALID_TABLE_DIMENSION, "Invalid table dimension: " + std::to_string(schema_.dimension)); res = ValidateTableDimension(schema_.dimension);
if(res != SERVER_SUCCESS) {
return res;
} }
engine::EngineType engine_type = EngineType(schema_.index_type); res = ValidateTableIndexType(schema_.index_type);
if(engine_type == engine::EngineType::INVALID) { if(res != SERVER_SUCCESS) {
return SetError(SERVER_INVALID_INDEX_TYPE, "Invalid index type: " + std::to_string(schema_.index_type)); return res;
} }
//step 2: construct table schema //step 2: construct table schema
...@@ -187,8 +192,10 @@ ServerError DescribeTableTask::OnExecute() { ...@@ -187,8 +192,10 @@ ServerError DescribeTableTask::OnExecute() {
try { try {
//step 1: check arguments //step 1: check arguments
if(table_name_.empty()) { ServerError res = SERVER_SUCCESS;
return SetError(SERVER_INVALID_TABLE_NAME, "Empty table name"); res = ValidateTableName(table_name_);
if(res != SERVER_SUCCESS) {
return res;
} }
//step 2: get table info //step 2: get table info
...@@ -230,10 +237,11 @@ ServerError HasTableTask::OnExecute() { ...@@ -230,10 +237,11 @@ ServerError HasTableTask::OnExecute() {
TimeRecorder rc("HasTableTask"); TimeRecorder rc("HasTableTask");
//step 1: check arguments //step 1: check arguments
if(table_name_.empty()) { ServerError res = SERVER_SUCCESS;
return SetError(SERVER_INVALID_TABLE_NAME, "Empty table name"); res = ValidateTableName(table_name_);
if(res != SERVER_SUCCESS) {
return res;
} }
//step 2: check table existence //step 2: check table existence
engine::Status stat = DBWrapper::DB()->HasTable(table_name_, has_table_); engine::Status stat = DBWrapper::DB()->HasTable(table_name_, has_table_);
if(!stat.ok()) { if(!stat.ok()) {
...@@ -264,8 +272,10 @@ ServerError DeleteTableTask::OnExecute() { ...@@ -264,8 +272,10 @@ ServerError DeleteTableTask::OnExecute() {
TimeRecorder rc("DeleteTableTask"); TimeRecorder rc("DeleteTableTask");
//step 1: check arguments //step 1: check arguments
if (table_name_.empty()) { ServerError res = SERVER_SUCCESS;
return SetError(SERVER_INVALID_TABLE_NAME, "Empty table name"); res = ValidateTableName(table_name_);
if(res != SERVER_SUCCESS) {
return res;
} }
//step 2: check table existence //step 2: check table existence
...@@ -346,8 +356,10 @@ ServerError AddVectorTask::OnExecute() { ...@@ -346,8 +356,10 @@ ServerError AddVectorTask::OnExecute() {
TimeRecorder rc("AddVectorTask"); TimeRecorder rc("AddVectorTask");
//step 1: check arguments //step 1: check arguments
if (table_name_.empty()) { ServerError res = SERVER_SUCCESS;
return SetError(SERVER_INVALID_TABLE_NAME, "Empty table name"); res = ValidateTableName(table_name_);
if(res != SERVER_SUCCESS) {
return res;
} }
if(record_array_.empty()) { if(record_array_.empty()) {
...@@ -435,8 +447,10 @@ ServerError SearchVectorTask::OnExecute() { ...@@ -435,8 +447,10 @@ ServerError SearchVectorTask::OnExecute() {
TimeRecorder rc("SearchVectorTask"); TimeRecorder rc("SearchVectorTask");
//step 1: check arguments //step 1: check arguments
if (table_name_.empty()) { ServerError res = SERVER_SUCCESS;
return SetError(SERVER_INVALID_TABLE_NAME, "Empty table name"); res = ValidateTableName(table_name_);
if(res != SERVER_SUCCESS) {
return res;
} }
if(top_k_ <= 0) { if(top_k_ <= 0) {
...@@ -548,8 +562,10 @@ ServerError GetTableRowCountTask::OnExecute() { ...@@ -548,8 +562,10 @@ ServerError GetTableRowCountTask::OnExecute() {
TimeRecorder rc("GetTableRowCountTask"); TimeRecorder rc("GetTableRowCountTask");
//step 1: check arguments //step 1: check arguments
if (table_name_.empty()) { ServerError res = SERVER_SUCCESS;
return SetError(SERVER_INVALID_TABLE_NAME, "Empty table name"); res = ValidateTableName(table_name_);
if(res != SERVER_SUCCESS) {
return res;
} }
//step 2: get row count //step 2: get row count
......
#include <src/db/ExecutionEngine.h>
#include "ValidationUtil.h"
#include "Log.h"
namespace zilliz {
namespace milvus {
namespace server {
constexpr size_t table_name_size_limit = 16384;
constexpr int64_t table_dimension_limit = 16384;
ServerError
ValidateTableName(const std::string &table_name) {
// Table name shouldn't be empty.
if (table_name.empty()) {
SERVER_LOG_ERROR << "Empty table name";
return SERVER_INVALID_TABLE_NAME;
}
// Table name size shouldn't exceed 16384.
if (table_name.size() > table_name_size_limit) {
SERVER_LOG_ERROR << "Table name size exceed the limitation";
return SERVER_INVALID_TABLE_NAME;
}
// Table name first character should be underscore or character.
char first_char = table_name[0];
if (first_char != '_' && std::isalpha(first_char) == 0) {
SERVER_LOG_ERROR << "Table name first character isn't underscore or character: " << first_char;
return SERVER_INVALID_TABLE_NAME;
}
int64_t table_name_size = table_name.size();
for (int64_t i = 1; i < table_name_size; ++i) {
char name_char = table_name[i];
if (name_char != '_' && std::isalnum(name_char) == 0) {
SERVER_LOG_ERROR << "Table name character isn't underscore or alphanumber: " << name_char;
return SERVER_INVALID_TABLE_NAME;
}
}
return SERVER_SUCCESS;
}
ServerError
ValidateTableDimension(int64_t dimension) {
if (dimension <= 0 || dimension > table_dimension_limit) {
SERVER_LOG_ERROR << "Table dimension excceed the limitation: " << table_dimension_limit;
return SERVER_INVALID_VECTOR_DIMENSION;
} else {
return SERVER_SUCCESS;
}
}
ServerError
ValidateTableIndexType(int32_t index_type) {
auto engine_type = engine::EngineType(index_type);
switch (engine_type) {
case engine::EngineType::FAISS_IDMAP:
case engine::EngineType::FAISS_IVFFLAT: {
SERVER_LOG_DEBUG << "Index type: " << index_type;
return SERVER_SUCCESS;
}
default: {
return SERVER_INVALID_INDEX_TYPE;
}
}
}
}
}
}
\ No newline at end of file
#pragma once
#include "Error.h"
namespace zilliz {
namespace milvus {
namespace server {
ServerError
ValidateTableName(const std::string& table_name);
ServerError
ValidateTableDimension(int64_t dimension);
ServerError
ValidateTableIndexType(int32_t index_type);
}
}
}
\ No newline at end of file
...@@ -12,7 +12,6 @@ aux_source_directory(${MILVUS_ENGINE_SRC}/config config_files) ...@@ -12,7 +12,6 @@ aux_source_directory(${MILVUS_ENGINE_SRC}/config config_files)
set(unittest_srcs set(unittest_srcs
${CMAKE_CURRENT_SOURCE_DIR}/main.cpp) ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)
#${EASYLOGGINGPP_INCLUDE_DIR}/easylogging++.cc)
set(require_files set(require_files
${MILVUS_ENGINE_SRC}/server/ServerConfig.cpp ${MILVUS_ENGINE_SRC}/server/ServerConfig.cpp
...@@ -44,4 +43,5 @@ add_subdirectory(index_wrapper) ...@@ -44,4 +43,5 @@ add_subdirectory(index_wrapper)
#add_subdirectory(faiss_wrapper) #add_subdirectory(faiss_wrapper)
#add_subdirectory(license) #add_subdirectory(license)
add_subdirectory(metrics) add_subdirectory(metrics)
add_subdirectory(storage) add_subdirectory(storage)
\ No newline at end of file add_subdirectory(utils)
\ No newline at end of file
...@@ -3,17 +3,20 @@ ...@@ -3,17 +3,20 @@
// Unauthorized copying of this file, via any medium is strictly prohibited. // Unauthorized copying of this file, via any medium is strictly prohibited.
// Proprietary and confidential. // Proprietary and confidential.
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <gtest/gtest.h>
#include <thread>
#include <easylogging++.h>
#include <boost/filesystem.hpp>
#include "utils.h" #include "utils.h"
#include "db/DB.h" #include "db/DB.h"
#include "db/DBImpl.h" #include "db/DBImpl.h"
#include "db/MetaConsts.h" #include "db/MetaConsts.h"
#include "db/Factories.h" #include "db/Factories.h"
#include <gtest/gtest.h>
#include <easylogging++.h>
#include <boost/filesystem.hpp>
#include <thread>
#include <random>
using namespace zilliz::milvus; using namespace zilliz::milvus;
namespace { namespace {
......
...@@ -3,17 +3,19 @@ ...@@ -3,17 +3,19 @@
// Unauthorized copying of this file, via any medium is strictly prohibited. // Unauthorized copying of this file, via any medium is strictly prohibited.
// Proprietary and confidential. // Proprietary and confidential.
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <gtest/gtest.h>
#include <thread>
#include <easylogging++.h>
#include <boost/filesystem.hpp>
#include "utils.h" #include "utils.h"
#include "db/DB.h" #include "db/DB.h"
#include "db/DBImpl.h" #include "db/DBImpl.h"
#include "db/MetaConsts.h" #include "db/MetaConsts.h"
#include "db/Factories.h" #include "db/Factories.h"
#include <gtest/gtest.h>
#include <easylogging++.h>
#include <boost/filesystem.hpp>
#include <thread>
#include <random>
using namespace zilliz::milvus; using namespace zilliz::milvus;
namespace { namespace {
......
...@@ -3,10 +3,11 @@ ...@@ -3,10 +3,11 @@
// Unauthorized copying of this file, via any medium is strictly prohibited. // Unauthorized copying of this file, via any medium is strictly prohibited.
// Proprietary and confidential. // Proprietary and confidential.
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <gtest/gtest.h>
#include "db/scheduler/task/SearchTask.h" #include "db/scheduler/task/SearchTask.h"
#include <gtest/gtest.h>
#include <cmath>
#include <vector> #include <vector>
using namespace zilliz::milvus; using namespace zilliz::milvus;
......
...@@ -4,12 +4,15 @@ ...@@ -4,12 +4,15 @@
// Proprietary and confidential. // Proprietary and confidential.
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#include <gtest/gtest.h>
#include "wrapper/Operand.h" #include "wrapper/Operand.h"
#include "wrapper/Index.h" #include "wrapper/Index.h"
#include "wrapper/IndexBuilder.h" #include "wrapper/IndexBuilder.h"
#include <gtest/gtest.h>
#include <random>
using namespace zilliz::milvus::engine; using namespace zilliz::milvus::engine;
......
#-------------------------------------------------------------------------------
# Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
# Unauthorized copying of this file, via any medium is strictly prohibited.
# Proprietary and confidential.
#-------------------------------------------------------------------------------
# Make sure that your call to link_directories takes place before your call to the relevant add_executable.
include_directories("${CUDA_TOOLKIT_ROOT_DIR}/include")
link_directories("${CUDA_TOOLKIT_ROOT_DIR}/lib64")
set(validation_util_src
${MILVUS_ENGINE_SRC}/utils/ValidationUtil.cpp
${MILVUS_ENGINE_SRC}/utils/ValidationUtil.h)
set(validation_util_test_src
${unittest_srcs}
${validation_util_src}
${require_files}
ValidationUtilTest.cpp
)
add_executable(valication_util_test
${validation_util_test_src}
${config_files})
target_link_libraries(valication_util_test
${unittest_libs}
boost_filesystem)
install(TARGETS valication_util_test DESTINATION bin)
\ No newline at end of file
////////////////////////////////////////////////////////////////////////////////
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
// Unauthorized copying of this file, via any medium is strictly prohibited.
// Proprietary and confidential.
////////////////////////////////////////////////////////////////////////////////
#include <gtest/gtest.h>
#include "utils/ValidationUtil.h"
#include "utils/Error.h"
#include <string>
using namespace zilliz::milvus::server;
TEST(ValidationUtilTest, TableNameTest) {
std::string table_name = "Normal123_";
ServerError res = ValidateTableName(table_name);
ASSERT_EQ(res, SERVER_SUCCESS);
table_name = "12sds";
res = ValidateTableName(table_name);
ASSERT_EQ(res, SERVER_INVALID_TABLE_NAME);
table_name = "";
res = ValidateTableName(table_name);
ASSERT_EQ(res, SERVER_INVALID_TABLE_NAME);
table_name = "_asdasd";
res = ValidateTableName(table_name);
ASSERT_EQ(res, SERVER_SUCCESS);
table_name = "!@#!@";
res = ValidateTableName(table_name);
ASSERT_EQ(res, SERVER_INVALID_TABLE_NAME);
table_name = "中文";
res = ValidateTableName(table_name);
ASSERT_EQ(res, SERVER_INVALID_TABLE_NAME);
table_name = std::string('a', 32768);
res = ValidateTableName(table_name);
ASSERT_EQ(res, SERVER_INVALID_TABLE_NAME);
}
TEST(ValidationUtilTest, TableDimensionTest) {
ASSERT_EQ(ValidateTableDimension(-1), SERVER_INVALID_VECTOR_DIMENSION);
ASSERT_EQ(ValidateTableDimension(0), SERVER_INVALID_VECTOR_DIMENSION);
ASSERT_EQ(ValidateTableDimension(16385), SERVER_INVALID_VECTOR_DIMENSION);
ASSERT_EQ(ValidateTableDimension(16384), SERVER_SUCCESS);
ASSERT_EQ(ValidateTableDimension(1), SERVER_SUCCESS);
}
TEST(ValidationUtilTest, TableIndexTypeTest) {
ASSERT_EQ(ValidateTableIndexType(0), SERVER_INVALID_INDEX_TYPE);
ASSERT_EQ(ValidateTableIndexType(1), SERVER_SUCCESS);
ASSERT_EQ(ValidateTableIndexType(2), SERVER_SUCCESS);
ASSERT_EQ(ValidateTableIndexType(3), SERVER_INVALID_INDEX_TYPE);
ASSERT_EQ(ValidateTableIndexType(4), SERVER_INVALID_INDEX_TYPE);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册