diff --git a/native/.settings/language.settings.xml b/native/.settings/language.settings.xml index f43c01d7c..0ddc48020 100644 --- a/native/.settings/language.settings.xml +++ b/native/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -16,7 +16,7 @@ - + diff --git a/native/build.gradle b/native/build.gradle index 915c5cd21..adbbc7422 100644 --- a/native/build.gradle +++ b/native/build.gradle @@ -14,10 +14,6 @@ * permissions and limitations under the License. See accompanying * LICENSE file. */ -//plugins{ -//id "de.undercouch.download" version "3.4.3" -//} - buildscript { repositories { maven { url 'https://plugins.gradle.org/m2' } @@ -46,16 +42,16 @@ if ((rootProject.name.contains('native') && !rootProject.hasProperty('skipNative String distDir = "${rootProject.projectDir}/dist" String thriftVersion = '1.0.0-1' - String boostVersion = '1.59.0' + String newThriftVersion = '1.0.0-2' + String boostVersion = '1.69.0' String mpirVersion = '2.7.2' String opensslVersion = '1.0.2h' String unixodbcVersion = '2.3.4' String googletestVersion = '1.7.0' - String oldReleasesDir = "https://github.com/SnappyDataInc/thrift/releases/download/${thriftVersion}" + String oldReleasesDir = "https://github.com/SnappyDataInc/thrift/releases/download/${newThriftVersion}" String releasesDir = oldReleasesDir - String newThriftVersion = '1.0.0-2' String newBoostVersion = '1.65.1' String newUnixodbcVersion = '2.3.4' String newGoogletestVersion = '1.8.0' @@ -142,8 +138,7 @@ if ((rootProject.name.contains('native') && !rootProject.hasProperty('skipNative dependsOn downloadDependencies inputs.files dependencies.collect { [ "${distDir}/${it}" ] }.flatten() - // outputs.files dependencies.collect { [ "${distDir}/${it.replaceAll('-[^-]*.tar.bz2', '')}" ] }.flatten() - + //outputs.files dependencies.collect { [ "${distDir}/${it.replaceAll('-[^-]*.tar.bz2', '')}" ] }.flatten() doLast { outputs.files.each { d -> delete d } dependencies.each { tarball -> @@ -281,15 +276,15 @@ if ((rootProject.name.contains('native') && !rootProject.hasProperty('skipNative '-rdynamic', '-ldl', '-z', 'defs' } else if (toolChain in VisualCpp) { // explicitly include UCRT since its still not passed through by gradle - String VS_2015_INCLUDE_DIR = 'C:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/ucrt' - String VS_2015_LIB_DIR = 'C:/Program Files (x86)/Windows Kits/10/Lib/10.0.10240.0/ucrt' - String VS_2015_INCLUDE_DIR_UM = 'C:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/um' - String VS_2015_LIB_DIR_UM = 'C:/Program Files (x86)/Windows Kits/10/Lib/10.0.10240.0/um' - String VS_2015_INCLUDE_DIR_SHARED = 'C:/Program Files (x86)/Windows Kits/10/Include/10.0.10240.0/shared' + String VS_2017_INCLUDE_DIR = 'C:/Program Files (x86)/Windows Kits/10/Include/10.0.17763.0/ucrt' + String VS_2017_LIB_DIR = 'C:/Program Files (x86)/Windows Kits/10/Lib/10.0.17763.0/ucrt' + String VS_2017_INCLUDE_DIR_UM = 'C:/Program Files (x86)/Windows Kits/10/Include/10.0.17763.0/um' + String VS_2017_LIB_DIR_UM = 'C:/Program Files (x86)/Windows Kits/10/Lib/10.0.17763.0/um' + String VS_2017_INCLUDE_DIR_SHARED = 'C:/Program Files (x86)/Windows Kits/10/Include/10.0.17763.0/shared' cppCompiler.args '/W3', '/FS', '/Zc:inline', '/WX', '/EHsc', '/Fdsnappyclient.pdb', '/errorReport:prompt', - "/I${VS_2015_INCLUDE_DIR_UM}", "/I${VS_2015_INCLUDE_DIR_SHARED}", - "/I${VS_2015_INCLUDE_DIR}" + "/I${VS_2017_INCLUDE_DIR_UM}", "/I${VS_2017_INCLUDE_DIR_SHARED}", + "/I${VS_2017_INCLUDE_DIR}" if (buildType == buildTypes.debug) { cppCompiler.define '_DEBUG' cppCompiler.args '/Od', '/Gm', '/ZI', '/RTC1', '/MDd' @@ -298,9 +293,9 @@ if ((rootProject.name.contains('native') && !rootProject.hasProperty('skipNative cppCompiler.args '/O2', '/GL', '/Oi', '/Gm-', '/Zi', '/MD' } if (targetPlatform == platforms.x64) { - linker.args "/LIBPATH:${VS_2015_LIB_DIR}/x64:${VS_2015_LIB_DIR_UM}/x64" + linker.args "/LIBPATH:${VS_2017_LIB_DIR}/x64:${VS_2017_LIB_DIR_UM}/x64" } else { - linker.args "/LIBPATH:${VS_2015_LIB_DIR}/x86:${VS_2015_LIB_DIR_UM}/x86" + linker.args "/LIBPATH:${VS_2017_LIB_DIR}/x86:${VS_2017_LIB_DIR_UM}/x86" } } } diff --git a/native/src/snappyclient/cpp/SQLState.cpp b/native/src/snappyclient/cpp/SQLState.cpp index 5fbbc3c68..08d9b30ba 100644 --- a/native/src/snappyclient/cpp/SQLState.cpp +++ b/native/src/snappyclient/cpp/SQLState.cpp @@ -131,6 +131,8 @@ const SQLState SQLState::DATA_CONTAINER_CLOSED("40XD0", ExceptionSeverity::TRANSACTION_SEVERITY); const SQLState SQLState::THRIFT_PROTOCOL_ERROR("58015", ExceptionSeverity::SESSION_SEVERITY); +const SQLState SQLState::NODE_BUCKET_MOVED("X0Z18", + ExceptionSeverity::TRANSACTION_SEVERITY); void SQLState::staticInitialize() { } diff --git a/native/src/snappyclient/cpp/impl/ClientService.cpp b/native/src/snappyclient/cpp/impl/ClientService.cpp index 41adbdc67..1e0fe22cb 100644 --- a/native/src/snappyclient/cpp/impl/ClientService.cpp +++ b/native/src/snappyclient/cpp/impl/ClientService.cpp @@ -104,7 +104,10 @@ std::string ClientService::s_hostName; std::string ClientService::s_hostId; boost::mutex ClientService::s_globalLock; bool ClientService::s_initialized = false; - +std::set NetConnection::failoverSQLStateSet={ "08001", + "08003", "08004", "08006", "X0J15", "X0Z32", "XN001", "XN014", "XN016", + "58009", "58014", "58015", "58016", "58017", "57017", "58010", "30021", + "XJ040", "XJ041", "XSDA3", "XSDA4", "XSDAJ", "XJ217" }; void DEFAULT_OUTPUT_FN(const char *str) { LogWriter::info() << str << _SNAPPY_NEWLINE; } @@ -216,11 +219,23 @@ void ClientService::handleUnknownException(const char* op) { } void ClientService::handleSnappyException(const thrift::SnappyException& se) { + FailoverStatus status = NetConnection::getFailoverStatus(se.exceptionData.sqlState,se.exceptionData.errorCode,se); + if(status== FailoverStatus::NONE){ throw GET_SQLEXCEPTION(se); + }else if(status== FailoverStatus::RETRY){ + // need to do failover to new server, so get the next one + //close the connection explicitly since server may still be alive + close(); + std::set failedServers; + updateFailedServersForCurrent(failedServers,true,nullptr); + thrift::HostAddress hostAddr= m_connHosts.at(0); + openConnection(hostAddr,failedServers); + } } void ClientService::handleTTransportException(const char* op, const TTransportException& tte) { + checkConnection(op); throwSQLExceptionForNodeFailure(op, tte); @@ -235,18 +250,20 @@ void ClientService::handleTProtocolException(const char* op, } void ClientService::handleTException(const char* op, const TException& te) { - checkConnection(op); - - handleStdException(op, te); + if (this->m_loadBalance){ + // need to do failover to new server, so get the next one + //close the connection explicitly since server may still be alive + close(); + std::set failedServers; + updateFailedServersForCurrent(failedServers,true,nullptr); + thrift::HostAddress hostAddr= m_connHosts.at(0); + openConnection(hostAddr,failedServers); + }else{ + checkConnection(op); + + handleStdException(op, te); + } } -/* -void ClientService::handleException(const TException* te, - const std::set& failedServers, bool tryFailover, bool ignoreFailOver, - bool createNewConnection, const std::string& op) -{ - -}*/ - void ClientService::throwSQLExceptionForNodeFailure(const char* op, const std::exception& se) { std::ostringstream hostAddrStr; @@ -1518,3 +1535,39 @@ void ClientService::updateFailedServersForCurrent( controlService->searchRandomServer(failedServers, failure, pHost); } } +//void ClientService:: +FailoverStatus NetConnection::getFailoverStatus(const std::string& sqlState,const int32_t& errorCode, const TException& snappyEx){ + if(! std::strcmp(SQLState::SNAPPY_NODE_SHUTDOWN.getSQLState(),sqlState.c_str()) + || std::strcmp(SQLState::NODE_BUCKET_MOVED.getSQLState(),sqlState.c_str())){ + return FailoverStatus::RETRY; + } + /* for 08001 we have to, unfortunately, resort to string search to + * determine if failover makes sense or it is due to some problem + * with authentication or invalid properties */ + else if(!sqlState.compare("08001")){ + std::string msg(snappyEx.what()); + if(!msg.empty() && + ((msg.find("rror")!=std::string::npos) // cater to CONNECT_UNABLE_TO_CONNECT_TO_SERVER + || (msg.find("xception")!=std::string::npos ) // cater to CONNECT_SOCKET_EXCEPTION + ||(msg.find("ocket")!=std::string::npos))// cater to CONNECT_UNABLE_TO_OPEN_SOCKET_STREAM + ){ + return FailoverStatus::NEW_SERVER; + } + } + /* for 08004 we have to, unfortunately, resort to string search to + * determine if failover makes sense or it is due to some problem + * with authentication + */ + else if(!sqlState.compare("08004")){ + std::string msg(snappyEx.what()); + if(!msg.empty() && + (msg.find("connection refused") !=std::string::npos) + ){ + return FailoverStatus::NEW_SERVER; + } + } + else if(failoverSQLStateSet.find(sqlState)!= failoverSQLStateSet.end()){ + return FailoverStatus::NEW_SERVER; + } + return FailoverStatus::NONE; +} diff --git a/native/src/snappyclient/cpp/impl/ClientService.h b/native/src/snappyclient/cpp/impl/ClientService.h index 992961e81..9a190874d 100644 --- a/native/src/snappyclient/cpp/impl/ClientService.h +++ b/native/src/snappyclient/cpp/impl/ClientService.h @@ -63,7 +63,11 @@ namespace impl { class ClientTransport; class ControlConnection; - + enum class FailoverStatus :unsigned char{ + NONE, /** no failover to be done */ + NEW_SERVER, /** failover to a new server */ + RETRY /** retry to the same server */ + }; class SnappyDataClient : public thrift::SnappyDataServiceClient { public: SnappyDataClient(protocol::TProtocol* prot) : @@ -359,7 +363,14 @@ namespace impl { } }; +class NetConnection{ +private: + /** set of SQLState strings that denote failover should be done */ + static std::set failoverSQLStateSet; +public: + static FailoverStatus getFailoverStatus(const std::string& sqlState,const int32_t& errorCode, const TException& snappyEx); + }; } /* namespace impl */ } /* namespace client */ } /* namespace snappydata */ diff --git a/native/src/snappyclient/cpp/impl/ControlConnection.cpp b/native/src/snappyclient/cpp/impl/ControlConnection.cpp index c373459a1..42c2f0397 100644 --- a/native/src/snappyclient/cpp/impl/ControlConnection.cpp +++ b/native/src/snappyclient/cpp/impl/ControlConnection.cpp @@ -69,8 +69,12 @@ ControlConnection::ControlConnection(ClientService *const &service) :m_serverGro boost::assign::insert(m_snappyServerTypeSet)(service->getServerType(true,false,false)); std::copy(m_locators.begin(),m_locators.end(),std::inserter(m_controlHostSet,m_controlHostSet.end())); m_controlLocator = nullptr; +// //initliaze failoverSQLStateSet +// short arrSize = sizeof(failoverSQLStateArray)/sizeof(failoverSQLStateArray[0]); +// for(short i =0; i< arrSize;++i){ +// failoverSQLStateSet.insert(failoverSQLStateArray[i]); +// } } - const boost::optional ControlConnection::getOrCreateControlConnection( const std::vector& hostAddrs, ClientService *const &service, std::exception* failure){ @@ -102,9 +106,9 @@ const boost::optional ControlConnection::getOrCreateControlC " as registered but having different type " + Utils::getServerTypeString(contrConnServerType) + " than connection " + Utils::getServerTypeString( serviceServerType) ; SnappyExceptionData snappyExData; - // snappyExData.__set_sqlState("08006.C");// TODO: discuss with sumedh about correct SQLState + snappyExData.__set_sqlState("08006"); snappyExData.__set_reason(msg); - + //snappyExData.__set_errorCode(17002); //TODO:: Need to confirm with sumedh ex->__set_exceptionData(snappyExData); ex->__set_serverInfo(hostAddr.hostName + ":" + portStr ); throw ex; @@ -131,9 +135,7 @@ const boost::optional ControlConnection::getOrCreateControlC } void ControlConnection::getLocatorPreferredServer(thrift::HostAddress& prefHostAddr,std::set& failedServers, std::setserverGroups){ - // TODO: SanityManager m_controlLocator->getPreferredServer(prefHostAddr,m_snappyServerTypeSet,serverGroups,failedServers); - //TODO:SanityManager } void ControlConnection::getPreferredServer(thrift::HostAddress& preferredServer,std::exception* failure,bool forFailover){ std::set failedServers; @@ -143,7 +145,6 @@ void ControlConnection::getPreferredServer(thrift::HostAddress& preferredServer, void ControlConnection::getPreferredServer(thrift::HostAddress& preferredServer,std::exception* failure, std::set& failedServers, std::set& serverGroups,bool forFailover){ - //boost::lock_guard localGuard(m_lock); if(m_controlLocator == nullptr) { failoverToAvailableHost(failedServers, false,failure); @@ -155,22 +156,18 @@ void ControlConnection::getPreferredServer(thrift::HostAddress& preferredServer, try{ if(forFailover){ - //TODO: SanityManager //refresh the full host list std::vector prefServerAndAllHosts; m_controlLocator->getAllServersWithPreferredServer(prefServerAndAllHosts,m_snappyServerTypeSet,serverGroups,failedServers); - //TODO :: refresh new server list--like java do. if(! prefServerAndAllHosts.empty()) { std::vector allHosts(prefServerAndAllHosts.begin() +1,prefServerAndAllHosts.end()); refreshAllHosts(allHosts); preferredServer = prefServerAndAllHosts.at(0); } - //TODO :SanityManger }else{ getLocatorPreferredServer(preferredServer,failedServers,serverGroups); } - // TODO: SanityManager if(preferredServer.port <=0){ /*For this case we don't have a locator or locator unable to * determine a preferred server, so choose some server randomly @@ -187,14 +184,16 @@ void ControlConnection::getPreferredServer(thrift::HostAddress& preferredServer, } searchRandomServer(skipServers, failure,preferredServer); } - //TODO: Sanitymanger return; }catch(thrift::SnappyException &snEx){ - // TODO: - //Discuss with Sumedh - throw unexpectedError(snEx, m_controlHost); + FailoverStatus status = NetConnection::getFailoverStatus(snEx.exceptionData.sqlState,snEx.exceptionData.errorCode,snEx); + if(status== FailoverStatus::NONE){ + throw snEx; + }else if(status== FailoverStatus::RETRY){ + forFailover = true; + continue; + } }catch(TException &tex){ - // TODO: SanityManager //Search for a new host for locator query // for the first call do not mark controlhost as failed but retry(e.g. for a reconnect case) if(firstCall){ @@ -205,7 +204,7 @@ void ControlConnection::getPreferredServer(thrift::HostAddress& preferredServer, m_controlLocator->getOutputProtocol()->getTransport()->close(); failoverToAvailableHost(failedServers,true,failure); if(failure ==nullptr){ - failure = &(tex);// TODO: need to look again + failure = &(tex); } }catch(std::exception &ex){ throw unexpectedError(ex, m_controlHost); @@ -216,8 +215,6 @@ void ControlConnection::getPreferredServer(thrift::HostAddress& preferredServer, void ControlConnection::searchRandomServer(const std::set& skipServers,std::exception* failure, thrift::HostAddress& hostAddress){ - - //TODO: Need to discuss implemetation of this method and also ClientService:: updateFailedServersForCurrent with sumedh std::vector searchServers; // Note: Do not use unordered_set -- reason is http://www.cplusplus.com/forum/general/198319/ std::copy(m_controlHostSet.begin(),m_controlHostSet.end(),std::inserter(searchServers,searchServers.end())); @@ -241,7 +238,6 @@ void ControlConnection::failoverToAvailableHost(std::set& f std::exception* failure){ boost::lock_guard localGuard(m_lock); for(auto iterator = m_controlHostSet.begin();iterator!= m_controlHostSet.end(); ++iterator ){ - // NEXT: for(thrift::HostAddress controlAddr : m_controlHostSet){ thrift::HostAddress controlAddr = *iterator; if(checkFailedControlHosts && ! failedServers.empty() && (failedServers.find(controlAddr) != failedServers.end())){ continue; @@ -263,14 +259,13 @@ void ControlConnection::failoverToAvailableHost(std::set& f m_snappyServerType == thrift::ServerType::THRIFT_LOCATOR_CP_SSL || m_snappyServerType == thrift::ServerType::THRIFT_SNAPPY_BP_SSL || m_snappyServerType==thrift::ServerType::THRIFT_SNAPPY_CP_SSL){ - // TODO: Find out whether SnappyTSSLSocket is needed or not, or any other thing is required TSSLSocketFactory sslSocketFactory; tTransport = sslSocketFactory.createSocket(controlAddr.hostName,controlAddr.port); }else if(m_snappyServerType == thrift::ServerType::THRIFT_LOCATOR_BP || m_snappyServerType== thrift::ServerType::THRIFT_LOCATOR_CP || m_snappyServerType== thrift::ServerType::THRIFT_SNAPPY_BP || m_snappyServerType== thrift::ServerType::THRIFT_SNAPPY_CP){ - tTransport = boost::make_shared(controlAddr.hostName,controlAddr.port); // TODO: Find out whether SnappyTSocket is needed or not, or any other thing is required + tTransport = boost::make_shared(controlAddr.hostName,controlAddr.port); } tTransport->open(); TTransportFactory* transportFactory = nullptr; @@ -302,13 +297,12 @@ void ControlConnection::failoverToAvailableHost(std::set& f break; } }catch(TException &tExp){ - failure = &tExp; // TODO: need to look again + failure = &tExp; failedServers.insert(controlAddr); if(outTransport != nullptr){ outTransport->close(); } continue; - //goto NEXT; }catch(std::exception &ex){ throw unexpectedError(ex,controlAddr); } @@ -329,8 +323,9 @@ const thrift::SnappyException* ControlConnection:: unexpectedError(const std::ex } thrift::SnappyException *snappyEx = new thrift::SnappyException(); SnappyExceptionData snappyExData; - //snappyExData.__set_sqlState(std::string(SQLState::UNKNOWN_EXCEPTION));// TODO: discuss with sumedh about correct SQLState + snappyExData.__set_sqlState(std::string(SQLState::UNKNOWN_EXCEPTION.getSQLState())); snappyExData.__set_reason(ex.what()); + snappyEx->__set_exceptionData(snappyExData); std::string portNum; @@ -369,7 +364,6 @@ void ControlConnection::refreshAllHosts(const std::vector& m_controlHostSet.insert(allHosts.begin(),allHosts.end()); } - thrift::SnappyException* ControlConnection::failoverExhausted(const std::set& failedServers, std::exception* failure) { @@ -381,14 +375,11 @@ thrift::SnappyException* ControlConnection::failoverExhausted(const std::set__set_exceptionData(snappyExData); - //snappyExData.__set_sqlState();// - // TODO: complete this funtion snappyEx->__set_serverInfo(failedServerString); return snappyEx; } - diff --git a/native/src/snappyclient/cpp/impl/ControlConnection.h b/native/src/snappyclient/cpp/impl/ControlConnection.h index 36e53fe27..ae57e1f2e 100644 --- a/native/src/snappyclient/cpp/impl/ControlConnection.h +++ b/native/src/snappyclient/cpp/impl/ControlConnection.h @@ -68,6 +68,11 @@ namespace io { namespace client { namespace impl { +// enum class FailoverStatus :unsigned char{ +// NONE, /** no failover to be done */ +// NEW_SERVER, /** failover to a new server */ +// RETRY /** retry to the same server */ +// }; /** * Holds locator, server information to use for failover. Also provides * convenience methods to actually search for an appropriate host for @@ -97,6 +102,12 @@ namespace io { /** Global lock for {@link allConnections} */ static boost::mutex s_allConnsLock; +// /** array of SQLState strings that denote failover should be done */ +// std::string failoverSQLStateArray[23] = { "08001", +// "08003", "08004", "08006", "X0J15", "X0Z32", "XN001", "XN014", "XN016", +// "58009", "58014", "58015", "58016", "58017", "57017", "58010", "30021", +// "XJ040", "XJ041", "XSDA3", "XSDA4", "XSDAJ", "XJ217" }; +// std::set failoverSQLStateSet; /*********Member functions**************/ ControlConnection():m_serverGroups(std::set()){}; ControlConnection(ClientService *const &service); @@ -115,6 +126,7 @@ namespace io { void getPreferredServer(thrift::HostAddress& preferredServer,std::exception* failure, bool forFailover = false); + public: static const boost::optional getOrCreateControlConnection( diff --git a/native/src/snappyclient/cpp/types/DateTime.cpp b/native/src/snappyclient/cpp/types/DateTime.cpp index fe34dfa71..a6927b2ba 100644 --- a/native/src/snappyclient/cpp/types/DateTime.cpp +++ b/native/src/snappyclient/cpp/types/DateTime.cpp @@ -116,8 +116,8 @@ DateTime DateTime::parseTime(const std::string& str, boost::posix_time::time_duration td = boost::posix_time::duration_from_string(str); boost::gregorian::date::ymd_type ymd = today.year_month_day(); - return DateTime(ymd.year, ymd.month, ymd.day, td.hours(), td.minutes(), - td.seconds(), utc); + return DateTime(static_cast( ymd.year), static_cast(ymd.month), static_cast( ymd.day), static_cast(td.hours()), static_cast(td.minutes()), + static_cast(td.seconds()), utc); } catch (const std::exception& e) { std::string err(str); err.append(": ").append(e.what()); @@ -144,8 +144,8 @@ DateTime DateTime::parseDateTime(const std::string& str, // call parse_time_duration with remaining string boost::posix_time::time_duration td = boost::posix_time::duration_from_string(timeStr); - return DateTime(ymd.year, ymd.month, ymd.day, td.hours(), td.minutes(), - td.seconds(), utc); + return DateTime(static_cast(ymd.year), static_cast(ymd.month), static_cast(ymd.day), static_cast(td.hours()), static_cast(td.minutes()), + static_cast(td.seconds()), utc); } catch (const std::exception& e) { std::string err(str); err.append(": ").append(e.what()); @@ -286,7 +286,7 @@ void DateTime::toTime(std::string& str, const bool utc) const { InternalUtils::convertEpochSecsToPosixTime(m_secsSinceEpoch); const auto td = dateTime.time_of_day(); - bufp = toTimeString(td.hours(), td.minutes(), td.seconds(), bufp); + bufp = toTimeString(static_cast(td.hours()), static_cast(td.minutes()), static_cast(td.seconds()), bufp); str.append(buf, bufp - &buf[0]); } else { boost::local_time::local_date_time localTime( @@ -294,7 +294,7 @@ void DateTime::toTime(std::string& str, const bool utc) const { InternalUtils::s_localTimeZone); const auto td = localTime.time_of_day(); - bufp = toTimeString(td.hours(), td.minutes(), td.seconds(), bufp); + bufp = toTimeString(static_cast(td.hours()), static_cast(td.minutes()), static_cast(td.seconds()), bufp); str.append(buf, bufp - &buf[0]); } } catch (const std::exception&) { @@ -311,8 +311,8 @@ void DateTime::toDateTime(std::string& str, const bool utc) const { auto ymd = dateTime.date().year_month_day(); auto td = dateTime.time_of_day(); - toString(uint16_t(ymd.year), ymd.month.as_number(), ymd.day.as_number(), - td.hours(), td.minutes(), td.seconds(), 0, str); + toString(static_cast(ymd.year), static_cast(ymd.month.as_number()), static_cast(ymd.day.as_number()), + static_cast(td.hours()), static_cast(td.minutes()), static_cast(td.seconds()), 0, str); } else { boost::local_time::local_date_time localTime( InternalUtils::convertEpochSecsToPosixTime(m_secsSinceEpoch), @@ -320,8 +320,8 @@ void DateTime::toDateTime(std::string& str, const bool utc) const { auto ymd = localTime.date().year_month_day(); auto td = localTime.time_of_day(); - toString(uint16_t(ymd.year), ymd.month.as_number(), ymd.day.as_number(), - td.hours(), td.minutes(), td.seconds(), 0, str); + toString(static_cast(ymd.year), ymd.month.as_number(), ymd.day.as_number(), + static_cast(td.hours()), static_cast(td.minutes()), static_cast(td.seconds()), 0, str); } } catch (const std::exception&) { throw GET_SQLEXCEPTION2(SQLStateMessage::LANG_DATE_RANGE_EXCEPTION_MSG1, diff --git a/native/src/snappyclient/cpp/types/Timestamp.cpp b/native/src/snappyclient/cpp/types/Timestamp.cpp index 80e4fbda5..9ffeec385 100644 --- a/native/src/snappyclient/cpp/types/Timestamp.cpp +++ b/native/src/snappyclient/cpp/types/Timestamp.cpp @@ -117,8 +117,8 @@ Timestamp Timestamp::parseString(const std::string& str, boost::date_time::parse_delimited_time_duration< _snappy_impl::nano_time_duration>(timeStr); // nanoseconds will lie within int32 limits - return Timestamp(ymd.year, ymd.month, ymd.day, td.hours(), td.minutes(), - td.seconds(), static_cast(td.fractional_seconds()), utc); + return Timestamp(static_cast(ymd.year), static_cast(ymd.month), static_cast(ymd.day), static_cast(td.hours()), static_cast(td.minutes()), + static_cast(td.seconds()), static_cast(td.fractional_seconds()), utc); } catch (const std::exception& e) { std::string err(str); err.append(": ").append(e.what()); @@ -142,7 +142,7 @@ std::string& Timestamp::toString(std::string& str, const bool utc) const { boost::posix_time::time_duration td = dateTime.time_of_day(); return DateTime::toString(uint16_t(ymd.year), ymd.month.as_number(), - ymd.day.as_number(), td.hours(), td.minutes(), td.seconds(), m_nanos, + ymd.day.as_number(), static_cast(td.hours()), static_cast(td.minutes()), static_cast(td.seconds()), m_nanos, str); } catch (const std::exception&) { throw GET_SQLEXCEPTION2(SQLStateMessage::LANG_DATE_RANGE_EXCEPTION_MSG1, @@ -189,7 +189,7 @@ std::ostream& operator <<(std::ostream& stream, Timestamp ts) { boost::posix_time::time_duration td = dateTime.time_of_day(); return DateTime::toString(uint16_t(ymd.year), ymd.month.as_number(), - ymd.day.as_number(), td.hours(), td.minutes(), td.seconds(), + static_cast(ymd.day.as_number()), static_cast(td.hours()), static_cast(td.minutes()), static_cast(td.seconds()), ts.getNanos(), stream); } catch (const std::exception&) { throw GET_SQLEXCEPTION2(SQLStateMessage::LANG_DATE_RANGE_EXCEPTION_MSG1, diff --git a/native/src/snappyclient/headers/SQLState.h b/native/src/snappyclient/headers/SQLState.h index af498269b..7ec1081d7 100644 --- a/native/src/snappyclient/headers/SQLState.h +++ b/native/src/snappyclient/headers/SQLState.h @@ -377,6 +377,11 @@ namespace client { * protocol is detected (can be due to server failure). */ static const SQLState THRIFT_PROTOCOL_ERROR; + /** + * SQLState of the exception thrown when an error + * is detected due to bucket moved. + */ + static const SQLState NODE_BUCKET_MOVED; }; } /* namespace client */