Commit ccd37c7f authored by Axel Auweter's avatar Axel Auweter
Browse files

Significant performance improvements for ticket #45

parent c1bd5deb
......@@ -85,7 +85,7 @@ public:
* @param start Start of the time series.
* @param end End of the time series.
*/
void query(std::list<SensorDataStoreReading>& result, SensorId sid, DCDBTimeStamp start, DCDBTimeStamp end);
void query(std::list<SensorDataStoreReading>& result, SensorId& sid, DCDBTimeStamp& start, DCDBTimeStamp& end);
/**
* @brief This function queries the integrated value (val * sec)
......@@ -96,7 +96,7 @@ public:
* @param end End of the time series.
* @return SDS_OK if ok, SDS_EMPTYSET if not at least 2 readings in interval.
*/
SDSQueryResult querySum(int64_t& result, SensorId sid, DCDBTimeStamp start, DCDBTimeStamp end);
SDSQueryResult querySum(int64_t& result, SensorId& sid, DCDBTimeStamp& start, DCDBTimeStamp& end);
/**
* @brief This function truncates all sensor data that is older than
......
......@@ -52,7 +52,7 @@ public:
/**
* @brief Raw constructor. Initializes the object with an existing raw time.
*/
DCDBTimeStamp(uint64_t ts);
DCDBTimeStamp(uint64_t ts) {raw = ts;}
/**
* @brief String constructor. Initializes the object by best guess from a time string.
......
......@@ -61,7 +61,7 @@ public:
* @param start Start of the time series.
* @param end End of the time series.
*/
void query(std::list<SensorDataStoreReading>& result, SensorId sid, DCDBTimeStamp start, DCDBTimeStamp end);
void query(std::list<SensorDataStoreReading>& result, SensorId& sid, DCDBTimeStamp& start, DCDBTimeStamp& end);
/**
* @brief This function queries the integrated value
......@@ -72,7 +72,7 @@ public:
* @param end End of the time series.
* @return SDS_OK if ok, SDS_EMPTYSET if not at least 2 readings in interval.
*/
SDSQueryResult querySum(int64_t& result, SensorId sid, DCDBTimeStamp start, DCDBTimeStamp end);
SDSQueryResult querySum(int64_t& result, SensorId& sid, DCDBTimeStamp& start, DCDBTimeStamp& end);
/**
* @brief This function truncates all sensor data that is older than
......
......@@ -103,7 +103,8 @@ DCDB_C_RESULT dcdbQuerySum(
/* Iterate over the expanded list of sensorIds and sum up the results */
for (std::list<SensorId>::iterator sit = sensorIds.begin(); sit != sensorIds.end(); sit++) {
int64_t tmp_result = 0;
if (sensorDataStore.querySum(tmp_result, *sit, start, end) == SDS_EMPTYSET) {
DCDBTimeStamp startTs(start), endTs(end);
if (sensorDataStore.querySum(tmp_result, *sit, startTs, endTs) == SDS_EMPTYSET) {
/* In case there is no reading for this sensor, invalidate everything */
*result = 0;
return DCDB_C_EMPTYSET;
......@@ -211,7 +212,8 @@ DCDB_C_RESULT dcdbQuerySumMultiple(
/* Iterate over the expanded list of sensorIds and sum up the results */
for (std::list<SensorId>::iterator sit = sensorIds.begin(); sit != sensorIds.end(); sit++) {
int64_t tmp_result = 0;
if (sensorDataStore.querySum(tmp_result, *sit, start, end) == SDS_EMPTYSET) {
DCDBTimeStamp startTs(start), endTs(end);
if (sensorDataStore.querySum(tmp_result, *sit, startTs, endTs) == SDS_EMPTYSET) {
/* In case there is no reading for this sensor, invalidate everything */
*result = 0;
return DCDB_C_EMPTYSET;
......
......@@ -153,7 +153,7 @@ void SensorDataStoreImpl::setTTL(uint64_t ttl)
* and creates a SensorDataStoreReading object for each
* entry which is stored in the result list.
*/
void SensorDataStoreImpl::query(std::list<SensorDataStoreReading>& result, SensorId sid, DCDBTimeStamp start, DCDBTimeStamp end)
void SensorDataStoreImpl::query(std::list<SensorDataStoreReading>& result, SensorId& sid, DCDBTimeStamp& start, DCDBTimeStamp& end)
{
CassError rc = CASS_OK;
CassStatement* statement = NULL;
......@@ -192,17 +192,17 @@ void SensorDataStoreImpl::query(std::list<SensorDataStoreReading>& result, Senso
const CassResult* cresult = cass_future_get_result(future);
CassIterator* rows = cass_iterator_from_result(cresult);
SensorDataStoreReading entry;
while (cass_iterator_next(rows)) {
const CassRow* row = cass_iterator_get_row(rows);
SensorDataStoreReading entry;
cass_int64_t ts, value;
cass_value_get_int64(cass_row_get_column_by_name(row, "ts"), &ts);
cass_value_get_int64(cass_row_get_column_by_name(row, "value"), &value);
entry.sensorId = sid;
entry.timeStamp = DCDBTimeStamp((uint64_t)ts);
entry.timeStamp = (uint64_t)ts;
entry.value = (int64_t)value;
result.push_back(entry);
......@@ -233,7 +233,7 @@ void SensorDataStoreImpl::query(std::list<SensorDataStoreReading>& result, Senso
* by first querying for the result set list using query() and then
* summing up the result.
*/
SDSQueryResult SensorDataStoreImpl::querySum(int64_t& result, SensorId sid, DCDBTimeStamp start, DCDBTimeStamp end)
SDSQueryResult SensorDataStoreImpl::querySum(int64_t& result, SensorId& sid, DCDBTimeStamp& start, DCDBTimeStamp& end)
{
std::list<SensorDataStoreReading> queryResult;
......@@ -429,7 +429,7 @@ void SensorDataStore::setTTL(uint64_t ttl)
* forwards to the insert function of the SensorDataStoreImpl
* class.
*/
void SensorDataStore::query(std::list<SensorDataStoreReading>& result, SensorId sid, DCDBTimeStamp start, DCDBTimeStamp end)
void SensorDataStore::query(std::list<SensorDataStoreReading>& result, SensorId& sid, DCDBTimeStamp& start, DCDBTimeStamp& end)
{
impl->query(result, sid, start, end);
}
......@@ -440,7 +440,7 @@ void SensorDataStore::query(std::list<SensorDataStoreReading>& result, SensorId
* forwards to the insert function of the SensorDataStoreImpl
* class.
*/
SDSQueryResult SensorDataStore::querySum(int64_t& result, SensorId sid, DCDBTimeStamp start, DCDBTimeStamp end)
SDSQueryResult SensorDataStore::querySum(int64_t& result, SensorId& sid, DCDBTimeStamp& start, DCDBTimeStamp& end)
{
return impl->querySum(result, sid, start, end);
}
......
......@@ -113,14 +113,6 @@ DCDBTimeStamp::DCDBTimeStamp()
setNow();
}
/**
* This constructor sets the internal raw value directly to the supplied argument.
*/
DCDBTimeStamp::DCDBTimeStamp(uint64_t ts)
{
raw = ts;
}
/**
* This constructor sets the time using the magic implemented in guessFromString.
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment