10000 Fuerte changes from comm-task-refactor branch (#9422) · Mars2018/arangodb@241d5d1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 241d5d1

Browse files
graetzerjsteemann
authored andcommitted
Fuerte changes from comm-task-refactor branch (arangodb#9422)
1 parent c2b6450 commit 241d5d1

30 files changed

+1134
-1033
lines changed

3rdParty/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ endif()
295295
add_library(fuerte STATIC
296296
${CMAKE_CURRENT_SOURCE_DIR}/fuerte/src/connection.cpp
297297
${CMAKE_CURRENT_SOURCE_DIR}/fuerte/src/ConnectionBuilder.cpp
298+
${CMAKE_CURRENT_SOURCE_DIR}/fuerte/src/GeneralConnection.cpp
298299
${CMAKE_CURRENT_SOURCE_DIR}/fuerte/src/helper.cpp
299300
${CMAKE_CURRENT_SOURCE_DIR}/fuerte/src/http.cpp
300301
${CMAKE_CURRENT_SOURCE_DIR}/fuerte/src/HttpConnection.cpp

3rdParty/fuerte/include/fuerte/VpackInit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include <fuerte/types.h>
3030
#include <velocypack/AttributeTranslator.h>
31+
#include <velocypack/Options.h>
3132

3233
namespace arangodb { namespace fuerte { inline namespace v1 { namespace helper {
3334

3rdParty/fuerte/include/fuerte/connection.h

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,18 @@ class Connection : public std::enable_shared_from_this<Connection> {
4141
public:
4242
virtual ~Connection();
4343

44-
/// Connectin state
44+
/// Connection state
45+
/// Disconnected <---------+
46+
/// + |
47+
/// | +-------------------+--> Failed
48+
/// | | |
49+
/// v + +
50+
/// Connecting +-----> Connected
4551
enum class State {
4652
Disconnected = 0,
4753
Connecting = 1,
4854
Connected = 2,
49-
Failed = 3 /// broken permanently (i.e. bad authentication)
55+
Failed = 3 /// canceled or broken permanently (i.e. bad authentication)
5056
};
5157

5258
/// @brief Send a request to the server and wait into a response it received.
@@ -80,7 +86,7 @@ class Connection : public std::enable_shared_from_this<Connection> {
8086

8187
/// @brief Return the number of bytes that still need to be transmitted
8288
std::size_t bytesToSend() const {
83-
return _bytesToSend.load(std::memory_order_acquire);
89+
return _bytesToSend.load(std::memory_order_relaxed);
8490
}
8591

8692
/// @brief connection state
@@ -132,10 +138,11 @@ class ConnectionBuilder {
132138
// Create an connection and start opening it.
133139
std::shared_ptr<Connection> connect(EventLoopService& eventLoopService);
134140

135-
inline std::chrono::milliseconds timeout() const { return _conf._connectionTimeout;}
136-
/// @brief set the connection timeout (60s default)
137-
ConnectionBuilder& timeout(std::chrono::milliseconds t) {
138-
_conf._connectionTimeout = t;
141+
/// @brief idle connection timeout (60s default)
142+
inline std::chrono::milliseconds idleTimeout() const { return _conf._idleTimeout;}
143+
/// @brief set the idle connection timeout (60s default)
144+
ConnectionBuilder& idleTimeout(std::chrono::milliseconds t) {
145+
_conf._idleTimeout = t;
139146
return *this;
140147
}
141148

3rdParty/fuerte/include/fuerte/detail/vst.h

Lines changed: 28 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static size_t const bufferLength = 4096UL;
3939
// static size_t const chunkMaxBytes = 1000UL;
4040
static size_t const minChunkHeaderSize = 16;
4141
static size_t const maxChunkHeaderSize = 24;
42-
static size_t const defaultMaxChunkSize = 30000;
42+
static size_t const defaultMaxChunkSize = 1024 * 32;
4343

4444
/////////////////////////////////////////////////////////////////////////////////////
4545
// DataStructures
@@ -49,19 +49,11 @@ static size_t const defaultMaxChunkSize = 30000;
4949
struct ChunkHeader {
5050

5151
// data used in the specification
52-
uint32_t _chunkLength; // length of this chunk includig chunkHeader
52+
uint32_t _chunkLength; // length of chunk content (including chunkHeader)
5353
uint32_t _chunkX; // number of chunks or chunk number
5454
uint64_t _messageID; // messageid
5555
uint64_t _messageLength; // length of total payload
5656

57-
// Used when receiving the response:
58-
// Offset of start of content of this chunk in
59-
// RequestItem._responseChunkContent.
60-
size_t _responseChunkContentOffset;
61-
/// Content length of this chunk (only used
62-
/// during read operations).
63-
size_t _responseContentLength;
64-
6557
// Return length of this chunk (in host byte order)
6658
inline uint32_t chunkLength() const { return _chunkLength; }
6759
// Return message ID of this chunk (in host byte order)
@@ -82,101 +74,42 @@ struct ChunkHeader {
8274
return 0; // Not known
8375
}
8476

85-
// writeHeaderToVST1_0 write the chunk to the given buffer in VST 1.0 format.
77+
// writeHeaderToVST1_0 writes the chunk to the given buffer in VST 1.0 format.
8678
// The length of the buffer is returned.
8779
size_t writeHeaderToVST1_0(size_t chunkDataLen, velocypack::Buffer<uint8_t>&) const;
8880

89-
// writeHeaderToVST1_1 write the chunk to the given buffer in VST 1.1 format.
81+
// writeHeaderToVST1_1 writes the chunk to the given buffer in VST 1.1 format.
9082
// The length of the buffer is returned.
9183
size_t writeHeaderToVST1_1(size_t chunkDataLen, velocypack::Buffer<uint8_t>& buffer) const;
9284
};
9385

94-
95-
// chunkHeaderLength returns the length of a VST chunk header for given
96-
// arguments.
97-
/*inline std::size_t chunkHeaderLength(VSTVersion vstVersion, bool isFirst, bool
98-
isSingle) {
99-
switch (vstVersion) {
100-
case VST1_0:
101-
if (isFirst && !isSingle) {
102-
return maxChunkHeaderSize;
103-
}
104-
return minChunkHeaderSize;
105-
case VST1_1:
106-
return maxChunkHeaderSize;
107-
default:
108-
throw std::logic_error("Unknown VST version");
109-
}
110-
}*/
111-
112-
// Item that represents a Request in flight
113-
struct RequestItem {
114-
/// ID of this message
115-
MessageID _messageID;
116-
/// Reference to the request we're processing
117-
std::unique_ptr<Request> _request;
118-
/// Callback for when request is done (in error or succeeded)
119-
RequestCallback _callback;
120 F42D -
/// point in time when the message expires
121-
std::chrono::steady_clock::time_point _expires;
122-
123-
// ======= Request variables =======
124-
125-
/// Buffer used to hold chunk headers and message header
126-
velocypack::Buffer<uint8_t> _requestMetadata;
127-
128-
/// Temporary list of buffers goin to be send by the socket.
129-
std::vector<asio_ns::const_buffer> _requestBuffers;
130-
131-
// ======= Response variables =======
132-
133-
/// @brief List of chunks that have been received.
134-
std::vector<ChunkHeader> _responseChunks;
135-
/// Buffer containing content of received chunks.
136-
/// Not necessarily in a sorted order!
137-
velocypack::Buffer<uint8_t> _responseChunkContent;
138-
/// The number of chunks we're expecting (0==not know yet).
139-
size_t _responseNumberOfChunks;
140-
141-
inline MessageID messageID() { return _messageID; }
142-
inline void invokeOnError(Error e) {
143-
_callback(e, std::move(_request), nullptr);
144-
}
145-
146-
/// prepareForNetwork prepares the internal structures for
147-
/// writing the request to the network.
148-
void prepareForNetwork(VSTVersion);
149-
150-
// prepare structures with a given message header and payload
151-
void prepareForNetwork(VSTVersion,
152-
asio_ns::const_buffer header,
153-
asio_ns::const_buffer payload);
154-
155-
// add the given chunk to the list of response chunks.
156-
void addChunk(ChunkHeader&& chunk,
157-
asio_ns::const_buffer const& data);
158-
// try to assembly the received chunks into a response.
159-
// returns NULL if not all chunks are available.
160-
std::unique_ptr<velocypack::Buffer<uint8_t>> assemble();
161-
162-
// Flush all memory needed for sending this request.
163-
inline void resetSendData() {
164-
_requestMetadata.clear();
165-
_requestBuffers.clear();
166-
}
86+
struct Chunk {
87+
ChunkHeader header;
88+
asio_ns::const_buffer body;
16789
};
16890

16991
namespace message {
17092

171-
/// @brief creates a slice containing a VST request header.
172-
velocypack::Buffer<uint8_t> requestHeader(RequestHeader const&);
173-
/// @brief creates a slice containing a VST request header.
174-
velocypack::Buffer<uint8_t> responseHeader(ResponseHeader const&);
93+
/// @brief creates a slice containing a VST request-message header.
94+
void requestHeader(RequestHeader const&, velocypack::Buffer<uint8_t>&);
95+
/// @brief creates a slice containing a VST response-message header.
96+
void responseHeader(ResponseHeader const&, velocypack::Buffer<uint8_t>&);
17597
/// @brief creates a slice containing a VST auth message with JWT encryption
176-
velocypack::Buffer<uint8_t> authJWT(std::string const& token);
177-
/// @brief creates a slice containing a VST auth message with plain enctyption
178-
velocypack::Buffer<uint8_t> authBasic(std::string const& username,
179-
std::string const& password);
98+
void authJWT(std::string const& token, velocypack::Buffer<uint8_t>&);
99+
/// @brief creates a slice containing a VST auth message with plain encryption
100+
void authBasic(std::string const& username,
101+
std::string const& password,
102+
velocypack::Buffer<uint8_t>&);
103+
104+
/// @brief take existing buffers and partitions into chunks
105+
/// @param buffer is containing the metadata. If non-empty this will be used
106+
/// as a prefix to the payload.
107+
/// @param payload the payload that is going to be partitioned
108+
void prepareForNetwork(VSTVersion vstVersion,
109+
MessageID messageId,
110+
velocypack::Buffer<uint8_t>& buffer,
111+
asio_ns::const_buffer payload,
112+
std::vector<asio_ns::const_buffer>& result);
180113
}
181114

182115
/////////////////////////////////////////////////////////////////////////////////////
@@ -193,10 +126,10 @@ std::size_t isChunkComplete(uint8_t const* const begin,
193126
std::size_t const length);
194127

195128
// readChunkHeaderVST1_0 reads a chunk header in VST1.0 format.
196-
std::pair<ChunkHeader, asio_ns::const_buffer> readChunkHeaderVST1_0(uint8_t const*);
129+
Chunk readChunkHeaderVST1_0(uint8_t const*);
197130

198131
// readChunkHeaderVST1_1 reads a chunk header in VST1.1 format.
199-
std::pair<ChunkHeader, asio_ns::const_buffer> readChunkHeaderVST1_1(uint8_t const*);
132+
Chunk readChunkHeaderVST1_1(uint8_t const*);
200133

201134
/// @brief verifies header input and checks correct length
202135
/// @return message type or MessageType::Undefined on an error

3rdParty/fuerte/include/fuerte/helper.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#pragma once
2323
#ifndef ARANGO_CXX_DRIVER_HELPER
2424
#define ARANGO_CXX_DRIVER_HELPER
25+
2526
#include <fuerte/message.h>
2627
#include <fuerte/types.h>
2728
#include <sstream>
@@ -107,5 +108,9 @@ std::string mapToKeys(std::unordered_map<K, V, A> map) {
107108

108109
std::string encodeBase64(std::string const&);
109110
std::string encodeBase64U(std::string const&);
111+
112+
/// checks if connection was closed and returns
113+
/// Error::ConnectionClosed instead of the the specified error
114+
fuerte::Error checkEOFError(asio_ns::error_code e, fuerte::Error c);
110115
}}} // namespace arangodb::fuerte::v1
111116
#endif

3rdParty/fuerte/include/fuerte/message.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@
3636
#include <velocypack/Slice.h>
3737

3838
namespace arangodb { namespace fuerte { inline namespace v1 {
39+
const std::string fu_content_length_key("content-length");
3940
const std::string fu_content_type_key("content-type");
4041
const std::string fu_accept_key("accept");
42+
const std::string fu_keep_alive_key("keep-alive");
4143

4244
struct MessageHeader {
4345
/// arangodb message format version
@@ -47,7 +49,7 @@ struct MessageHeader {
4749
/// Header meta data (equivalent to HTTP headers)
4850
StringMap meta;
4951

50-
#ifndef NDEBUG
52+
#ifdef FUERTE_DEBUG
5153
std::size_t byteSize; // for debugging
5254
#endif
5355

@@ -265,7 +267,7 @@ class Response final : public Message {
265267

266268
/// @brief move in the payload
267269
void setPayload(velocypack::Buffer<uint8_t> buffer, std::size_t payloadOffset);
268-
270+
269271
private:
270272
velocypack::Buffer<uint8_t> _payload;
271273
std::size_t _payloadOffset;

3rdParty/fuerte/include/fuerte/types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ struct ConnectionConfiguration {
175175
_host("localhost"),
176176
_port("8529"),
177177
_verifyHost(false),
178-
_connectionTimeout(60000),
178+
_idleTimeout(120000),
179179
_maxConnectRetries(3),
180180
_authenticationType(AuthenticationType::None),
181181
_user(""),
@@ -191,7 +191,7 @@ struct ConnectionConfiguration {
191191
std::string _port;
192192
bool _verifyHost;
193193

194-
std::chrono::milliseconds _connectionTimeout;
194+
std::chrono::milliseconds _idleTimeout;
195195
unsigned _maxConnectRetries;
196196

197197
AuthenticationType _authenticationType;

3rdParty/fuerte/src/AsioSockets.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,6 @@ struct Socket<fuerte::SocketType::Unix> {
189189
asio_ns::local::stream_protocol::socket socket;
190190
};
191191
#endif // ASIO_HAS_LOCAL_SOCKETS
192-
193-
inline fuerte::Error checkEOFError(asio_ns::error_code e, fuerte::Error c) {
194-
return e == asio_ns::error::misc_errors::eof ? fuerte::Error::ConnectionClosed : c;
195-
}
196192

197193
}}} // namespace arangodb::fuerte::v1
198194
#endif

0 commit comments

Comments
 (0)
0