ClientProxy.cpp 19.9 KB
Newer Older
1
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
J
jinhai 已提交
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
J
jinhai 已提交
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.
J
jinhai 已提交
11

Y
yukun 已提交
12
#include "grpc/ClientProxy.h"
S
starlord 已提交
13 14 15

#include <memory>
#include <string>
S
starlord 已提交
16
#include <vector>
S
starlord 已提交
17

18 19 20
#include "grpc-gen/gen-milvus/milvus.grpc.pb.h"

#define MILVUS_SDK_VERSION "0.7.0";
K
kun yu 已提交
21 22

namespace milvus {
23 24 25

static const char* EXTRA_PARAM_KEY = "params";

K
kun yu 已提交
26
bool
S
starlord 已提交
27
UriCheck(const std::string& uri) {
S
starlord 已提交
28
    size_t index = uri.find_first_of(':', 0);
S
starlord 已提交
29
    return (index != std::string::npos);
K
kun yu 已提交
30 31
}

32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
template<typename T>
void
ConstructSearchParam(const std::string& table_name,
                     const std::vector<std::string>& partition_tag_array,
                     int64_t topk,
                     const std::string& extra_params,
                     T& search_param) {
    search_param.set_table_name(table_name);
    search_param.set_topk(topk);
    milvus::grpc::KeyValuePair* kv = search_param.add_extra_params();
    kv->set_key(EXTRA_PARAM_KEY);
    kv->set_value(extra_params);

    for (auto& tag : partition_tag_array) {
        search_param.add_partition_tag_array(tag);
    }
}

G
groot 已提交
50 51
void
CopyRowRecord(::milvus::grpc::RowRecord* target, const RowRecord& src) {
G
groot 已提交
52 53 54 55 56 57 58 59 60
    if (!src.float_data.empty()) {
        auto vector_data = target->mutable_float_data();
        vector_data->Resize(static_cast<int>(src.float_data.size()), 0.0);
        memcpy(vector_data->mutable_data(), src.float_data.data(), src.float_data.size() * sizeof(float));
    }

    if (!src.binary_data.empty()) {
        target->set_binary_data(src.binary_data.data(), src.binary_data.size());
    }
G
groot 已提交
61 62
}

63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
void
ConstructPartitionStat(const ::milvus::grpc::PartitionStat& grpc_partition_stat, PartitionStat& partition_stat) {
    partition_stat.tag = grpc_partition_stat.tag();
    partition_stat.row_count = grpc_partition_stat.total_row_count();
    for (int i = 0; i < grpc_partition_stat.segments_stat_size(); i++) {
        auto& grpc_seg_stat = grpc_partition_stat.segments_stat(i);
        SegmentStat seg_stat;
        seg_stat.row_count = grpc_seg_stat.row_count();
        seg_stat.segment_name = grpc_seg_stat.segment_name();
        seg_stat.index_name = grpc_seg_stat.index_name();
        seg_stat.data_size = grpc_seg_stat.data_size();
        partition_stat.segments_stat.emplace_back(seg_stat);
    }
}

K
kun yu 已提交
78
Status
S
starlord 已提交
79
ClientProxy::Connect(const ConnectParam& param) {
K
kun yu 已提交
80 81 82 83 84
    std::string uri = param.ip_address + ":" + param.port;

    channel_ = ::grpc::CreateChannel(uri, ::grpc::InsecureChannelCredentials());
    if (channel_ != nullptr) {
        connected_ = true;
K
kun yu 已提交
85 86
        client_ptr_ = std::make_shared<GrpcClient>(channel_);
        return Status::OK();
K
kun yu 已提交
87
    }
S
starlord 已提交
88

89
    std::string reason = "connect Failed!";
S
starlord 已提交
90 91
    connected_ = false;
    return Status(StatusCode::NotConnected, reason);
K
kun yu 已提交
92 93 94
}

Status
S
starlord 已提交
95
ClientProxy::Connect(const std::string& uri) {
K
kun yu 已提交
96
    if (!UriCheck(uri)) {
S
starlord 已提交
97
        return Status(StatusCode::InvalidAgument, "Invalid uri");
K
kun yu 已提交
98
    }
K
kun yu 已提交
99
    size_t index = uri.find_first_of(':', 0);
K
kun yu 已提交
100 101 102 103 104 105 106 107 108 109 110 111

    ConnectParam param;
    param.ip_address = uri.substr(0, index);
    param.port = uri.substr(index + 1);

    return Connect(param);
}

Status
ClientProxy::Connected() const {
    try {
        std::string info;
112
        return client_ptr_->Cmd("", info);
S
starlord 已提交
113
    } catch (std::exception& ex) {
K
kun yu 已提交
114 115 116 117 118 119
        return Status(StatusCode::NotConnected, "connection lost: " + std::string(ex.what()));
    }
}

Status
ClientProxy::Disconnect() {
K
kun yu 已提交
120
    try {
K
kun yu 已提交
121
        Status status = client_ptr_->Disconnect();
K
kun yu 已提交
122 123
        connected_ = false;
        channel_.reset();
K
kun yu 已提交
124
        return status;
S
starlord 已提交
125
    } catch (std::exception& ex) {
126
        return Status(StatusCode::UnknownError, "Failed to disconnect: " + std::string(ex.what()));
K
kun yu 已提交
127
    }
K
kun yu 已提交
128 129 130 131
}

std::string
ClientProxy::ClientVersion() const {
Y
yukun 已提交
132
    return MILVUS_SDK_VERSION;
K
kun yu 已提交
133 134 135
}

Status
S
starlord 已提交
136
ClientProxy::CreateTable(const TableSchema& param) {
K
kun yu 已提交
137 138
    try {
        ::milvus::grpc::TableSchema schema;
139
        schema.set_table_name(param.table_name);
K
kun yu 已提交
140
        schema.set_dimension(param.dimension);
141
        schema.set_index_file_size(param.index_file_size);
S
starlord 已提交
142
        schema.set_metric_type(static_cast<int32_t>(param.metric_type));
K
kun yu 已提交
143

K
kun yu 已提交
144
        return client_ptr_->CreateTable(schema);
S
starlord 已提交
145
    } catch (std::exception& ex) {
146
        return Status(StatusCode::UnknownError, "Failed to create table: " + std::string(ex.what()));
K
kun yu 已提交
147 148 149 150
    }
}

bool
S
starlord 已提交
151
ClientProxy::HasTable(const std::string& table_name) {
K
kun yu 已提交
152
    Status status = Status::OK();
K
kun yu 已提交
153 154
    ::milvus::grpc::TableName grpc_table_name;
    grpc_table_name.set_table_name(table_name);
K
kun yu 已提交
155 156
    bool result = client_ptr_->HasTable(grpc_table_name, status);
    return result;
K
kun yu 已提交
157 158 159
}

Status
S
starlord 已提交
160
ClientProxy::DropTable(const std::string& table_name) {
K
kun yu 已提交
161 162 163
    try {
        ::milvus::grpc::TableName grpc_table_name;
        grpc_table_name.set_table_name(table_name);
K
kun yu 已提交
164
        return client_ptr_->DropTable(grpc_table_name);
S
starlord 已提交
165
    } catch (std::exception& ex) {
166
        return Status(StatusCode::UnknownError, "Failed to drop table: " + std::string(ex.what()));
K
kun yu 已提交
167 168 169 170
    }
}

Status
S
starlord 已提交
171
ClientProxy::CreateIndex(const IndexParam& index_param) {
K
kun yu 已提交
172
    try {
Y
Yu Kun 已提交
173
        ::milvus::grpc::IndexParam grpc_index_param;
174
        grpc_index_param.set_table_name(index_param.table_name);
175 176 177 178
        grpc_index_param.set_index_type(static_cast<int32_t>(index_param.index_type));
        milvus::grpc::KeyValuePair* kv = grpc_index_param.add_extra_params();
        kv->set_key(EXTRA_PARAM_KEY);
        kv->set_value(index_param.extra_params);
Y
Yu Kun 已提交
179
        return client_ptr_->CreateIndex(grpc_index_param);
S
starlord 已提交
180
    } catch (std::exception& ex) {
181
        return Status(StatusCode::UnknownError, "Failed to build index: " + std::string(ex.what()));
K
kun yu 已提交
182 183 184
    }
}

K
kun yu 已提交
185
Status
G
groot 已提交
186 187
ClientProxy::Insert(const std::string& table_name, const std::string& partition_tag,
                    const std::vector<RowRecord>& record_array, std::vector<int64_t>& id_array) {
K
kun yu 已提交
188
    Status status = Status::OK();
K
kun yu 已提交
189
    try {
Y
Yu Kun 已提交
190 191
        ::milvus::grpc::InsertParam insert_param;
        insert_param.set_table_name(table_name);
G
groot 已提交
192
        insert_param.set_partition_tag(partition_tag);
K
kun yu 已提交
193

S
starlord 已提交
194 195
        for (auto& record : record_array) {
            ::milvus::grpc::RowRecord* grpc_record = insert_param.add_row_record_array();
G
groot 已提交
196
            CopyRowRecord(grpc_record, record);
K
kun yu 已提交
197 198
        }

S
starlord 已提交
199
        // Single thread
Y
Yu Kun 已提交
200 201
        ::milvus::grpc::VectorIds vector_ids;
        if (!id_array.empty()) {
202
            /* set user's ids */
G
groot 已提交
203 204 205
            auto row_ids = insert_param.mutable_row_id_array();
            row_ids->Resize(static_cast<int>(id_array.size()), -1);
            memcpy(row_ids->mutable_data(), id_array.data(), id_array.size() * sizeof(int64_t));
206
            status = client_ptr_->Insert(insert_param, vector_ids);
Y
Yu Kun 已提交
207
        } else {
208
            status = client_ptr_->Insert(insert_param, vector_ids);
209 210
            /* return Milvus generated ids back to user */
            id_array.insert(id_array.end(), vector_ids.vector_id_array().begin(), vector_ids.vector_id_array().end());
K
kun yu 已提交
211
        }
S
starlord 已提交
212
    } catch (std::exception& ex) {
213
        return Status(StatusCode::UnknownError, "Failed to add vector: " + std::string(ex.what()));
K
kun yu 已提交
214 215
    }

K
kun yu 已提交
216
    return status;
K
kun yu 已提交
217 218
}

219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
Status
ClientProxy::GetVectorByID(const std::string& table_name, int64_t vector_id, RowRecord& vector_data) {
    try {
        ::milvus::grpc::VectorIdentity vector_identity;
        vector_identity.set_table_name(table_name);
        vector_identity.set_id(vector_id);

        ::milvus::grpc::VectorData grpc_data;
        Status status = client_ptr_->GetVectorByID(vector_identity, grpc_data);
        if (!status.ok()) {
            return status;
        }

        int float_size = grpc_data.vector_data().float_data_size();
        if (float_size > 0) {
            vector_data.float_data.resize(float_size);
            memcpy(vector_data.float_data.data(), grpc_data.vector_data().float_data().data(),
                   float_size * sizeof(float));
        }

        auto byte_size = grpc_data.vector_data().binary_data().length();
        if (byte_size > 0) {
            vector_data.binary_data.resize(byte_size);
            memcpy(vector_data.binary_data.data(), grpc_data.vector_data().binary_data().data(), byte_size);
        }

        return status;
    } catch (std::exception& ex) {
        return Status(StatusCode::UnknownError, "Failed to get vector by id: " + std::string(ex.what()));
    }
}

Status
ClientProxy::GetIDsInSegment(const std::string& table_name, const std::string& segment_name,
                             std::vector<int64_t>& id_array) {
    try {
        ::milvus::grpc::GetVectorIDsParam param;
        param.set_table_name(table_name);
        param.set_segment_name(segment_name);

        ::milvus::grpc::VectorIds vector_ids;
        Status status = client_ptr_->GetIDsInSegment(param, vector_ids);
        if (!status.ok()) {
            return status;
        }

        id_array.insert(id_array.end(), vector_ids.vector_id_array().begin(), vector_ids.vector_id_array().end());

        return status;
    } catch (std::exception& ex) {
        return Status(StatusCode::UnknownError, "Failed to get vector by id: " + std::string(ex.what()));
    }
}

K
kun yu 已提交
273
Status
274 275
ClientProxy::Search(const std::string& table_name, const std::vector<std::string>& partition_tag_array,
                    const std::vector<RowRecord>& query_record_array, int64_t topk, const std::string& extra_params,
276
                    TopKQueryResult& topk_query_result) {
K
kun yu 已提交
277
    try {
S
starlord 已提交
278
        // step 1: convert vectors data
Y
Yu Kun 已提交
279
        ::milvus::grpc::SearchParam search_param;
280 281 282 283 284 285
        ConstructSearchParam(table_name,
                             partition_tag_array,
                             topk,
                             extra_params,
                             search_param);

S
starlord 已提交
286 287
        for (auto& record : query_record_array) {
            ::milvus::grpc::RowRecord* row_record = search_param.add_query_record_array();
G
groot 已提交
288
            CopyRowRecord(row_record, record);
K
kun yu 已提交
289 290
        }

291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
        // step 2: search vectors
        ::milvus::grpc::TopKQueryResult result;
        Status status = client_ptr_->Search(search_param, result);
        if (result.row_num() == 0) {
            return status;
        }

        // step 3: convert result array
        topk_query_result.reserve(result.row_num());
        int64_t nq = result.row_num();
        int64_t topk = result.ids().size() / nq;
        for (int64_t i = 0; i < result.row_num(); i++) {
            milvus::QueryResult one_result;
            one_result.ids.resize(topk);
            one_result.distances.resize(topk);
            memcpy(one_result.ids.data(), result.ids().data() + topk * i, topk * sizeof(int64_t));
            memcpy(one_result.distances.data(), result.distances().data() + topk * i, topk * sizeof(float));
            topk_query_result.emplace_back(one_result);
K
kun yu 已提交
309 310
        }

311 312 313 314 315 316
        return status;
    } catch (std::exception& ex) {
        return Status(StatusCode::UnknownError, "Failed to search vectors: " + std::string(ex.what()));
    }
}

K
kun yu 已提交
317
Status
S
starlord 已提交
318
ClientProxy::DescribeTable(const std::string& table_name, TableSchema& table_schema) {
K
kun yu 已提交
319 320 321
    try {
        ::milvus::grpc::TableSchema grpc_schema;

322
        Status status = client_ptr_->DescribeTable(table_name, grpc_schema);
K
kun yu 已提交
323

324
        table_schema.table_name = grpc_schema.table_name();
K
kun yu 已提交
325
        table_schema.dimension = grpc_schema.dimension();
326
        table_schema.index_file_size = grpc_schema.index_file_size();
S
starlord 已提交
327
        table_schema.metric_type = static_cast<MetricType>(grpc_schema.metric_type());
K
kun yu 已提交
328 329

        return status;
S
starlord 已提交
330
    } catch (std::exception& ex) {
331
        return Status(StatusCode::UnknownError, "Failed to describe table: " + std::string(ex.what()));
K
kun yu 已提交
332 333 334 335
    }
}

Status
S
starlord 已提交
336
ClientProxy::CountTable(const std::string& table_name, int64_t& row_count) {
K
kun yu 已提交
337
    try {
K
kun yu 已提交
338
        Status status;
339 340 341
        ::milvus::grpc::TableName grpc_table_name;
        grpc_table_name.set_table_name(table_name);
        row_count = client_ptr_->CountTable(grpc_table_name, status);
K
kun yu 已提交
342
        return status;
S
starlord 已提交
343
    } catch (std::exception& ex) {
344
        return Status(StatusCode::UnknownError, "Failed to show tables: " + std::string(ex.what()));
K
kun yu 已提交
345 346 347 348
    }
}

Status
S
starlord 已提交
349
ClientProxy::ShowTables(std::vector<std::string>& table_array) {
K
kun yu 已提交
350
    try {
351 352 353 354 355 356 357 358 359
        Status status;
        milvus::grpc::TableNameList table_name_list;
        status = client_ptr_->ShowTables(table_name_list);

        table_array.resize(table_name_list.table_names_size());
        for (uint64_t i = 0; i < table_name_list.table_names_size(); ++i) {
            table_array[i] = table_name_list.table_names(i);
        }
        return status;
S
starlord 已提交
360
    } catch (std::exception& ex) {
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
        return Status(StatusCode::UnknownError, "Failed to show tables: " + std::string(ex.what()));
    }
}

Status
ClientProxy::ShowTableInfo(const std::string& table_name, TableInfo& table_info) {
    try {
        Status status;
        ::milvus::grpc::TableName grpc_table_name;
        grpc_table_name.set_table_name(table_name);
        milvus::grpc::TableInfo grpc_table_info;
        status = client_ptr_->ShowTableInfo(grpc_table_name, grpc_table_info);

        // get native info
        table_info.total_row_count = grpc_table_info.total_row_count();

        // get partitions info
        for (int i = 0; i < grpc_table_info.partitions_stat_size(); i++) {
            auto& grpc_partition_stat = grpc_table_info.partitions_stat(i);
            PartitionStat partition_stat;
            ConstructPartitionStat(grpc_partition_stat, partition_stat);
            table_info.partitions_stat.emplace_back(partition_stat);
        }

        return status;
    } catch (std::exception& ex) {
        return Status(StatusCode::UnknownError, "Failed to show table info: " + std::string(ex.what()));
K
kun yu 已提交
388 389 390 391 392
    }
}

std::string
ClientProxy::ServerVersion() const {
K
kun yu 已提交
393
    Status status = Status::OK();
K
kun yu 已提交
394 395
    try {
        std::string version;
396
        Status status = client_ptr_->Cmd("version", version);
K
kun yu 已提交
397
        return version;
S
starlord 已提交
398
    } catch (std::exception& ex) {
K
kun yu 已提交
399 400 401 402 403 404
        return "";
    }
}

std::string
ClientProxy::ServerStatus() const {
K
kun yu 已提交
405
    if (channel_ == nullptr) {
K
kun yu 已提交
406 407 408 409 410
        return "not connected to server";
    }

    try {
        std::string dummy;
411
        Status status = client_ptr_->Cmd("", dummy);
K
kun yu 已提交
412
        return "server alive";
S
starlord 已提交
413
    } catch (std::exception& ex) {
K
kun yu 已提交
414 415 416 417
        return "connection lost";
    }
}

Y
Yu Kun 已提交
418
Status
419
ClientProxy::DeleteByID(const std::string& table_name, const std::vector<int64_t>& id_array) {
420
    try {
421 422 423 424 425 426 427 428
        ::milvus::grpc::DeleteByIDParam delete_by_id_param;
        delete_by_id_param.set_table_name(table_name);

        for (auto id : id_array) {
            delete_by_id_param.add_id_array(id);
        }

        return client_ptr_->DeleteByID(delete_by_id_param);
S
starlord 已提交
429
    } catch (std::exception& ex) {
430
        return Status(StatusCode::UnknownError, "Failed to delete by range: " + std::string(ex.what()));
431
    }
Y
Yu Kun 已提交
432 433 434
}

Status
S
starlord 已提交
435
ClientProxy::PreloadTable(const std::string& table_name) const {
Y
Yu Kun 已提交
436 437 438 439 440
    try {
        ::milvus::grpc::TableName grpc_table_name;
        grpc_table_name.set_table_name(table_name);
        Status status = client_ptr_->PreloadTable(grpc_table_name);
        return status;
S
starlord 已提交
441
    } catch (std::exception& ex) {
442
        return Status(StatusCode::UnknownError, "Failed to preload tables: " + std::string(ex.what()));
Y
Yu Kun 已提交
443
    }
Y
Yu Kun 已提交
444 445
}

446
Status
S
starlord 已提交
447
ClientProxy::DescribeIndex(const std::string& table_name, IndexParam& index_param) const {
448 449 450
    try {
        ::milvus::grpc::TableName grpc_table_name;
        grpc_table_name.set_table_name(table_name);
451

452 453
        ::milvus::grpc::IndexParam grpc_index_param;
        Status status = client_ptr_->DescribeIndex(grpc_table_name, grpc_index_param);
454 455 456 457 458 459 460 461
        index_param.index_type = static_cast<IndexType>(grpc_index_param.index_type());

        for (int i = 0; i < grpc_index_param.extra_params_size(); i++) {
            const milvus::grpc::KeyValuePair& kv = grpc_index_param.extra_params(i);
            if (kv.key() == EXTRA_PARAM_KEY) {
                index_param.extra_params = kv.value();
            }
        }
462 463

        return status;
S
starlord 已提交
464
    } catch (std::exception& ex) {
465
        return Status(StatusCode::UnknownError, "Failed to describe index: " + std::string(ex.what()));
466
    }
Y
Yu Kun 已提交
467 468 469
}

Status
S
starlord 已提交
470
ClientProxy::DropIndex(const std::string& table_name) const {
471 472 473 474 475
    try {
        ::milvus::grpc::TableName grpc_table_name;
        grpc_table_name.set_table_name(table_name);
        Status status = client_ptr_->DropIndex(grpc_table_name);
        return status;
S
starlord 已提交
476
    } catch (std::exception& ex) {
477
        return Status(StatusCode::UnknownError, "Failed to drop index: " + std::string(ex.what()));
478
    }
Y
Yu Kun 已提交
479 480
}

G
groot 已提交
481 482 483 484 485 486 487 488 489
Status
ClientProxy::CreatePartition(const PartitionParam& partition_param) {
    try {
        ::milvus::grpc::PartitionParam grpc_partition_param;
        grpc_partition_param.set_table_name(partition_param.table_name);
        grpc_partition_param.set_tag(partition_param.partition_tag);
        Status status = client_ptr_->CreatePartition(grpc_partition_param);
        return status;
    } catch (std::exception& ex) {
490
        return Status(StatusCode::UnknownError, "Failed to create partition: " + std::string(ex.what()));
G
groot 已提交
491 492 493 494
    }
}

Status
495
ClientProxy::ShowPartitions(const std::string& table_name, PartitionTagList& partition_tag_array) const {
G
groot 已提交
496 497 498 499 500
    try {
        ::milvus::grpc::TableName grpc_table_name;
        grpc_table_name.set_table_name(table_name);
        ::milvus::grpc::PartitionList grpc_partition_list;
        Status status = client_ptr_->ShowPartitions(grpc_table_name, grpc_partition_list);
501
        partition_tag_array.resize(grpc_partition_list.partition_tag_array_size());
502
        for (uint64_t i = 0; i < grpc_partition_list.partition_tag_array_size(); ++i) {
503
            partition_tag_array[i] = grpc_partition_list.partition_tag_array(i);
G
groot 已提交
504 505 506
        }
        return status;
    } catch (std::exception& ex) {
507
        return Status(StatusCode::UnknownError, "Failed to show partitions: " + std::string(ex.what()));
G
groot 已提交
508 509 510 511 512 513 514 515 516 517 518 519
    }
}

Status
ClientProxy::DropPartition(const PartitionParam& partition_param) {
    try {
        ::milvus::grpc::PartitionParam grpc_partition_param;
        grpc_partition_param.set_table_name(partition_param.table_name);
        grpc_partition_param.set_tag(partition_param.partition_tag);
        Status status = client_ptr_->DropPartition(grpc_partition_param);
        return status;
    } catch (std::exception& ex) {
520
        return Status(StatusCode::UnknownError, "Failed to drop partition: " + std::string(ex.what()));
G
groot 已提交
521 522 523
    }
}

524 525 526
Status
ClientProxy::GetConfig(const std::string& node_name, std::string& value) const {
    try {
527
        return client_ptr_->Cmd("get_config " + node_name, value);
528
    } catch (std::exception& ex) {
529
        return Status(StatusCode::UnknownError, "Failed to get config: " + node_name);
530 531 532 533 534 535 536
    }
}

Status
ClientProxy::SetConfig(const std::string& node_name, const std::string& value) const {
    try {
        std::string dummy;
537
        return client_ptr_->Cmd("set_config " + node_name + " " + value, dummy);
538
    } catch (std::exception& ex) {
539
        return Status(StatusCode::UnknownError, "Failed to set config: " + node_name);
540 541 542
    }
}

543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573
Status
ClientProxy::FlushTable(const std::string& table_name) {
    try {
        std::string dummy;
        return client_ptr_->Flush(table_name);
    } catch (std::exception& ex) {
        return Status(StatusCode::UnknownError, "Failed to flush");
    }
}

Status
ClientProxy::Flush() {
    try {
        std::string dummy;
        return client_ptr_->Flush("");
    } catch (std::exception& ex) {
        return Status(StatusCode::UnknownError, "Failed to flush");
    }
}

Status
ClientProxy::CompactTable(const std::string& table_name) {
    try {
        ::milvus::grpc::TableName grpc_table_name;
        grpc_table_name.set_table_name(table_name);
        Status status = client_ptr_->Compact(grpc_table_name);
        return status;
    } catch (std::exception& ex) {
        return Status(StatusCode::UnknownError, "Failed to compact table: " + std::string(ex.what()));
    }
}
574

S
starlord 已提交
575
}  // namespace milvus