Skip to content

Commit

Permalink
* Ported IO serialization utilities to linux
Browse files Browse the repository at this point in the history
* Fixed memory leaks in RPC module and its tests
* Fixed crash that would happen upon transportation of exception from
  another thread
* Fixed crash that would happen upon elaboration of report with extended
  RPC error information
* Fixed bug in WWS module that would make channel properties (additional
  to the ones defined in wsutil.exe generated source) be ignored
* Reduced memory footprint of WWS hosts
* More fault tolerance/graceful degradation in Broker, WWS and RPC
  modules: attempt to recover from loss of connection or bad reply, using
  retries when applicable
* Added capability of non-hardcoded settings in XML configuration of
  applications
* Changes in most important parameters for tests no longer require
  recompilation from source because they are now XML configured
* Dependency libraries on Windows are updated: Boost v1.65.1 and POCO C++
  1.7.9
* Improvements on build & setup process for POSIX
* Build/install for Windows from source code of solution and dependencies
  is now fully automated by Powershell script
* Port to Windows 7: Win32 projects now run in Win7 (and theorically XP
  too) when compiled by vs140_xp toolset
  • Loading branch information
faburaya committed Nov 26, 2017
1 parent d5c95ee commit 1ef5f4f
Show file tree
Hide file tree
Showing 99 changed files with 7,400 additions and 4,502 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ ipch/
*.ncb
*.opensdf
*.sdf
*.db
*.VC.db
*.VC.opendb
*.cachefile

# Visual Studio profiler
Expand Down Expand Up @@ -151,7 +152,6 @@ ClientBin/
*~
*.dbmdl
*.[Pp]ublish.xml
*.pfx
*.publishsettings
*.xbf

Expand Down
597 changes: 350 additions & 247 deletions 3FD.sln

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions 3FD/3FD.WinRT.UWP.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -188,34 +188,34 @@
<PropertyGroup />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<GenerateManifest>false</GenerateManifest>
<IncludePath>$(BOOST_HOME)\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<IncludePath>$(BOOST_HOME)\include;$(VC_IncludePath);$(WindowsSDK_IncludePath)</IncludePath>
<IntDir>$(Platform)\$(Configuration)\WinRT.UWP\</IntDir>
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\$(MSBuildProjectName)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<GenerateManifest>false</GenerateManifest>
<IncludePath>$(BOOST_HOME)\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<IncludePath>$(BOOST_HOME)\include;$(VC_IncludePath);$(WindowsSDK_IncludePath)</IncludePath>
<IntDir>$(Platform)\$(Configuration)\WinRT.UWP\</IntDir>
<OutDir>$(SolutionDir)$(Platform)\$(Configuration)\$(MSBuildProjectName)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
<GenerateManifest>false</GenerateManifest>
<IncludePath>$(BOOST_HOME)\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<IncludePath>$(BOOST_HOME)\include;$(VC_IncludePath);$(WindowsSDK_IncludePath)</IncludePath>
<IntDir>$(Platform)\$(Configuration)\WinRT.UWP\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">
<GenerateManifest>false</GenerateManifest>
<IncludePath>$(BOOST_HOME)\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<IncludePath>$(BOOST_HOME)\include;$(VC_IncludePath);$(WindowsSDK_IncludePath)</IncludePath>
<IntDir>$(Platform)\$(Configuration)\WinRT.UWP\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<GenerateManifest>false</GenerateManifest>
<IncludePath>$(BOOST_HOME)\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<IncludePath>$(BOOST_HOME)\include;$(VC_IncludePath);$(WindowsSDK_IncludePath)</IncludePath>
<IntDir>$(Platform)\$(Configuration)\WinRT.UWP\</IntDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<GenerateManifest>false</GenerateManifest>
<IncludePath>$(BOOST_HOME)\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<IncludePath>$(BOOST_HOME)\include;$(VC_IncludePath);$(WindowsSDK_IncludePath)</IncludePath>
<IntDir>$(Platform)\$(Configuration)\WinRT.UWP\</IntDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
Expand Down
142 changes: 115 additions & 27 deletions 3FD/3FD.vcxproj

Large diffs are not rendered by default.

