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

each send is considered a transaction #498

Merged
merged 5 commits into from
Aug 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Add: support for MongoDB replica sets (using the new -rplSet CLI parameter) (Issue #493)
- Fix: each send is now considered a separate transaction (Issue #478)
12 changes: 7 additions & 5 deletions src/lib/logMsg/logMsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
#include <time.h>
Copy link
Member

Choose a reason for hiding this comment

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

CHANGES_NEXT_RELEASE entry missing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in 4c5157a

#include <stdint.h> /* int64, ... */

#include "common/globals.h" /* transactionIdSet */



/******************************************************************************
Expand Down Expand Up @@ -1747,11 +1749,11 @@ do \
*
* LM_TRANSACTION_START -
*/
#define LM_TRANSACTION_START(ip, port, path) \
do \
{ \
transactionIdSet(); \
LM_I(("Starting transaction from %s:%d%s", ip, port, path)); \
#define LM_TRANSACTION_START(keyword, ip, port, path) \
do \
{ \
transactionIdSet(); \
LM_I(("Starting transaction %s %s:%d%s", keyword, ip, port, path)); \
} while (0)


Expand Down
21 changes: 9 additions & 12 deletions src/lib/ngsiNotify/onTimeIntervalThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ static void doNotification(OnIntervalThreadParams* params, const std::string& te
int current = getCurrentTime();

/* Send notification (only if subscription is not expired and there is actual data)*/
if (current < csi.expiration) {

if (current < csi.expiration)
{
/* Throttling check (only if throttling is used and at least one notification has been sent) */
if (csi.throttling < 0 || csi.lastNotification < 0 || csi.lastNotification + csi.throttling < current) {

if (csi.throttling < 0 || csi.lastNotification < 0 || csi.lastNotification + csi.throttling < current)
{
/* Query database for data */
NotifyContextRequest ncr;

// FIXME P7: mongoGetContextElementResponses ALWAYS returns SccOk !!!
if (mongoGetContextElementResponses(csi.entityIdVector, csi.attributeList, &(ncr.contextElementResponseVector), &err, tenant) != SccOk)
{
Expand All @@ -78,9 +79,6 @@ static void doNotification(OnIntervalThreadParams* params, const std::string& te

if (ncr.contextElementResponseVector.size() > 0)
{
// New transactionId for each notification
LM_TRANSACTION_START_URL(csi.url.c_str()); // OnTimeInterval Notification Starts

/* Complete NotifyContextRequest */
// FIXME: implement a proper originator string
ncr.originator.set("localhost");
Expand All @@ -95,16 +93,15 @@ static void doNotification(OnIntervalThreadParams* params, const std::string& te

ncr.contextElementResponseVector.release();
csi.release();

LM_TRANSACTION_END(); // OnTimeInterval Notification ends here
}
else
{
LM_T(LmtNotifier, ("notification not sent due to empty context elements response vector)"));
LM_T(LmtNotifier, ("notification not sent due to empty context elements response vector)"));
}
}
else {
LM_T(LmtNotifier, ("notification not sent due to throttling (current time: %d)", current));
else
{
LM_T(LmtNotifier, ("notification not sent due to throttling (current time: %d)", current));
}
}

Expand Down
23 changes: 20 additions & 3 deletions src/lib/rest/clientSocketHttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,46 +148,55 @@ std::string sendHttpSocket

++callNo;

LM_TRANSACTION_START("to", ip.c_str(), port, resource.c_str());

// Preconditions check
if (port == 0)
{
LM_E(("Runtime Error (port is ZERO)"));
LM_TRANSACTION_END();
return "error";
}

if (ip.empty())
{
LM_E(("Runtime Error (ip is empty)"));
LM_TRANSACTION_END();
return "error";
}

if (verb.empty())
{
LM_E(("Runtime Error (verb is empty)"));
LM_TRANSACTION_END();
return "error";
}

if (resource.empty())
{
LM_E(("Runtime Error (resource is empty)"));
LM_TRANSACTION_END();
return "error";
}

if ((content_type.empty()) && (!content.empty()))
{
LM_E(("Runtime Error (Content-Type is empty but there is actual content)"));
LM_TRANSACTION_END();
return "error";
}

if ((!content_type.empty()) && (content.empty()))
{
LM_E(("Runtime Error (Content-Type non-empty but there is no content)"));
LM_TRANSACTION_END();
return "error";
}

if ((curl = curl_easy_init()) == NULL)
{
LM_E(("Runtime Error (could not init libcurl)"));
LM_TRANSACTION_END();
return "error";
}

Expand Down Expand Up @@ -298,6 +307,7 @@ std::string sendHttpSocket
free(httpResponse->memory);
delete httpResponse;

LM_TRANSACTION_END();
return "error";
}

Expand Down Expand Up @@ -334,7 +344,7 @@ std::string sendHttpSocket
else
{
// The Response is here
LM_I(("Notification Successfully Sent"));
LM_I(("Notification Successfully Sent to %s", url.c_str()));
result.assign(httpResponse->memory, httpResponse->size);
}

Expand All @@ -345,6 +355,7 @@ std::string sendHttpSocket
free(httpResponse->memory);
delete httpResponse;

LM_TRANSACTION_END();
Copy link
Member

Choose a reason for hiding this comment

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

While we mantain the old function, the LM_TRANSACTION_START()/LM_TRANSACTION_END() should be also adjusted in the #else/#endif block below this lines.

Copy link
Member Author

Choose a reason for hiding this comment

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

True, just in case ...

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in 4c5157a

return result;
}

Expand All @@ -361,6 +372,8 @@ int socketHttpConnect(const std::string& host, unsigned short port)
struct addrinfo* peer;
char port_str[10];

LM_TRANSACTION_START("to", ip.c_str(), port, resource.c_str());

memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = 0;
Expand All @@ -386,12 +399,14 @@ int socketHttpConnect(const std::string& host, unsigned short port)
if (getaddrinfo(host.c_str(), port_str, &hints, &peer) != 0)
{
LM_W(("Notification failure for %s:%d (getaddrinfo: %s)", host.c_str(), port, strerror(errno)));
LM_TRANSACTION_END();
return -1;
}

if ((fd = socket(peer->ai_family, peer->ai_socktype, peer->ai_protocol)) == -1)
{
LM_W(("Notification failure for %s:%d (socket: %s)", host.c_str(), port, strerror(errno)));
LM_TRANSACTION_END();
return -1;
}

Expand All @@ -400,10 +415,12 @@ int socketHttpConnect(const std::string& host, unsigned short port)
freeaddrinfo(peer);
close(fd);
LM_W(("Notification failure for %s:%d (connect: %s)", host.c_str(), port, strerror(errno)));
LM_TRANSACTION_END();
return -1;
}

freeaddrinfo(peer);
LM_TRANSACTION_END();
return fd;
}

Expand Down Expand Up @@ -641,7 +658,7 @@ std::string sendHttpSocket
else
{
memcpy(response, buffer, nb);
LM_I(("Notification Successfully Sent"));
LM_I(("Notification Successfully Sent to %s:%d%s", ip.c_str(), port, resource.c_str()));
LM_T(LmtClientInputPayload, ("Received from HTTP server:\n%s", response));
}

Expand All @@ -651,7 +668,7 @@ std::string sendHttpSocket
else
{
LM_T(LmtClientInputPayload, ("not waiting for response"));
LM_I(("Notification Successfully Sent"));
LM_I(("Notification Successfully Sent to %s:%d%s", ip.c_str(), port, resource.c_str()));
result = "";
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/rest/rest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ static int connectionTreat
//
// Transaction starts here
//
LM_TRANSACTION_START(ip, port, url); // Incoming REST request starts
LM_TRANSACTION_START("from", ip, port, url); // Incoming REST request starts
Copy link
Member

Choose a reason for hiding this comment

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

It is not part of this PR but just to check... where is the LM_TRANSACTION_END() corresponding to this start? (A URL to the line/file in gitub.com will be welcomed ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

NTC




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ payload='<?xml version="1.0"?>
orionCurl --url "$url" --payload "$payload"
SUB_ID=$(echo "$_response" | grep subscriptionId | awk -F '>' '{print $2}' | awk -F '<' '{print $1}' | grep -v '^$' )

# Interval from 0 to 5: we recieve some three notifications (t=0, t=2, t=4)
# Interval from 0 to 5: we receive some three notifications (t=0, t=2, t=4)
sleep 5

echo "2: ++++++++++++++++++++"
Expand All @@ -100,7 +100,7 @@ payload='<?xml version="1.0"?>
</updateContextSubscriptionRequest>'
orionCurl --url "$url" --payload "$payload"

#Interval from 5 to 14: we will recieve three notifications (t=5, t=9, t=13)
# Interval from 5 to 14: we will receive three notifications (t=5, t=9, t=13)
sleep 9

echo "3: ++++++++++++++++++++"
Expand Down Expand Up @@ -370,6 +370,3 @@ TIMES: REGEX((0, 2, 4, 5, 9, 13, 14, 24, 34, 35, 37, 39, 53, 65, 67, 69|0, 2, 4,
--TEARDOWN--
brokerStop CB
accumulatorStop

mv /tmp/contextBroker.log /tmp/contextBroker.log.oti