You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by jb...@apache.org on 2017/06/22 21:06:58 UTC
[4/5] geode-native git commit: GEODE-2552: Replaced sleeps and timers
with std::chrono
GEODE-2552: Replaced sleeps and timers with std::chrono
- Replace NanoSleep with std::this_thread::sleepFor
- Replaced custom time/duration with std::crono.
- Replaced NanoTimer with std::chrono.
- Replaced millisleep with std::this_thread::sleep_for.
Project: http://git-wip-us.apache.org/repos/asf/geode-native/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode-native/commit/bfec2fa7
Tree: http://git-wip-us.apache.org/repos/asf/geode-native/tree/bfec2fa7
Diff: http://git-wip-us.apache.org/repos/asf/geode-native/diff/bfec2fa7
Branch: refs/heads/develop
Commit: bfec2fa7e464bf8b7d45f259b6952ba6ba53f5ef
Parents: 0cc06f0
Author: Jacob Barrett <jb...@pivotal.io>
Authored: Sat Feb 25 13:18:12 2017 -0800
Committer: Ernie Burghardt <eb...@pivotal.io>
Committed: Thu Jun 22 13:54:12 2017 -0700
----------------------------------------------------------------------
src/cppcache/include/geode/geode_globals.hpp | 14 ---
.../integration-test/ThinClientDurable.hpp | 23 ++--
.../ThinClientDurableFailover.hpp | 17 +--
.../ThinClientDurableInterest.hpp | 15 +--
.../testThinClientConflation.cpp | 11 +-
.../testThinClientCqDurable.cpp | 10 +-
.../testThinClientHAEventIDMap.cpp | 22 ++--
.../testThinClientHAPeriodicAck.cpp | 18 ++--
src/cppcache/src/EvictionController.cpp | 19 ++--
src/cppcache/src/LocalRegion.cpp | 21 ++--
src/cppcache/src/Log.cpp | 6 +-
src/cppcache/src/NanoTimer.cpp | 53 ----------
src/cppcache/src/NanoTimer.hpp | 39 -------
src/cppcache/src/TcrConnectionManager.cpp | 14 ++-
src/cppcache/src/TcrEndpoint.cpp | 18 +++-
src/cppcache/src/Utils.cpp | 5 +-
src/cppcache/src/Utils.hpp | 6 +-
src/cppcache/src/statistics/HostStatSampler.cpp | 105 ++++++++++---------
src/cppcache/src/statistics/HostStatSampler.hpp | 8 +-
.../src/statistics/PoolStatsSampler.cpp | 44 ++++----
.../src/statistics/StatArchiveWriter.cpp | 51 +++++----
.../src/statistics/StatArchiveWriter.hpp | 12 ++-
src/cppcache/test/NanoTimerTest.cpp | 30 ------
src/quickstart/cpp/DurableClient.cpp | 2 +-
24 files changed, 249 insertions(+), 314 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/include/geode/geode_globals.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/include/geode/geode_globals.hpp b/src/cppcache/include/geode/geode_globals.hpp
index a22cfdd..ae3b56d 100644
--- a/src/cppcache/include/geode/geode_globals.hpp
+++ b/src/cppcache/include/geode/geode_globals.hpp
@@ -96,12 +96,8 @@
#define __has_cpp_attribute(x) 0
#endif
-<<<<<<< HEAD
#if __cplusplus >= 201402L
#if __has_cpp_attribute(deprecated)
-=======
-#if __cplusplus >= 201402L && __has_cpp_attribute(deprecated)
->>>>>>> GEODE-2531: Replace HostAsm::atomic with std::atomic.
// C++14 standard deprecated attribute
#define __DEPRECATED__(msg) [[deprecated(msg)]]
#else
@@ -126,16 +122,6 @@
#include <cstdint>
-namespace apache {
-namespace geode {
-namespace client {
-
-extern void CPPCACHE_EXPORT millisleep(uint32_t millis);
-
-} // namespace client
-} // namespace geode
-} // namespace apache
-
#include "Log.hpp"
#include "Assert.hpp"
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/integration-test/ThinClientDurable.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/integration-test/ThinClientDurable.hpp b/src/cppcache/integration-test/ThinClientDurable.hpp
index a10ef20..5faad78 100644
--- a/src/cppcache/integration-test/ThinClientDurable.hpp
+++ b/src/cppcache/integration-test/ThinClientDurable.hpp
@@ -29,6 +29,9 @@
#include "fw_dunit.hpp"
#include "ThinClientHelper.hpp"
+#include <thread>
+#include <chrono>
+
/* Testing Parameters Param's Value
Termination : Keepalive = true/ false, Client crash / Netdown
Restart Time: Before Timeout / After Timeout
@@ -61,7 +64,7 @@ class OperMonitor : public CacheListener {
CacheableInt32Ptr value = nullptr;
try {
value = std::dynamic_pointer_cast<CacheableInt32>(event.getNewValue());
- } catch (Exception) {
+ } catch (Exception&) {
// do nothing.
}
@@ -198,22 +201,22 @@ void feederUpdate(int value, int ignoreR2 = false) {
continue;
}
createIntEntry(regionNames[regIdx], mixKeys[0], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
createIntEntry(regionNames[regIdx], mixKeys[1], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
createIntEntry(regionNames[regIdx], mixKeys[2], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
createIntEntry(regionNames[regIdx], mixKeys[3], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
destroyEntry(regionNames[regIdx], mixKeys[0]);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
destroyEntry(regionNames[regIdx], mixKeys[1]);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
destroyEntry(regionNames[regIdx], mixKeys[2]);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
destroyEntry(regionNames[regIdx], mixKeys[3]);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
}
@@ -315,7 +318,7 @@ DUNIT_TASK_DEFINITION(FEEDER, FeederUpdate1)
feederUpdate(1);
// Wait 5 seconds for events to be removed from ha queues.
- apache::geode::client::millisleep(5000);
+ std::this_thread::sleep_for(std::chrono::seconds(5));
LOG("FeederUpdate1 complete.");
}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/integration-test/ThinClientDurableFailover.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/integration-test/ThinClientDurableFailover.hpp b/src/cppcache/integration-test/ThinClientDurableFailover.hpp
index 628c342..07fc425 100644
--- a/src/cppcache/integration-test/ThinClientDurableFailover.hpp
+++ b/src/cppcache/integration-test/ThinClientDurableFailover.hpp
@@ -29,6 +29,9 @@
#include "fw_dunit.hpp"
#include "ThinClientHelper.hpp"
+#include <thread>
+#include <chrono>
+
/* Testing Parameters Param's Value
Termination : Keepalive = true/ false, Client crash
Restart Time: Before Timeout / After Timeout
@@ -59,7 +62,7 @@ class OperMonitor : public CacheListener {
CacheableInt32Ptr value = nullptr;
try {
value = std::dynamic_pointer_cast<CacheableInt32>(event.getNewValue());
- } catch (Exception) {
+ } catch (Exception&) {
// do nothing.
}
@@ -182,9 +185,9 @@ void initClientCache(int redundancy, int durableTimeout, OperMonitorPtr& mon,
void feederUpdate(int value) {
createIntEntry(regionNames[0], mixKeys[0], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
createIntEntry(regionNames[0], mixKeys[1], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
/* Close Client 1 with option keep alive = true*/
@@ -219,7 +222,7 @@ DUNIT_TASK_DEFINITION(SERVER1, StartServer2)
}
// sleep for 3 seconds to allow redundancy monitor to detect new server.
- apache::geode::client::millisleep(3000);
+ std::this_thread::sleep_for(std::chrono::seconds(3));
LOG("SERVER started");
}
END_TASK_DEFINITION
@@ -247,7 +250,7 @@ DUNIT_TASK_DEFINITION(FEEDER, FeederUpdate1)
feederUpdate(1);
// Wait 5 seconds for events to be removed from ha queues.
- apache::geode::client::millisleep(5000);
+ std::this_thread::sleep_for(std::chrono::seconds(5));
LOG("FeederUpdate1 complete.");
}
@@ -258,7 +261,7 @@ DUNIT_TASK_DEFINITION(FEEDER, FeederUpdate2)
feederUpdate(2);
// Wait 5 seconds for events to be removed from ha queues.
- apache::geode::client::millisleep(5000);
+ std::this_thread::sleep_for(std::chrono::seconds(5));
LOG("FeederUpdate2 complete.");
}
@@ -307,7 +310,7 @@ DUNIT_TASK_DEFINITION(SERVER1, CloseServer1)
{
CacheHelper::closeServer(1);
// Wait 2 seconds to allow client failover.
- apache::geode::client::millisleep(2000);
+ std::this_thread::sleep_for(std::chrono::seconds(2));
LOG("SERVER closed");
}
END_TASK_DEFINITION
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/integration-test/ThinClientDurableInterest.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/integration-test/ThinClientDurableInterest.hpp b/src/cppcache/integration-test/ThinClientDurableInterest.hpp
index eba3789..29507e0 100644
--- a/src/cppcache/integration-test/ThinClientDurableInterest.hpp
+++ b/src/cppcache/integration-test/ThinClientDurableInterest.hpp
@@ -29,6 +29,9 @@
#include "fw_dunit.hpp"
#include "ThinClientHelper.hpp"
+#include <thread>
+#include <chrono>
+
/* This is to test
1- If client doesn't do explicit registration on reconnect, durable events shud
be recieved.
@@ -181,21 +184,21 @@ void initClientRemoveIntrest(int ClientIdx, OperMonitorPtr mon) {
void feederUpdate(int value) {
createIntEntry(regionNames[0], mixKeys[0], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
createIntEntry(regionNames[0], mixKeys[1], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
void feederUpdate1(int value) {
createIntEntry(regionNames[0], mixKeys[0], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
createIntEntry(regionNames[0], mixKeys[1], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
createIntEntry(regionNames[1], mixKeys[2], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
createIntEntry(regionNames[1], mixKeys[3], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
DUNIT_TASK_DEFINITION(FEEDER, FeederInit)
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/integration-test/testThinClientConflation.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/integration-test/testThinClientConflation.cpp b/src/cppcache/integration-test/testThinClientConflation.cpp
index aa93b8b..5be6103 100644
--- a/src/cppcache/integration-test/testThinClientConflation.cpp
+++ b/src/cppcache/integration-test/testThinClientConflation.cpp
@@ -18,6 +18,9 @@
#include "fw_dunit.hpp"
#include "ThinClientHelper.hpp"
+#include <thread>
+#include <chrono>
+
/* Testing Parameters Param's Value
Server Conflation: on / off
Client side conflation setting on/ off / server / not set
@@ -176,7 +179,7 @@ DUNIT_TASK_DEFINITION(CLIENT1, ValidateClient1Conflation)
{
// Client Already Initiated , Send Client Ready and wait
getHelper()->cachePtr->readyForEvents();
- apache::geode::client::millisleep(5000);
+ std::this_thread::sleep_for(std::chrono::seconds(5));
mon1C1->validate(true);
LOG("Client 1 region 1 verified for conflation = true");
@@ -191,7 +194,7 @@ DUNIT_TASK_DEFINITION(CLIENT2, ValidateClient2Conflation)
{
// Client Already Initiated , Send Client Ready and wait
getHelper()->cachePtr->readyForEvents();
- apache::geode::client::millisleep(5000);
+ std::this_thread::sleep_for(std::chrono::seconds(5));
mon1C2->validate(false);
LOG("Client 2 region 1 verified for conflation = false");
@@ -227,7 +230,7 @@ DUNIT_TASK_DEFINITION(CLIENT1, ValidateClient1Server)
{
// Client Already Initiated , Send Client Ready and wait
getHelper()->cachePtr->readyForEvents();
- apache::geode::client::millisleep(5000);
+ std::this_thread::sleep_for(std::chrono::seconds(5));
mon1C1->validate(true);
LOG("Client 1 region 1 verified for conflation = server");
@@ -242,7 +245,7 @@ DUNIT_TASK_DEFINITION(CLIENT2, ValidateClient2None)
{
// Client Already Initiated , Send Client Ready and wait
getHelper()->cachePtr->readyForEvents();
- apache::geode::client::millisleep(5000);
+ std::this_thread::sleep_for(std::chrono::seconds(5));
mon1C2->validate(true);
LOG("Client 2 region 1 verified for no conflation setting");
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/integration-test/testThinClientCqDurable.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/integration-test/testThinClientCqDurable.cpp b/src/cppcache/integration-test/testThinClientCqDurable.cpp
index 85f8e64..1039d07 100644
--- a/src/cppcache/integration-test/testThinClientCqDurable.cpp
+++ b/src/cppcache/integration-test/testThinClientCqDurable.cpp
@@ -24,6 +24,8 @@
#include <ace/OS.h>
#include <ace/High_Res_Timer.h>
#include <string>
+#include <thread>
+#include <chrono>
#define ROOT_SCOPE DISTRIBUTED_ACK
@@ -219,7 +221,7 @@ void RunDurableCqClient() {
// execute Cq Query
qry->execute();
- apache::geode::client::millisleep(10000);
+ std::this_thread::sleep_for(std::chrono::seconds(10));
LOGINFO("Executed new CqQuery");
@@ -230,7 +232,7 @@ void RunDurableCqClient() {
LOGINFO("Sent ReadyForEvents message to server");
// wait for some time to recieve events
- apache::geode::client::millisleep(10000);
+ std::this_thread::sleep_for(std::chrono::seconds(10));
// Close the Geode Cache with keepalive = true. Server will queue events
// for
@@ -266,7 +268,7 @@ void RunFeederClient() {
regionPtr->put(keyPtr, valPtr);
}
- apache::geode::client::millisleep(10000);
+ std::this_thread::sleep_for(std::chrono::seconds(10));
LOGINFO("put on 0-10 keys done.");
// Close the Geode Cache
@@ -299,7 +301,7 @@ void RunFeederClient1() {
regionPtr->put(keyPtr, valPtr);
}
- apache::geode::client::millisleep(10000);
+ std::this_thread::sleep_for(std::chrono::seconds(10));
LOGINFO("put on 0-10 keys done.");
// Close the Geode Cache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/integration-test/testThinClientHAEventIDMap.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/integration-test/testThinClientHAEventIDMap.cpp b/src/cppcache/integration-test/testThinClientHAEventIDMap.cpp
index ba7b6b9..6112541 100644
--- a/src/cppcache/integration-test/testThinClientHAEventIDMap.cpp
+++ b/src/cppcache/integration-test/testThinClientHAEventIDMap.cpp
@@ -20,6 +20,8 @@
#include <ace/OS.h>
#include <string>
+#include <thread>
+#include <chrono>
#define ROOT_NAME "testThinClientHAEventIDMap"
#define ROOT_SCOPE DISTRIBUTED_ACK
@@ -484,21 +486,21 @@ DUNIT_TASK_DEFINITION(CLIENT1, CreateEntries)
{
for (int value = 1; value <= 100; value++) {
createIntEntry(regionNames[0], keys[0], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
createIntEntry(regionNames[0], keys[1], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
createIntEntry(regionNames[0], keys[2], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
createIntEntry(regionNames[0], keys[3], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
createIntEntry(regionNames[1], keys[0], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
createIntEntry(regionNames[1], keys[1], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
createIntEntry(regionNames[1], keys[2], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
createIntEntry(regionNames[1], keys[3], value);
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
}
END_TASK_DEFINITION
@@ -514,8 +516,8 @@ END_TASK_DEFINITION
DUNIT_TASK_DEFINITION(CLIENT2, VerifyClient2Entries)
{
- apache::geode::client::millisleep(
- 30000); // wait 30 sec for notifications to complete
+ // wait 30 sec for notifications to complete
+ std::this_thread::sleep_for(std::chrono::seconds(30));
verifyIntEntry(regionNames[0], keys[0], 100);
verifyIntEntry(regionNames[0], keys[1], 100);
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/integration-test/testThinClientHAPeriodicAck.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/integration-test/testThinClientHAPeriodicAck.cpp b/src/cppcache/integration-test/testThinClientHAPeriodicAck.cpp
index d347c34..ddd47b3 100644
--- a/src/cppcache/integration-test/testThinClientHAPeriodicAck.cpp
+++ b/src/cppcache/integration-test/testThinClientHAPeriodicAck.cpp
@@ -20,6 +20,8 @@
#include <ace/OS.h>
#include <string>
+#include <thread>
+#include <chrono>
#define ROOT_NAME "testThinClientHAPeriodicAck"
#define ROOT_SCOPE DISTRIBUTED_ACK
@@ -488,21 +490,21 @@ DUNIT_TASK_DEFINITION(CLIENT1, CreateEntries)
{
for (int value = 1; value <= 100; value++) {
createIntEntry(regionNames[0], keys[0], value);
- apache::geode::client::millisleep(50);
+ std::this_thread::sleep_for(std::chrono::milliseconds(50));
createIntEntry(regionNames[0], keys[1], value);
- apache::geode::client::millisleep(50);
+ std::this_thread::sleep_for(std::chrono::milliseconds(50));
createIntEntry(regionNames[0], keys[2], value);
- apache::geode::client::millisleep(50);
+ std::this_thread::sleep_for(std::chrono::milliseconds(50));
createIntEntry(regionNames[0], keys[3], value);
- apache::geode::client::millisleep(50);
+ std::this_thread::sleep_for(std::chrono::milliseconds(50));
createIntEntry(regionNames[1], keys[0], value);
- apache::geode::client::millisleep(50);
+ std::this_thread::sleep_for(std::chrono::milliseconds(50));
createIntEntry(regionNames[1], keys[1], value);
- apache::geode::client::millisleep(50);
+ std::this_thread::sleep_for(std::chrono::milliseconds(50));
createIntEntry(regionNames[1], keys[2], value);
- apache::geode::client::millisleep(50);
+ std::this_thread::sleep_for(std::chrono::milliseconds(50));
createIntEntry(regionNames[1], keys[3], value);
- apache::geode::client::millisleep(50);
+ std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
}
END_TASK_DEFINITION
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/src/EvictionController.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/EvictionController.cpp b/src/cppcache/src/EvictionController.cpp
index 726e464..64049a2 100644
--- a/src/cppcache/src/EvictionController.cpp
+++ b/src/cppcache/src/EvictionController.cpp
@@ -23,7 +23,9 @@
#include "ReadWriteLock.hpp"
#include <string>
-using namespace apache::geode::client;
+namespace apache {
+namespace geode {
+namespace client {
const char* EvictionController::NC_EC_Thread = "NC EC Thread";
EvictionController::EvictionController(size_t maxHeapSize,
@@ -54,7 +56,7 @@ int EvictionController::svc() {
int64_t pendingEvictions = 0;
while (m_run) {
int64_t readInfo = 0;
- readInfo = (int64_t)m_queue.get(1500);
+ readInfo = m_queue.get(1500);
if (readInfo == 0) continue;
processHeapInfo(readInfo, pendingEvictions);
@@ -62,7 +64,7 @@ int EvictionController::svc() {
int32_t size = m_queue.size();
for (int i = 0; i < size; i++) {
int64_t readInfo = 0;
- readInfo = (int64_t)m_queue.get();
+ readInfo = m_queue.get();
if (readInfo == 0) continue;
processHeapInfo(readInfo, pendingEvictions);
}
@@ -104,8 +106,6 @@ void EvictionController::processHeapInfo(int64_t& readInfo,
pendingEvictions += bytesToEvict;
if (evictionPercentage > 100) evictionPercentage = 100;
orderEvictions(evictionPercentage);
- // Sleep for 10 seconds to allow the evictions to catch up
- // apache::geode::client::millisleep(10); //taken this out for now
}
}
@@ -120,7 +120,7 @@ void EvictionController::deregisterRegion(std::string& name) {
// Iterate over regions vector and remove the one that we need to remove
WriteGuard guard(m_regionLock);
for (size_t i = 0; i < m_regions.size(); i++) {
- std::string str = (std::string)m_regions.at(i);
+ std::string str = m_regions.at(i);
if (str == name) {
std::vector<std::string>::iterator iter = m_regions.begin();
m_regions.erase(iter + i);
@@ -149,12 +149,12 @@ void EvictionController::evict(int32_t percentage) {
{
ReadGuard guard(m_regionLock);
for (size_t i = 0; i < m_regions.size(); i++) {
- regionTmpVector.push_back((std::string)m_regions.at(i));
+ regionTmpVector.push_back(m_regions.at(i));
}
}
for (size_t i = 0; i < regionTmpVector.size(); i++) {
- std::string str = (std::string)regionTmpVector.at(i);
+ std::string str = regionTmpVector.at(i);
RegionPtr rptr;
m_cacheImpl->getRegion(str.c_str(), rptr);
if (rptr != nullptr) {
@@ -165,3 +165,6 @@ void EvictionController::evict(int32_t percentage) {
}
}
}
+} // namespace client
+} // namespace geode
+} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/src/LocalRegion.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/LocalRegion.cpp b/src/cppcache/src/LocalRegion.cpp
index 246e9db..2e465cb 100644
--- a/src/cppcache/src/LocalRegion.cpp
+++ b/src/cppcache/src/LocalRegion.cpp
@@ -21,7 +21,6 @@
#include "CacheImpl.hpp"
#include "CacheRegionHelper.hpp"
#include "CacheableToken.hpp"
-#include "NanoTimer.hpp"
#include "Utils.hpp"
#include "EntryExpiryHandler.hpp"
@@ -34,7 +33,9 @@
#include <vector>
#include <geode/PoolManager.hpp>
-using namespace apache::geode::client;
+namespace apache {
+namespace geode {
+namespace client {
LocalRegion::LocalRegion(const std::string& name, CacheImpl* cache,
const RegionInternalPtr& rPtr,
@@ -649,7 +650,7 @@ void LocalRegion::setRegionExpiryTask() {
uint32_t duration = getRegionExpiryDuration();
RegionExpiryHandler* handler =
new RegionExpiryHandler(rptr, getRegionExpiryAction(), duration);
- long expiryTaskId =
+ int64_t expiryTaskId =
CacheImpl::expiryTaskManager->scheduleExpiryTask(handler, duration, 0);
handler->setExpiryTaskId(expiryTaskId);
LOGFINE(
@@ -669,7 +670,7 @@ void LocalRegion::registerEntryExpiryTask(MapEntryImplPtr& entry) {
uint32_t duration = getEntryExpiryDuration();
EntryExpiryHandler* handler =
new EntryExpiryHandler(rptr, entry, getEntryExpirationAction(), duration);
- long id =
+ int64_t id =
CacheImpl::expiryTaskManager->scheduleExpiryTask(handler, duration, 0);
if (Log::finestEnabled()) {
CacheableKeyPtr key;
@@ -1036,9 +1037,6 @@ GfErrType LocalRegion::getAllNoThrow(const VectorOfCacheableKey& keys,
return err;
}
-namespace apache {
-namespace geode {
-namespace client {
// encapsulates actions that need to be taken for a put() operation
class PutActions {
public:
@@ -1605,9 +1603,6 @@ class InvalidateActions {
private:
LocalRegion& m_region;
};
-} // namespace client
-} // namespace geode
-} // namespace apache
template <typename TAction>
GfErrType LocalRegion::updateNoThrow(const CacheableKeyPtr& key,
@@ -3101,7 +3096,7 @@ void LocalRegion::evict(int32_t percentage) {
if (m_released || m_destroyPending) return;
if (m_entries != nullptr) {
int32_t size = m_entries->size();
- int32_t entriesToEvict = (int32_t)(percentage * size) / 100;
+ int32_t entriesToEvict = (percentage * size) / 100;
// only invoked from EvictionController so static_cast is always safe
LRUEntriesMap* lruMap = static_cast<LRUEntriesMap*>(m_entries);
LOGINFO("Evicting %d entries. Current entry count is %d", entriesToEvict,
@@ -3154,3 +3149,7 @@ CacheablePtr LocalRegion::handleReplay(GfErrType& err,
}
TombstoneListPtr LocalRegion::getTombstoneList() { return m_tombstoneList; }
+
+} // namespace client
+} // namespace geode
+} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/src/Log.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/Log.cpp b/src/cppcache/src/Log.cpp
index 5a456a4..e42b9e0 100644
--- a/src/cppcache/src/Log.cpp
+++ b/src/cppcache/src/Log.cpp
@@ -21,6 +21,8 @@
#include <string>
#include <utility>
#include <vector>
+#include <thread>
+#include <chrono>
#include <ace/ACE.h>
#include <ace/Guard_T.h>
@@ -370,7 +372,7 @@ void Log::init(LogLevel level, const char* logFileName, int32_t logFileLimit,
break;
}
// continue after some sleep
- apache::geode::client::millisleep(200);
+ std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
/* (don't throw exception; try appending to existing file instead)
if (renameResult < 0) {
@@ -435,7 +437,7 @@ void Log::writeBanner() {
break;
}
// continue after some sleep
- apache::geode::client::millisleep(200);
+ std::this_thread::sleep_for(std::chrono::milliseconds(200));
}
if (!g_log) {
g_isLogFileOpened = false;
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/src/NanoTimer.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/NanoTimer.cpp b/src/cppcache/src/NanoTimer.cpp
deleted file mode 100644
index 25ec2e4..0000000
--- a/src/cppcache/src/NanoTimer.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "NanoTimer.hpp"
-#include <ace/OS.h>
-#include <ace/Time_Value.h>
-#include <ace/High_Res_Timer.h>
-
-// @TODO: Make these actually nano granularity when possible.
-
-namespace apache {
-namespace geode {
-namespace client {
-
-int64_t NanoTimer::now() {
- ACE_Time_Value now = ACE_High_Res_Timer::gettimeofday_hr();
- return (now.sec() * 1000000000ll) /* convert secs to nanosecs */
- + (now.usec() * 1000ll); /* convert microsecs to nanosecs */
-}
-
-void NanoTimer::sleep(uint32_t nanos) {
- timespec spec;
- spec.tv_sec = 0L;
- spec.tv_nsec = nanos;
- timespec remaining;
- remaining.tv_sec = 0L;
- remaining.tv_nsec = 0L;
- ACE_OS::nanosleep(&spec, &remaining);
-}
-
-void millisleep(uint32_t millis) {
- time_t secs = millis / 1000;
- suseconds_t usecs = (millis % 1000) * 1000;
- ACE_Time_Value duration(secs, usecs);
- ACE_OS::sleep(duration);
-}
-} // namespace client
-} // namespace geode
-} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/src/NanoTimer.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/NanoTimer.hpp b/src/cppcache/src/NanoTimer.hpp
deleted file mode 100644
index 8dbf4d8..0000000
--- a/src/cppcache/src/NanoTimer.hpp
+++ /dev/null
@@ -1,39 +0,0 @@
-#pragma once
-
-#ifndef GEODE_NANOTIMER_H_
-#define GEODE_NANOTIMER_H_
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <geode/geode_globals.hpp>
-
-namespace apache {
-namespace geode {
-namespace client {
-
-class CPPCACHE_EXPORT NanoTimer {
- public:
- static int64_t now();
-
- static void sleep(uint32_t nanos);
-};
-} // namespace client
-} // namespace geode
-} // namespace apache
-
-#endif // GEODE_NANOTIMER_H_
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/src/TcrConnectionManager.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/TcrConnectionManager.cpp b/src/cppcache/src/TcrConnectionManager.cpp
index b59acc9..71d2347 100644
--- a/src/cppcache/src/TcrConnectionManager.cpp
+++ b/src/cppcache/src/TcrConnectionManager.cpp
@@ -33,7 +33,12 @@
#include "ServerLocation.hpp"
#include <ace/INET_Addr.h>
#include <set>
-using namespace apache::geode::client;
+#include <thread>
+#include <chrono>
+
+namespace apache {
+namespace geode {
+namespace client {
volatile bool TcrConnectionManager::isNetDown = false;
volatile bool TcrConnectionManager::TEST_DURABLE_CLIENT_CRASH = false;
@@ -475,7 +480,7 @@ void TcrConnectionManager::netDown() {
isNetDown = true;
// sleep for 15 seconds to allow ping and redundancy threads to pause.
- apache::geode::client::millisleep(15000);
+ std::this_thread::sleep_for(std::chrono::seconds(15));
{
ACE_Guard<ACE_Recursive_Thread_Mutex> guard(m_endpoints.mutex());
@@ -498,7 +503,7 @@ void TcrConnectionManager::revive() {
// sleep for 15 seconds to allow redundancy thread to reestablish
// connections.
- apache::geode::client::millisleep(15000);
+ std::this_thread::sleep_for(std::chrono::seconds(15));
}
int TcrConnectionManager::redundancy(volatile bool &isRunning) {
@@ -601,3 +606,6 @@ GfErrType TcrConnectionManager::sendSyncRequestRegisterInterest(
return m_redundancyManager->sendSyncRequestRegisterInterest(
request, reply, attemptFailover, endpoint, theHADM, region);
}
+} // namespace client
+} // namespace geode
+} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/src/TcrEndpoint.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/TcrEndpoint.cpp b/src/cppcache/src/TcrEndpoint.cpp
index 4458930..8e99010 100644
--- a/src/cppcache/src/TcrEndpoint.cpp
+++ b/src/cppcache/src/TcrEndpoint.cpp
@@ -24,7 +24,13 @@
#include "Utils.hpp"
#include "DistributedSystemImpl.hpp"
-using namespace apache::geode::client;
+#include <thread>
+#include <chrono>
+
+namespace apache {
+namespace geode {
+namespace client {
+
#define throwException(ex) \
{ \
LOGFINEST("%s: %s", ex.getName(), ex.getMessage()); \
@@ -236,7 +242,7 @@ GfErrType TcrEndpoint::createNewConnection(
LOGINFO("Timeout in handshake with endpoint[%s]", m_name.c_str());
err = GF_TIMOUT;
m_needToConnectInLock = true; // while creating the connection
- apache::geode::client::millisleep(50);
+ std::this_thread::sleep_for(std::chrono::milliseconds(50));
} catch (const GeodeIOException& ex) {
LOGINFO("IO error[%d] in handshake with endpoint[%s]: %s",
ACE_OS::last_error(), m_name.c_str(), ex.getMessage());
@@ -774,7 +780,7 @@ inline bool TcrEndpoint::handleIOException(const std::string& message,
m_needToConnectInLock = true;
return false;
}
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
return true;
}
@@ -989,7 +995,7 @@ GfErrType TcrEndpoint::sendRequestWithRetry(
connection only when not a sticky connection.
closeConnection( conn );
}*/
- apache::geode::client::millisleep(10);
+ std::this_thread::sleep_for(std::chrono::milliseconds(10));
int32_t type = request.getMessageType();
epFailure = (type != TcrMessage::QUERY && type != TcrMessage::PUTALL &&
type != TcrMessage::PUT_ALL_WITH_CALLBACK &&
@@ -1336,3 +1342,7 @@ void TcrEndpoint::sendRequestForChunkedResponse(const TcrMessage& request,
void TcrEndpoint::closeFailedConnection(TcrConnection*& conn) {
closeConnection(conn);
}
+
+} // namespace client
+} // namespace geode
+} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/src/Utils.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/Utils.cpp b/src/cppcache/src/Utils.cpp
index f6f4e61..bc0605d 100644
--- a/src/cppcache/src/Utils.cpp
+++ b/src/cppcache/src/Utils.cpp
@@ -16,20 +16,21 @@
*/
#include <cstdio>
+#include <chrono>
#include <ace/OS.h>
#include <ace/Recursive_Thread_Mutex.h>
#include <ace/INET_Addr.h>
#include "Utils.hpp"
-#include "NanoTimer.hpp"
namespace apache {
namespace geode {
namespace client {
int RandGen::operator()(size_t max) {
- unsigned int seed = static_cast<unsigned int>(NanoTimer::now());
+ unsigned int seed = static_cast<unsigned int>(
+ std::chrono::system_clock::now().time_since_epoch().count());
return ACE_OS::rand_r(&seed) % max;
}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/src/Utils.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/Utils.hpp b/src/cppcache/src/Utils.hpp
index 16904ca..8dbe76d 100644
--- a/src/cppcache/src/Utils.hpp
+++ b/src/cppcache/src/Utils.hpp
@@ -29,7 +29,6 @@
#include <geode/ExceptionTypes.hpp>
#include <geode/CacheableString.hpp>
#include <geode/DataOutput.hpp>
-#include "NanoTimer.hpp"
#include <geode/statistics/Statistics.hpp>
#include <geode/SystemProperties.hpp>
#include <geode/DistributedSystem.hpp>
@@ -37,6 +36,7 @@
#include <string>
#include <unordered_set>
#include <memory>
+#include <chrono>
#ifdef __GNUC__
extern "C" {
@@ -145,7 +145,9 @@ class CPPCACHE_EXPORT Utils {
if (DistributedSystem::getSystemProperties() != nullptr) {
return (DistributedSystem::getSystemProperties()
->getEnableTimeStatistics())
- ? NanoTimer::now()
+ ? std::chrono::duration_cast<std::chrono::nanoseconds>(
+ std::chrono::steady_clock::now().time_since_epoch())
+ .count()
: 0;
} else {
return 0;
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/src/statistics/HostStatSampler.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/HostStatSampler.cpp b/src/cppcache/src/statistics/HostStatSampler.cpp
index 966187a..7f8788f 100644
--- a/src/cppcache/src/statistics/HostStatSampler.cpp
+++ b/src/cppcache/src/statistics/HostStatSampler.cpp
@@ -27,19 +27,18 @@
#include <ace/OS_NS_sys_stat.h>
#include <utility>
#include <vector>
+#include <chrono>
+#include <thread>
#include "HostStatSampler.hpp"
#include "HostStatHelper.hpp"
#include "StatArchiveWriter.hpp"
-#include <NanoTimer.hpp>
#include <geode/DistributedSystem.hpp>
#include <geode/SystemProperties.hpp>
#include <geode/Log.hpp>
#include "GeodeStatisticsFactory.hpp"
#include <ClientHealthStats.hpp>
#include <ClientProxyMembershipID.hpp>
-using namespace apache::geode::statistics;
-using namespace apache::geode::client;
namespace apache {
namespace geode {
@@ -59,8 +58,6 @@ typedef std::vector<std::pair<std::string, int64_t> > g_fileInfo;
} // namespace geode
} // namespace apache
-using namespace apache::geode::statistics::globals;
-
extern "C" {
int selector(const dirent* d) {
@@ -115,6 +112,15 @@ int comparator(const dirent** d1, const dirent** d2) {
}
}
+namespace apache {
+namespace geode {
+namespace statistics {
+
+using std::chrono::high_resolution_clock;
+using std::chrono::duration_cast;
+using std::chrono::milliseconds;
+using std::chrono::nanoseconds;
+
const char* HostStatSampler::NC_HSS_Thread = "NC HSS Thread";
HostStatSampler::HostStatSampler(const char* filePath, int64_t sampleIntervalMs,
@@ -128,17 +134,16 @@ HostStatSampler::HostStatSampler(const char* filePath, int64_t sampleIntervalMs,
m_archiver = nullptr;
m_samplerStats = new StatSamplerStats();
- ACE_Time_Value startTimeValue = ACE_OS::gettimeofday();
- m_startTime = startTimeValue.msec();
+ m_startTime = system_clock::now();
m_pid = ACE_OS::getpid();
m_statMngr = statMngr;
m_archiveFileName = filePath;
- g_statFile = filePath;
+ globals::g_statFile = filePath;
m_sampleRate = sampleIntervalMs;
rollIndex = 0;
m_archiveDiskSpaceLimit = statDiskSpaceLimit;
- g_spaceUsed = 0;
+ globals::g_spaceUsed = 0;
if (statDiskSpaceLimit != 0) {
m_isStatDiskSpaceEnabled = true;
@@ -171,24 +176,24 @@ HostStatSampler::HostStatSampler(const char* filePath, int64_t sampleIntervalMs,
m_archiveFileSizeLimit = m_archiveDiskSpaceLimit;
}
- g_statFileWithExt = initStatFileWithExt();
+ globals::g_statFileWithExt = initStatFileWithExt();
#ifdef _WIN32
// replace all '\' with '/' to make everything easier..
- size_t len = g_statFile.length() + 1;
+ size_t len = globals::g_statFile.length() + 1;
char* slashtmp = new char[len];
- ACE_OS::strncpy(slashtmp, g_statFile.c_str(), len);
- for (size_t i = 0; i < g_statFile.length(); i++) {
+ ACE_OS::strncpy(slashtmp, globals::g_statFile.c_str(), len);
+ for (size_t i = 0; i < globals::g_statFile.length(); i++) {
if (slashtmp[i] == '/') {
slashtmp[i] = '\\';
}
}
- g_statFile = slashtmp;
+ globals::g_statFile = slashtmp;
delete[] slashtmp;
slashtmp = nullptr;
#endif
- std::string dirname = ACE::dirname(g_statFile.c_str());
+ std::string dirname = ACE::dirname(globals::g_statFile.c_str());
// struct dirent **resultArray;
// int entries_count = ACE_OS::scandir(dirname.c_str(), &resultArray,
// selector, comparator);
@@ -219,14 +224,14 @@ HostStatSampler::HostStatSampler(const char* filePath, int64_t sampleIntervalMs,
resultArray = nullptr;
}*/
- FILE* existingFile = fopen(g_statFileWithExt.c_str(), "r");
+ FILE* existingFile = fopen(globals::g_statFileWithExt.c_str(), "r");
if (existingFile != nullptr && statFileLimit > 0) {
fclose(existingFile);
/* adongre
* CID 28820: Resource leak (RESOURCE_LEAK)
*/
existingFile = nullptr;
- changeArchive(g_statFileWithExt);
+ changeArchive(globals::g_statFileWithExt);
} else {
writeGfs();
}
@@ -337,7 +342,9 @@ std::vector<Statistics*>& HostStatSampler::getNewStatistics() {
int64_t HostStatSampler::getSystemId() { return m_pid; }
-int64_t HostStatSampler::getSystemStartTime() { return m_startTime; }
+system_clock::time_point HostStatSampler::getSystemStartTime() {
+ return m_startTime;
+}
std::string HostStatSampler::getSystemDirectoryPath() {
ACE_utsname u;
@@ -358,7 +365,7 @@ void HostStatSampler::changeArchive(std::string filename) {
}
filename = chkForGFSExt(filename);
if (m_archiver != nullptr) {
- g_previoussamplesize = m_archiver->getSampleSize();
+ globals::g_previoussamplesize = m_archiver->getSampleSize();
m_archiver->closeFile();
}
// create new file only when tis file has some data; otherwise reuse it
@@ -622,16 +629,16 @@ void HostStatSampler::doSample(std::string& archivefilename) {
if (m_archiveFileSizeLimit != 0) {
int64_t size = m_archiver->getSampleSize();
int64_t bytesWritten =
- m_archiver->bytesWritten(); // + g_previoussamplesize;
+ m_archiver->bytesWritten(); // + globals::g_previoussamplesize;
if (bytesWritten > (m_archiveFileSizeLimit - size)) {
// roll the archive
changeArchive(archivefilename);
}
}
- g_spaceUsed += m_archiver->bytesWritten();
+ globals::g_spaceUsed += m_archiver->bytesWritten();
// delete older stat files if disk limit is about to be exceeded.
if ((m_archiveDiskSpaceLimit != 0) &&
- (g_spaceUsed >=
+ (globals::g_spaceUsed >=
(m_archiveDiskSpaceLimit - m_archiver->getSampleSize()))) {
checkDiskLimit();
}
@@ -643,10 +650,10 @@ void HostStatSampler::doSample(std::string& archivefilename) {
}
void HostStatSampler::checkDiskLimit() {
- g_fileInfo fileInfo;
- g_spaceUsed = 0;
+ globals::g_fileInfo fileInfo;
+ globals::g_spaceUsed = 0;
char fullpath[512] = {0};
- std::string dirname = ACE::dirname(g_statFile.c_str());
+ std::string dirname = ACE::dirname(globals::g_statFile.c_str());
// struct dirent **resultArray;
// int entries_count = ACE_OS::scandir(dirname.c_str(), &resultArray,
// selector, comparator);
@@ -658,11 +665,11 @@ void HostStatSampler::checkDiskLimit() {
ACE_OS::snprintf(fullpath, 512, "%s%c%s", dirname.c_str(),
ACE_DIRECTORY_SEPARATOR_CHAR, sds[i]->d_name);
ACE_OS::stat(fullpath, &statBuf);
- g_fileInfoPair = std::make_pair(fullpath, statBuf.st_size);
- fileInfo.push_back(g_fileInfoPair);
- g_spaceUsed += fileInfo[i - 1].second;
+ globals::g_fileInfoPair = std::make_pair(fullpath, statBuf.st_size);
+ fileInfo.push_back(globals::g_fileInfoPair);
+ globals::g_spaceUsed += fileInfo[i - 1].second;
}
- g_spaceUsed += m_archiver->bytesWritten();
+ globals::g_spaceUsed += m_archiver->bytesWritten();
/*for(int i = 0; i < entries_count; i++) {
ACE_OS::free ( resultArray[i] );
}
@@ -673,11 +680,11 @@ void HostStatSampler::checkDiskLimit() {
sds.close();
}
int fileIndex = 0;
- while ((g_spaceUsed >
+ while ((globals::g_spaceUsed >
m_archiveDiskSpaceLimit) /*&& (fileIndex < entries_count)*/) {
int64_t fileSize = fileInfo[fileIndex].second;
if (ACE_OS::unlink(fileInfo[fileIndex].first.c_str()) == 0) {
- g_spaceUsed -= fileSize;
+ globals::g_spaceUsed -= fileSize;
} else {
LOGWARN("%s\t%s\n", "Could not delete",
fileInfo[fileIndex].first.c_str());
@@ -697,8 +704,8 @@ int32_t HostStatSampler::svc(void) {
if (!m_isStatDiskSpaceEnabled) {
changeArchive(archivefilename);
}
- int32_t msSpentWorking = 0;
- int32_t msRate = static_cast<int32_t>(getSampleRate());
+ auto msSpentWorking = milliseconds::zero();
+ auto samplingRate = milliseconds(getSampleRate());
bool gotexception = false;
int waitTime = 0;
while (!m_stopRequested) {
@@ -714,26 +721,23 @@ int32_t HostStatSampler::svc(void) {
gotexception = false;
changeArchive(archivefilename);
}
- int64_t sampleStartNanos = NanoTimer::now();
+
+ auto sampleStart = high_resolution_clock::now();
doSample(archivefilename);
- int64_t sampleEndNanos = NanoTimer::now();
- int64_t nanosSpentWorking = sampleEndNanos - sampleStartNanos;
+ nanoseconds spentWorking = high_resolution_clock::now() - sampleStart;
// updating the sampler statistics
- accountForTimeSpentWorking(nanosSpentWorking);
- msSpentWorking = static_cast<int32_t>(nanosSpentWorking / 1000000);
-
- // Continous check for m_stopRequested to sped up stop time.
- int32_t msToWait = msRate - msSpentWorking;
- while (msToWait > 0) {
- ACE_Time_Value sleepTime;
- sleepTime.msec(msToWait > 100 ? 100 : msToWait);
- ACE_OS::sleep(sleepTime);
- msToWait -= 100;
- if (m_stopRequested) {
- break;
- }
+ accountForTimeSpentWorking(spentWorking.count());
+
+ // TODO: replace with condition on m_stopRequested
+ auto sleepDuration =
+ samplingRate - duration_cast<milliseconds>(spentWorking);
+ static const auto wakeInterval = milliseconds(100);
+ while (!m_stopRequested && sleepDuration > milliseconds::zero()) {
+ std::this_thread::sleep_for(
+ sleepDuration > wakeInterval ? wakeInterval : sleepDuration);
+ sleepDuration -= wakeInterval;
}
} catch (Exception& e) {
// log the exception and let the thread exit.
@@ -764,3 +768,6 @@ int32_t HostStatSampler::svc(void) {
m_running = false;
return 0;
}
+} // namespace statistics
+} // namespace geode
+} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/src/statistics/HostStatSampler.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/HostStatSampler.hpp b/src/cppcache/src/statistics/HostStatSampler.hpp
index a393815..7723799 100644
--- a/src/cppcache/src/statistics/HostStatSampler.hpp
+++ b/src/cppcache/src/statistics/HostStatSampler.hpp
@@ -22,6 +22,7 @@
#include <string>
#include <vector>
+#include <chrono>
#include <ace/Task.h>
#include <ace/Recursive_Thread_Mutex.h>
#include <geode/geode_globals.hpp>
@@ -50,6 +51,8 @@ namespace apache {
namespace geode {
namespace statistics {
+using std::chrono::system_clock;
+
class StatArchiveWriter;
class StatisticsManager;
/**
@@ -145,7 +148,7 @@ class CPPCACHE_EXPORT HostStatSampler : public ACE_Task_Base,
/**
* Returns the time this sampler's system was started.
*/
- int64_t getSystemStartTime();
+ system_clock::time_point getSystemStartTime();
/**
* Returns the path to this sampler's system directory; if it has one.
*/
@@ -212,7 +215,8 @@ class CPPCACHE_EXPORT HostStatSampler : public ACE_Task_Base,
StatisticsManager* m_statMngr;
int64_t m_pid;
- int64_t m_startTime;
+ system_clock::time_point m_startTime;
+
std::string initStatFileWithExt();
/**
* The archiveFile, after it exceeds archiveFileSizeLimit should be rolled
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/src/statistics/PoolStatsSampler.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/PoolStatsSampler.cpp b/src/cppcache/src/statistics/PoolStatsSampler.cpp
index 77a3f7b..96e5d78 100644
--- a/src/cppcache/src/statistics/PoolStatsSampler.cpp
+++ b/src/cppcache/src/statistics/PoolStatsSampler.cpp
@@ -21,10 +21,19 @@
#include <ThinClientPoolDM.hpp>
#include "GeodeStatisticsFactory.hpp"
#include <ClientHealthStats.hpp>
-#include <NanoTimer.hpp>
#include "HostStatHelper.hpp"
-using namespace apache::geode::statistics;
-using namespace apache::geode::client;
+#include <chrono>
+#include <thread>
+
+namespace apache {
+namespace geode {
+namespace statistics {
+
+using std::chrono::high_resolution_clock;
+using std::chrono::duration_cast;
+using std::chrono::milliseconds;
+using std::chrono::nanoseconds;
+
const char* PoolStatsSampler::NC_PSS_Thread = "NC PSS Thread";
PoolStatsSampler::PoolStatsSampler(int64_t sampleRate, CacheImpl* cache,
@@ -41,24 +50,20 @@ PoolStatsSampler::~PoolStatsSampler() {
int32_t PoolStatsSampler::svc() {
DistributedSystemImpl::setThreadName(NC_PSS_Thread);
- int32_t msSpentWorking = 0;
- int32_t msRate = static_cast<int32_t>(m_sampleRate);
+ auto msSpentWorking = milliseconds::zero();
+ auto samplingRate = milliseconds(m_sampleRate);
// ACE_Guard < ACE_Recursive_Thread_Mutex > _guard( m_lock );
while (!m_stopRequested) {
- int64_t sampleStartNanos = NanoTimer::now();
+ auto sampleStart = high_resolution_clock::now();
putStatsInAdminRegion();
- int64_t sampleEndNanos = NanoTimer::now();
- int64_t nanosSpentWorking = sampleEndNanos - sampleStartNanos;
- msSpentWorking = static_cast<int32_t>(nanosSpentWorking / 1000000);
- int32_t msToWait = msRate - msSpentWorking;
- while (msToWait > 0) {
- ACE_Time_Value sleepTime;
- sleepTime.msec(msToWait > 100 ? 100 : msToWait);
- ACE_OS::sleep(sleepTime);
- msToWait -= 100;
- if (m_stopRequested) {
- break;
- }
+ nanoseconds spentWorking = high_resolution_clock::now() - sampleStart;
+ auto sleepDuration =
+ samplingRate - duration_cast<milliseconds>(spentWorking);
+ static const auto wakeInterval = milliseconds(100);
+ while (!m_stopRequested && sleepDuration > milliseconds::zero()) {
+ std::this_thread::sleep_for(sleepDuration > wakeInterval ? wakeInterval
+ : sleepDuration);
+ sleepDuration -= wakeInterval;
}
}
return 0;
@@ -127,3 +132,6 @@ void PoolStatsSampler::putStatsInAdminRegion() {
LOGDEBUG("Exception occurred, trying again.");
}
}
+} // namespace statistics
+} // namespace geode
+} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/src/statistics/StatArchiveWriter.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/StatArchiveWriter.cpp b/src/cppcache/src/statistics/StatArchiveWriter.cpp
index 03bd92e..90e79f2 100644
--- a/src/cppcache/src/statistics/StatArchiveWriter.cpp
+++ b/src/cppcache/src/statistics/StatArchiveWriter.cpp
@@ -26,10 +26,16 @@
#include "StatArchiveWriter.hpp"
#include "GeodeStatisticsFactory.hpp"
-#include <NanoTimer.hpp>
-using namespace apache::geode::client;
-using namespace apache::geode::statistics;
+namespace apache {
+namespace geode {
+namespace statistics {
+
+using std::chrono::steady_clock;
+using std::chrono::system_clock;
+using std::chrono::duration_cast;
+using std::chrono::milliseconds;
+using std::chrono::nanoseconds;
// Constructor and Member functions of StatDataOutput class
@@ -321,20 +327,19 @@ StatArchiveWriter::StatArchiveWriter(std::string outfile,
this->sampler = samplerArg;
// write the time, system property etc.
- this->previousTimeStamp = NanoTimer::now();
- this->previousTimeStamp += NANOS_PER_MILLI / 2;
- this->previousTimeStamp /= NANOS_PER_MILLI;
- ACE_Time_Value now = ACE_OS::gettimeofday();
- int64_t epochsec = now.sec();
- int64_t initialDate = epochsec * 1000;
+ this->previousTimeStamp = steady_clock::now();
this->dataBuffer->writeByte(HEADER_TOKEN);
this->dataBuffer->writeByte(ARCHIVE_VERSION);
- this->dataBuffer->writeLong(initialDate);
+ this->dataBuffer->writeLong(
+ duration_cast<milliseconds>(system_clock::now().time_since_epoch())
+ .count());
int64_t sysId = sampler->getSystemId();
this->dataBuffer->writeLong(sysId);
- int64_t sysStartTime = sampler->getSystemStartTime();
- this->dataBuffer->writeLong(sysStartTime);
+ this->dataBuffer->writeLong(
+ duration_cast<milliseconds>(
+ sampler->getSystemStartTime().time_since_epoch())
+ .count());
int32_t tzOffset = ACE_OS::timezone();
// offset in milli seconds
tzOffset = tzOffset * -1 * 1000;
@@ -342,7 +347,7 @@ StatArchiveWriter::StatArchiveWriter(std::string outfile,
struct tm *tm_val;
time_t clock = ACE_OS::time();
- tm_val = localtime(&clock);
+ tm_val = ACE_OS::localtime(&clock);
char buf[512] = {0};
ACE_OS::strftime(buf, sizeof(buf), "%Z", tm_val);
std::string tzId(buf);
@@ -389,7 +394,7 @@ int64_t StatArchiveWriter::bytesWritten() { return bytesWrittenToFile; }
int64_t StatArchiveWriter::getSampleSize() { return m_samplesize; }
-void StatArchiveWriter::sample(int64_t timeStamp) {
+void StatArchiveWriter::sample(const steady_clock::time_point &timeStamp) {
ACE_Guard<ACE_Recursive_Thread_Mutex> guard(sampler->getStatListMutex());
m_samplesize = dataBuffer->getBytesWritten();
@@ -408,10 +413,7 @@ void StatArchiveWriter::sample(int64_t timeStamp) {
m_samplesize = dataBuffer->getBytesWritten() - m_samplesize;
}
-void StatArchiveWriter::sample() {
- int64_t timestamp = NanoTimer::now();
- sample(timestamp);
-}
+void StatArchiveWriter::sample() { sample(steady_clock::now()); }
void StatArchiveWriter::close() {
sample();
@@ -512,13 +514,13 @@ void StatArchiveWriter::resampleResources() {
}
}
-void StatArchiveWriter::writeTimeStamp(int64_t timeStamp) {
- timeStamp += NANOS_PER_MILLI / 2;
- timeStamp /= NANOS_PER_MILLI;
- int64_t delta = timeStamp - this->previousTimeStamp;
+void StatArchiveWriter::writeTimeStamp(
+ const steady_clock::time_point &timeStamp) {
+ int32_t delta =
+ duration_cast<milliseconds>(timeStamp - this->previousTimeStamp).count();
if (delta > MAX_SHORT_TIMESTAMP) {
dataBuffer->writeShort(static_cast<int16_t>(INT_TIMESTAMP_TOKEN));
- dataBuffer->writeInt(static_cast<int32_t>(delta));
+ dataBuffer->writeInt(delta);
} else {
dataBuffer->writeShort(static_cast<uint16_t>(delta));
}
@@ -615,3 +617,6 @@ void StatArchiveWriter::writeResourceInst(StatDataOutput *dataOut,
dataOut->writeByte(static_cast<int8_t>(instId));
}
}
+} // namespace statistics
+} // namespace geode
+} // namespace apache
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/src/statistics/StatArchiveWriter.hpp
----------------------------------------------------------------------
diff --git a/src/cppcache/src/statistics/StatArchiveWriter.hpp b/src/cppcache/src/statistics/StatArchiveWriter.hpp
index 10b50a3..55f30cb 100644
--- a/src/cppcache/src/statistics/StatArchiveWriter.hpp
+++ b/src/cppcache/src/statistics/StatArchiveWriter.hpp
@@ -33,6 +33,7 @@
#include <geode/Log.hpp>
#include <geode/DataOutput.hpp>
#include <NonCopyable.hpp>
+#include <chrono>
using namespace apache::geode::client;
@@ -54,7 +55,6 @@ const int16_t ILLEGAL_RESOURCE_INST_ID_TOKEN = -1;
const int32_t MAX_SHORT_RESOURCE_INST_ID = 65535;
const int32_t MAX_SHORT_TIMESTAMP = 65534;
const int32_t INT_TIMESTAMP_TOKEN = 65535;
-const int64_t NANOS_PER_MILLI = 1000000;
/** @file
*/
@@ -62,6 +62,10 @@ const int64_t NANOS_PER_MILLI = 1000000;
namespace apache {
namespace geode {
namespace statistics {
+
+using std::chrono::system_clock;
+using std::chrono::steady_clock;
+
/**
* Some of the classes which are used by the StatArchiveWriter Class
* 1. StatDataOutput // Just a wrapper around DataOutput so that the number of
@@ -200,7 +204,7 @@ class CPPCACHE_EXPORT StatArchiveWriter {
private:
HostStatSampler *sampler;
StatDataOutput *dataBuffer;
- int64_t previousTimeStamp;
+ steady_clock::time_point previousTimeStamp;
int32_t resourceTypeId;
int32_t resourceInstId;
int32_t statResourcesModCount;
@@ -215,7 +219,7 @@ class CPPCACHE_EXPORT StatArchiveWriter {
void sampleResources();
void resampleResources();
void writeResourceInst(StatDataOutput *, int32_t);
- void writeTimeStamp(int64_t timeStamp);
+ void writeTimeStamp(const steady_clock::time_point &timeStamp);
void writeStatValue(StatisticDescriptor *f, int64_t v, DataOutput dataOut);
ResourceType *getResourceType(Statistics *);
bool resourceInstMapHas(Statistics *sp);
@@ -232,7 +236,7 @@ class CPPCACHE_EXPORT StatArchiveWriter {
* Archives a sample snapshot at the given timeStamp.
* @param timeStamp a value obtained using NanoTimer::now.
*/
- void sample(int64_t timeStamp);
+ void sample(const steady_clock::time_point &timeStamp);
/**
* Archives a sample snapshot at the current time.
*/
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/cppcache/test/NanoTimerTest.cpp
----------------------------------------------------------------------
diff --git a/src/cppcache/test/NanoTimerTest.cpp b/src/cppcache/test/NanoTimerTest.cpp
deleted file mode 100644
index 7c10ab5..0000000
--- a/src/cppcache/test/NanoTimerTest.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <gtest/gtest.h>
-
-#include <NanoTimer.hpp>
-
-using namespace apache::geode::client;
-
-TEST(NanoTimerTest, ValidateSleep) {
- const int64_t before = NanoTimer::now();
- NanoTimer::sleep(3000000UL /* nano-seconds */);
- const int64_t after = NanoTimer::now();
- EXPECT_LE(3000000L /* nano-seconds */, (after - before))
- << "Slept at least three milli-seconds";
-}
http://git-wip-us.apache.org/repos/asf/geode-native/blob/bfec2fa7/src/quickstart/cpp/DurableClient.cpp
----------------------------------------------------------------------
diff --git a/src/quickstart/cpp/DurableClient.cpp b/src/quickstart/cpp/DurableClient.cpp
index 909172a..b406237 100644
--- a/src/quickstart/cpp/DurableClient.cpp
+++ b/src/quickstart/cpp/DurableClient.cpp
@@ -83,7 +83,7 @@ void RunDurableClient() {
LOGINFO("Sent ReadyForEvents message to server");
// wait for some time to recieve events
- apache::geode::client::millisleep(1000);
+ std::this_thread::sleep_for(std::chrono::seconds(1));
// Close the Geode Cache with keepalive = true. Server will queue events
// for