Search in sources :

Example 16 with Measurement

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

the class TestSetTagIndex method testTagIndexPerformance.

// @Test
public void testTagIndexPerformance() throws IOException, InterruptedException {
    MiscUtils.delete(new File("target/perf/index-dir"));
    MiscUtils.delete(new File("target/perf/data-dir"));
    DiskStorageEngine engine = new DiskStorageEngine();
    HashMap<String, String> conf = new HashMap<>();
    conf.put("index.dir", "target/perf/index-dir");
    conf.put("data.dir", "target/perf/data-dir");
    engine.configure(conf, Executors.newScheduledThreadPool(1, new BackgrounThreadFactory("bgt")));
    final long ms = System.currentTimeMillis();
    ExecutorService es = Executors.newCachedThreadPool();
    for (int k = 0; k < 6; k++) {
        es.submit(() -> {
            for (int i = 0; i < 200_000_000; i++) {
                try {
                    engine.getOrCreateTimeSeries("db1", "m1", "v10", Arrays.asList(String.valueOf(i % 10_000), "test=" + "asdasdasd" + String.valueOf(i % 5), "test2=" + String.valueOf(i % 5), "goliath=" + String.valueOf(i % 100_000), "goliath2=" + String.valueOf(i % 1_500)), 4096, true);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (i % 1_000_000 == 0) {
                    System.out.println(i + "  " + (System.currentTimeMillis() - ms) / 1000);
                }
            }
        });
    }
    es.shutdown();
    es.awaitTermination(1000, TimeUnit.SECONDS);
    System.err.println("Index time:" + (System.currentTimeMillis() - ms));
    Map<String, Map<String, Measurement>> index = engine.getMeasurementMap();
    assertEquals(1, index.size());
    Entry<String, Map<String, Measurement>> next = index.entrySet().iterator().next();
    assertEquals("db1", next.getKey());
    Entry<String, Measurement> itr = next.getValue().entrySet().iterator().next();
    assertEquals("m1", itr.getKey());
}
Also used : Measurement(com.srotya.sidewinder.core.storage.Measurement) BackgrounThreadFactory(com.srotya.sidewinder.core.utils.BackgrounThreadFactory) HashMap(java.util.HashMap) DiskStorageEngine(com.srotya.sidewinder.core.storage.disk.DiskStorageEngine) IOException(java.io.IOException) ExecutorService(java.util.concurrent.ExecutorService) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Example 17 with Measurement

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

the class DiskStorageEngine method loadDatabases.

protected void loadDatabases() throws IOException {
    for (String dataDir : dataDirs) {
        File mdDir = new File(dataDir);
        if (!mdDir.exists()) {
            return;
        }
        File[] dbs = mdDir.listFiles();
        for (File db : dbs) {
            if (!db.isDirectory()) {
                continue;
            }
            Map<String, Measurement> measurementMap = new ConcurrentHashMap<>();
            String dbName = db.getName();
            databaseMap.put(dbName, measurementMap);
            DBMetadata metadata = readMetadata(dbName);
            dbMetadataMap.put(dbName, metadata);
            logger.info("Loading database:" + dbName);
            loadMeasurements(dbName, measurementMap, metadata);
        }
    }
}
Also used : Measurement(com.srotya.sidewinder.core.storage.Measurement) DBMetadata(com.srotya.sidewinder.core.storage.DBMetadata) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) File(java.io.File)

Example 18 with Measurement

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

the class DiskStorageEngine method getOrCreateDatabase.

@Override
public Map<String, Measurement> getOrCreateDatabase(String dbName) throws IOException {
    Map<String, Measurement> measurementMap = databaseMap.get(dbName);
    if (measurementMap == null) {
        synchronized (databaseMap) {
            if ((measurementMap = databaseMap.get(dbName)) == null) {
                measurementMap = new ConcurrentHashMap<>();
                databaseMap.put(dbName, measurementMap);
                createDatabaseDirectory(dbName);
                DBMetadata metadata = new DBMetadata();
                metadata.setRetentionHours(defaultRetentionHours);
                dbMetadataMap.put(dbName, metadata);
                saveDBMetadata(dbName, metadata);
                logger.info("Created new database:" + dbName + "\t with retention period:" + defaultRetentionHours + " hours");
                metricsDbCounter.inc();
            }
        }
    }
    return measurementMap;
}
Also used : Measurement(com.srotya.sidewinder.core.storage.Measurement) DBMetadata(com.srotya.sidewinder.core.storage.DBMetadata)

Example 19 with Measurement

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

the class DiskStorageEngine method loadMeasurements.

protected void loadMeasurements(String dbName, Map<String, Measurement> measurementMap, DBMetadata metadata) throws IOException {
    File file = new File(dbDirectoryPath(dbName));
    if (!file.exists() || file.listFiles() == null) {
        return;
    }
    List<Future<?>> futures = new ArrayList<>();
    for (File measurementMdFile : file.listFiles()) {
        if (!measurementMdFile.isDirectory()) {
            continue;
        }
        String measurementName = measurementMdFile.getName();
        Measurement measurement = new PersistentMeasurement();
        measurementMap.put(measurementName, measurement);
        logger.info("Loading measurements:" + measurementName);
        futures.add(bgTaskPool.submit(() -> {
            try {
                measurement.configure(conf, this, dbName, measurementName, dbIndexPath(dbName), dbDirectoryPath(dbName), metadata, bgTaskPool);
            } catch (IOException e) {
                logger.log(Level.SEVERE, "Error recovering measurement:" + measurementName, e);
            }
        }));
    }
    for (Future<?> future : futures) {
        try {
            future.get();
        } catch (InterruptedException | ExecutionException e) {
            logger.log(Level.SEVERE, "Error future get recovering measurement, db:" + dbName, e);
        }
    }
}
Also used : Measurement(com.srotya.sidewinder.core.storage.Measurement) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) File(java.io.File)

Example 20 with Measurement

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

the class DiskStorageEngine method dropDatabase.

@Override
public void dropDatabase(String dbName) throws Exception {
    synchronized (databaseMap) {
        Map<String, Measurement> remove = databaseMap.remove(dbName);
        for (Measurement measurement : remove.values()) {
            measurement.close();
        }
        boolean result = MiscUtils.delete(new File(dbDirectoryPath(dbName)));
        if (!result) {
            throw new Exception("Database(" + dbName + ") deletion(data) failed due file deletion issues");
        }
        result = MiscUtils.delete(new File(dbIndexPath(dbName)));
        if (!result) {
            throw new Exception("Database(" + dbName + ") deletion(index) failed due file deletion issues");
        }
        metricsDbCounter.dec();
        logger.info("Database(" + dbName + ") deleted");
    }
}
Also used : Measurement(com.srotya.sidewinder.core.storage.Measurement) File(java.io.File) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

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