Search in sources :

Example 1 with ReaderOutOfDateException

use of io.questdb.cairo.sql.ReaderOutOfDateException in project questdb by bluestreak01.

the class TruncateTest method testDropTableWithCachedPlan.

private void testDropTableWithCachedPlan(String query) throws Exception {
    assertMemoryLeak(() -> {
        compiler.compile("create table y as (" + "select timestamp_sequence(0, 1000000000) timestamp," + " rnd_symbol('a','b',null) symbol1 " + " from long_sequence(10)" + ") timestamp (timestamp)", sqlExecutionContext);
        try (RecordCursorFactory factory = compiler.compile(query, sqlExecutionContext).getRecordCursorFactory()) {
            try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
                sink.clear();
                TestUtils.printCursor(cursor, factory.getMetadata(), true, sink, printer);
            }
            compiler.compile("drop table y", sqlExecutionContext);
            compiler.compile("create table y as ( " + " select " + " timestamp_sequence('1970-01-01T02:30:00.000000Z', 1000000000L) timestamp " + " ,rnd_str('a','b','c', 'd', 'e', 'f',null) symbol2" + " ,rnd_str('a','b',null) symbol1" + " from long_sequence(10)" + ")", sqlExecutionContext);
            try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
                TestUtils.printCursor(cursor, factory.getMetadata(), true, sink, printer);
                Assert.fail();
            } catch (ReaderOutOfDateException e) {
                TestUtils.assertContains(e.getFlyweightMessage(), "cannot be used because table schema has changed [table='y']");
            }
        }
    });
}
Also used : RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) ReaderOutOfDateException(io.questdb.cairo.sql.ReaderOutOfDateException)

Example 2 with ReaderOutOfDateException

use of io.questdb.cairo.sql.ReaderOutOfDateException in project questdb by bluestreak01.

the class JsonQueryProcessor method execute0.

public void execute0(JsonQueryProcessorState state) throws PeerDisconnectedException, PeerIsSlowToReadException, ServerDisconnectException {
    metrics.jsonQuery().markStart();
    state.startExecutionTimer();
    final HttpConnectionContext context = state.getHttpConnectionContext();
    // do not set random for new request to avoid copying random from previous request into next one
    // the only time we need to copy random from state is when we resume request execution
    sqlExecutionContext.with(context.getCairoSecurityContext(), null, null, context.getFd(), interruptor.of(context.getFd()));
    state.info().$("exec [q='").utf8(state.getQuery()).$("']").$();
    final RecordCursorFactory factory = QueryCache.getInstance().poll(state.getQuery());
    try {
        if (factory != null) {
            try {
                sqlExecutionContext.storeTelemetry(CompiledQuery.SELECT, Telemetry.ORIGIN_HTTP_JSON);
                executeCachedSelect(state, factory, configuration.getKeepAliveHeader());
            } catch (ReaderOutOfDateException e) {
                LOG.info().$(e.getFlyweightMessage()).$();
                Misc.free(factory);
                compileQuery(state);
            }
        } else {
            // new query
            compileQuery(state);
        }
    } catch (SqlException e) {
        syntaxError(context.getChunkedResponseSocket(), e, state, configuration.getKeepAliveHeader());
        readyForNextRequest(context);
    } catch (EntryUnavailableException e) {
        LOG.info().$("[fd=").$(context.getFd()).$("] Resource busy, will retry").$();
        throw RetryOperationException.INSTANCE;
    } catch (CairoError | CairoException e) {
        internalError(context.getChunkedResponseSocket(), e.getFlyweightMessage(), e, state);
        readyForNextRequest(context);
    } catch (PeerIsSlowToReadException | PeerDisconnectedException e) {
        // re-throw the exception
        throw e;
    } catch (Throwable e) {
        state.error().$("Uh-oh. Error!").$(e).$();
        throw ServerDisconnectException.INSTANCE;
    }
}
Also used : RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) CairoError(io.questdb.cairo.CairoError) PeerIsSlowToReadException(io.questdb.network.PeerIsSlowToReadException) CairoException(io.questdb.cairo.CairoException) EntryUnavailableException(io.questdb.cairo.EntryUnavailableException) ReaderOutOfDateException(io.questdb.cairo.sql.ReaderOutOfDateException) PeerDisconnectedException(io.questdb.network.PeerDisconnectedException)

Example 3 with ReaderOutOfDateException

use of io.questdb.cairo.sql.ReaderOutOfDateException in project questdb by bluestreak01.

the class LineTcpReceiverTest method testTableTableIdChangedOnRecreate.