11 changes: 4 additions & 7 deletions 3FD/3FD.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,6 @@
<ClCompile Include="web_wws_impl_utils.cpp">
<Filter>Source Files\WWS</Filter>
</ClCompile>
<ClCompile Include="web_wws_impl_utils_wsasyncoper.cpp">
<Filter>Source Files\WWS</Filter>
</ClCompile>
<ClCompile Include="cmdline.cpp">
<Filter>Source Files\core</Filter>
</ClCompile>
Expand All @@ -400,13 +397,13 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
<Xml Include="config3fd-template.xml">
<CustomBuild Include="wsdl-example.wsdl">
<Filter>Resource Files</Filter>
</Xml>
</CustomBuild>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="wsdl-example.wsdl">
<Xml Include="3fd-config-template.xml">
<Filter>Resource Files</Filter>
</CustomBuild>
</Xml>
</ItemGroup>
</Project>
87 changes: 87 additions & 0 deletions 3FD/3fd-config-template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<common>
<log>
<!-- Has effect in POSIX & Windows desktop apps only -->
<entry key="writeToConsole" value="true" />

<entry key="purgeCount" value="10" />

<!-- The maximum age a log file (in days) can reach before being purged -->
<entry key="purgeAge" value="365" />

<!-- For Windows (Phone) Store apps, this is the only parameter that applies for logging.
It determines the maximum size (in KB) the text log can reach before it is shifted to a
new one. After that, the old file is compacted and moved to the app temporary data store. -->
<entry key="sizeLimit" value="2048" />
</log>
</common>

<framework>
<dependencies>
<!-- Has effect in POSIX & Windows desktop apps only -->
<entry key="opencl" value="false" />
</dependencies>

<stackTracing>
<!-- The initial reserved capacity for the container which stores the stack trace -->
<entry key="logInitialCap" value="64" />
</stackTracing>

<gc>
<entry key="msgLoopSleepTimeoutMillisecs" value="100" />
<entry key="memoryBlocksPoolInitialSize" value="128" />
<entry key="memoryBlocksPoolGrowingFactor" value="1.0" />
<entry key="sptrObjsHashTabInitSizeLog2" value="8" />

<!-- Should be less than 0.75 at most, so as to avoid
the performance degradation of linear probing -->
<entry key="sptrObjsHashTabLoadFactorThreshold" value="0.7" />
</gc>

<!-- OpenCL module is only present in POSIX & Windows desktop apps: -->
<opencl>
<entry key="maxSourceCodeLineLength" value="128" />
<entry key="maxBuildLogSize" value="5120" />
</opencl>

<!-- ISAM module is only present in Windows platform: -->
<isam>
<entry key="useWindowsFileCache" value="true" />
</isam>

<broker>
<entry key="dbConnTimeoutSecs" value="15" />
<entry key="dbConnMaxRetries" value="10" />
</broker>

<!-- RPC module is only present in Windows platform: -->
<rpc>
<entry key="cliSrvConnectMaxRetries" value="10" />
<entry key="cliSrvConnRetrySleepSecs" value="3" />
<entry key="cliCallMaxRetries" value="10" />

<!-- time interval for simple retry -->
<entry key="cliCallRetrySleepMs" value="500" />

<!-- time slot for retry with exponential back-off -->
<entry key="cliCallRetryTimeSlotMs" value="250" />
</rpc>

<!-- WWS module is only present in Windows platform: -->
<wws>
<entry key="proxyConnMaxRetries" value="10" />
<entry key="proxyCallMaxRetries" value="10" />

<!-- time interval for simple retry -->
<entry key="proxyCallRetrySleepSecs" value="3" />

<!-- time slot for retry with exponential back-off -->
<entry key="proxyCallRetryTimeSlotMs" value="500" />
</wws>
</framework>

<application>
<!-- Here you can insert settings for your application IN A FLAT HIERARCHY-->
</application>
</configuration>
21 changes: 16 additions & 5 deletions 3FD/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ cmake_minimum_required(VERSION 2.6)

project(3FD)

#####################
# Macro definitions:

add_definitions(
-DENABLE_3FD_CST
-DENABLE_3FD_ERR_IMPL_DETAILS
Expand All @@ -18,18 +20,20 @@ if(buildType STREQUAL release)
add_definitions(-DNDEBUG)
endif()

set(POCO_ROOT "/opt/poco-1.7.5")
set(BOOST_HOME "/opt/boost-1.60")

########################
# Include directories:

include_directories(
"${PROJECT_SOURCE_DIR}"
"${PROJECT_SOURCE_DIR}/../btree"
"${PROJECT_SOURCE_DIR}/../OpenCL"
"${POCO_ROOT}/include"
"${BOOST_HOME}/include"
"$ENV{POCO_ROOT}/include"
"$ENV{BOOST_HOME}/include"
)

########################
# Dependency libraries:

# Static library source files:
add_library(3FD STATIC
broker_impl.cpp
Expand Down Expand Up @@ -69,3 +73,10 @@ add_library(3FD STATIC
utils_memorypool.cpp
)

################
# Installation:

install(
TARGETS 3FD
DESTINATION "${PROJECT_SOURCE_DIR}/../build/bin"
)
6 changes: 3 additions & 3 deletions 3FD/broker.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ namespace broker
{
private:

Poco::Data::Session m_dbSession;
std::unique_ptr<Poco::Data::Session> m_dbSession;

string m_serviceURL;

Expand All @@ -152,7 +152,6 @@ namespace broker

/// <summary>
/// Helps synchronizing with an asynchronous write to a broker queue.
/// The underlying implementation is NOT THREAD SAFE!
/// </summary>
class INTFOPT IAsyncWrite
{
Expand Down Expand Up @@ -207,13 +206,14 @@ namespace broker
/// <summary>
/// Represents a queue in the broker, into which
/// a service can write messages to another.
/// The underlying implementation is NOT THREAD SAFE!
/// </summary>
/// <seealso cref="notcopiable" />
class QueueWriter : notcopiable, OdbcClient
{
private:

Poco::Data::Session m_dbSession;
std::unique_ptr<Poco::Data::Session> m_dbSession;

string m_serviceURL;

Expand Down
99 changes: 99 additions & 0 deletions 3FD/broker_impl.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "stdafx.h"
#include "broker_impl.h"
#include "configuration.h"
#include "logger.h"
#include "utils_io.h"

#include <Poco/Data/ODBC/Connector.h>

namespace _3fd
Expand All @@ -23,6 +27,7 @@ namespace broker
}
}


/// <summary>
/// Converts an enumerated type of message content validation to a label.
/// </summary>
Expand All @@ -42,6 +47,7 @@ namespace broker
}
}


/// <summary>
/// Initializes a new instance of the <see cref="OdbcClient"/> class.
/// </summary>
Expand All @@ -50,5 +56,98 @@ namespace broker
Poco::Data::ODBC::Connector::registerConnector();
}


/// <summary>
/// Gets an ODBC database connection.
/// Fails with an exception only after timeout and a number
/// of retries specified in framework configuration file.
/// </summary>
/// <param name="connString">The connection string.</param>
/// <returns>The succesfully established connection.</returns>
std::unique_ptr<Poco::Data::Session> GetConnection(const string &connString)
{
int retryCount(0);

while (true)
{
try
{
static const auto timeout =
core::AppConfig::GetSettings().framework.broker.dbConnTimeoutSecs;

return std::unique_ptr<Poco::Data::Session>(
new Poco::Data::Session("ODBC", connString, timeout)
);
}
catch (Poco::Data::ConnectionFailedException &ex)
{
static const auto maxRetries =
core::AppConfig::GetSettings().framework.broker.dbConnMaxRetries;

if (retryCount >= maxRetries)
ex.rethrow();
}

++retryCount;
}
}


/// <summary>
/// Checks the state of a database connection.
/// Fails with an exception only if disconnected and after a
/// number of retries specified in framework configuration file.
/// </summary>
/// <param name="connString">The connection string.</param>
/// <returns>A refence to the checked connection.</returns>
Poco::Data::Session &CheckConnection(Poco::Data::Session &dbSession)
{
if (dbSession.isConnected())
return dbSession;

static const auto maxRetries =
core::AppConfig::GetSettings().framework.broker.dbConnMaxRetries;

int retryCount(1);

if (retryCount <= maxRetries)
{
std::array<char, 512> bufErrMsg;

utils::SerializeTo(bufErrMsg,
"Lost connection to broker queue in database '", dbSession.uri(),
"'. Client will attempt reconnection up to ", maxRetries, " time(s)");

core::Logger::Write(bufErrMsg.data(), core::Logger::PRIO_WARNING);
}

// loop for reconnection:
while (true)
{
try
{
dbSession.reconnect();

std::array<char, 512> bufErrMsg;

utils::SerializeTo(bufErrMsg,
"Succesfully reconnected to broker queue in database '",
dbSession.uri(), '\'');

core::Logger::Write(bufErrMsg.data(), core::Logger::PRIO_WARNING);

return dbSession;
}
catch (Poco::Data::ConnectionFailedException &ex)
{
if (retryCount >= maxRetries)
ex.rethrow();
}

++retryCount;

}// end of loop
}

}// end of namespace broker
}// end of namespace _3fd
4 changes: 4 additions & 0 deletions 3FD/broker_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ namespace broker

const char *ToString(MessageContentValidation msgContentValidation);

std::unique_ptr<Poco::Data::Session> GetConnection(const string &connString);

Poco::Data::Session &CheckConnection(Poco::Data::Session &dbSession);

}// end of namespace broker
}// end of namespace _3fd

Expand Down
Loading

0 comments on commit 1ef5f4f

Please sign in to comment.