Search in sources :

Example 41 with Series

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

the class TestMemStorageEngine method testCompaction.

@Test
public void testCompaction() 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");
    conf2.put("compaction.codec", "gorilla");
    conf2.put("compaction.delay", "1");
    conf2.put("compaction.frequency", "1");
    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);
    }
    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);
    Thread.sleep(2000);
    ts = System.nanoTime();
    queryDataPoints = engine.queryDataPoints(dbName, measurementName, valueFieldName, curr - 1, curr + 20000 * 1000 + 1, null, null);
    ts = System.nanoTime() - ts;
    System.out.println("After compaction:" + ts / 1000 + "us");
    bucketRawMap = series.getBucketRawMap();
    assertEquals(2, bucketRawMap.values().iterator().next().size());
    assertEquals(10000, queryDataPoints.iterator().next().getDataPoints().size());
    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);
    }
}
Also used : TimeSeries(com.srotya.sidewinder.core.storage.TimeSeries) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) 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) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 42 with Series

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

the class TestMemStorageEngine method testAddAndReadDataPointsWithTagFilters.

@Test
public void testAddAndReadDataPointsWithTagFilters() throws Exception {
    MemStorageEngine engine = new MemStorageEngine();
    engine.configure(new HashMap<>(), bgTasks);
    long curr = System.currentTimeMillis();
    String dbName = "test";
    String measurementName = "cpu";
    String valueFieldName = "value";
    String tag = "host=123123";
    for (int i = 1; i <= 3; i++) {
        engine.writeDataPoint(dbName, measurementName, valueFieldName, Arrays.asList(tag + i, tag + (i + 1)), curr + i, 2 * i);
    }
    assertEquals(1, engine.getAllMeasurementsForDb(dbName).size());
    SimpleTagFilter filter1 = new SimpleTagFilter(FilterType.EQUALS, "host", "1231231");
    SimpleTagFilter filter2 = new SimpleTagFilter(FilterType.EQUALS, "host", "1231232");
    List<Series> queryDataPoints = engine.queryDataPoints(dbName, measurementName, valueFieldName, curr - 1, curr + 4, new ComplexTagFilter(ComplexFilterType.OR, Arrays.asList(filter1, filter2)), null, null);
    assertEquals(2, queryDataPoints.size());
    assertEquals(1, queryDataPoints.iterator().next().getDataPoints().size());
    Collections.sort(queryDataPoints);
    int i = 1;
    for (Series list : queryDataPoints) {
        List<DataPoint> dataPoints = list.getDataPoints();
        DataPoint dataPoint = dataPoints.get(0);
        assertEquals(i + curr, dataPoint.getTimestamp());
        i++;
    }
    Set<String> tagKeys = engine.getTagKeysForMeasurement(dbName, measurementName);
    assertEquals(new HashSet<>(Arrays.asList("host")), tagKeys);
    assertEquals(new HashSet<>(Arrays.asList("1231231", "1231232", "1231233", "1231234")), engine.getTagValuesForMeasurement(dbName, measurementName, "host"));
    Set<String> fieldsForMeasurement = engine.getFieldsForMeasurement(dbName, measurementName);
    assertEquals(new HashSet<>(Arrays.asList(valueFieldName)), fieldsForMeasurement);
    try {
        engine.getTagKeysForMeasurement(dbName + "1", measurementName);
        fail("This measurement should not exist");
    } catch (Exception e) {
    }
    try {
        engine.getTagKeysForMeasurement(dbName, measurementName + "1");
        fail("This measurement should not exist");
    } catch (Exception e) {
    }
    try {
        engine.getFieldsForMeasurement(dbName + "1", measurementName);
        fail("This measurement should not exist");
    } catch (Exception e) {
    }
    try {
        engine.getFieldsForMeasurement(dbName, measurementName + "1");
        fail("This measurement should not exist");
    } catch (Exception e) {
    }
}
Also used : ComplexTagFilter(com.srotya.sidewinder.core.filters.ComplexTagFilter) SimpleTagFilter(com.srotya.sidewinder.core.filters.SimpleTagFilter) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Point(com.srotya.sidewinder.core.rpc.Point) ItemNotFoundException(com.srotya.sidewinder.core.storage.ItemNotFoundException) RejectException(com.srotya.sidewinder.core.storage.RejectException) IOException(java.io.IOException) TimeSeries(com.srotya.sidewinder.core.storage.TimeSeries) Series(com.srotya.sidewinder.core.storage.Series) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Test(org.junit.Test)

