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);
}
}
}
}
}
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;
}
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);
}
}
}
}
}
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();
}
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());
}
Aggregations