Skip to content

Commit

Permalink
Merge pull request #4081 from dseurotech/fix-configurable_avoidance_o…
Browse files Browse the repository at this point in the history
…f_fetch_metrics_before_upsert

⚡ [Datastore] Datastore - Reduce the number of queries to keep the registry info updates
  • Loading branch information
Coduz authored Jul 11, 2024
2 parents 8c549bb + 997258e commit e37c4fe
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.eclipse.kapua.service.datastore.internal.schema.Metadata;
import org.eclipse.kapua.service.datastore.internal.schema.MetricInfoSchema;
import org.eclipse.kapua.service.datastore.internal.schema.SchemaUtil;
import org.eclipse.kapua.service.datastore.internal.setting.DatastoreSettings;
import org.eclipse.kapua.service.datastore.internal.setting.DatastoreSettingsKey;
import org.eclipse.kapua.service.datastore.model.MetricInfo;
import org.eclipse.kapua.service.datastore.model.MetricInfoListResult;
import org.eclipse.kapua.service.datastore.model.query.MetricInfoQuery;
Expand Down Expand Up @@ -131,16 +133,19 @@ public BulkUpdateResponse upstore(MetricInfo[] metricInfos)

BulkUpdateRequest bulkRequest = new BulkUpdateRequest();
boolean performUpdate = false;
final boolean shouldFetchBeforeUpsertInCacheMiss = DatastoreSettings.getInstance().getBoolean(DatastoreSettingsKey.CONFIG_CACHE_METRICS_FETCH_FROM_SOURCE_BEFORE_UPSERT, true);
// Create a bulk request
for (MetricInfo metricInfo : metricInfos) {
String metricInfoId = MetricInfoField.getOrDeriveId(metricInfo.getId(), metricInfo);
// fix #REPLACE_ISSUE_NUMBER
if (!DatastoreCacheManager.getInstance().getMetricsCache().get(metricInfoId)) {
StorableId storableId = STORABLE_ID_FACTORY.newStorableId(metricInfoId);
MetricInfo storedField = find(metricInfo.getScopeId(), storableId);
if (storedField != null) {
DatastoreCacheManager.getInstance().getMetricsCache().put(metricInfoId, true);
continue;
if (shouldFetchBeforeUpsertInCacheMiss) {
StorableId storableId = STORABLE_ID_FACTORY.newStorableId(metricInfoId);
MetricInfo storedField = find(metricInfo.getScopeId(), storableId);
if (storedField != null) {
DatastoreCacheManager.getInstance().getMetricsCache().put(metricInfoId, true);
continue;
}
}
performUpdate = true;
Metadata metadata = mediator.getMetadata(metricInfo.getScopeId(), metricInfo.getFirstMessageOn().getTime());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public enum DatastoreSettingsKey implements SettingKey {
* Metadata cache maximum size (default value is no specific cache value is defined)
*/
CONFIG_CACHE_METADATA_LOCAL_SIZE_MAXIMUM("datastore.cache.metadata.local.size.maximum"),
/**
* Metrics behaviour switch - when the cache does not know a specific metric, should the system ask ES about it (set to true, default) or just send an upsert for non-cached metrics (set to
* false)?
*/
CONFIG_CACHE_METRICS_FETCH_FROM_SOURCE_BEFORE_UPSERT("datastore.cache.metrics.fetchBeforeUpsert"),
/**
* Enable datastore timing profile
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ datastore.cache.metadata.local.size.maximum=1000
#datastore.cache.metrics.local.size.maximum=1100
#datastore.cache.metrics.local.expire.after=120
#datastore.cache.metrics.local.expire.strategy=TOUCHED
#datastore.cache.metrics.fetchBeforeUpsert=false
#
# Datastore index prefix
datastore.index.prefix=
Expand Down

0 comments on commit e37c4fe

Please sign in to comment.