Search in sources :

Example 6 with EntryLockedException

use of io.questdb.cairo.pool.ex.EntryLockedException in project questdb by bluestreak01.

the class SqlOptimiser method openReaderAndEnumerateColumns.

private void openReaderAndEnumerateColumns(SqlExecutionContext executionContext, QueryModel model) throws SqlException {
    final ExpressionNode tableNameNode = model.getTableName();
    // table name must not contain quotes by now
    final CharSequence tableName = tableNameNode.token;
    final int tableNamePosition = tableNameNode.position;
    int lo = 0;
    int hi = tableName.length();
    if (Chars.startsWith(tableName, QueryModel.NO_ROWID_MARKER)) {
        lo += QueryModel.NO_ROWID_MARKER.length();
    }
    if (lo == hi) {
        throw SqlException.$(tableNamePosition, "come on, where is table name?");
    }
    int status = engine.getStatus(executionContext.getCairoSecurityContext(), path, tableName, lo, hi);
    if (status == TableUtils.TABLE_DOES_NOT_EXIST) {
        try {
            model.getTableName().type = ExpressionNode.FUNCTION;
            parseFunctionAndEnumerateColumns(model, executionContext);
            return;
        } catch (SqlException e) {
            throw SqlException.$(tableNamePosition, "" + "table does not exist [name=").put(tableName).put(']');
        }
    }
    if (status == TableUtils.TABLE_RESERVED) {
        throw SqlException.$(tableNamePosition, "table directory is of unknown format");
    }
    try (TableReader r = engine.getReader(executionContext.getCairoSecurityContext(), tableLookupSequence.of(tableName, lo, hi - lo), TableUtils.ANY_TABLE_ID, TableUtils.ANY_TABLE_VERSION)) {
        model.setTableVersion(r.getVersion());
        model.setTableId(r.getMetadata().getId());
        copyColumnsFromMetadata(model, r.getMetadata(), false);
    } catch (EntryLockedException e) {
        throw SqlException.position(tableNamePosition).put("table is locked: ").put(tableLookupSequence);
    } catch (CairoException e) {
        throw SqlException.position(tableNamePosition).put(e);
    }
}
Also used : FlyweightCharSequence(io.questdb.std.str.FlyweightCharSequence) EntryLockedException(io.questdb.cairo.pool.ex.EntryLockedException)

Aggregations

EntryLockedException (io.questdb.cairo.pool.ex.EntryLockedException)6 CountDownLatch (java.util.concurrent.CountDownLatch)4 Test (org.junit.Test)4 SOCountDownLatch (io.questdb.mp.SOCountDownLatch)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 PoolClosedException (io.questdb.cairo.pool.ex.PoolClosedException)1 AbstractLineSender (io.questdb.cutlass.line.AbstractLineSender)1 AuthenticatedLineTcpSender (io.questdb.cutlass.line.AuthenticatedLineTcpSender)1 LineTcpSender (io.questdb.cutlass.line.LineTcpSender)1 FlyweightCharSequence (io.questdb.std.str.FlyweightCharSequence)1 StringSink (io.questdb.std.str.StringSink)1 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1