@Test
public void testTableTableIdChangedOnRecreate() throws Exception {
    try (SqlCompiler compiler = new SqlCompiler(engine);
        SqlExecutionContext sqlExecutionContext = new SqlExecutionContextImpl(engine, 1).with(AllowAllCairoSecurityContext.INSTANCE, new BindVariableServiceImpl(configuration), null, -1, null)) {
        compiler.compile("create table weather as (" + "select x as windspeed," + "x*2 as timetocycle, " + "cast(x as timestamp) as ts " + "from long_sequence(2)) timestamp(ts) ", sqlExecutionContext);
        CompiledQuery cq = compiler.compile("weather", sqlExecutionContext);
        try (RecordCursorFactory cursorFactory = cq.getRecordCursorFactory()) {
            try (RecordCursor cursor = cursorFactory.getCursor(sqlExecutionContext)) {
                TestUtils.printCursor(cursor, cursorFactory.getMetadata(), true, sink, printer);
                TestUtils.assertEquals("windspeed\ttimetocycle\tts\n" + "1\t2\t1970-01-01T00:00:00.000001Z\n" + "2\t4\t1970-01-01T00:00:00.000002Z\n", sink);
            }
            compiler.compile("drop table weather", sqlExecutionContext);
            runInContext((receiver) -> {
                String lineData = "weather windspeed=1.0 631150000000000000\n" + "weather windspeed=2.0 631152000000000000\n" + "weather timetocycle=0.0,windspeed=3.0 631160000000000000\n" + "weather windspeed=4.0 631170000000000000\n";
                sendLinger(receiver, lineData, "weather");
            });
            try (RecordCursor cursor = cursorFactory.getCursor(sqlExecutionContext)) {
                TestUtils.printCursor(cursor, cursorFactory.getMetadata(), true, sink, printer);
                Assert.fail();
            } catch (ReaderOutOfDateException ignored) {
            }
        }
    }
}
Also used : SqlExecutionContextImpl(io.questdb.griffin.SqlExecutionContextImpl) SqlCompiler(io.questdb.griffin.SqlCompiler) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) SqlExecutionContext(io.questdb.griffin.SqlExecutionContext) BindVariableServiceImpl(io.questdb.griffin.engine.functions.bind.BindVariableServiceImpl) ReaderOutOfDateException(io.questdb.cairo.sql.ReaderOutOfDateException) CompiledQuery(io.questdb.griffin.CompiledQuery) Test(org.junit.Test)

Example 4 with ReaderOutOfDateException

use of io.questdb.cairo.sql.ReaderOutOfDateException in project questdb by bluestreak01.

the class FullFwdDataFrameCursorFactoryTest method testFactory.

@Test
public void testFactory() throws Exception {
    assertMemoryLeak(() -> {
        final int N = 100;
        // separate two symbol columns with primitive. It will make problems apparent if index does not shift correctly
        try (TableModel model = new TableModel(configuration, "x", PartitionBy.DAY).col("a", ColumnType.STRING).col("b", ColumnType.SYMBOL).indexed(true, N / 4).col("i", ColumnType.INT).col("c", ColumnType.SYMBOL).indexed(true, N / 4).timestamp()) {
            CairoTestUtils.create(model);
        }
        final Rnd rnd = new Rnd();
        final String[] symbols = new String[N];
        final int M = 1000;
        final long increment = 1000000 * 60L * 10;
        for (int i = 0; i < N; i++) {
            symbols[i] = rnd.nextChars(8).toString();
        }
        // prepare the data
        long timestamp = 0;
        try (TableWriter writer = new TableWriter(configuration, "x")) {
            for (int i = 0; i < M; i++) {
                TableWriter.Row row = writer.newRow(timestamp += increment);
                row.putStr(0, rnd.nextChars(20));
                row.putSym(1, symbols[rnd.nextPositiveInt() % N]);
                row.putInt(2, rnd.nextInt());
                row.putSym(3, symbols[rnd.nextPositiveInt() % N]);
                row.append();
            }
            writer.commit();
        }
        FullFwdDataFrameCursorFactory factory = new FullFwdDataFrameCursorFactory(engine, "x", TableUtils.ANY_TABLE_ID, 0);
        long count = 0;
        try (DataFrameCursor cursor = factory.getCursor(AllowAllSqlSecurityContext.INSTANCE)) {
            DataFrame frame;
            while ((frame = cursor.next()) != null) {
                count += frame.getRowHi() - frame.getRowLo();
            }
        }
        Assert.assertEquals(0, engine.getBusyReaderCount());
        Assert.assertEquals(M, count);
        try (TableWriter writer = engine.getWriter(AllowAllCairoSecurityContext.INSTANCE, "x", "testing")) {
            writer.removeColumn("b");
        }
        try {
            factory.getCursor(AllowAllSqlSecurityContext.INSTANCE);
            Assert.fail();
        } catch (ReaderOutOfDateException ignored) {
        }
    });
}
Also used : DataFrameCursor(io.questdb.cairo.sql.DataFrameCursor) Rnd(io.questdb.std.Rnd) DataFrame(io.questdb.cairo.sql.DataFrame) ReaderOutOfDateException(io.questdb.cairo.sql.ReaderOutOfDateException) Test(org.junit.Test)

Example 5 with ReaderOutOfDateException

use of io.questdb.cairo.sql.ReaderOutOfDateException in project questdb by bluestreak01.

the class FullBwdDataFrameCursorTest method testReload.

