From 7d99005d5597223f491a3d111c97c8007d7186f5 Mon Sep 17 00:00:00 2001 From: Uddipta Maity Date: Thu, 24 Sep 2015 15:33:43 -0700 Subject: [PATCH] Fixing backward compatible issues in wdt service Summary: Fixing backward compatible issues in wdt service Reviewed By: @nikunjy Differential Revision: D2477964 committer: Service User --- CMakeLists.txt | 2 +- WdtBase.cpp | 19 +++++++++++++++---- WdtBase.h | 5 +++++ WdtConfig.h | 6 +++--- WdtFlags.cpp.inc | 2 ++ WdtOptions.h | 5 +++++ wdtCmdLine.cpp | 4 ++++ 7 files changed, 35 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c5a23b6..e5297b2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,7 @@ cmake_minimum_required(VERSION 3.2) # There is no C per se in WDT but if you use CXX only here many checks fail # Version is Major.Minor.YYMMDDX for up to 10 releases per day # Minor currently is also the protocol version - has to match with Protocol.cpp -project("WDT" LANGUAGES C CXX VERSION 1.19.1509220) +project("WDT" LANGUAGES C CXX VERSION 1.20.1509240) # On MacOS this requires the latest (master) CMake (and/or CMake 3.1.1/3.2) set(CMAKE_CXX_STANDARD 11) diff --git a/WdtBase.cpp b/WdtBase.cpp index dd613a1b..8de386e4 100644 --- a/WdtBase.cpp +++ b/WdtBase.cpp @@ -186,7 +186,12 @@ WdtUri& WdtUri::operator=(const string& url) { return *this; } +// hard-coding +const int WdtTransferRequest::LEGACY_PROTCOL_VERSION = 16; + const string WdtTransferRequest::TRANSFER_ID_PARAM{"id"}; +// legacy protocol version +const string WdtTransferRequest::LEGACY_PROTOCOL_VERSION_PARAM{"protocol"}; /** RECeiver's Protocol Version */ const string WdtTransferRequest::RECEIVER_PROTOCOL_VERSION_PARAM{"recpv"}; const string WdtTransferRequest::DIRECTORY_PARAM{"dir"}; @@ -223,9 +228,9 @@ WdtTransferRequest::WdtTransferRequest(const string& uriString) { protocolVersion = folly::to( wdtUri.getQueryParam(RECEIVER_PROTOCOL_VERSION_PARAM)); } catch (std::exception& e) { - LOG(ERROR) << "Error parsing protocol version " - << wdtUri.getQueryParam(RECEIVER_PROTOCOL_VERSION_PARAM); - errorCode = URI_PARSE_ERROR; + LOG(WARNING) << "Error parsing protocol version " + << wdtUri.getQueryParam(RECEIVER_PROTOCOL_VERSION_PARAM) << " " + << e.what(); } string portsStr(wdtUri.getQueryParam(PORTS_PARAM)); StringPiece portsList(portsStr); // pointers into portsStr @@ -281,6 +286,11 @@ string WdtTransferRequest::generateUrl(bool genFull) const { wdtUri.setQueryParam(TRANSFER_ID_PARAM, transferId); wdtUri.setQueryParam(RECEIVER_PROTOCOL_VERSION_PARAM, folly::to(protocolVersion)); + const auto &options = WdtOptions::get(); + if (options.url_backward_compatibility) { + wdtUri.setQueryParam(LEGACY_PROTOCOL_VERSION_PARAM, + folly::to(LEGACY_PROTCOL_VERSION)); + } serializePorts(wdtUri); if (genFull) { wdtUri.setQueryParam(DIRECTORY_PARAM, directory); @@ -303,7 +313,8 @@ void WdtTransferRequest::serializePorts(WdtUri& wdtUri) const { } prevPort = ports[i]; } - if (hasHoles) { + const auto &options = WdtOptions::get(); + if (hasHoles || options.url_backward_compatibility) { wdtUri.setQueryParam(PORTS_PARAM, getSerializedPortsList()); } else { wdtUri.setPort(ports[0]); diff --git a/WdtBase.h b/WdtBase.h index 5e4d5d87..a1916c19 100644 --- a/WdtBase.h +++ b/WdtBase.h @@ -155,8 +155,13 @@ struct WdtTransferRequest { /// Operator for finding if two request objects are equal bool operator==(const WdtTransferRequest& that) const; + const static int LEGACY_PROTCOL_VERSION; + /// Names of the get parameters for different fields const static std::string TRANSFER_ID_PARAM; + /// Legacy protocol version. Need this because older wdt needs protocol + /// version to be present in the url and it needs the key to be "protocol" + const static std::string LEGACY_PROTOCOL_VERSION_PARAM; /** Constant for for the protocol version get parameter in uri */ const static std::string RECEIVER_PROTOCOL_VERSION_PARAM; const static std::string DIRECTORY_PARAM; diff --git a/WdtConfig.h b/WdtConfig.h index 5d5b441f..3ebeed91 100644 --- a/WdtConfig.h +++ b/WdtConfig.h @@ -7,10 +7,10 @@ #include #define WDT_VERSION_MAJOR 1 -#define WDT_VERSION_MINOR 19 -#define WDT_VERSION_BUILD 1509220 +#define WDT_VERSION_MINOR 20 +#define WDT_VERSION_BUILD 1509240 // Add -fbcode to version str -#define WDT_VERSION_STR "1.19.1509220-fbcode" +#define WDT_VERSION_STR "1.20.1509240-fbcode" // Tie minor and proto version #define WDT_PROTOCOL_VERSION WDT_VERSION_MINOR diff --git a/WdtFlags.cpp.inc b/WdtFlags.cpp.inc index 6588c191..3bef79ca 100644 --- a/WdtFlags.cpp.inc +++ b/WdtFlags.cpp.inc @@ -148,3 +148,5 @@ WDT_OPT(resume_using_dir_tree, bool, "supported if preallocation and block mode are disabled"); WDT_OPT(open_files_during_discovery, bool, "If true, files are opened when they are discovered"); +WDT_OPT(url_backward_compatibility, bool, + "If true, we send url that works with older version(<19)"); diff --git a/WdtOptions.h b/WdtOptions.h index 9354ce51..c19959cb 100644 --- a/WdtOptions.h +++ b/WdtOptions.h @@ -295,6 +295,11 @@ class WdtOptions { */ bool open_files_during_discovery{false}; + /** + * If true, we send url that works with older version(<19) + */ + bool url_backward_compatibility{false}; + /** * @return whether files should be pre-allocated or not */ diff --git a/wdtCmdLine.cpp b/wdtCmdLine.cpp index c62c2a2e..845c692d 100644 --- a/wdtCmdLine.cpp +++ b/wdtCmdLine.cpp @@ -187,6 +187,10 @@ int main(int argc, char *argv[]) { } else { LOG(INFO) << "Input url: " << FLAGS_connection_url; reqPtr = folly::make_unique(FLAGS_connection_url); + if (reqPtr->errorCode != OK) { + LOG(ERROR) << "Invalid url " << errorCodeToStr(reqPtr->errorCode); + return ERROR; + } reqPtr->directory = FLAGS_directory; } WdtTransferRequest &req = *reqPtr;