Search in sources :

Example 1 with TableDefEx

use of org.spf4j.tsdb2.TSDBQuery.TableDefEx in project spf4j by zolyfarkas.

the class TSDBQuery method getAllTablesWithDataRanges.

@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED")
public static ListMultimap<String, TableDefEx> getAllTablesWithDataRanges(final File tsdbFile) throws IOException {
    ListMultimap<String, TableDefEx> result = ArrayListMultimap.create();
    TLongObjectMap<TableDefEx> id2Def = new TLongObjectHashMap<>();
    try (TSDBReader reader = new TSDBReader(tsdbFile, 8192)) {
        Either<TableDef, DataBlock> read;
        while ((read = reader.read()) != null) {
            if (read.isLeft()) {
                final TableDef left = read.getLeft();
                final TableDefEx tableDefEx = new TableDefEx(left, Long.MAX_VALUE, 0L);
                id2Def.put(left.id, tableDefEx);
                result.put(tableDefEx.getTableDef().getName(), tableDefEx);
            } else {
                DataBlock right = read.getRight();
                long baseTs = right.baseTimestamp;
                for (DataRow row : right.getValues()) {
                    TableDefEx tdex = id2Def.get(row.tableDefId);
                    if (tdex == null) {
                        throw new IOException("Potentially corupted file data row with no tableDef " + row);
                    }
                    long ts = baseTs + row.relTimeStamp;
                    if (ts < tdex.getStartTime()) {
                        tdex.setStartTime(ts);
                    }
                    if (ts > tdex.getEndTime()) {
                        tdex.setEndTime(ts);
                    }
                }
            }
        }
    }
    return result;
}
Also used : TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) IOException(java.io.IOException) TableDef(org.spf4j.tsdb2.avro.TableDef) DataRow(org.spf4j.tsdb2.avro.DataRow) DataBlock(org.spf4j.tsdb2.avro.DataBlock) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 2 with TableDefEx

use of org.spf4j.tsdb2.TSDBQuery.TableDefEx in project spf4j by zolyfarkas.

the class FileMonitorAspectTest method testFileIOMonitoring.

/**
 * Test of nioReadLong method, of class FileMonitorAspect.
 */
@Test
public void testFileIOMonitoring() throws Exception {
    System.setProperty("spf4j.perf.file.sampleTimeMillis", "1000");
    File tempFile = File.createTempFile("test", ".tmp");
    tempFile.deleteOnExit();
    try (Writer fw = new OutputStreamWriter(Files.newOutputStream(tempFile.toPath()), StandardCharsets.UTF_8)) {
        for (int i = 0; i < 10; i++) {
            fw.write("bla bla test\n");
            Thread.sleep(500);
        }
    }
    Thread.sleep(1000);
    try (BufferedReader fr = new BufferedReader(new InputStreamReader(Files.newInputStream(tempFile.toPath()), StandardCharsets.UTF_8))) {
        String line = fr.readLine();
        while (line != null) {
            LOG.debug("Read: {}", line);
            line = fr.readLine();
            Thread.sleep(500);
        }
    }
    TSDBWriter dbWriter = ((TSDBMeasurementStore) RecorderFactory.MEASUREMENT_STORE).getDBWriter();
    dbWriter.flush();
    final File file = dbWriter.getFile();
    ListMultimap<String, TableDefEx> allTables = TSDBQuery.getAllTablesWithDataRanges(file);
    LOG.debug("Tables {}", allTables);
    Map<String, Collection<TableDefEx>> asMap = allTables.asMap();
    Assert.assertThat(asMap, (Matcher) Matchers.hasKey("file-write,org.spf4j.perf.aspects.FileMonitorAspectTest"));
    Assert.assertThat(asMap, (Matcher) Matchers.hasKey("file-read,org.spf4j.perf.aspects.FileMonitorAspectTest"));
    List<TableDefEx> get = allTables.get("file-write,org.spf4j.perf.aspects.FileMonitorAspectTest");
    Assert.assertTrue(get.get(0).getStartTime() != 0);
    Assert.assertTrue(OperatingSystem.getOpenFileDescriptorCount() > 0);
}
Also used : InputStreamReader(java.io.InputStreamReader) TableDefEx(org.spf4j.tsdb2.TSDBQuery.TableDefEx) TSDBWriter(org.spf4j.tsdb2.TSDBWriter) BufferedReader(java.io.BufferedReader) Collection(java.util.Collection) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) TSDBWriter(org.spf4j.tsdb2.TSDBWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) TSDBMeasurementStore(org.spf4j.perf.impl.ms.tsdb.TSDBMeasurementStore) Test(org.junit.Test)

Aggregations

SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 Collection (java.util.Collection)1 Test (org.junit.Test)1 TSDBMeasurementStore (org.spf4j.perf.impl.ms.tsdb.TSDBMeasurementStore)1 TableDefEx (org.spf4j.tsdb2.TSDBQuery.TableDefEx)1 TSDBWriter (org.spf4j.tsdb2.TSDBWriter)1 DataBlock (org.spf4j.tsdb2.avro.DataBlock)1 DataRow (org.spf4j.tsdb2.avro.DataRow)1 TableDef (org.spf4j.tsdb2.avro.TableDef)1