/proc/self/cwd/source/extensions/filters/network/redis_proxy/command_splitter.h
Line | Count | Source (jump to first uncovered line) |
1 | | #pragma once |
2 | | |
3 | | #include <memory> |
4 | | |
5 | | #include "envoy/common/pure.h" |
6 | | #include "envoy/event/dispatcher.h" |
7 | | #include "envoy/stream_info/stream_info.h" |
8 | | |
9 | | #include "source/extensions/filters/network/common/redis/client.h" |
10 | | #include "source/extensions/filters/network/common/redis/codec.h" |
11 | | |
12 | | namespace Envoy { |
13 | | namespace Extensions { |
14 | | namespace NetworkFilters { |
15 | | namespace RedisProxy { |
16 | | namespace CommandSplitter { |
17 | | |
18 | | /** |
19 | | * A handle to a split request. |
20 | | */ |
21 | | class SplitRequest { |
22 | | public: |
23 | 0 | virtual ~SplitRequest() = default; |
24 | | |
25 | | /** |
26 | | * Cancel the request. No further request callbacks will be called. |
27 | | */ |
28 | | virtual void cancel() PURE; |
29 | | }; |
30 | | |
31 | | using SplitRequestPtr = std::unique_ptr<SplitRequest>; |
32 | | |
33 | | /** |
34 | | * Split request callbacks. |
35 | | */ |
36 | | class SplitCallbacks { |
37 | | public: |
38 | 0 | virtual ~SplitCallbacks() = default; |
39 | | |
40 | | /** |
41 | | * Called to verify that commands should be processed. |
42 | | * @return bool true if commands from this client connection can be processed, false if not. |
43 | | */ |
44 | | virtual bool connectionAllowed() PURE; |
45 | | |
46 | | /** |
47 | | * Called when a quit command has been received. |
48 | | */ |
49 | | virtual void onQuit() PURE; |
50 | | |
51 | | /** |
52 | | * Called when an authentication command has been received with a password. |
53 | | * @param password supplies the AUTH password provided by the downstream client. |
54 | | */ |
55 | | virtual void onAuth(const std::string& password) PURE; |
56 | | |
57 | | /** |
58 | | * Called when an authentication command has been received with a username and password. |
59 | | * @param username supplies the AUTH username provided by the downstream client. |
60 | | * @param password supplies the AUTH password provided by the downstream client. |
61 | | */ |
62 | | virtual void onAuth(const std::string& username, const std::string& password) PURE; |
63 | | |
64 | | /** |
65 | | * Called when the response is ready. |
66 | | * @param value supplies the response which is now owned by the callee. |
67 | | */ |
68 | | virtual void onResponse(Common::Redis::RespValuePtr&& value) PURE; |
69 | | |
70 | | /** |
71 | | * Called to retrieve information about the current Redis transaction. |
72 | | * @return reference to a Transaction instance of the current connection. |
73 | | */ |
74 | | virtual Common::Redis::Client::Transaction& transaction() PURE; |
75 | | }; |
76 | | |
77 | | /** |
78 | | * A command splitter that takes incoming redis commands and splits them as appropriate to a |
79 | | * backend connection pool. |
80 | | */ |
81 | | class Instance { |
82 | | public: |
83 | 0 | virtual ~Instance() = default; |
84 | | |
85 | | /** |
86 | | * Make a split redis request capable of being retried/redirected. |
87 | | * @param request supplies the split request to make (ownership transferred to call). |
88 | | * @param callbacks supplies the split request completion callbacks. |
89 | | * @param dispatcher supplies dispatcher used for delay fault timer. |
90 | | * @param stream_info reference to the stream info used for formatting the key. |
91 | | * @return SplitRequestPtr a handle to the active request or nullptr if the request has already |
92 | | * been satisfied (via onResponse() being called). The splitter ALWAYS calls |
93 | | * onResponse() for a given request. |
94 | | */ |
95 | | virtual SplitRequestPtr makeRequest(Common::Redis::RespValuePtr&& request, |
96 | | SplitCallbacks& callbacks, Event::Dispatcher& dispatcher, |
97 | | const StreamInfo::StreamInfo& stream_info) PURE; |
98 | | }; |
99 | | |
100 | | } // namespace CommandSplitter |
101 | | } // namespace RedisProxy |
102 | | } // namespace NetworkFilters |
103 | | } // namespace Extensions |
104 | | } // namespace Envoy |