Search in sources :

Example 6 with TimeSeries

use of com.srotya.sidewinder.core.storage.TimeSeries in project sidewinder by srotya.

the class TestPersistentMeasurement method testOptimizationsLambdaInvoke.

@Test
public void testOptimizationsLambdaInvoke() throws IOException {
    long ts = System.currentTimeMillis();
    MiscUtils.delete(new File("target/db42/"));
    List<String> tags = Arrays.asList("test=1", "test=2");
    PersistentMeasurement m = new PersistentMeasurement();
    Map<String, String> map = new HashMap<>();
    map.put("disk.compression.class", ByzantineWriter.class.getName());
    map.put("malloc.file.max", String.valueOf(2 * 1024 * 1024));
    m.configure(map, null, DBNAME, "m1", "target/db42/index", "target/db42/data", metadata, bgTaskPool);
    int LIMIT = 1000;
    for (int i = 0; i < LIMIT; i++) {
        TimeSeries t = m.getOrCreateTimeSeries("value1", tags, 4096, false, map);
        t.addDataPoint(TimeUnit.MILLISECONDS, ts + i * 1000, 1L);
    }
    m.runCleanupOperation("print", s -> {
        // don't cleanup anything
        return new ArrayList<>();
    });
}
Also used : TimeSeries(com.srotya.sidewinder.core.storage.TimeSeries) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ByzantineWriter(com.srotya.sidewinder.core.storage.compression.byzantine.ByzantineWriter) ArrayList(java.util.ArrayList) File(java.io.File) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Test(org.junit.Test)

Example 7 with TimeSeries

use of com.srotya.sidewinder.core.storage.TimeSeries in project sidewinder by srotya.

the class TestMemStorageEngine method testCompactionThreadSafety.

@Test
public void testCompactionThreadSafety() throws IOException, InterruptedException {
    MemStorageEngine engine = new MemStorageEngine();
    HashMap<String, String> conf2 = new HashMap<>();
    conf2.put("default.bucket.size", "409600");
    conf2.put("compaction.enabled", "true");
    conf2.put("use.query.pool", "false");
    engine.configure(conf2, bgTasks);
    final long curr = 1497720652566L;
    String dbName = "test";
    String measurementName = "cpu";
    String valueFieldName = "value";
    String tag = "host=123123";
    List<String> tags = Arrays.asList(tag);
    for (int i = 1; i <= 10000; i++) {
        engine.writeDataPoint(MiscUtils.buildDataPoint(dbName, measurementName, valueFieldName, tags, curr + i * 1000, i * 1.1));
    }
    long ts = System.nanoTime();
    List<Series> queryDataPoints = engine.queryDataPoints(dbName, measurementName, valueFieldName, curr - 1000, curr + 10000 * 1000 + 1, null, null);
    ts = System.nanoTime() - ts;
    System.out.println("Before compaction:" + ts / 1000 + "us");
    assertEquals(1, queryDataPoints.size());
    assertEquals(10000, queryDataPoints.iterator().next().getDataPoints().size());
    List<DataPoint> dataPoints = queryDataPoints.iterator().next().getDataPoints();
    for (int i = 1; i <= 10000; i++) {
        DataPoint dp = dataPoints.get(i - 1);
        assertEquals("Bad ts:" + i, curr + i * 1000, dp.getTimestamp());
        assertEquals(dp.getValue(), i * 1.1, 0.001);
    }
    final TimeSeries series = engine.getOrCreateTimeSeries(dbName, measurementName, valueFieldName, tags, 409600, false);
    SortedMap<String, List<Writer>> bucketRawMap = series.getBucketRawMap();
    assertEquals(1, bucketRawMap.size());
    int size = bucketRawMap.values().iterator().next().size();
    assertTrue(series.getCompactionSet().size() < size);
    assertTrue(size > 2);
    final AtomicBoolean bool = new AtomicBoolean(false);
    bgTasks.execute(() -> {
        while (!bool.get()) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                break;
            }
        }
        try {
            series.addDataPoint(TimeUnit.MILLISECONDS, curr + 1000 * 10001, 1.11);
            bool.set(false);
        } catch (IOException e) {
            e.printStackTrace();
            return;
        }
    });
    series.compact(l -> {
        bool.set(true);
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        if (!bool.get()) {
            throw new RuntimeException("Synchronized block failed");
        }
    });
    Thread.sleep(100);
    assertTrue(!bool.get());
}
Also used : TimeSeries(com.srotya.sidewinder.core.storage.TimeSeries) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IOException(java.io.IOException) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Point(com.srotya.sidewinder.core.rpc.Point) TimeSeries(com.srotya.sidewinder.core.storage.TimeSeries) Series(com.srotya.sidewinder.core.storage.Series) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 8 with TimeSeries

use of com.srotya.sidewinder.core.storage.TimeSeries 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 9 with TimeSeries

use of com.srotya.sidewinder.core.storage.TimeSeries in project sidewinder by srotya.

the class MemStorageEngine method updateTimeSeriesRetentionPolicy.

@Override
public void updateTimeSeriesRetentionPolicy(String dbName, String measurementName, String valueFieldName, List<String> tags, int retentionHours) throws IOException {
    TimeSeries series = getOrCreateTimeSeries(dbName, measurementName, valueFieldName, tags, defaultTimebucketSize, true);
    series.setRetentionHours(retentionHours);
}
Also used : TimeSeries(com.srotya.sidewinder.core.storage.TimeSeries)

Example 10 with TimeSeries

use of com.srotya.sidewinder.core.storage.TimeSeries 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)

Aggregations

TimeSeries (com.srotya.sidewinder.core.storage.TimeSeries)22 DataPoint (com.srotya.sidewinder.core.storage.DataPoint)14 Test (org.junit.Test)14 File (java.io.File)12 LinkedHashMap (java.util.LinkedHashMap)12 HashMap (java.util.HashMap)11 IOException (java.io.IOException)9 Series (com.srotya.sidewinder.core.storage.Series)8 ArrayList (java.util.ArrayList)8 ByzantineWriter (com.srotya.sidewinder.core.storage.compression.byzantine.ByzantineWriter)6 Measurement (com.srotya.sidewinder.core.storage.Measurement)5 BackgrounThreadFactory (com.srotya.sidewinder.core.utils.BackgrounThreadFactory)5 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 Point (com.srotya.sidewinder.core.rpc.Point)4 List (java.util.List)4 ExecutorService (java.util.concurrent.ExecutorService)4 DBMetadata (com.srotya.sidewinder.core.storage.DBMetadata)3 SeriesFieldMap (com.srotya.sidewinder.core.storage.SeriesFieldMap)3 Tag (com.srotya.sidewinder.core.filters.Tag)2