Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FOGL-6891: Handle storage service restart #893

Draft
wants to merge 10 commits into
base: develop
Choose a base branch
from
4 changes: 4 additions & 0 deletions C/common/include/storage_client.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class StorageClient {
public:
StorageClient(HttpClient *client);
StorageClient(const std::string& hostname, const unsigned short port);
StorageClient(const std::string& hostname, const unsigned short port, std::map<std::thread::id, std::atomic<int>>*);
~StorageClient();
ResultSet *queryTable(const std::string& schema, const std::string& tablename, const Query& query);
ResultSet *queryTable(const std::string& tablename, const Query& query);
Expand Down Expand Up @@ -78,6 +79,8 @@ class StorageClient {

void registerManagement(ManagementClient *mgmnt) { m_management = mgmnt; };
bool createSchema(const std::string&);
std::map<std::thread::id, std::atomic<int>>* getSeqNumMap() { return &m_seqnum_map; }
std::ostringstream& getUrlBase() { return m_urlbase; }

private:
void handleUnexpectedResponse(const char *operation,
Expand All @@ -91,6 +94,7 @@ class StorageClient {
HttpClient *getHttpClient(void);
bool openStream();
bool streamReadings(const std::vector<Reading *> & readings);
void handle_storage_service_restart();

std::ostringstream m_urlbase;
std::string m_host;
Expand Down
2 changes: 1 addition & 1 deletion C/common/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
using namespace std;

// uncomment line below to get uSec level timestamps
// #define ADD_USEC_TS
#define ADD_USEC_TS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably best not to checkin with this uncommented


inline long getCurrTimeUsec()
{
Expand Down
10 changes: 8 additions & 2 deletions C/common/management_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,15 @@ HttpClient *ManagementClient::getHttpClient() {

std::thread::id thread_id = std::this_thread::get_id();

// m_logger->info("ManagementClient: Checking for HttpClient object: m_urlbase=%s", m_urlbase.str().c_str());

m_mtx_client_map.lock();
item = m_client_map.find(thread_id);

if (item == m_client_map.end() ) {

// Adding a new HttpClient
m_logger->info("ManagementClient: Instantiating a new HttpClient object: m_urlbase=%s", m_urlbase.str().c_str());
client = new HttpClient(m_urlbase.str());
m_client_map[thread_id] = client;
}
Expand All @@ -106,6 +109,8 @@ string payload;
try {
service.asJSON(payload);

m_logger->info("ManagementClient::registerService: POST to /fledge/service: payload=%s", payload.c_str());

auto res = this->getHttpClient()->request("POST", "/fledge/service", payload);
Document doc;
string response = res->content.string();
Expand Down Expand Up @@ -856,7 +861,7 @@ std::vector<AssetTrackingTuple*>& ManagementClient::getAssetTrackingTuples(const
return (*vec);
}
} catch (const SimpleWeb::system_error &e) {
m_logger->error("Fetch/parse of asset tracking tuples for service %s failed: %s.", serviceName.c_str(), e.what());
m_logger->error("%s: Fetch/parse of asset tracking tuples for service %s failed: %s.", __FUNCTION__, serviceName.c_str(), e.what());
//throw;
}
catch (...) {
Expand Down Expand Up @@ -1485,7 +1490,8 @@ AssetTrackingTuple* ManagementClient::getAssetTrackingTuple(const std::string& s
return tuple;
}
} catch (const SimpleWeb::system_error &e) {
m_logger->error("Fetch/parse of asset tracking tuples for service %s failed: %s.",
m_logger->error("%s: Fetch/parse of asset tracking tuples for service %s failed: %s.",
__FUNCTION__,
serviceName.c_str(),
e.what());
} catch (...) {
Expand Down
Loading