Search in sources :

Example 6 with DBMetadata

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

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

the class DiskStorageEngine method readMetadata.

protected DBMetadata readMetadata(String dbName) throws IOException {
    String path = dbDirectoryPath(dbName) + "/.md";
    File file = new File(path);
    if (!file.exists()) {
        return new DBMetadata(defaultRetentionHours);
    }
    List<String> lines = MiscUtils.readAllLines(file);
    StringBuilder builder = new StringBuilder();
    for (String line : lines) {
        builder.append(line);
    }
    logger.info("JSON for metadata:" + builder.toString());
    DBMetadata metadata = new Gson().fromJson(builder.toString(), DBMetadata.class);
    if (metadata == null) {
        throw new IOException("Invalid metadata for:" + dbName);
    }
    return metadata;
}
Also used : DBMetadata(com.srotya.sidewinder.core.storage.DBMetadata) Gson(com.google.gson.Gson) IOException(java.io.IOException) File(java.io.File)

Example 8 with DBMetadata

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

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

the class TestDiskStorageEngine method testConfigure.

@Test
public void testConfigure() throws IOException {
    StorageEngine engine = new DiskStorageEngine();
    try {
        engine.writeDataPoint(MiscUtils.buildDataPoint("test", "ss", "value", Arrays.asList("t=e"), System.currentTimeMillis(), 2.2));
        fail("Engine not initialized, shouldn't be able to write a datapoint");
    } catch (Exception e) {
    }
    try {
        // FileUtils.forceDelete(new File("target/db2/"));
        MiscUtils.delete(new File("targer/db2/"));
        HashMap<String, String> map = new HashMap<>();
        // map.put("metadata.dir", "target/db2/mdq");
        map.put("index.dir", "target/db2/index");
        map.put("data.dir", "target/db2/data");
        map.put(StorageEngine.PERSISTENCE_DISK, "true");
        map.put("default.series.retention.hours", "32");
        engine.configure(map, bgTasks);
    } catch (IOException e) {
        fail("No IOException should be thrown");
    }
    try {
        engine.writeDataPoint(MiscUtils.buildDataPoint("test", "ss", "value", Arrays.asList("t=e"), System.currentTimeMillis(), 2.2));
        String md = new String(Files.readAllBytes(new File("target/db2/data/test/.md").toPath()), Charset.forName("utf8"));
        DBMetadata metadata = new Gson().fromJson(md, DBMetadata.class);
        assertEquals(32, metadata.getRetentionHours());
    } catch (Exception e) {
        e.printStackTrace();
        fail("Engine is initialized, no IO Exception should be thrown:" + e.getMessage());
    }
    engine.disconnect();
}
Also used : DBMetadata(com.srotya.sidewinder.core.storage.DBMetadata) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Gson(com.google.gson.Gson) IOException(java.io.IOException) StorageEngine(com.srotya.sidewinder.core.storage.StorageEngine) File(java.io.File) ItemNotFoundException(com.srotya.sidewinder.core.storage.ItemNotFoundException) RejectException(com.srotya.sidewinder.core.storage.RejectException) IOException(java.io.IOException) Test(org.junit.Test)

Example 10 with DBMetadata

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

the class TestMappedBitmapTagIndex method testDiskTagIndexFilterEvaluation.

@Test
public void testDiskTagIndexFilterEvaluation() throws IOException, InterruptedException {
    MiscUtils.delete(new File("target/s7"));
    String indexDir = "target/s7";
    new File(indexDir).mkdirs();
    PersistentMeasurement m = new PersistentMeasurement();
    Map<String, String> conf = new HashMap<>();
    m.configure(conf, engine, "d", "m", "target/s7/i/bitmap", "target/s7/d/bitmap", new DBMetadata(), null);
    MappedBitmapTagIndex index = new MappedBitmapTagIndex(indexDir, "s7", m);
    for (int i = 0; i < 10_000; i++) {
        index.index("key", String.valueOf(i), i);
        String valueOf = String.valueOf(i);
        m.getSeriesListAsList().add(new SeriesFieldMap(valueOf));
    }
    TagFilter filter = new SimpleTagFilter(FilterType.GREATER_THAN, "key", "9");
    Set<String> keys = index.searchRowKeysForTagFilter(filter);
    assertEquals(1110, keys.size());
    filter = new SimpleTagFilter(FilterType.GREATER_THAN_EQUALS, "key", "9");
    keys = index.searchRowKeysForTagFilter(filter);
    assertEquals(1111, keys.size());
    filter = new SimpleTagFilter(FilterType.LESS_THAN, "key", "10");
    keys = index.searchRowKeysForTagFilter(filter);
    assertEquals(2, keys.size());
    filter = new SimpleTagFilter(FilterType.LESS_THAN_EQUALS, "key", "1000");
    keys = index.searchRowKeysForTagFilter(filter);
    // keys.stream().forEach(System.out::println);
    assertEquals(5, keys.size());
}
Also used : DBMetadata(com.srotya.sidewinder.core.storage.DBMetadata) HashMap(java.util.HashMap) TagFilter(com.srotya.sidewinder.core.filters.TagFilter) SimpleTagFilter(com.srotya.sidewinder.core.filters.SimpleTagFilter) ComplexTagFilter(com.srotya.sidewinder.core.filters.ComplexTagFilter) SimpleTagFilter(com.srotya.sidewinder.core.filters.SimpleTagFilter) File(java.io.File) SeriesFieldMap(com.srotya.sidewinder.core.storage.SeriesFieldMap) Test(org.junit.Test)

Aggregations

DBMetadata (com.srotya.sidewinder.core.storage.DBMetadata)13 File (java.io.File)9 HashMap (java.util.HashMap)7 Test (org.junit.Test)7 SimpleTagFilter (com.srotya.sidewinder.core.filters.SimpleTagFilter)6 SeriesFieldMap (com.srotya.sidewinder.core.storage.SeriesFieldMap)6 Measurement (com.srotya.sidewinder.core.storage.Measurement)5 ComplexTagFilter (com.srotya.sidewinder.core.filters.ComplexTagFilter)4 TagFilter (com.srotya.sidewinder.core.filters.TagFilter)4 Gson (com.google.gson.Gson)2 TimeSeries (com.srotya.sidewinder.core.storage.TimeSeries)2 IOException (java.io.IOException)2 ItemNotFoundException (com.srotya.sidewinder.core.storage.ItemNotFoundException)1 RejectException (com.srotya.sidewinder.core.storage.RejectException)1 StorageEngine (com.srotya.sidewinder.core.storage.StorageEngine)1 LinkedHashMap (java.util.LinkedHashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1