From bfaa1bd26cbb322d2d71141f6925a1b6f6d703f4 Mon Sep 17 00:00:00 2001 From: Dhruba Borthakur Date: Tue, 10 Jul 2012 10:19:49 -0700 Subject: [PATCH] Cleanup thrift header files. Move thrift api from thrift/leveldb.thrift to thrift/if/leveldb.thrift Summary: Test Plan: Reviewers: CC: Task ID: # Blame Rev: --- thrift/README | 7 + thrift/gen-cpp/leveldb_types.h | 39 ++++ thrift/{ => if}/leveldb.thrift | 0 thrift/lib/cpp/TARGETS | 46 ----- thrift/lib/cpp/Thrift.h | 16 ++ thrift/lib/cpp/async/TARGETS | 103 ----------- thrift/lib/cpp/async/TAsyncChannel.h | 6 + thrift/lib/cpp/async/TAsyncSSLSocket.h | 55 +++++- thrift/lib/cpp/async/TAsyncSocket.h | 59 +++++++ thrift/lib/cpp/async/TAsyncTransport.h | 14 ++ thrift/lib/cpp/async/TEventServer.h | 26 +++ thrift/lib/cpp/async/TEventWorker.h | 16 +- thrift/lib/cpp/async/TNotificationQueue.h | 2 +- thrift/lib/cpp/async/TStreamAsyncChannel.h | 17 +- thrift/lib/cpp/async/TZlibAsyncChannel.h | 18 +- .../lib/cpp/concurrency/PosixThreadFactory.h | 37 ++-- thrift/lib/cpp/concurrency/TARGETS | 17 -- thrift/lib/cpp/concurrency/Thread.h | 12 +- thrift/lib/cpp/concurrency/test/TARGETS | 45 ----- thrift/lib/cpp/processor/TARGETS | 9 - thrift/lib/cpp/processor/test/TARGETS | 24 --- thrift/lib/cpp/protocol/TARGETS | 18 -- thrift/lib/cpp/protocol/TCompactProtocol.h | 6 +- thrift/lib/cpp/protocol/THeaderProtocol.h | 2 +- thrift/lib/cpp/protocol/neutronium/TARGETS | 24 --- .../lib/cpp/protocol/neutronium/test/TARGETS | 41 ----- thrift/lib/cpp/server/TARGETS | 30 ---- thrift/lib/cpp/server/test/TARGETS | 60 ------- thrift/lib/cpp/test/TARGETS | 167 ------------------ thrift/lib/cpp/test/loadgen/TARGETS | 32 ---- thrift/lib/cpp/transport/TARGETS | 88 --------- thrift/lib/cpp/transport/THeader.h | 12 +- thrift/lib/cpp/transport/test/TARGETS | 69 -------- thrift/lib/cpp/util/TARGETS | 74 -------- thrift/lib/cpp/util/test/TARGETS | 17 -- 35 files changed, 318 insertions(+), 890 deletions(-) rename thrift/{ => if}/leveldb.thrift (100%) delete mode 100644 thrift/lib/cpp/TARGETS delete mode 100644 thrift/lib/cpp/async/TARGETS delete mode 100644 thrift/lib/cpp/concurrency/TARGETS delete mode 100644 thrift/lib/cpp/concurrency/test/TARGETS delete mode 100644 thrift/lib/cpp/processor/TARGETS delete mode 100644 thrift/lib/cpp/processor/test/TARGETS delete mode 100644 thrift/lib/cpp/protocol/TARGETS delete mode 100644 thrift/lib/cpp/protocol/neutronium/TARGETS delete mode 100644 thrift/lib/cpp/protocol/neutronium/test/TARGETS delete mode 100644 thrift/lib/cpp/server/TARGETS delete mode 100644 thrift/lib/cpp/server/test/TARGETS delete mode 100644 thrift/lib/cpp/test/TARGETS delete mode 100644 thrift/lib/cpp/test/loadgen/TARGETS delete mode 100644 thrift/lib/cpp/transport/TARGETS delete mode 100644 thrift/lib/cpp/transport/test/TARGETS delete mode 100644 thrift/lib/cpp/util/TARGETS delete mode 100644 thrift/lib/cpp/util/test/TARGETS diff --git a/thrift/README b/thrift/README index 756f742c4..bd3b336a5 100644 --- a/thrift/README +++ b/thrift/README @@ -1,5 +1,7 @@ This directory has the thrift server code that exposes leveldb apis. +The thrift api is specified in thrift/if/leveldb.thrift. + The thrift header files are in ./thrift/lib. These are part of Apache Thrift code base and are needed for compilation of the leveldb thrift server. The thrift libraries are copied into ./thrift/libs. @@ -16,3 +18,8 @@ enviroment variables appropriately: You can run the leveldb server unit tests by ./leveldb_server_test +You can regenerate the thrift cpp files by doing the following + +cd ./thrift +thrift --gen cpp if/leveldb.thrift + diff --git a/thrift/gen-cpp/leveldb_types.h b/thrift/gen-cpp/leveldb_types.h index 1756bcb08..034644f9f 100644 --- a/thrift/gen-cpp/leveldb_types.h +++ b/thrift/gen-cpp/leveldb_types.h @@ -28,6 +28,19 @@ extern const std::map _CompressionType_VALUES_TO_NAMES; extern const std::map _CompressionType_NAMES_TO_VALUES; +} // namespace +namespace apache { namespace thrift { +template<> +inline constexpr ::Tleveldb::CompressionType TEnumTraits< ::Tleveldb::CompressionType>::min() { +return ::Tleveldb::CompressionType::kNoCompression; +} +template<> +inline constexpr ::Tleveldb::CompressionType TEnumTraits< ::Tleveldb::CompressionType>::max() { +return ::Tleveldb::CompressionType::kSnappyCompression; +} +}} // apache:thrift + +namespace Tleveldb { enum Code { kOk = 0, kNotFound = 1, @@ -42,6 +55,19 @@ extern const std::map _Code_VALUES_TO_NAMES; extern const std::map _Code_NAMES_TO_VALUES; +} // namespace +namespace apache { namespace thrift { +template<> +inline constexpr ::Tleveldb::Code TEnumTraits< ::Tleveldb::Code>::min() { +return ::Tleveldb::Code::kOk; +} +template<> +inline constexpr ::Tleveldb::Code TEnumTraits< ::Tleveldb::Code>::max() { +return ::Tleveldb::Code::kEnd; +} +}} // apache:thrift + +namespace Tleveldb { enum IteratorType { seekToFirst = 0, seekToLast = 1, @@ -52,6 +78,19 @@ extern const std::map _IteratorType_VALUES_TO_NAMES; extern const std::map _IteratorType_NAMES_TO_VALUES; +} // namespace +namespace apache { namespace thrift { +template<> +inline constexpr ::Tleveldb::IteratorType TEnumTraits< ::Tleveldb::IteratorType>::min() { +return ::Tleveldb::IteratorType::seekToFirst; +} +template<> +inline constexpr ::Tleveldb::IteratorType TEnumTraits< ::Tleveldb::IteratorType>::max() { +return ::Tleveldb::IteratorType::seekToKey; +} +}} // apache:thrift + +namespace Tleveldb { typedef std::string Text; typedef std::string Bytes; diff --git a/thrift/leveldb.thrift b/thrift/if/leveldb.thrift similarity index 100% rename from thrift/leveldb.thrift rename to thrift/if/leveldb.thrift diff --git a/thrift/lib/cpp/TARGETS b/thrift/lib/cpp/TARGETS deleted file mode 100644 index 8e0b3bfa5..000000000 --- a/thrift/lib/cpp/TARGETS +++ /dev/null @@ -1,46 +0,0 @@ -# TARGETS file for thrift/lib/cpp - -cpp_library ( - name = "thrift_exception", - srcs = [ - "TApplicationException.cpp", - ], - external_deps = [ - ('boost', None), - ], -) - -cpp_library ( - name = "thrift", - srcs = [ - "VirtualProfiling.cpp", - ], - deps = [ - "@/thrift/lib/cpp:thrift_base", - "@/thrift/lib/cpp/concurrency", - "@/thrift/lib/cpp/processor", - "@/thrift/lib/cpp/protocol", - "@/thrift/lib/cpp/server", - "@/thrift/lib/cpp/transport", - "@/thrift/lib/cpp:thrift_exception", - ] -) - -cpp_library ( - name = "thrift_base", - srcs = [ - "Thrift.cpp", - "EventHandlerBase.cpp", - ], - external_deps = [ - ('boost', None), - ], -) - -cpp_library( - name = "reflection", - srcs = [], - deps = [ - "@/thrift/lib/thrift:reflection-cpp", - ], -) diff --git a/thrift/lib/cpp/Thrift.h b/thrift/lib/cpp/Thrift.h index b739c5376..c46ce5146 100644 --- a/thrift/lib/cpp/Thrift.h +++ b/thrift/lib/cpp/Thrift.h @@ -77,6 +77,16 @@ struct TEnumTraits { * Note the use of helper function 'findValue(...)', below. */ static bool findValue(const char* name, T* outValue); + + /** + * Return the minimum value. + */ + static constexpr T min(); + + /** + * Return the maximum value. + */ + static constexpr T max(); private: /** * Helper method used by codegen implementation of findName, Supports @@ -216,6 +226,12 @@ extern TOutput GlobalOutput; * Should never be instantiated, only caught. */ class TException : public std::exception { +public: + TException() {} + TException(TException&&) {} + TException(const TException&) {} + TException& operator=(const TException&) { return *this; } + TException& operator=(TException&&) { return *this; } }; /** diff --git a/thrift/lib/cpp/async/TARGETS b/thrift/lib/cpp/async/TARGETS deleted file mode 100644 index 6c6411b27..000000000 --- a/thrift/lib/cpp/async/TARGETS +++ /dev/null @@ -1,103 +0,0 @@ -# The base async library -cpp_library( - name = 'async_base', - srcs = [ - 'TAsyncServerSocket.cpp', - 'TAsyncSignalHandler.cpp', - 'TAsyncSocket.cpp', - 'TAsyncTimeout.cpp', - 'TBinaryAsyncChannel.cpp', - 'THeaderAsyncChannel.cpp', - 'TEventBase.cpp', - 'TEventBaseManager.cpp', - 'TEventHandler.cpp', - 'TFramedAsyncChannel.cpp', - 'TNotificationPipe.cpp', - 'TUnframedAsyncChannel.cpp', - 'THttpAsyncChannel.cpp', - ], - deps = [ - '@/folly/experimental/io', - '@/thrift/lib/cpp:thrift_base', - '@/thrift/lib/cpp/transport', - '@/thrift/lib/cpp/transport:header', - '@/thrift/lib/cpp/protocol', - '@/thrift/lib/cpp/server', - '@/thrift/lib/cpp/util:httpparser', - ], - external_deps = [ ('libevent', None) ], -) - -# TEventServer library (async name is used all over), now depends on ssl -cpp_library( - name = 'async', - srcs = [ - 'TEventConnection.cpp', - 'TEventServer.cpp', - 'TEventTask.cpp', - 'TEventWorker.cpp', - ], - deps = [ - ':async_ssl', - ], -) - -cpp_library ( - name = "async_ssl", - srcs = [ - 'TAsyncSSLServerSocket.cpp', - 'TAsyncSSLSocket.cpp', - ], - deps = [ - ":async_base", - "@/thrift/lib/cpp/transport:transport_ssl", - ], - external_deps = [ ("openssl", None, "ssl"), - ("openssl", None, "crypto") ], -) - -# This library is the same as async_ssl, except that it has the debug -# logging level set to 4, whereas async_ssl has debug logging disabled. -cpp_library ( - name = "async_ssl_log", - srcs = [ - 'TAsyncSSLServerSocket.cpp', - 'TAsyncSSLSocket.cpp', - ], - deps = [ - ":async_base", - "@/thrift/lib/cpp/transport:transport_ssl", - ], - external_deps = [ ("openssl", None, "ssl"), - ("openssl", None, "crypto") ], - preprocessor_flags = [ - "-DT_GLOBAL_DEBUGGING_LEVEL=4" - ], - output_subdir = "async_ssl_log", -) - -cpp_library( - name = 'zlib', - srcs = [ - 'TZlibAsyncChannel.cpp', - ], - deps = [ - ':async', - '@/thrift/lib/cpp/transport:zlib', - ], -) - -# Parts of the async library that depend on C++11 features. -# This is separate from the main async library for now so that users who cannot -# depend on C++11 features yet will still be able to use the bulk of the async -# library. -cpp_library( - name = 'async_cxx11', - srcs = [ - 'TAsyncTimeoutSet.cpp', - ], - deps = [ - ':async_base', - '@/folly', - ], -) diff --git a/thrift/lib/cpp/async/TAsyncChannel.h b/thrift/lib/cpp/async/TAsyncChannel.h index ebf9e6e8a..6ac10c6f1 100644 --- a/thrift/lib/cpp/async/TAsyncChannel.h +++ b/thrift/lib/cpp/async/TAsyncChannel.h @@ -103,6 +103,12 @@ class TAsyncChannel { return sendAndRecvMessage(cob, cob, sendBuf, recvBuf); } + /** + * Cancel pending callbacks. Use this when the channel is closing because the + * server had been shut down. + */ + virtual void cancelCallbacks() = 0; + // TODO(dreiss): Make this nonvirtual when TFramedSocketAsyncChannel gets // renamed to TFramedAsyncChannel. virtual boost::shared_ptr getTransport() = 0; diff --git a/thrift/lib/cpp/async/TAsyncSSLSocket.h b/thrift/lib/cpp/async/TAsyncSSLSocket.h index f5b312f10..6aa5411f6 100644 --- a/thrift/lib/cpp/async/TAsyncSSLSocket.h +++ b/thrift/lib/cpp/async/TAsyncSSLSocket.h @@ -120,6 +120,14 @@ class TAsyncSSLSocket : public TAsyncSocket { TAsyncSSLSocket* sslSocket_; }; + /** + * These are passed to the application via errno, so values have to be + * outside the valid errno range + */ + enum SSLError { + SSL_CLIENT_RENEGOTIATION_ATTEMPT = 0x8001 + }; + /** * Create a client TAsyncSSLSocket */ @@ -128,6 +136,8 @@ class TAsyncSSLSocket : public TAsyncSocket { TAsyncSocket(evb), corked_(false), server_(false), + handshakeComplete_(false), + renegotiateAttempted_(false), sslState_(STATE_UNINIT), ctx_(ctx), handshakeCallback_(NULL), @@ -176,7 +186,7 @@ class TAsyncSSLSocket : public TAsyncSocket { } /** - * TODO: implement support for SSL renegosiation. + * TODO: implement support for SSL renegotiation. * * This involves proper handling of the SSL_ERROR_WANT_READ/WRITE * code as a result of SSL_write/read(), instead of returning an @@ -293,6 +303,41 @@ class TAsyncSSLSocket : public TAsyncSocket { */ bool getSSLSessionReused() const; + /** + * Get the negociated cipher name for this SSL connection. + * Returns the cipher used or the constant value "NONE" when no SSL session + * has been established. + */ + const char *getNegotiatedCipherName() const; + + /** + * Get the SSL version for this connection. + * Possible return values are SSL2_VERSION, SSL3_VERSION, TLS1_VERSION, + * with hexa representations 0x200, 0x300, 0x301, + * or 0 if no SSL session has been established. + */ + int getSSLVersion() const; + + /* Get the number of bytes read from the wire (including protocol + * overhead). Returns 0 once the connection has been closed. + */ + unsigned long getBytesRead() const { + if (ssl_ != NULL) { + return BIO_number_read(SSL_get_rbio(ssl_)); + } + return 0; + } + + /* Get the number of bytes written to the wire (including protocol + * overhead). Returns 0 once the connection has been closed. + */ + unsigned long getBytesWritten() const { + if (ssl_ != NULL) { + return BIO_number_written(SSL_get_wbio(ssl_)); + } + return 0; + } + virtual void attachEventBase(TEventBase* eventBase) { TAsyncSocket::attachEventBase(eventBase); handshakeTimeout_.attachEventBase(eventBase); @@ -339,10 +384,18 @@ class TAsyncSSLSocket : public TAsyncSocket { void invokeHandshakeCallback(); + static void sslInfoCallback(const SSL *ssl, int type, int val); + // Whether we've applied the TCP_CORK option to the socket bool corked_; // SSL related members. bool server_; + // Used to prevent client-initiated renegotiation. Note that TAsyncSSLSocket + // doesn't fully support renegotiation, so we could just fail all attempts + // to enforce this. Once it is supported, we should make it an option + // to disable client-initiated renegotiation. + bool handshakeComplete_; + bool renegotiateAttempted_; SSLStateEnum sslState_; boost::shared_ptr ctx_; // Callback for SSL_accept() or SSL_connect() diff --git a/thrift/lib/cpp/async/TAsyncSocket.h b/thrift/lib/cpp/async/TAsyncSocket.h index ea18a81af..7c829ead0 100644 --- a/thrift/lib/cpp/async/TAsyncSocket.h +++ b/thrift/lib/cpp/async/TAsyncSocket.h @@ -285,6 +285,32 @@ class TAsyncSocket : public TAsyncTransport, return sendTimeout_; } + /** + * Set the maximum number of reads to execute from the underlying + * socket each time the TEventBase detects that new ingress data is + * available. The default is unlimited, but callers can use this method + * to limit the amount of data read from the socket per event loop + * iteration. + * + * @param maxReads Maximum number of reads per data-available event; + * a value of zero means unlimited. + */ + void setMaxReadsPerEvent(uint16_t maxReads) { + maxReadsPerEvent_ = maxReads; + } + + /** + * Get the maximum number of reads this object will execute from + * the underlying socket each time the TEventBase detects that new + * ingress data is available. + * + * @returns Maximum number of reads per data-available event; a value + * of zero means unlimited. + */ + uint16_t getMaxReadsPerEvent() const { + return maxReadsPerEvent_; + } + // Methods inherited from TAsyncTransport // See the documentation in TAsyncTransport.h virtual void setReadCallback(ReadCallback* callback); @@ -298,6 +324,7 @@ class TAsyncSocket : public TAsyncTransport, virtual void close(); virtual void closeNow(); + virtual void closeWithReset(); virtual void shutdownWrite(); virtual void shutdownWriteNow(); @@ -333,6 +360,24 @@ class TAsyncSocket : public TAsyncTransport, */ int setNoDelay(bool noDelay); + /* + * Forces ACKs to be sent immediately + * + * @return Returns 0 if the TCP_QUICKACK flag was successfully updated, + * or a non-zero errno value on error. + */ + int setQuickAck(bool quickack); + + /** + * Set the send bufsize + */ + int setSendBufSize(size_t bufsize); + + /** + * Set the recv bufsize + */ + int setRecvBufSize(size_t bufsize); + /** * Generic API for reading a socket option. * @@ -459,6 +504,19 @@ class TAsyncSocket : public TAsyncTransport, */ virtual ssize_t performRead(void* buf, size_t buflen); + /** + * Populate an iovec array from an IOBuf and attempt to write it. + * + * @param callback Write completion/error callback. + * @param vec Target iovec array; caller retains ownership. + * @param count Number of IOBufs to write, beginning at start of buf. + * @param buf Chain of iovecs. + * @param cork Whether to delay the output until a subsequent + * non-corked write. + */ + void writeChainImpl(WriteCallback* callback, iovec* vec, + size_t count, std::unique_ptr&& buf, bool cork); + /** * Write as much data as possible to the socket without blocking, * and queue up any leftover data to send when the socket can @@ -536,6 +594,7 @@ class TAsyncSocket : public TAsyncTransport, uint16_t eventFlags_; ///< TEventBase::HandlerFlags settings int fd_; ///< The socket file descriptor uint32_t sendTimeout_; ///< The send timeout, in milliseconds + uint16_t maxReadsPerEvent_; ///< Max reads per event loop iteration TEventBase* eventBase_; ///< The TEventBase WriteTimeout writeTimeout_; ///< A timeout for connect and write IoHandler ioHandler_; ///< A TEventHandler to monitor the fd diff --git a/thrift/lib/cpp/async/TAsyncTransport.h b/thrift/lib/cpp/async/TAsyncTransport.h index 76ab7c15b..068e3201c 100644 --- a/thrift/lib/cpp/async/TAsyncTransport.h +++ b/thrift/lib/cpp/async/TAsyncTransport.h @@ -286,6 +286,20 @@ class TAsyncTransport { */ virtual void closeNow() = 0; + /** + * Reset the transport immediately. + * + * This closes the transport immediately, sending a reset to the remote peer + * if possible to indicate abnormal shutdown. + * + * Note that not all subclasses implement this reset functionality: some + * subclasses may treat reset() the same as closeNow(). Subclasses that use + * TCP transports should terminate the connection with a TCP reset. + */ + virtual void closeWithReset() { + closeNow(); + } + /** * Perform a half-shutdown of the write side of the transport. * diff --git a/thrift/lib/cpp/async/TEventServer.h b/thrift/lib/cpp/async/TEventServer.h index 296d3e5e1..f05598154 100644 --- a/thrift/lib/cpp/async/TEventServer.h +++ b/thrift/lib/cpp/async/TEventServer.h @@ -246,6 +246,11 @@ class TEventServer : public apache::thrift::server::TServer { */ uint32_t maxNumMsgsInPipe_; + /** + * The max number of active connections for each worker + */ + int32_t maxNumActiveConnectionsPerWorker_; + /** * The transport type to use */ @@ -320,6 +325,7 @@ class TEventServer : public apache::thrift::server::TServer { queuingMode_(false), acceptRateAdjustSpeed_(0), maxNumMsgsInPipe_(T_MAX_NUM_MESSAGES_IN_PIPE), + maxNumActiveConnectionsPerWorker_(0), transportType_(T_ASYNC_DEFAULT_TRANSPORT_TYPE) { processor->setAsyncServer(this); } @@ -360,6 +366,7 @@ class TEventServer : public apache::thrift::server::TServer { queuingMode_(false), acceptRateAdjustSpeed_(0), maxNumMsgsInPipe_(T_MAX_NUM_MESSAGES_IN_PIPE), + maxNumActiveConnectionsPerWorker_(0), transportType_(T_ASYNC_DEFAULT_TRANSPORT_TYPE) { processor->setAsyncServer(this); @@ -407,6 +414,7 @@ class TEventServer : public apache::thrift::server::TServer { queuingMode_(false), acceptRateAdjustSpeed_(0), maxNumMsgsInPipe_(T_MAX_NUM_MESSAGES_IN_PIPE), + maxNumActiveConnectionsPerWorker_(0), transportType_(T_ASYNC_DEFAULT_TRANSPORT_TYPE) { processor->setAsyncServer(this); @@ -452,6 +460,7 @@ class TEventServer : public apache::thrift::server::TServer { queuingMode_(false), acceptRateAdjustSpeed_(0), maxNumMsgsInPipe_(T_MAX_NUM_MESSAGES_IN_PIPE), + maxNumActiveConnectionsPerWorker_(0), transportType_(T_ASYNC_DEFAULT_TRANSPORT_TYPE) { processor->setAsyncServer(this); @@ -498,6 +507,7 @@ class TEventServer : public apache::thrift::server::TServer { queuingMode_(true), acceptRateAdjustSpeed_(0), maxNumMsgsInPipe_(T_MAX_NUM_MESSAGES_IN_PIPE), + maxNumActiveConnectionsPerWorker_(0), transportType_(T_ASYNC_DEFAULT_TRANSPORT_TYPE) { setProtocolFactory(protocolFactory); setThreadManager(threadManager); @@ -542,6 +552,7 @@ class TEventServer : public apache::thrift::server::TServer { queuingMode_(true), acceptRateAdjustSpeed_(0), maxNumMsgsInPipe_(T_MAX_NUM_MESSAGES_IN_PIPE), + maxNumActiveConnectionsPerWorker_(0), transportType_(T_ASYNC_DEFAULT_TRANSPORT_TYPE) { setDuplexProtocolFactory(duplexProtocolFactory); setThreadManager(threadManager); @@ -671,6 +682,21 @@ class TEventServer : public apache::thrift::server::TServer { maxNumMsgsInPipe_ = num; } + /** + * Get the maxmum number of active connections each TAsyncWorker can have + */ + int32_t getMaxNumActiveConnectionsPerWorker() const { + return maxNumActiveConnectionsPerWorker_; + } + + /** + * Set the maxmum number of active connections each TAsyncWorker can have. + * Zero means unlimited + */ + void setMaxNumActiveConnectionsPerWorker(int32_t num) { + maxNumActiveConnectionsPerWorker_ = num; + } + /** * Get the speed of adjusting connection accept rate. */ diff --git a/thrift/lib/cpp/async/TEventWorker.h b/thrift/lib/cpp/async/TEventWorker.h index ef57271a1..8fcbd21c3 100644 --- a/thrift/lib/cpp/async/TEventWorker.h +++ b/thrift/lib/cpp/async/TEventWorker.h @@ -129,6 +129,9 @@ class TEventWorker : */ ConnectionMap activeConnectionMap_; + // Max number of active connections + int32_t maxNumActiveConnections_; + public: /** @@ -156,7 +159,8 @@ class TEventWorker : server_(server), eventBase_(), workerID_(workerID), - transportType_(TEventServer::FRAMED) { + transportType_(TEventServer::FRAMED), + maxNumActiveConnections_(0) { setDuplexProtocolFactory(protocolFactory); transportType_ = server->getTransportType(); @@ -174,7 +178,7 @@ class TEventWorker : * of freeing up memory, so nothing to be done here but release the * connection stack. */ - virtual ~TEventWorker(); + virtual ~TEventWorker(); /** * Get my TAsyncProcessorFactory object. @@ -212,6 +216,14 @@ class TEventWorker : return workerID_; } + void setMaxNumActiveConnections(int32_t numActiveConnections) { + maxNumActiveConnections_ = numActiveConnections; + } + + int32_t getMaxNumActiveConnections() const { + return maxNumActiveConnections_; + } + /** * Dispose of a TEventConnection object. * Will add to a pool of these objects or destroy as necessary. diff --git a/thrift/lib/cpp/async/TNotificationQueue.h b/thrift/lib/cpp/async/TNotificationQueue.h index 3817a85fc..e2538e079 100644 --- a/thrift/lib/cpp/async/TNotificationQueue.h +++ b/thrift/lib/cpp/async/TNotificationQueue.h @@ -175,7 +175,7 @@ class TNotificationQueue { FdType fdType = FdType::EVENTFD) : spinlock_(), eventfd_(-1), - pipeFds_({-1, -1}), + pipeFds_{-1, -1}, advisoryMaxQueueSize_(maxSize), queue_() { if (fdType == FdType::EVENTFD) { diff --git a/thrift/lib/cpp/async/TStreamAsyncChannel.h b/thrift/lib/cpp/async/TStreamAsyncChannel.h index 3f9985ce1..3e9ec9f00 100644 --- a/thrift/lib/cpp/async/TStreamAsyncChannel.h +++ b/thrift/lib/cpp/async/TStreamAsyncChannel.h @@ -194,7 +194,8 @@ class TStreamAsyncChannel : public TAsyncEventChannel, protected TAsyncTransport::WriteCallback, protected TAsyncTimeout { public: - TStreamAsyncChannel(const boost::shared_ptr& transport); + explicit TStreamAsyncChannel( + const boost::shared_ptr& transport); /** * Helper function to create a shared_ptr. @@ -328,6 +329,15 @@ class TStreamAsyncChannel : public TAsyncEventChannel, return recvTimeout_; } + /** + * Cancel pending callbacks. Use this when the channel is closing because the + * server had been shut down. + */ + virtual void cancelCallbacks() { + readCallback_ = NULL; + readErrorCallback_ = NULL; + } + /** * Get the TAsyncTransport used by this channel. */ @@ -407,6 +417,11 @@ class TStreamAsyncChannel : public TAsyncEventChannel, return req; } + void clearCallbacks() { + readCallback_ = NULL; + readErrorCallback_ = NULL; + } + void failAllReads(); boost::shared_ptr transport_; diff --git a/thrift/lib/cpp/async/TZlibAsyncChannel.h b/thrift/lib/cpp/async/TZlibAsyncChannel.h index a56770d95..bf32bc800 100644 --- a/thrift/lib/cpp/async/TZlibAsyncChannel.h +++ b/thrift/lib/cpp/async/TZlibAsyncChannel.h @@ -26,7 +26,8 @@ namespace apache { namespace thrift { namespace async { class TZlibAsyncChannel : public TAsyncEventChannel { public: - TZlibAsyncChannel(const boost::shared_ptr& channel); + explicit TZlibAsyncChannel( + const boost::shared_ptr& channel); /** * Helper function to create a shared_ptr. @@ -85,6 +86,11 @@ class TZlibAsyncChannel : public TAsyncEventChannel { channel_->setRecvTimeout(milliseconds); } + virtual void cancelCallbacks() { + sendRequest_.cancelCallbacks(); + recvRequest_.cancelCallbacks(); + } + protected: /** * Protected destructor. @@ -109,6 +115,11 @@ class TZlibAsyncChannel : public TAsyncEventChannel { void send(TAsyncEventChannel* channel); + void cancelCallbacks() { + callback_ = NULL; + errorCallback_ = NULL; + } + private: void invokeCallback(VoidCallback callback); void sendSuccess(); @@ -137,6 +148,11 @@ class TZlibAsyncChannel : public TAsyncEventChannel { void recv(TAsyncEventChannel* channel); + void cancelCallbacks() { + callback_ = NULL; + errorCallback_ = NULL; + } + private: void invokeCallback(VoidCallback callback); void recvSuccess(); diff --git a/thrift/lib/cpp/concurrency/PosixThreadFactory.h b/thrift/lib/cpp/concurrency/PosixThreadFactory.h index 1055a04c6..7d7de185e 100644 --- a/thrift/lib/cpp/concurrency/PosixThreadFactory.h +++ b/thrift/lib/cpp/concurrency/PosixThreadFactory.h @@ -68,27 +68,37 @@ class PosixThreadFactory : public ThreadFactory { DECREMENT = 8 }; + static const POLICY kDefaultPolicy = ROUND_ROBIN; + static const PRIORITY kDefaultPriority = NORMAL; + static const int kDefaultStackSizeMB = 1; + /** - * Posix thread (pthread) factory. All threads created by a factory are reference-counted - * via boost::shared_ptr and boost::weak_ptr. The factory guarantees that threads and - * the Runnable tasks they host will be properly cleaned up once the last strong reference - * to both is given up. + * Posix thread (pthread) factory. All threads created by a factory are + * reference-counted via boost::shared_ptr and boost::weak_ptr. The factory + * guarantees that threads and the Runnable tasks they host will be properly + * cleaned up once the last strong reference to both is given up. * - * Threads are created with the specified policy, priority, stack-size and detachable-mode - * detached means the thread is free-running and will release all system resources the - * when it completes. A detachable thread is not joinable. The join method - * of a detachable thread will return immediately with no error. + * Threads are created with the specified policy, priority, stack-size and + * detachable-mode detached means the thread is free-running and will release + * all system resources the when it completes. A detachable thread is not + * joinable. The join method of a detachable thread will return immediately + * with no error. * * By default threads are not joinable. */ - - explicit PosixThreadFactory(POLICY policy=ROUND_ROBIN, - PRIORITY priority=NORMAL, - int stackSize=1, + explicit PosixThreadFactory(POLICY policy=kDefaultPolicy, + PRIORITY priority=kDefaultPriority, + int stackSize=kDefaultStackSizeMB, bool detached=true); + explicit PosixThreadFactory(DetachState detached); + // From ThreadFactory; - boost::shared_ptr newThread(boost::shared_ptr runnable) const; + boost::shared_ptr newThread( + const boost::shared_ptr& runnable) const; + boost::shared_ptr newThread( + const boost::shared_ptr& runnable, + DetachState detachState) const; // From ThreadFactory; Thread::id_t getCurrentThreadId() const; @@ -121,6 +131,7 @@ class PosixThreadFactory : public ThreadFactory { * Sets detached mode of threads */ virtual void setDetached(bool detached); + virtual void setDetached(DetachState detached); /** * Gets current detached mode diff --git a/thrift/lib/cpp/concurrency/TARGETS b/thrift/lib/cpp/concurrency/TARGETS deleted file mode 100644 index 2663ab449..000000000 --- a/thrift/lib/cpp/concurrency/TARGETS +++ /dev/null @@ -1,17 +0,0 @@ -# TARGETS file for thrift/lib/cpp/concurrency - -cpp_library ( - name = "concurrency", - srcs = [ - "Util.cpp", - "Monitor.cpp", - "Mutex.cpp", - "PosixThreadFactory.cpp", - "ThreadManager.cpp", - "TimerManager.cpp" - ], - deps = [ '@/common/base:profiler', - '@/thrift/lib/cpp:thrift_base' ], -) - - diff --git a/thrift/lib/cpp/concurrency/Thread.h b/thrift/lib/cpp/concurrency/Thread.h index 198223a18..790d357b1 100644 --- a/thrift/lib/cpp/concurrency/Thread.h +++ b/thrift/lib/cpp/concurrency/Thread.h @@ -110,8 +110,18 @@ class Thread { class ThreadFactory { public: + enum DetachState { + ATTACHED, + DETACHED + }; + virtual ~ThreadFactory() {} - virtual boost::shared_ptr newThread(boost::shared_ptr runnable) const = 0; + virtual boost::shared_ptr newThread( + const boost::shared_ptr& runnable) const = 0; + + virtual boost::shared_ptr newThread( + const boost::shared_ptr& runnable, + DetachState detachState) const = 0; /** Gets the current thread id or unknown_thread_id if the current thread is not a thrift thread */ diff --git a/thrift/lib/cpp/concurrency/test/TARGETS b/thrift/lib/cpp/concurrency/test/TARGETS deleted file mode 100644 index 3d1b19a23..000000000 --- a/thrift/lib/cpp/concurrency/test/TARGETS +++ /dev/null @@ -1,45 +0,0 @@ -# TARGETS file for thrift/lib/cpp/concurrency/test - -cpp_binary ( - name = "test", - srcs = [ - "Tests.cpp" - ], - deps = [ - "@/thrift/lib/cpp/concurrency" - ] -) - -cpp_unittest ( - name = "test_mutex", - srcs = [ - "RWMutexTest.cpp" - ], - deps = [ - "@/thrift/lib/cpp/concurrency", - "@/thrift/lib/cpp:thrift", - ], - external_deps = [ - ('boost', '>= 1.37', 'boost_unit_test_framework'), - ], - type = 'boost', - owner = 'putivsky', - emails = ['adback-dev@lists.facebook.com', - 'thrift-team@lists.facebook.com'], - -) - -cpp_unittest( - name = 'ThreadManagerTests', - srcs = [ - 'ThreadManagerTests.cpp', - ], - deps = [ - '@/thrift/lib/cpp/concurrency', - ], - external_deps = [ - ('boost', '>= 1.37', 'boost_unit_test_framework'), - ], - type = 'boost', - emails = ['thrift-team@lists.facebook.com'], -) diff --git a/thrift/lib/cpp/processor/TARGETS b/thrift/lib/cpp/processor/TARGETS deleted file mode 100644 index d5f363053..000000000 --- a/thrift/lib/cpp/processor/TARGETS +++ /dev/null @@ -1,9 +0,0 @@ -# TARGETS file for thrift/lib/cpp/processor - -cpp_library ( - name = "processor", - srcs = [ - "PeekProcessor.cpp" - ], - deps = [ "@/thrift/lib/cpp/transport" ] -) diff --git a/thrift/lib/cpp/processor/test/TARGETS b/thrift/lib/cpp/processor/test/TARGETS deleted file mode 100644 index 9cb4d8b22..000000000 --- a/thrift/lib/cpp/processor/test/TARGETS +++ /dev/null @@ -1,24 +0,0 @@ -cpp_unittest( - name = 'ProcessorTest', - srcs = [ - 'EventLog.cpp', - 'ProcessorTest.cpp', - 'ServerThread.cpp', - ], - deps = [ - ':thrift', - '@/thrift/lib/cpp/server:nonblocking', - ], - external_deps = [ - # Versions of boost lower than 1.37 don't support BOOST_AUTO_TEST_CASE. - ('boost', '>= 1.37', 'boost_unit_test_framework'), - ], - type = 'boost', - emails = ['thrift-team@lists.facebook.com'], -) - -cpp_library( - name = 'thrift', - thrift_srcs = { 'proc.thrift' : ['ParentService', 'ChildService']}, - thrift_cpp_options = 'templates', -) diff --git a/thrift/lib/cpp/protocol/TARGETS b/thrift/lib/cpp/protocol/TARGETS deleted file mode 100644 index cb128d068..000000000 --- a/thrift/lib/cpp/protocol/TARGETS +++ /dev/null @@ -1,18 +0,0 @@ -# TARGETS file for thrift/lib/cpp/protocol - -cpp_library ( - name = "protocol", - srcs = [ - "TBase64Utils.cpp", - "TDebugProtocol.cpp", - "TJSONProtocol.cpp", - "TSimpleJSONProtocol.cpp", - "THeaderProtocol.cpp", - "TPhpSerializeProtocol.cpp", - ], - deps = [ - "@/thrift/lib/cpp/transport", - "@/thrift/lib/cpp/transport:header", - "@/thrift/lib/cpp:thrift_exception", - ], -) diff --git a/thrift/lib/cpp/protocol/TCompactProtocol.h b/thrift/lib/cpp/protocol/TCompactProtocol.h index ff2b99a74..ebef27272 100644 --- a/thrift/lib/cpp/protocol/TCompactProtocol.h +++ b/thrift/lib/cpp/protocol/TCompactProtocol.h @@ -37,6 +37,8 @@ class TCompactProtocolT static const int8_t VERSION_N = 2; static const int8_t VERSION_LOW = 1; static const int8_t VERSION_DOUBLE_BE = 2; + static const int8_t PROTOCOL_ID = static_cast(0x82); + static const int8_t VERSION_MASK = 0x1f; // 0001 1111 protected: // Normally we can define static const data members of integral @@ -44,10 +46,8 @@ class TCompactProtocolT // high bit is set (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49896) // unless we cast to a value that fits in an int8_t (0x82 and 0xE0 are // uint8_t) - static const int8_t PROTOCOL_ID = static_cast(0x82); - static const int8_t TYPE_MASK = static_cast(0xE0); - static const int8_t VERSION_MASK = 0x1f; // 0001 1111 + static const int8_t TYPE_MASK = static_cast(0xE0); static const int32_t TYPE_SHIFT_AMOUNT = 5; Transport_* trans_; diff --git a/thrift/lib/cpp/protocol/THeaderProtocol.h b/thrift/lib/cpp/protocol/THeaderProtocol.h index ac9730cc4..02277ff65 100644 --- a/thrift/lib/cpp/protocol/THeaderProtocol.h +++ b/thrift/lib/cpp/protocol/THeaderProtocol.h @@ -279,7 +279,7 @@ class THeaderProtocol const boost::shared_ptr& outTrans, std::bitset* clientTypes) { assert(dynamic_cast(inTrans.get()) == NULL - && dynamic_cast(outTrans.get()) == NULL); + && dynamic_cast(outTrans.get()) == NULL); return boost::shared_ptr( new THeaderTransport(inTrans, outTrans, clientTypes) diff --git a/thrift/lib/cpp/protocol/neutronium/TARGETS b/thrift/lib/cpp/protocol/neutronium/TARGETS deleted file mode 100644 index 130a998e9..000000000 --- a/thrift/lib/cpp/protocol/neutronium/TARGETS +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright 2011 Facebook -# @author Tudor Bosman (tudorb@fb.com) - -cpp_library( - name = "neutronium", - srcs = [ - "Schema.cpp", - "Encoder.cpp", - "Decoder.cpp", - "InternTable.cpp", - ], - thrift_srcs = { - "intern_table.thrift": [], - }, - deps = [ - "@/folly", - "@/folly/experimental/io", - "@/thrift/lib/cpp/protocol", - ], - external_deps = [ - ("boost", None, "boost"), - ], -) - diff --git a/thrift/lib/cpp/protocol/neutronium/test/TARGETS b/thrift/lib/cpp/protocol/neutronium/test/TARGETS deleted file mode 100644 index df99ef6df..000000000 --- a/thrift/lib/cpp/protocol/neutronium/test/TARGETS +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright 2011 Facebook -# @author Tudor Bosman (tudorb@fb.com) - -thrift_library( - name = "if", - thrift_srcs = { - "neutronium_test.thrift" : [], - }, - languages = ["cpp"], - thrift_cpp_options = "templates=only,neutronium", - cpp_deps = [], -) - -cpp_unittest( - name = "intern_table_test", - srcs = ["InternTableTest.cpp"], - deps = [ - "@/thrift/lib/cpp/protocol/neutronium", - "@/external/gflags", - ], - external_deps = [ - ("gtest", None, "gtest_main"), - ], - type = 'gtest', -) - -cpp_unittest( - name = "neutronium_test", - srcs = ["NeutroniumTest.cpp"], - deps = [ - "@/thrift/lib/cpp/protocol/neutronium", - "@/thrift/lib/cpp/util", - ":if-cpp", - "@/common/fbunit:old_folly_benchmark", - ], - external_deps = [ - ("gtest", None), - ], - type = 'gtest', -) - diff --git a/thrift/lib/cpp/server/TARGETS b/thrift/lib/cpp/server/TARGETS deleted file mode 100644 index 967deceaf..000000000 --- a/thrift/lib/cpp/server/TARGETS +++ /dev/null @@ -1,30 +0,0 @@ -# TARGETS file for thrift/lib/cpp/server - -cpp_library ( - name = "server", - srcs = [ - "TRpcTransportContext.cpp", - "TServer.cpp", - "TSimpleServer.cpp", - "TThreadedServer.cpp", - "TThreadPoolServer.cpp", - ], - deps = [ - "@/thrift/lib/cpp/concurrency", - "@/thrift/lib/cpp/transport", - ] -) - -cpp_library ( - name = "nonblocking", - srcs = [ "TNonblockingServer.cpp" ], - deps = [ - ":server", - "@/thrift/lib/cpp/concurrency", - "@/thrift/lib/cpp/transport", - "@/thrift/lib/cpp/transport:header", - "@/thrift/lib/cpp/protocol:protocol", - ], - preprocessor_flags = [ "-DTCP_LOW_MIN_RTO=15" ], - external_deps = [ ('libevent', None) ], -) diff --git a/thrift/lib/cpp/server/test/TARGETS b/thrift/lib/cpp/server/test/TARGETS deleted file mode 100644 index 0cb7f9a60..000000000 --- a/thrift/lib/cpp/server/test/TARGETS +++ /dev/null @@ -1,60 +0,0 @@ -cpp_binary ( - name = "aggregatorserver_test", - srcs = [ - "AggregatorServerTest.cpp", - ], - deps = [ - "@/thrift/lib/cpp/async", - "@/thrift/lib/cpp/concurrency", - "@/thrift/lib/cpp/protocol", - "@/thrift/lib/cpp/server:nonblocking", - "@/common/fb303/cpp:fb303", - "@/common/base:profiler", - ":aggregator_test_thrift", - ], - allocator='tcmalloc', -) - -cpp_binary ( - name = "aggregatorclient_test", - srcs = [ - "AggregatorClientTest.cpp", - ], - deps = [ - "@/thrift/lib/cpp/async", - "@/thrift/lib/cpp/concurrency", - "@/thrift/lib/cpp/protocol", - "@/common/fb303/cpp:fb303", - "@/common/base:profiler", - "@/common/client_mgmt:asyncclient", - "@/common/logging:logging", - ":aggregator_test_thrift", - ], - allocator='tcmalloc', -) - -cpp_library ( - name = "aggregator_test_thrift", - thrift_srcs = { "AggregatorTest.thrift" : [ "AggregatorTest" ] }, - thrift_cpp_options = "cob_style", - deps = [ - "@/common/fb303/if:fb303-cpp", - ], -) - -cpp_unittest( - name = "conn_ctx_test", - srcs = [ - "ConnCtxTest.cpp", - ], - thrift_srcs = { "connctx.thrift" : [ "ConnCtxService" ] }, - deps = [ - "@/thrift/lib/cpp/test:util", - "@/thrift/lib/cpp/util:nonblocking", - ], - external_deps = [ - ('boost', '>= 1.37', 'boost_unit_test_framework'), - ], - type = 'boost', - emails = ['thrift-team@lists.facebook.com'], -) diff --git a/thrift/lib/cpp/test/TARGETS b/thrift/lib/cpp/test/TARGETS deleted file mode 100644 index 6c8cb6787..000000000 --- a/thrift/lib/cpp/test/TARGETS +++ /dev/null @@ -1,167 +0,0 @@ -cpp_unittest( - name = 'TEventBaseTest', - srcs = [ - 'TEventBaseTest.cpp', - ], - deps = [ - ':util', - '@/thrift/lib/cpp/async', - ], - external_deps = [ - ('boost', '>= 1.37', 'boost_unit_test_framework'), - ], - type = 'boost', - emails = ['thrift-team@lists.facebook.com'], -) - -cpp_unittest( - name = 'TAsyncChannelTest', - srcs = [ - 'TAsyncChannelTest.cpp', - ], - deps = [ - ':util', - '@/thrift/lib/cpp/async', - ], - external_deps = [ - ('boost', '>= 1.37', 'boost_unit_test_framework'), - ], - type = 'boost', - emails = ['thrift-team@lists.facebook.com'], -) - -cpp_unittest( - name = 'TAsyncChannelClientTest', - srcs = [ - 'TAsyncChannelClientTest.cpp', - ], - deps = [ - ':util', - '@/thrift/lib/cpp/async:zlib', - '@/thrift/lib/cpp/util:nonblocking', - '@/thrift/lib/cpp/util:httpparser', - '@/thrift/perf/cpp:load-handler', - ], - external_deps = [ - ('boost', '>= 1.37', 'boost_unit_test_framework'), - ], - type = 'boost', - emails = ['thrift-team@lists.facebook.com'], -) - -cpp_unittest( - name = 'TAsyncSocketTest', - srcs = [ - 'TAsyncSocketTest.cpp', - ], - deps = [ - ':util', - '@/thrift/lib/cpp/async', - ], - external_deps = [ - ('boost', '>= 1.37', 'boost_unit_test_framework'), - ], - type = 'boost', - emails = ['thrift-team@lists.facebook.com'], -) - -cpp_unittest( - name = 'TAsyncSSLSocketTest', - srcs = [ - 'TAsyncSSLSocketTest.cpp', - ], - deps = [ - ':util', - '@/thrift/lib/cpp/async:async_ssl', - ], - external_deps = [ - ('boost', '>= 1.37', 'boost_unit_test_framework'), - ], - type = 'boost', - emails = ['ti-bugs@lists.facebook.com', - 'thrift-team@lists.facebook.com'], -) - -cpp_unittest( - name = 'TAsyncTimeoutSetTest', - srcs = [ - 'TAsyncTimeoutSetTest.cpp', - ], - deps = [ - ':util', - '@/thrift/lib/cpp/async:async_cxx11', - ], - type = 'boost', - emails = ['thrift-team@lists.facebook.com'], -) - -cpp_unittest( - name = 'TNotificationQueueTest', - srcs = [ - 'TNotificationQueueTest.cpp', - ], - deps = [ - ':async_util', - '@/thrift/lib/cpp/async:async_cxx11', - ], - type = 'boost', - emails = ['thrift-team@lists.facebook.com'], -) - -cpp_unittest( - name = 'TNotificationPipeTest', - srcs = [ - 'TNotificationPipeTest.cpp', - ], - deps = [ - ':async_util', - ':util', - '@/thrift/lib/cpp/async', - ], - external_deps = [ - ('boost', '>= 1.37', 'boost_unit_test_framework'), - ], - type = 'boost', - emails = ['thrift-team@lists.facebook.com'], -) - -cpp_library( - name = 'util', - srcs = [ - 'NetworkUtil.cpp', - 'SocketPair.cpp', - 'TimeUtil.cpp', - ], - deps = [ - '@/thrift/lib/cpp/transport', - ], -) - -cpp_library( - name = 'async_util', - srcs = [ - 'ScopedEventBaseThread.cpp', - ], - deps = [ - '@/thrift/lib/cpp/async', - '@/thrift/lib/cpp/concurrency', - ], -) - -cpp_library ( - name = "DebugProtocolLib", - thrift_srcs = { - "DebugProtocolTest.thrift" : "DebugProtocolService" - }, - thrift_cpp_options = "templates" -) - -cpp_binary ( - name = "DebugProtocol", - srcs = [ - "DebugProtocolTest.cpp", - ], - deps = [ - ":DebugProtocolLib", - ], -) diff --git a/thrift/lib/cpp/test/loadgen/TARGETS b/thrift/lib/cpp/test/loadgen/TARGETS deleted file mode 100644 index a2db31670..000000000 --- a/thrift/lib/cpp/test/loadgen/TARGETS +++ /dev/null @@ -1,32 +0,0 @@ -cpp_library( - name = 'loadgen', - srcs = [ - 'Controller.cpp', - 'LatencyMonitor.cpp', - 'LatencyScoreBoard.cpp', - 'LoadConfig.cpp', - 'loadgen.cpp', - 'QpsMonitor.cpp', - 'QpsScoreBoard.cpp', - 'RNG.cpp', - 'TerminalMonitor.cpp', - 'WeightedLoadConfig.cpp', - ], - deps = [ - '@/common/time:time', - ], - external_deps = [ - ('boost', None, 'boost'), - ], -) - -cpp_binary( - name = 'perftest', - srcs = [ - 'PerfTest.cpp', - ], - deps = [ - ':loadgen', - '@/common/config', - ], -) diff --git a/thrift/lib/cpp/transport/TARGETS b/thrift/lib/cpp/transport/TARGETS deleted file mode 100644 index d85bead36..000000000 --- a/thrift/lib/cpp/transport/TARGETS +++ /dev/null @@ -1,88 +0,0 @@ -# TARGETS file for thrift/lib/cpp/transport - -cpp_library( - name = "transport", - srcs = [ - "TFileTransport.cpp", - "TFDTransport.cpp", - "THttpClient.cpp", - "THttpServer.cpp", - "THttpTransport.cpp", - "TServerSocket.cpp", - "TSimpleFileTransport.cpp", - "TSocket.cpp", - "TSocketAddress.cpp", - "TSocketPool.cpp", - "TTransportException.cpp", - "TTransportUtils.cpp", - "TBufferTransports.cpp", - "TMemPagedFactory.cpp", - "TMemPagedTransport.cpp", - ], - deps = [ - "@/thrift/lib/cpp:thrift_base", - "@/thrift/lib/cpp/concurrency", - "@/external/google_base", - ], - preprocessor_flags = [ "-DTCP_LOW_MIN_RTO=15" ], -) - -cpp_library( - name = "transport_ssl", - srcs = [ - "TSSLSocket.cpp", - "TSSLServerSocket.cpp", - ], - deps = [ - ":transport", - "@/thrift/lib/cpp/concurrency", - ], - external_deps = [ ('openssl', None, 'ssl') ], -) - -cpp_library( - name = "header", - srcs = [ "THeaderTransport.cpp", - "THeader.cpp" ], - deps = [ - ":transport", - "@/folly/experimental/io:io", - "@/thrift/lib/cpp/util:internal_util", - ], - external_deps = [ ('zlib', None, 'z'), - ('snappy', None) - ], -) - -cpp_library( - name = "zlib", - srcs = [ "TZlibTransport.cpp" ], - deps = [ - ":transport", - ], - external_deps = [ ('zlib', None, 'z') ], -) - -cpp_library( - name = "hdfs_transport", - srcs = [ "HDFS.cpp", - "THDFSFileTransport.cpp", - ], - - system_deps = [ "-Lexternal/hadoop/latest/", - "-L$(JAVA_HOME)/jre/lib/amd64/server/", - "-Lexternal/jvm/", - "-ljvm", - "-lhdfs" - ], - preprocessor_flags = [ "-I@@@JAVA_HOME@@@/include", - "-I@@@JAVA_HOME@@@/include/linux", - "-Iexternal/hadoop/latest", - ], - shared_system_deps = [ "hdfs", - "jvm", - ], - deps = [ - "@/thrift/lib/cpp:thrift_base", - ], -) diff --git a/thrift/lib/cpp/transport/THeader.h b/thrift/lib/cpp/transport/THeader.h index 62e13d7ea..01524e538 100644 --- a/thrift/lib/cpp/transport/THeader.h +++ b/thrift/lib/cpp/transport/THeader.h @@ -23,6 +23,7 @@ #include #include "thrift/lib/cpp/protocol/TBinaryProtocol.h" +#include "thrift/lib/cpp/protocol/TCompactProtocol.h" #include "thrift/lib/cpp/protocol/TProtocolTypes.h" #include "folly/experimental/io/IOBuf.h" @@ -34,14 +35,15 @@ #include // Don't include the unknown client. -#define CLIENT_TYPES_LEN 4 +#define CLIENT_TYPES_LEN 5 enum CLIENT_TYPE { THRIFT_HEADER_CLIENT_TYPE = 0, THRIFT_FRAMED_DEPRECATED = 1, THRIFT_UNFRAMED_DEPRECATED = 2, THRIFT_HTTP_CLIENT_TYPE = 3, - THRIFT_UNKNOWN_CLIENT_TYPE = 4, + THRIFT_FRAMED_COMPACT = 4, + THRIFT_UNKNOWN_CLIENT_TYPE = 5, }; namespace apache { namespace thrift { namespace transport { @@ -270,6 +272,12 @@ class THeader { */ size_t getMaxWriteHeadersSize() const; + /** + * Returns whether the 1st byte of the protocol payload should be hadled + * as compact framed. + */ + bool compactFramed(uint32_t magic); + struct infoIdType { enum idType { // start at 1 to avoid confusing header padding for an infoId diff --git a/thrift/lib/cpp/transport/test/TARGETS b/thrift/lib/cpp/transport/test/TARGETS deleted file mode 100644 index e024909eb..000000000 --- a/thrift/lib/cpp/transport/test/TARGETS +++ /dev/null @@ -1,69 +0,0 @@ -cpp_unittest( - name = 'THeaderTest', - srcs = [ - 'THeaderTest.cpp', - ], - deps = [ - '@/thrift/lib/cpp/transport:header', - ], - external_deps = [ - ('boost', '>= 1.37', 'boost_unit_test_framework'), - ], - type = 'boost', - emails = ['thrift-team@lists.facebook.com'], -) - -cpp_unittest( - name = 'TSocketAddressTest', - srcs = [ - 'TSocketAddressTest.cpp', - ], - deps = [ - '@/thrift/lib/cpp/transport', - ], - external_deps = [ - ('boost', '>= 1.37', 'boost_unit_test_framework'), - ], - type = 'boost', - emails = ['thrift-team@lists.facebook.com'], -) - -cpp_unittest( - name = 'TSSLSocketTest', - srcs = [ - 'TSSLSocketTest.cpp', - ], - deps = [ - '@/thrift/lib/cpp/transport:transport_ssl', - '@/thrift/lib/cpp/util', - ], - external_deps = [ - ('boost', '>= 1.37', 'boost_unit_test_framework'), - ], - type = 'boost', - emails = [ - 'ti-bugs@lists.facebook.com', - 'thrift-team@lists.facebook.com', - ], -) - -cpp_unittest ( - name = "TSocketPoolTest", - srcs = [ - "TSocketPoolTest.cpp", - ], - deps = [ - '@/common/fbunit', - '@/thrift/lib/cpp/transport', - ], -) - -cpp_binary ( - name = "ttransport_test", - srcs = [ - "TransportTest.cpp", - ], - deps = [ - "@/thrift/lib/cpp/transport", - ] -) diff --git a/thrift/lib/cpp/util/TARGETS b/thrift/lib/cpp/util/TARGETS deleted file mode 100644 index 0f0995f95..000000000 --- a/thrift/lib/cpp/util/TARGETS +++ /dev/null @@ -1,74 +0,0 @@ -cpp_library( - name = 'util', - srcs = [ - 'ScopedServerThread.cpp', - 'ServerCreatorBase.cpp', - 'SyncServerCreator.cpp', - 'TSimpleServerCreator.cpp', - 'TThreadedServerCreator.cpp', - 'TThreadPoolServerCreator.cpp', - ], - deps = [ - '@/thrift/lib/cpp/server', - '@/thrift/lib/cpp/protocol', - '@/folly', - ], -) - -cpp_library( - name = 'internal_util', - srcs = [ - 'VarintUtils.cpp', - ], - deps = [ - '@/folly', - ], - external_deps = [ - ('gflags', None, 'gflags'), - ('glog', None, 'glog'), - ], -) - -cpp_library( - name = 'nonblocking', - srcs = [ - 'TNonblockingServerCreator.cpp', - ], - deps = [ - ':util', - '@/thrift/lib/cpp/server:nonblocking', - ], -) - -cpp_library( - name = 'async', - srcs = [ - 'TEventServerCreator.cpp', - ], - deps = [ - ':util', - '@/thrift/lib/cpp/async', - ], -) - -cpp_library( - name = 'httpparser', - srcs = [ - 'THttpParser.cpp', - ], - deps = [ - '@/thrift/lib/cpp/transport', -], -) - -cpp_unittest( - name = 'ThriftSerializerTest', - srcs = [ 'ThriftSerializerTest.cpp' ], - thrift_srcs = { 'ThriftSerializerTest.thrift' : [ ] }, - thrift_cpp_options = 'templates', - deps = [ '@/common/strings:strings', - '@/common/fbunit', - ], -) - - diff --git a/thrift/lib/cpp/util/test/TARGETS b/thrift/lib/cpp/util/test/TARGETS deleted file mode 100644 index 5b56e3846..000000000 --- a/thrift/lib/cpp/util/test/TARGETS +++ /dev/null @@ -1,17 +0,0 @@ -cpp_unittest( - name = 'ServerCreatorTest', - srcs = [ - 'ServerCreatorTest.cpp', - ], - deps = [ - '@/thrift/lib/cpp/util:async', - '@/thrift/lib/cpp/util:nonblocking', - '@/thrift/perf/cpp:load-handler', - '@/thrift/perf/cpp:async-load-handler', - ], - external_deps = [ - ('boost', '>= 1.37', 'boost_unit_test_framework'), - ], - type = 'boost', - emails = ['thrift-team@lists.facebook.com'], -) -- GitLab