use of com.srotya.sidewinder.core.storage.Measurement in project sidewinder by srotya.
the class DiskStorageEngine method updateTimeSeriesRetentionPolicy.
@Override
public void updateTimeSeriesRetentionPolicy(String dbName, int retentionHours) throws IOException {
DBMetadata metadata = dbMetadataMap.get(dbName);
synchronized (dbMetadataMap) {
metadata.setRetentionHours(retentionHours);
saveDBMetadata(dbName, metadata);
Map<String, Measurement> measurementMap = databaseMap.get(dbName);
if (measurementMap != null) {
for (Measurement sortedMap : measurementMap.values()) {
for (TimeSeries timeSeries : sortedMap.getTimeSeries()) {
timeSeries.setRetentionHours(retentionHours);
}
}
}
}
}
use of com.srotya.sidewinder.core.storage.Measurement in project sidewinder by srotya.
the class DiskStorageEngine method getOrCreateMeasurement.
protected Measurement getOrCreateMeasurement(Map<String, Measurement> measurementMap, String measurementName, String dbName) throws IOException {
Measurement measurement = measurementMap.get(measurementName);
if (measurement == null) {
synchronized (databaseMap) {
if ((measurement = measurementMap.get(measurementName)) == null) {
measurement = new PersistentMeasurement();
measurement.configure(conf, this, dbName, measurementName, dbIndexPath(dbName), dbDirectoryPath(dbName), dbMetadataMap.get(dbName), bgTaskPool);
measurementMap.put(measurementName, measurement);
logger.info("Created new measurement:" + measurementName);
metricsMeasurementCounter.inc();
}
}
}
return measurement;
}
use of com.srotya.sidewinder.core.storage.Measurement in project sidewinder by srotya.
the class MemStorageEngine method configure.
@Override
public void configure(Map<String, String> conf, ScheduledExecutorService bgTaskPool) throws IOException {
this.conf = conf;
this.bgTaskPool = bgTaskPool;
this.defaultRetentionHours = Integer.parseInt(conf.getOrDefault(RETENTION_HOURS, String.valueOf(DEFAULT_RETENTION_HOURS)));
logger.info("Setting default timeseries retention hours policy to:" + defaultRetentionHours);
databaseMap = new ConcurrentHashMap<>();
dbMetadataMap = new ConcurrentHashMap<>();
try {
archiver = (Archiver) Class.forName(conf.getOrDefault("archiver.class", NoneArchiver.class.getName())).newInstance();
archiver.init(conf);
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
logger.log(Level.SEVERE, "Failed to instantiate archiver", e);
}
this.defaultTimebucketSize = Integer.parseInt(conf.getOrDefault(DEFAULT_BUCKET_SIZE, String.valueOf(DEFAULT_TIME_BUCKET_CONSTANT)));
conf.put(PERSISTENCE_DISK, "false");
if (bgTaskPool != null) {
bgTaskPool.scheduleAtFixedRate(() -> {
for (Entry<String, Map<String, Measurement>> measurementMap : databaseMap.entrySet()) {
for (Entry<String, Measurement> measurementEntry : measurementMap.getValue().entrySet()) {
Measurement value = measurementEntry.getValue();
try {
value.collectGarbage(archiver);
} catch (IOException e) {
logger.log(Level.SEVERE, "Failed collect garbage for measurement:" + value.getMeasurementName(), e);
}
}
}
}, Integer.parseInt(conf.getOrDefault(GC_FREQUENCY, DEFAULT_GC_FREQUENCY)), Integer.parseInt(conf.getOrDefault(GC_DELAY, DEFAULT_GC_DELAY)), TimeUnit.SECONDS);
if (Boolean.parseBoolean(conf.getOrDefault(StorageEngine.COMPACTION_ENABLED, "false"))) {
logger.info("Compaction is enabled");
bgTaskPool.scheduleAtFixedRate(() -> {
for (Entry<String, Map<String, Measurement>> measurementMap : databaseMap.entrySet()) {
for (Entry<String, Measurement> measurementEntry : measurementMap.getValue().entrySet()) {
Measurement value = measurementEntry.getValue();
try {
value.compact();
} catch (Exception e) {
logger.log(Level.SEVERE, "Failed compaction for measurement:" + value.getMeasurementName(), e);
}
}
}
}, Integer.parseInt(conf.getOrDefault(COMPACTION_FREQUENCY, DEFAULT_COMPACTION_FREQUENCY)), Integer.parseInt(conf.getOrDefault(COMPACTION_DELAY, DEFAULT_COMPACTION_DELAY)), TimeUnit.SECONDS);
} else {
logger.warning("Compaction is disabled");
}
}
enableMetricsService();
}
use of com.srotya.sidewinder.core.storage.Measurement in project sidewinder by srotya.
the class MemStorageEngine method updateTimeSeriesRetentionPolicy.
@Override
public void updateTimeSeriesRetentionPolicy(String dbName, int retentionHours) {
DBMetadata metadata = dbMetadataMap.get(dbName);
synchronized (metadata) {
metadata.setRetentionHours(retentionHours);
Map<String, Measurement> measurementMap = databaseMap.get(dbName);
if (measurementMap != null) {
for (Measurement sortedMap : measurementMap.values()) {
for (TimeSeries timeSeries : sortedMap.getTimeSeries()) {
timeSeries.setRetentionHours(retentionHours);
}
}
}
}
}
use of com.srotya.sidewinder.core.storage.Measurement in project sidewinder by srotya.
the class MemStorageEngine method getOrCreateMeasurement.
protected Measurement getOrCreateMeasurement(Map<String, Measurement> measurementMap, String dbName, String measurementName) throws IOException {
Measurement measurement = measurementMap.get(measurementName);
if (measurement == null) {
synchronized (measurementMap) {
if ((measurement = measurementMap.get(measurementName)) == null) {
measurement = new MemoryMeasurement();
measurement.configure(conf, this, dbName, measurementName, "", "", dbMetadataMap.get(dbName), bgTaskPool);
measurementMap.put(measurementName, measurement);
logger.info("Created new measurement:" + measurementName);
metricsMeasurementCounter.inc();
}
}
}
return measurement;
}
Aggregations