Search in sources :

Example 11 with DBMetadata

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

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

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

the class MemStorageEngine method getOrCreateDatabase.

@Override
public Map<String, Measurement> getOrCreateDatabase(String dbName) {
    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);
                DBMetadata metadata = new DBMetadata();
                metadata.setRetentionHours(defaultRetentionHours);
                dbMetadataMap.put(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)

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