Search in sources :

Example 1 with CairoException

use of io.questdb.cairo.CairoException in project questdb by bluestreak01.

the class DropTableTest method testDropBusyWriter.

@Test
public void testDropBusyWriter() throws Exception {
    assertMemoryLeak(() -> {
        CompiledQuery cc = compiler.compile("create table 'large table' (a int)", sqlExecutionContext);
        Assert.assertEquals(CompiledQuery.CREATE_TABLE, cc.getType());
        try (TableWriter ignored = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "large table", "testing")) {
            compiler.compile("drop table 'large table'", sqlExecutionContext);
        } catch (CairoException e) {
            TestUtils.assertContains(e.getFlyweightMessage(), "Could not lock");
        }
    });
}
Also used : TableWriter(io.questdb.cairo.TableWriter) CairoException(io.questdb.cairo.CairoException) Test(org.junit.Test)

Example 2 with CairoException

use of io.questdb.cairo.CairoException in project questdb by bluestreak01.

the class MemoryCARWImplTest method testMaxPages.

@Test
public void testMaxPages() {
    int pageSize = 256;
    int maxPages = 3;
    int sz = 256 * 3;
    try (MemoryARW mem = new MemoryCARWImpl(pageSize, maxPages, MemoryTag.NATIVE_DEFAULT)) {
        Assert.assertEquals(pageSize, mem.size());
        int n = 0;
        try {
            while (n <= sz) {
                mem.putByte((byte) n);
                n++;
            }
            Assert.fail();
        } catch (CairoException ex) {
            Assert.assertTrue(ex.getMessage().contains("breached"));
        }
        Assert.assertEquals(sz, n);
        for (n = 0; n < sz; n++) {
            byte b = mem.getByte(n);
            Assert.assertEquals((byte) n, b);
        }
    }
}
Also used : CairoException(io.questdb.cairo.CairoException) MemoryARW(io.questdb.cairo.vm.api.MemoryARW) Test(org.junit.Test)

Example 3 with CairoException

use of io.questdb.cairo.CairoException in project questdb by bluestreak01.

the class MemoryCARWImplTest method testLong256PartialStr.

@Test
public void testLong256PartialStr() {
    final String expected = "0x5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed";
    long pageSize = 128;
    Long256Impl long256 = new Long256Impl();
    Long256Impl long256a = new Long256Impl();
    try (MemoryARW mem = new MemoryCARWImpl(pageSize, Integer.MAX_VALUE, MemoryTag.NATIVE_DEFAULT)) {
        mem.putLong256(expected);
        mem.putLong256(expected);
        mem.getLong256(0, long256);
        String actual = "0x";
        if (long256.getLong3() != 0) {
            actual += Long.toHexString(long256.getLong3());
        }
        if (long256.getLong2() != 0) {
            actual += Long.toHexString(long256.getLong2());
        }
        if (long256.getLong1() != 0) {
            actual += Long.toHexString(long256.getLong1());
        }
        if (long256.getLong0() != 0) {
            actual += Long.toHexString(long256.getLong0());
        }
        Assert.assertEquals(expected, actual);
        mem.getLong256(Long256.BYTES, long256a);
        String actual2 = "0x";
        if (long256a.getLong3() != 0) {
            actual2 += Long.toHexString(long256a.getLong3());
        }
        if (long256a.getLong2() != 0) {
            actual2 += Long.toHexString(long256a.getLong2());
        }
        if (long256a.getLong1() != 0) {
            actual2 += Long.toHexString(long256a.getLong1());
        }
        if (long256a.getLong0() != 0) {
            actual2 += Long.toHexString(long256a.getLong0());
        }
        Assert.assertEquals(expected, actual2);
        long o = mem.getAppendOffset();
        mem.putLong256(expected, 2, expected.length());
        Assert.assertEquals(long256, mem.getLong256A(o));
        String padded = "JUNK" + expected + "MOREJUNK";
        mem.putLong256(padded, 6, 4 + expected.length());
        Assert.assertEquals(long256, mem.getLong256A(o));
        try {
            mem.putLong256(padded);
            Assert.fail();
        } catch (CairoException ex) {
            Assert.assertTrue(ex.getMessage().contains("invalid long256"));
            Assert.assertTrue(ex.getMessage().contains(padded));
        }
    }
}
Also used : CairoException(io.questdb.cairo.CairoException) MemoryARW(io.questdb.cairo.vm.api.MemoryARW) Test(org.junit.Test)

Example 4 with CairoException

use of io.questdb.cairo.CairoException 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 5 with CairoException

use of io.questdb.cairo.CairoException in project questdb by bluestreak01.

the class ContinuousMemoryMTest method testTruncateRemapFailed.

@Test
public void testTruncateRemapFailed() {
    FilesFacade ff = new FilesFacadeImpl() {

        int counter = 1;

        boolean failTruncate = false;

        @Override
        public long mremap(long fd, long addr, long previousSize, long newSize, long offset, int mode, int memoryTag) {
            if (--counter < 0) {
                failTruncate = true;
                return -1;
            }
            return super.mremap(fd, addr, previousSize, newSize, offset, mode, memoryTag);
        }

        @Override
        public boolean truncate(long fd, long size) {
            if (failTruncate) {
                return false;
            }
            return super.truncate(fd, size);
        }
    };
    try (Path path = new Path().of(root).concat("tmp4").$()) {
        ff.touch(path);
        try {
            MemoryMARW mem = Vm.getMARWInstance();
            try {
                mem.of(ff, path, FilesFacadeImpl._16M, -1, MemoryTag.MMAP_DEFAULT);
                // this is larger than page size
                for (int i = 0; i < 3_000_000; i++) {
                    mem.putLong(i * 8, i + 1);
                }
                try {
                    mem.truncate();
                    Assert.fail();
                } catch (CairoException e) {
                    TestUtils.assertContains(e.getFlyweightMessage(), "could not remap file");
                }
            } finally {
                mem.close();
            }
            long fileLen = ff.length(path);
            Assert.assertNotEquals(0, fileLen);
            try (MemoryMR roMem = new MemoryCMRImpl(ff, path, fileLen, MemoryTag.MMAP_DEFAULT)) {
                Assert.assertEquals(fileLen, roMem.size());
                for (int i = 0; i < fileLen; i++) {
                    Assert.assertEquals(0, roMem.getByte(i));
                }
            }
        } finally {
            Assert.assertTrue(ff.remove(path));
        }
    }
}
Also used : Path(io.questdb.std.str.Path) CairoException(io.questdb.cairo.CairoException) Test(org.junit.Test) AbstractCairoTest(io.questdb.cairo.AbstractCairoTest)

Aggregations

CairoException (io.questdb.cairo.CairoException)7 Test (org.junit.Test)5 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)2 MemoryARW (io.questdb.cairo.vm.api.MemoryARW)2 AbstractCairoTest (io.questdb.cairo.AbstractCairoTest)1 CairoError (io.questdb.cairo.CairoError)1 EntryUnavailableException (io.questdb.cairo.EntryUnavailableException)1 TableWriter (io.questdb.cairo.TableWriter)1 ReaderOutOfDateException (io.questdb.cairo.sql.ReaderOutOfDateException)1 RecordCursor (io.questdb.cairo.sql.RecordCursor)1 DefaultTextConfiguration (io.questdb.cutlass.text.DefaultTextConfiguration)1 TextConfiguration (io.questdb.cutlass.text.TextConfiguration)1 PeerDisconnectedException (io.questdb.network.PeerDisconnectedException)1 PeerIsSlowToReadException (io.questdb.network.PeerIsSlowToReadException)1 Path (io.questdb.std.str.Path)1