Search in sources :

Example 6 with Measurement

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);
                }
            }
        }
    }
}
Also used : Measurement(com.srotya.sidewinder.core.storage.Measurement) DBMetadata(com.srotya.sidewinder.core.storage.DBMetadata) TimeSeries(com.srotya.sidewinder.core.storage.TimeSeries)

Example 7 with Measurement

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;
}
Also used : Measurement(com.srotya.sidewinder.core.storage.Measurement)

Example 8 with 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();
}
Also used : Measurement(com.srotya.sidewinder.core.storage.Measurement) IOException(java.io.IOException) NoneArchiver(com.srotya.sidewinder.core.storage.archival.NoneArchiver) IOException(java.io.IOException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) SeriesFieldMap(com.srotya.sidewinder.core.storage.SeriesFieldMap)

Example 9 with Measurement

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);
                }
            }
        }
    }
}
Also used : Measurement(com.srotya.sidewinder.core.storage.Measurement) DBMetadata(com.srotya.sidewinder.core.storage.DBMetadata) TimeSeries(com.srotya.sidewinder.core.storage.TimeSeries)

Example 10 with Measurement

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;
}
Also used : Measurement(com.srotya.sidewinder.core.storage.Measurement)

Aggregations

Measurement (com.srotya.sidewinder.core.storage.Measurement)25 File (java.io.File)13 IOException (java.io.IOException)11 Test (org.junit.Test)8 TimeSeries (com.srotya.sidewinder.core.storage.TimeSeries)7 DBMetadata (com.srotya.sidewinder.core.storage.DBMetadata)5 SeriesFieldMap (com.srotya.sidewinder.core.storage.SeriesFieldMap)5 BackgrounThreadFactory (com.srotya.sidewinder.core.utils.BackgrounThreadFactory)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ExecutorService (java.util.concurrent.ExecutorService)4 DataPoint (com.srotya.sidewinder.core.storage.DataPoint)3 ItemNotFoundException (com.srotya.sidewinder.core.storage.ItemNotFoundException)3 RejectException (com.srotya.sidewinder.core.storage.RejectException)3 Series (com.srotya.sidewinder.core.storage.Series)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ExecutionException (java.util.concurrent.ExecutionException)3 StorageEngine (com.srotya.sidewinder.core.storage.StorageEngine)2 NoneArchiver (com.srotya.sidewinder.core.storage.archival.NoneArchiver)2 ByzantineWriter (com.srotya.sidewinder.core.storage.compression.byzantine.ByzantineWriter)2