GrpcRequestTask.h 7.7 KB
Newer Older
J
jinhai 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you 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
//
//   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.

K
kun yu 已提交
18
#pragma once
S
starlord 已提交
19

S
starlord 已提交
20
#include "db/Types.h"
S
starlord 已提交
21
#include "server/grpc_impl/GrpcRequestScheduler.h"
S
starlord 已提交
22
#include "utils/Status.h"
K
kun yu 已提交
23

S
starlord 已提交
24 25
#include "grpc/gen-milvus/milvus.grpc.pb.h"
#include "grpc/gen-status/status.pb.h"
K
kun yu 已提交
26 27 28

#include <condition_variable>
#include <memory>
S
starlord 已提交
29
#include <string>
S
starlord 已提交
30
#include <vector>
K
kun yu 已提交
31 32 33

namespace milvus {
namespace server {
Y
Yu Kun 已提交
34
namespace grpc {
K
kun yu 已提交
35 36

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Y
Yu Kun 已提交
37
class CreateTableTask : public GrpcBaseTask {
S
starlord 已提交
38
 public:
Y
Yu Kun 已提交
39
    static BaseTaskPtr
S
starlord 已提交
40
    Create(const ::milvus::grpc::TableSchema* schema);
K
kun yu 已提交
41

S
starlord 已提交
42
 protected:
S
starlord 已提交
43
    explicit CreateTableTask(const ::milvus::grpc::TableSchema* schema);
K
kun yu 已提交
44

S
starlord 已提交
45
    Status
Y
Yu Kun 已提交
46
    OnExecute() override;
K
kun yu 已提交
47

S
starlord 已提交
48
 private:
S
starlord 已提交
49
    const ::milvus::grpc::TableSchema* schema_;
K
kun yu 已提交
50 51 52
};

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Y
Yu Kun 已提交
53
class HasTableTask : public GrpcBaseTask {
S
starlord 已提交
54
 public:
Y
Yu Kun 已提交
55
    static BaseTaskPtr
S
starlord 已提交
56
    Create(const std::string& table_name, bool& has_table);
K
kun yu 已提交
57

S
starlord 已提交
58
 protected:
S
starlord 已提交
59
    HasTableTask(const std::string& table_name, bool& has_table);
K
kun yu 已提交
60

S
starlord 已提交
61
    Status
Y
Yu Kun 已提交
62
    OnExecute() override;
K
kun yu 已提交
63

S
starlord 已提交
64
 private:
K
kun yu 已提交
65
    std::string table_name_;
S
starlord 已提交
66
    bool& has_table_;
K
kun yu 已提交
67 68 69
};

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Y
Yu Kun 已提交
70
class DescribeTableTask : public GrpcBaseTask {
S
starlord 已提交
71
 public:
Y
Yu Kun 已提交
72
    static BaseTaskPtr
S
starlord 已提交
73
    Create(const std::string& table_name, ::milvus::grpc::TableSchema* schema);
K
kun yu 已提交
74

S
starlord 已提交
75
 protected:
S
starlord 已提交
76
    DescribeTableTask(const std::string& table_name, ::milvus::grpc::TableSchema* schema);
K
kun yu 已提交
77

S
starlord 已提交
78
    Status
Y
Yu Kun 已提交
79
    OnExecute() override;
K
kun yu 已提交
80

S
starlord 已提交
81
 private:
K
kun yu 已提交
82
    std::string table_name_;
S
starlord 已提交
83
    ::milvus::grpc::TableSchema* schema_;
K
kun yu 已提交
84 85 86
};

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Y
Yu Kun 已提交
87
class DropTableTask : public GrpcBaseTask {
S
starlord 已提交
88
 public:
Y
Yu Kun 已提交
89
    static BaseTaskPtr
S
starlord 已提交
90
    Create(const std::string& table_name);
K
kun yu 已提交
91

S
starlord 已提交
92
 protected:
S
starlord 已提交
93
    explicit DropTableTask(const std::string& table_name);
K
kun yu 已提交
94

S
starlord 已提交
95
    Status
Y
Yu Kun 已提交
96
    OnExecute() override;
K
kun yu 已提交
97

S
starlord 已提交
98
 private:
K
kun yu 已提交
99 100 101 102
    std::string table_name_;
};

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Y
Yu Kun 已提交
103
class CreateIndexTask : public GrpcBaseTask {
S
starlord 已提交
104
 public:
Y
Yu Kun 已提交
105
    static BaseTaskPtr
S
starlord 已提交
106
    Create(const ::milvus::grpc::IndexParam* index_param);
K
kun yu 已提交
107

S
starlord 已提交
108
 protected:
S
starlord 已提交
109
    explicit CreateIndexTask(const ::milvus::grpc::IndexParam* index_param);
K
kun yu 已提交
110

S
starlord 已提交
111
    Status
Y
Yu Kun 已提交
112
    OnExecute() override;
K
kun yu 已提交
113

S
starlord 已提交
114
 private:
S
starlord 已提交
115
    const ::milvus::grpc::IndexParam* index_param_;
K
kun yu 已提交
116 117 118
};

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Y
Yu Kun 已提交
119
class ShowTablesTask : public GrpcBaseTask {
S
starlord 已提交
120
 public:
Y
Yu Kun 已提交
121
    static BaseTaskPtr
S
starlord 已提交
122
    Create(::milvus::grpc::TableNameList* table_name_list);
K
kun yu 已提交
123

S
starlord 已提交
124
 protected:
S
starlord 已提交
125
    explicit ShowTablesTask(::milvus::grpc::TableNameList* table_name_list);
K
kun yu 已提交
126

S
starlord 已提交
127
    Status
Y
Yu Kun 已提交
128
    OnExecute() override;
K
kun yu 已提交
129

S
starlord 已提交
130
 private:
S
starlord 已提交
131
    ::milvus::grpc::TableNameList* table_name_list_;
K
kun yu 已提交
132 133 134
};

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Y
Yu Kun 已提交
135
class InsertTask : public GrpcBaseTask {
S
starlord 已提交
136
 public:
Y
Yu Kun 已提交
137
    static BaseTaskPtr
S
starlord 已提交
138
    Create(const ::milvus::grpc::InsertParam* insert_param, ::milvus::grpc::VectorIds* record_ids);
K
kun yu 已提交
139

S
starlord 已提交
140
 protected:
S
starlord 已提交
141
    InsertTask(const ::milvus::grpc::InsertParam* insert_param, ::milvus::grpc::VectorIds* record_ids);
K
kun yu 已提交
142

S
starlord 已提交
143
    Status
Y
Yu Kun 已提交
144
    OnExecute() override;
K
kun yu 已提交
145

S
starlord 已提交
146
 private:
S
starlord 已提交
147 148
    const ::milvus::grpc::InsertParam* insert_param_;
    ::milvus::grpc::VectorIds* record_ids_;
K
kun yu 已提交
149 150 151
};

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Y
Yu Kun 已提交
152
class SearchTask : public GrpcBaseTask {
S
starlord 已提交
153
 public:
Y
Yu Kun 已提交
154
    static BaseTaskPtr
S
starlord 已提交
155
    Create(const ::milvus::grpc::SearchParam* search_param, const std::vector<std::string>& file_id_array,
156
           ::milvus::grpc::TopKQueryResult* response);
K
kun yu 已提交
157

S
starlord 已提交
158
 protected:
S
starlord 已提交
159
    SearchTask(const ::milvus::grpc::SearchParam* search_param, const std::vector<std::string>& file_id_array,
160
               ::milvus::grpc::TopKQueryResult* response);
K
kun yu 已提交
161

S
starlord 已提交
162
    Status
Y
Yu Kun 已提交
163
    OnExecute() override;
K
kun yu 已提交
164

S
starlord 已提交
165
 private:
S
starlord 已提交
166
    const ::milvus::grpc::SearchParam* search_param_;
K
kun yu 已提交
167
    std::vector<std::string> file_id_array_;
168
    ::milvus::grpc::TopKQueryResult* topk_result_;
K
kun yu 已提交
169 170 171
};

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Y
Yu Kun 已提交
172
class CountTableTask : public GrpcBaseTask {
S
starlord 已提交
173
 public:
Y
Yu Kun 已提交
174
    static BaseTaskPtr
S
starlord 已提交
175
    Create(const std::string& table_name, int64_t& row_count);
K
kun yu 已提交
176

S
starlord 已提交
177
 protected:
S
starlord 已提交
178
    CountTableTask(const std::string& table_name, int64_t& row_count);
K
kun yu 已提交
179

S
starlord 已提交
180
    Status
Y
Yu Kun 已提交
181
    OnExecute() override;
K
kun yu 已提交
182

S
starlord 已提交
183
 private:
K
kun yu 已提交
184
    std::string table_name_;
S
starlord 已提交
185
    int64_t& row_count_;
K
kun yu 已提交
186 187 188
};

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Y
Yu Kun 已提交
189
class CmdTask : public GrpcBaseTask {
S
starlord 已提交
190
 public:
Y
Yu Kun 已提交
191
    static BaseTaskPtr
S
starlord 已提交
192
    Create(const std::string& cmd, std::string& result);
K
kun yu 已提交
193

S
starlord 已提交
194
 protected:
S
starlord 已提交
195
    CmdTask(const std::string& cmd, std::string& result);
K
kun yu 已提交
196

S
starlord 已提交
197
    Status
Y
Yu Kun 已提交
198
    OnExecute() override;
K
kun yu 已提交
199

S
starlord 已提交
200
 private:
K
kun yu 已提交
201
    std::string cmd_;
S
starlord 已提交
202
    std::string& result_;
K
kun yu 已提交
203
};
Y
Yu Kun 已提交
204 205 206

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class DeleteByRangeTask : public GrpcBaseTask {
S
starlord 已提交
207
 public:
Y
Yu Kun 已提交
208
    static BaseTaskPtr
S
starlord 已提交
209
    Create(const ::milvus::grpc::DeleteByRangeParam* delete_by_range_param);
Y
Yu Kun 已提交
210

S
starlord 已提交
211
 protected:
S
starlord 已提交
212
    explicit DeleteByRangeTask(const ::milvus::grpc::DeleteByRangeParam* delete_by_range_param);
Y
Yu Kun 已提交
213

S
starlord 已提交
214
    Status
Y
Yu Kun 已提交
215 216
    OnExecute() override;

S
starlord 已提交
217
 private:
S
starlord 已提交
218
    const ::milvus::grpc::DeleteByRangeParam* delete_by_range_param_;
Y
Yu Kun 已提交
219 220 221 222
};

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class PreloadTableTask : public GrpcBaseTask {
S
starlord 已提交
223
 public:
Y
Yu Kun 已提交
224
    static BaseTaskPtr
S
starlord 已提交
225
    Create(const std::string& table_name);
Y
Yu Kun 已提交
226

S
starlord 已提交
227
 protected:
S
starlord 已提交
228
    explicit PreloadTableTask(const std::string& table_name);
Y
Yu Kun 已提交
229

S
starlord 已提交
230
    Status
Y
Yu Kun 已提交
231 232
    OnExecute() override;

S
starlord 已提交
233
 private:
Y
Yu Kun 已提交
234 235 236 237 238
    std::string table_name_;
};

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class DescribeIndexTask : public GrpcBaseTask {
S
starlord 已提交
239
 public:
Y
Yu Kun 已提交
240
    static BaseTaskPtr
S
starlord 已提交
241
    Create(const std::string& table_name, ::milvus::grpc::IndexParam* index_param);
Y
Yu Kun 已提交
242

S
starlord 已提交
243
 protected:
S
starlord 已提交
244
    DescribeIndexTask(const std::string& table_name, ::milvus::grpc::IndexParam* index_param);
Y
Yu Kun 已提交
245

S
starlord 已提交
246
    Status
Y
Yu Kun 已提交
247 248
    OnExecute() override;

S
starlord 已提交
249
 private:
Y
Yu Kun 已提交
250
    std::string table_name_;
S
starlord 已提交
251
    ::milvus::grpc::IndexParam* index_param_;
Y
Yu Kun 已提交
252 253 254 255
};

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class DropIndexTask : public GrpcBaseTask {
S
starlord 已提交
256
 public:
Y
Yu Kun 已提交
257
    static BaseTaskPtr
S
starlord 已提交
258
    Create(const std::string& table_name);
Y
Yu Kun 已提交
259

S
starlord 已提交
260
 protected:
S
starlord 已提交
261
    explicit DropIndexTask(const std::string& table_name);
Y
Yu Kun 已提交
262

S
starlord 已提交
263
    Status
264 265
    OnExecute() override;

S
starlord 已提交
266
 private:
Y
Yu Kun 已提交
267 268 269
    std::string table_name_;
};

S
starlord 已提交
270 271 272
}  // namespace grpc
}  // namespace server
}  // namespace milvus