1 | /** |
2 | * Copyright 2021 Alibaba, Inc. and its affiliates. All Rights Reserved. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | |
16 | * \author Hongqing.hu |
17 | * \date Mar 2021 |
18 | * \brief Write request builder interface definition |
19 | */ |
20 | |
21 | #pragma once |
22 | |
23 | #include "agent/column_order.h" |
24 | #include "agent/write_request.h" |
25 | #include "proto/proxima_be.pb.h" |
26 | |
27 | namespace proxima { |
28 | namespace be { |
29 | namespace server { |
30 | |
31 | /*! WriteRequestBuilder |
32 | */ |
33 | class WriteRequestBuilder { |
34 | public: |
35 | //! build write request |
36 | static int build(const meta::CollectionMeta &meta, |
37 | const agent::ColumnOrder &column_order, |
38 | const proto::WriteRequest &pb_request, |
39 | agent::WriteRequest *write_request); |
40 | |
41 | private: |
42 | static void get_index_and_forward_mode(const proto::WriteRequest &request, |
43 | const meta::CollectionMeta &meta, |
44 | bool *index_full_match, |
45 | bool *forward_full_match); |
46 | |
47 | static int validate_request(const proto::WriteRequest &request, |
48 | const meta::CollectionMeta &meta, |
49 | const agent::ColumnOrder &column_order, |
50 | bool index_full_match, bool forward_full_match); |
51 | |
52 | |
53 | static int build_proxy_request(const meta::CollectionMeta &meta, |
54 | const agent::ColumnOrder &column_order, |
55 | const proto::WriteRequest &pb_request, |
56 | bool index_full_match, bool forward_full_match, |
57 | agent::WriteRequest *write_request); |
58 | |
59 | static int build_direct_request(const meta::CollectionMeta &meta, |
60 | const agent::ColumnOrder &column_order, |
61 | const proto::WriteRequest &pb_request, |
62 | bool index_full_match, |
63 | bool forward_full_match, |
64 | agent::WriteRequest *write_request); |
65 | |
66 | static int build_record(const proto::WriteRequest::Row &row, |
67 | const proto::WriteRequest::RowMeta &row_meta, |
68 | const meta::CollectionMeta &meta, |
69 | const agent::ColumnOrder &column_order, |
70 | bool index_full_match, bool forward_full_match, |
71 | index::CollectionDataset *dataset); |
72 | |
73 | static int build_forwards_data(const proto::WriteRequest::Row &row, |
74 | const proto::WriteRequest::RowMeta &row_meta, |
75 | const agent::ColumnOrder &column_order, |
76 | const meta::CollectionMeta &meta, |
77 | bool forward_full_match, |
78 | index::CollectionDataset::RowData *row_data); |
79 | |
80 | static int build_indexes_data(const proto::WriteRequest::Row &row, |
81 | const proto::WriteRequest::RowMeta &row_meta, |
82 | const meta::CollectionMeta &meta, |
83 | bool index_full_match, |
84 | index::CollectionDataset::RowData *row_data); |
85 | }; |
86 | |
87 | |
88 | } // end namespace server |
89 | } // namespace be |
90 | } // end namespace proxima |
91 | |