• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef REMOTE_EXECUTOR_PACKET_H
17 #define REMOTE_EXECUTOR_PACKET_H
18 
19 #include <cstdint>
20 #include <string>
21 #include "isync_packet.h"
22 #include "message.h"
23 #include "prepared_stmt.h"
24 #include "relational_row_data_set.h"
25 #include "sync_types.h"
26 #include "version.h"
27 
28 namespace DistributedDB {
29 class RemoteExecutorRequestPacket : public ISyncPacket {
30 public:
31     RemoteExecutorRequestPacket() = default;
32     ~RemoteExecutorRequestPacket() override = default;
33 
34     uint32_t GetVersion() const;
35 
36     void SetVersion(uint32_t version);
37 
38     uint32_t GetFlag() const;
39 
40     void SetFlag(uint32_t flag);
41 
42     const PreparedStmt &GetPreparedStmt() const;
43 
44     bool IsNeedResponse() const;
45 
46     void SetNeedResponse();
47 
48     void SetExtraConditions(const std::map<std::string, std::string> &extraConditions);
49 
50     std::map<std::string, std::string> GetExtraConditions() const;
51 
52     uint32_t CalculateLen() const override;
53 
54     int Serialization(Parcel &parcel) const override;
55 
56     int DeSerialization(Parcel &parcel) override;
57 
58     void SetOpCode(PreparedStmt::ExecutorOperation opCode);
59 
60     void SetSql(const std::string &sql);
61 
62     void SetBindArgs(const std::vector<std::string> &bindArgs);
63 
64     void SetSecLabel(int32_t secLabel);
65 
66     int32_t GetSecLabel() const;
67 
68     static RemoteExecutorRequestPacket* Create();
69 
70     static void Release(RemoteExecutorRequestPacket *&packet);
71 
72     static constexpr uint32_t REQUEST_PACKET_VERSION_V1 = SOFTWARE_VERSION_RELEASE_6_0;
73     static constexpr uint32_t REQUEST_PACKET_VERSION_V2 = SOFTWARE_VERSION_RELEASE_6_0 + 1; // 1 is version 107
74     static constexpr uint32_t REQUEST_PACKET_VERSION_V3 = SOFTWARE_VERSION_RELEASE_6_0 + 2; // 2 is version 108
75     // abandon not set security label in v4
76     static constexpr uint32_t REQUEST_PACKET_VERSION_V4 = SOFTWARE_VERSION_RELEASE_6_0 + 3; // 3 is version 109
77     static constexpr uint32_t REQUEST_PACKET_VERSION_CURRENT = REQUEST_PACKET_VERSION_V4;
78 private:
79     uint32_t version_ = 0u;
80     uint32_t flag_ = 0u; // 0x01 mean need reply ack
81     PreparedStmt preparedStmt_;
82     std::map<std::string, std::string> extraConditions_;
83     int32_t secLabel_ = UNKNOWN_SECURITY_LABEL; // source sec label
84 };
85 
86 class RemoteExecutorAckPacket : public ISyncPacket {
87 public:
88     RemoteExecutorAckPacket() = default;
89 
90     ~RemoteExecutorAckPacket() override = default;
91 
92     uint32_t GetVersion() const;
93 
94     void SetVersion(uint32_t version);
95 
96     uint32_t GetFlag() const;
97 
98     void SetFlag(uint32_t flag);
99 
100     int32_t GetAckCode() const;
101 
102     void SetAckCode(int32_t ackCode);
103 
104     void MoveInRowDataSet(RelationalRowDataSet &&rowDataSet);
105 
106     RelationalRowDataSet &&MoveOutRowDataSet() const;
107 
108     bool IsLastAck() const;
109 
110     void SetLastAck();
111 
112     SecurityOption GetSecurityOption() const;
113 
114     void SetSecurityOption(const SecurityOption &option);
115 
116     uint32_t CalculateLen() const override;
117 
118     int Serialization(Parcel &parcel) const override;
119 
120     int DeSerialization(Parcel &parcel) override;
121 
122     static const uint32_t RESPONSE_PACKET_VERSION_V1 = SOFTWARE_VERSION_RELEASE_6_0;
123     static const uint32_t RESPONSE_PACKET_VERSION_CURRENT = RESPONSE_PACKET_VERSION_V1;
124 private:
125     uint32_t version_ = 0u;
126     int32_t ackCode_ = 0;
127     uint32_t flag_ = 0u; // 0x01 mean last one
128     mutable RelationalRowDataSet rowDataSet_;
129     int32_t secLabel_ = 0;
130     int32_t secFlag_ = 0;
131 };
132 }
133 #endif