use of com.srotya.sidewinder.core.storage.TimeSeries in project sidewinder by srotya.
the class TestPersistentMeasurement method testOptimizationsLambdaInvoke.
@Test
public void testOptimizationsLambdaInvoke() throws IOException {
long ts = System.currentTimeMillis();
MiscUtils.delete(new File("target/db42/"));
List<String> tags = Arrays.asList("test=1", "test=2");
PersistentMeasurement m = new PersistentMeasurement();
Map<String, String> map = new HashMap<>();
map.put("disk.compression.class", ByzantineWriter.class.getName());
map.put("malloc.file.max", String.valueOf(2 * 1024 * 1024));
m.configure(map, null, DBNAME, "m1", "target/db42/index", "target/db42/data", metadata, bgTaskPool);
int LIMIT = 1000;
for (int i = 0; i < LIMIT; i++) {
TimeSeries t = m.getOrCreateTimeSeries("value1", tags, 4096, false, map);
t.addDataPoint(TimeUnit.MILLISECONDS, ts + i * 1000, 1L);
}
m.runCleanupOperation("print", s -> {
// don't cleanup anything
return new ArrayList<>();
});
}
use of com.srotya.sidewinder.core.storage.TimeSeries 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());
}
use of com.srotya.sidewinder.core.storage.TimeSeries 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.TimeSeries in project sidewinder by srotya.
the class MemStorageEngine method updateTimeSeriesRetentionPolicy.
@Override
public void updateTimeSeriesRetentionPolicy(String dbName, String measurementName, String valueFieldName, List<String> tags, int retentionHours) throws IOException {
TimeSeries series = getOrCreateTimeSeries(dbName, measurementName, valueFieldName, tags, defaultTimebucketSize, true);
series.setRetentionHours(retentionHours);
}
use of com.srotya.sidewinder.core.storage.TimeSeries 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);
}
}
}
}
}
Aggregations