@Test
public void testReload() throws Exception {
    final String expected = "-409854405\t339631474\t1970-01-04T00:00:00.000000Z\n" + "1569490116\t1573662097\t1970-01-03T16:00:00.000000Z\n" + "806715481\t1545253512\t1970-01-03T08:00:00.000000Z\n" + "-1436881714\t-1575378703\t1970-01-03T00:00:00.000000Z\n" + "-1191262516\t-2041844972\t1970-01-02T16:00:00.000000Z\n" + "1868723706\t-847531048\t1970-01-02T08:00:00.000000Z\n" + "1326447242\t592859671\t1970-01-02T00:00:00.000000Z\n" + "73575701\t-948263339\t1970-01-01T16:00:00.000000Z\n" + "1548800833\t-727724771\t1970-01-01T08:00:00.000000Z\n" + "-1148479920\t315515118\t1970-01-01T00:00:00.000000Z\n";
    final String expectedNext = "-1975183723\t-1252906348\t1975-01-04T00:00:00.000000Z\n" + "-1125169127\t1631244228\t1975-01-03T16:00:00.000000Z\n" + "1404198\t-1715058769\t1975-01-03T08:00:00.000000Z\n" + "-1101822104\t-1153445279\t1975-01-03T00:00:00.000000Z\n" + "-1844391305\t-1520872171\t1975-01-02T16:00:00.000000Z\n" + "-85170055\t-1792928964\t1975-01-02T08:00:00.000000Z\n" + "-1432278050\t426455968\t1975-01-02T00:00:00.000000Z\n" + "1125579207\t-1849627000\t1975-01-01T16:00:00.000000Z\n" + "-1532328444\t-1458132197\t1975-01-01T08:00:00.000000Z\n" + "1530831067\t1904508147\t1975-01-01T00:00:00.000000Z\n";
    assertMemoryLeak(() -> {
        try (TableModel model = new TableModel(configuration, "x", PartitionBy.DAY).col("a", ColumnType.INT).col("b", ColumnType.INT).timestamp()) {
            CairoTestUtils.create(model);
        }
        Rnd rnd = new Rnd();
        long timestamp = 0;
        long increment = 3600000000L * 8;
        int N = 10;
        try (TableWriter w = new TableWriter(configuration, "x")) {
            for (int i = 0; i < N; i++) {
                TableWriter.Row row = w.newRow(timestamp);
                row.putInt(0, rnd.nextInt());
                row.putInt(1, rnd.nextInt());
                row.append();
                timestamp += increment;
            }
            w.commit();
            Assert.assertEquals(N, w.size());
            FullBwdDataFrameCursorFactory factory = new FullBwdDataFrameCursorFactory(engine, "x", TableUtils.ANY_TABLE_ID, 0);
            final TableReaderRecord record = new TableReaderRecord();
            try (final DataFrameCursor cursor = factory.getCursor(AllowAllSqlSecurityContext.INSTANCE)) {
                printCursor(record, cursor);
                TestUtils.assertEquals(expected, sink);
                // now add some more rows
                timestamp = TimestampFormatUtils.parseTimestamp("1975-01-01T00:00:00.000Z");
                for (int i = 0; i < N; i++) {
                    TableWriter.Row row = w.newRow(timestamp);
                    row.putInt(0, rnd.nextInt());
                    row.putInt(1, rnd.nextInt());
                    row.append();
                    timestamp += increment;
                }
                w.commit();
                Assert.assertTrue(cursor.reload());
                printCursor(record, cursor);
                TestUtils.assertEquals(expectedNext + expected, sink);
            }
            w.removeColumn("a");
            try {
                factory.getCursor(AllowAllSqlSecurityContext.INSTANCE);
                Assert.fail();
            } catch (ReaderOutOfDateException ignored) {
            }
        }
    });
}
Also used : DataFrameCursor(io.questdb.cairo.sql.DataFrameCursor) Rnd(io.questdb.std.Rnd) ReaderOutOfDateException(io.questdb.cairo.sql.ReaderOutOfDateException) Test(org.junit.Test)

Aggregations

ReaderOutOfDateException (io.questdb.cairo.sql.ReaderOutOfDateException)6 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)4 RecordCursor (io.questdb.cairo.sql.RecordCursor)3 Test (org.junit.Test)3 DataFrameCursor (io.questdb.cairo.sql.DataFrameCursor)2 Rnd (io.questdb.std.Rnd)2 CairoError (io.questdb.cairo.CairoError)1 CairoException (io.questdb.cairo.CairoException)1 EntryUnavailableException (io.questdb.cairo.EntryUnavailableException)1 DataFrame (io.questdb.cairo.sql.DataFrame)1 CompiledQuery (io.questdb.griffin.CompiledQuery)1 SqlCompiler (io.questdb.griffin.SqlCompiler)1 SqlExecutionContext (io.questdb.griffin.SqlExecutionContext)1 SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)1 BindVariableServiceImpl (io.questdb.griffin.engine.functions.bind.BindVariableServiceImpl)1 PeerDisconnectedException (io.questdb.network.PeerDisconnectedException)1 PeerIsSlowToReadException (io.questdb.network.PeerIsSlowToReadException)1