DescribeIndexRequest.cpp 2.8 KB
Newer Older
1
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
G
groot 已提交
2
//
3 4
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
G
groot 已提交
5
//
6 7 8 9 10
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions and limitations under the License.
G
groot 已提交
11

12
#include "server/delivery/request/DescribeIndexRequest.h"
G
groot 已提交
13 14 15 16 17
#include "server/DBWrapper.h"
#include "utils/Log.h"
#include "utils/TimeRecorder.h"
#include "utils/ValidationUtil.h"

S
shengjh 已提交
18
#include <fiu-local.h>
G
groot 已提交
19 20 21 22 23
#include <memory>

namespace milvus {
namespace server {

Z
Zhiru Zhu 已提交
24
DescribeIndexRequest::DescribeIndexRequest(const std::shared_ptr<Context>& context, const std::string& table_name,
25 26
                                           IndexParam& index_param)
    : BaseRequest(context, INFO_REQUEST_GROUP), table_name_(table_name), index_param_(index_param) {
G
groot 已提交
27 28 29
}

BaseRequestPtr
Z
Zhiru Zhu 已提交
30
DescribeIndexRequest::Create(const std::shared_ptr<Context>& context, const std::string& table_name,
31 32
                             IndexParam& index_param) {
    return std::shared_ptr<BaseRequest>(new DescribeIndexRequest(context, table_name, index_param));
G
groot 已提交
33 34 35 36 37
}

Status
DescribeIndexRequest::OnExecute() {
    try {
S
shengjh 已提交
38
        fiu_do_on("DescribeIndexRequest.OnExecute.throw_std_exception", throw std::exception());
G
groot 已提交
39
        std::string hdr = "DescribeIndexRequest(table=" + table_name_ + ")";
G
groot 已提交
40
        TimeRecorderAuto rc(hdr);
G
groot 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54

        // step 1: check arguments
        auto status = ValidationUtil::ValidateTableName(table_name_);
        if (!status.ok()) {
            return status;
        }

        // step 2: check table existence
        engine::TableIndex index;
        status = DBWrapper::DB()->DescribeIndex(table_name_, index);
        if (!status.ok()) {
            return status;
        }

G
groot 已提交
55 56 57 58 59 60 61 62
        // for binary vector, IDMAP and IVFLAT will be treated as BIN_IDMAP and BIN_IVFLAT internally
        // return IDMAP and IVFLAT for outside caller
        if (index.engine_type_ == (int32_t)engine::EngineType::FAISS_BIN_IDMAP) {
            index.engine_type_ = (int32_t)engine::EngineType::FAISS_IDMAP;
        } else if (index.engine_type_ == (int32_t)engine::EngineType::FAISS_BIN_IVFFLAT) {
            index.engine_type_ = (int32_t)engine::EngineType::FAISS_IVFFLAT;
        }

63 64 65
        index_param_.table_name_ = table_name_;
        index_param_.index_type_ = index.engine_type_;
        index_param_.nlist_ = index.nlist_;
G
groot 已提交
66 67 68 69 70 71 72 73 74
    } catch (std::exception& ex) {
        return Status(SERVER_UNEXPECTED_ERROR, ex.what());
    }

    return Status::OK();
}

}  // namespace server
}  // namespace milvus