Example 43 with Series

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

the class TestTransformFunctions method testLog.

@Test
public void testLog() {
    Function f = new LogFunction();
    List<Series> series = new ArrayList<>();
    Series s = new Series(Arrays.asList(new DataPoint(1L, 100), new DataPoint(1L, 1000)));
    series.add(s);
    List<Series> apply = f.apply(series);
    assertEquals(2, apply.get(0).getDataPoints().size());
    assertEquals(4.0, apply.get(0).getDataPoints().get(0).getLongValue(), 0.1);
    assertEquals(6.0, apply.get(0).getDataPoints().get(1).getLongValue(), 0.1);
}
Also used : Series(com.srotya.sidewinder.core.storage.Series) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 44 with Series

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

the class TestTransformFunctions method testSquare.

@Test
public void testSquare() {
    Function f = new SquareFunction();
    List<Series> series = new ArrayList<>();
    Series s = new Series(Arrays.asList(new DataPoint(1L, 3), new DataPoint(1L, 4)));
    series.add(s);
    List<Series> apply = f.apply(series);
    assertEquals(2, apply.get(0).getDataPoints().size());
    assertEquals(9, apply.get(0).getDataPoints().get(0).getLongValue());
    assertEquals(16, apply.get(0).getDataPoints().get(1).getLongValue());
}
Also used : Series(com.srotya.sidewinder.core.storage.Series) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 45 with Series

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

the class TestTransformFunctions method testLog10.

@Test
public void testLog10() {
    Function f = new Log10Function();
    List<Series> series = new ArrayList<>();
    Series s = new Series(Arrays.asList(new DataPoint(1L, 100), new DataPoint(1L, 1000)));
    series.add(s);
    List<Series> apply = f.apply(series);
    assertEquals(2, apply.get(0).getDataPoints().size());
    assertEquals(2, apply.get(0).getDataPoints().get(0).getLongValue(), 0.1);
    assertEquals(3, apply.get(0).getDataPoints().get(1).getLongValue(), 0.1);
}
Also used : Series(com.srotya.sidewinder.core.storage.Series) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Series (com.srotya.sidewinder.core.storage.Series)56 DataPoint (com.srotya.sidewinder.core.storage.DataPoint)49 Test (org.junit.Test)47 ArrayList (java.util.ArrayList)37 TimeSeries (com.srotya.sidewinder.core.storage.TimeSeries)21 IOException (java.io.IOException)18 LinkedHashMap (java.util.LinkedHashMap)16 HashMap (java.util.HashMap)15 Point (com.srotya.sidewinder.core.rpc.Point)13 ItemNotFoundException (com.srotya.sidewinder.core.storage.ItemNotFoundException)13 File (java.io.File)13 ReducingWindowedAggregator (com.srotya.sidewinder.core.functions.windowed.ReducingWindowedAggregator)10 RejectException (com.srotya.sidewinder.core.storage.RejectException)10 StorageEngine (com.srotya.sidewinder.core.storage.StorageEngine)7 List (java.util.List)7 ByzantineWriter (com.srotya.sidewinder.core.storage.compression.byzantine.ByzantineWriter)6 Tag (com.srotya.sidewinder.core.filters.Tag)5 SimpleTagFilter (com.srotya.sidewinder.core.filters.SimpleTagFilter)4 Measurement (com.srotya.sidewinder.core.storage.Measurement)4 WriterServiceBlockingStub (com.srotya.sidewinder.core.rpc.WriterServiceGrpc.WriterServiceBlockingStub)3