Search in sources :

Example 26 with DataPoint

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

the class TestMemStorageEngine method testAddAndReadDataPoints.

@Test
public void testAddAndReadDataPoints() throws Exception {
    MemStorageEngine engine = new MemStorageEngine();
    engine.configure(new HashMap<>(), bgTasks);
    long curr = System.currentTimeMillis();
    String dbName = "test";
    String measurementName = "cpu";
    String valueFieldName = "value";
    try {
        engine.writeDataPoint(MiscUtils.buildDataPoint(dbName, measurementName, valueFieldName, null, curr, 2 * 0));
        fail("Must reject the above datapoint due to missing tags");
    } catch (Exception e) {
    }
    String tag = "host=123123";
    for (int i = 1; i <= 3; i++) {
        engine.writeDataPoint(MiscUtils.buildDataPoint(dbName, measurementName, valueFieldName, Arrays.asList(tag), curr + i, 2 * i));
    }
    assertEquals(1, engine.getAllMeasurementsForDb(dbName).size());
    List<Series> queryDataPoints = engine.queryDataPoints(dbName, measurementName, valueFieldName, curr, curr + 3, null, null);
    assertEquals(1, queryDataPoints.size());
    int i = 1;
    assertEquals(3, queryDataPoints.iterator().next().getDataPoints().size());
    for (Series list : queryDataPoints) {
        for (DataPoint dataPoint : list.getDataPoints()) {
            assertEquals(curr + i, dataPoint.getTimestamp());
            i++;
        }
    }
    Set<String> tags = engine.getTagKeysForMeasurement(dbName, measurementName);
    assertEquals(new HashSet<>(Arrays.asList("host")), tags);
    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) {
    }
    assertEquals(1, engine.getFieldsForMeasurement(dbName, "c.*").size());
    assertEquals(1, engine.getFieldsForMeasurement(dbName, ".*").size());
    try {
        engine.getFieldsForMeasurement(dbName, "d.*");
        fail("This measurement should not exist");
    } catch (Exception e) {
    }
}
Also used : TimeSeries(com.srotya.sidewinder.core.storage.TimeSeries) Series(com.srotya.sidewinder.core.storage.Series) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ItemNotFoundException(com.srotya.sidewinder.core.storage.ItemNotFoundException) RejectException(com.srotya.sidewinder.core.storage.RejectException) IOException(java.io.IOException) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) Point(com.srotya.sidewinder.core.rpc.Point) Test(org.junit.Test)

Example 27 with DataPoint

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

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

the class TestMemStorageEngine method testSeriesToDataPointConversion.

@Test
public void testSeriesToDataPointConversion() throws IOException {
    List<DataPoint> points = new ArrayList<>();
    long headerTimestamp = System.currentTimeMillis();
    ByteBuffer buf = ByteBuffer.allocate(1024);
    Writer timeSeries = new ByzantineWriter();
    timeSeries.configure(conf, buf, true, 1, false);
    timeSeries.setHeaderTimestamp(headerTimestamp);
    timeSeries.addValue(headerTimestamp, 1L);
    TimeSeries.seriesToDataPoints("value", Arrays.asList("test=2"), points, timeSeries, null, null, false);
    assertEquals(1, points.size());
    points.clear();
    Predicate timepredicate = new BetweenPredicate(Long.MAX_VALUE, Long.MAX_VALUE);
    TimeSeries.seriesToDataPoints("value", Arrays.asList("test=2"), points, timeSeries, timepredicate, null, false);
    assertEquals(0, points.size());
}
Also used : BetweenPredicate(com.srotya.sidewinder.core.predicates.BetweenPredicate) DataPoint(com.srotya.sidewinder.core.storage.DataPoint) ByzantineWriter(com.srotya.sidewinder.core.storage.compression.byzantine.ByzantineWriter) ArrayList(java.util.ArrayList) ByteBuffer(java.nio.ByteBuffer) Writer(com.srotya.sidewinder.core.storage.compression.Writer) ByzantineWriter(com.srotya.sidewinder.core.storage.compression.byzantine.ByzantineWriter) Predicate(com.srotya.sidewinder.core.predicates.Predicate) BetweenPredicate(com.srotya.sidewinder.core.predicates.BetweenPredicate) Test(org.junit.Test)

Example 29 with DataPoint

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

the class TestTransformFunctions method testCubeRoot.

@Test
public void testCubeRoot() {
    Function f = new CbrtFunction();
    List<Series> series = new ArrayList<>();
    Series s = new Series(Arrays.asList(new DataPoint(1L, 27), new DataPoint(1L, 64)));
    series.add(s);
    List<Series> apply = f.apply(series);
    assertEquals(2, apply.get(0).getDataPoints().size());
    assertEquals(3, apply.get(0).getDataPoints().get(0).getLongValue());
    assertEquals(4, 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 30 with DataPoint

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

the class TestTransformFunctions method testCube.

@Test
public void testCube() {
    Function f = new CubeFunction();
    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(27, apply.get(0).getDataPoints().get(0).getLongValue());
    assertEquals(64, 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)

Aggregations

DataPoint (com.srotya.sidewinder.core.storage.DataPoint)67 Test (org.junit.Test)52 Series (com.srotya.sidewinder.core.storage.Series)40 ArrayList (java.util.ArrayList)39 IOException (java.io.IOException)16 Reader (com.srotya.sidewinder.core.storage.compression.Reader)13 TimeSeries (com.srotya.sidewinder.core.storage.TimeSeries)12 ByteBuffer (java.nio.ByteBuffer)11 ReducingWindowedAggregator (com.srotya.sidewinder.core.functions.windowed.ReducingWindowedAggregator)10 HashMap (java.util.HashMap)10 LinkedHashMap (java.util.LinkedHashMap)10 RejectException (com.srotya.sidewinder.core.storage.RejectException)9 File (java.io.File)9 Point (com.srotya.sidewinder.core.rpc.Point)8 ItemNotFoundException (com.srotya.sidewinder.core.storage.ItemNotFoundException)8 List (java.util.List)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 Tag (com.srotya.sidewinder.core.filters.Tag)5 Writer (com.srotya.sidewinder.core.storage.compression.Writer)5 ByzantineWriter (com.srotya.sidewinder.core.storage.compression.byzantine.ByzantineWriter)4