02.04., 9:00 - 11:00: Due to updates GitLab will be unavailable for some minutes between 09:00 and 11:00.

Commit a6e073a8 authored by Alessio Netti's avatar Alessio Netti

Further improvements to synchronization in collectagent

parent 7cd2bcac
......@@ -54,9 +54,11 @@ bool AnalyticsController::initialize(Configuration& settings) {
QueryEngine &_queryEngine = QueryEngine::getInstance();
if(_manager->probe(settings.cfgFilePath, settings.cfgFileName)) {
vector<string> topics;
_metadataStore->wait();
for(const auto& kv : _metadataStore->getMap())
if(kv.second.isValid())
topics.push_back(*kv.second.getPattern());
_metadataStore->release();
// Building the sensor navigator
try {
......
......@@ -48,9 +48,8 @@ void SensorCache::storeSensor(SensorId sid, uint64_t ts, int64_t val) {
wait();
auto sIt = sensorCache.find(sid);
if(sIt!=sensorCache.end()) {
CacheEntry& ce = sIt->second;
sIt->second.store(s);
release();
ce.store(s);
} else {
release();
// Spinning on the lock
......@@ -65,22 +64,23 @@ void SensorCache::storeSensor(SensorId sid, uint64_t ts, int64_t val) {
int64_t SensorCache::getSensor(SensorId sid, uint64_t avg) {
/* Remove the reserved bytes to leverage the standard find function */
sid.setRsvd(0);
wait();
sensorCache_t::iterator it = sensorCache.find(sid);
if (it == sensorCache.end()) {
release();
throw std::invalid_argument("Sid not found");
}
if (!it->second.checkValid())
{
{
release();
throw std::out_of_range("Sid outdated");
}
if (avg) {
return it->second.getAverage(avg);
} else {
return it->second.getLatest().value;
}
int64_t val = avg ? it->second.getAverage(avg) : it->second.getLatest().value;
release();
return val;
}
// Wildcards are not supported with string topics
......
......@@ -422,14 +422,14 @@ public:
* @param key Sensor key to be queried
* @return A reference to a sensorMetadata_t object
*/
const SensorMetadata& get(const string& key) {
SensorMetadata get(const string& key) {
wait();
auto it = _metadata.find(key);
if(it==_metadata.end()) {
release();
throw invalid_argument("MetadataStore: key " + key + " does not exist!");
} else {
const SensorMetadata& sm = it->second;
SensorMetadata sm = it->second;
release();
return sm;
}
......
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