Search in sources :

Example 31 with FilesFacadeImpl

use of io.questdb.std.FilesFacadeImpl in project questdb by bluestreak01.

the class LineTCPSenderMainVarLenStrings method main.

public static void main(String[] args) {
    final long count = 2_000_000_000L;
    String hostIPv4 = "127.0.0.1";
    int port = 9009;
    int bufferCapacity = 64;
    final Rnd rnd = new Rnd();
    long start = System.nanoTime();
    FilesFacade ff = new FilesFacadeImpl();
    try (Path path = new Path()) {
        long logFd = -1;
        if (args.length == 1) {
            path.put(args[0]).$();
            logFd = ff.openRW(path);
        }
        try (LineTcpSender sender = new LoggingLineTcpSender(Net.parseIPv4(hostIPv4), port, bufferCapacity, logFd, ff)) {
            for (int i = 0; i < count; i++) {
                sender.metric("md_msgs");
                sender.field("ts_nsec", rnd.nextPositiveLong()).field("pkt_size", rnd.nextPositiveInt()).field("pcap_file", nextString(rnd.nextPositiveInt() % 64, rnd)).field("raw_msg", nextString(rnd.nextPositiveInt() % 512, rnd)).field("Length", rnd.nextInt()).field("MsgSeqNum", i).field("MsgType", rnd.nextInt() % 1000).field("src_ip", rnd.nextString(rnd.nextPositiveInt() % 16)).field("dst_ip", rnd.nextString(rnd.nextPositiveInt() % 16)).field("src_port", rnd.nextInt() % 10000).field("dst_port", rnd.nextInt() % 10000).field("first_dir", rnd.nextBoolean()).$(i * 10_000_000L);
            }
            sender.flush();
        } finally {
            if (logFd > 0) {
                ff.close(logFd);
            }
        }
    }
    System.out.println("Actual rate: " + (count * 1_000_000_000L / (System.nanoTime() - start)));
}
Also used : Path(io.questdb.std.str.Path) FilesFacade(io.questdb.std.FilesFacade) Rnd(io.questdb.std.Rnd) LineTcpSender(io.questdb.cutlass.line.LineTcpSender) FilesFacadeImpl(io.questdb.std.FilesFacadeImpl)

Example 32 with FilesFacadeImpl

use of io.questdb.std.FilesFacadeImpl in project questdb by bluestreak01.

the class SqlCompilerTest method testCreateTableFail.

@Test
public void testCreateTableFail() throws Exception {
    FilesFacade ff = new FilesFacadeImpl() {

        // this count is very deliberately coincidental with
        int count = 8;

        // number of rows we are appending
        @Override
        public long mmap(long fd, long len, long offset, int flags, int memoryTag) {
            if (count-- > 0) {
                return super.mmap(fd, len, offset, flags, memoryTag);
            }
            return -1;
        }
    };
    assertFailure(ff, "create table x as (select cast(x as int) c, abs(rnd_int() % 650) a from long_sequence(5000000))", "Could not create table. See log for details");
}
Also used : FilesFacade(io.questdb.std.FilesFacade) FilesFacadeImpl(io.questdb.std.FilesFacadeImpl) Test(org.junit.Test)

Example 33 with FilesFacadeImpl

use of io.questdb.std.FilesFacadeImpl in project questdb by bluestreak01.

the class TableBackupTest method setup.

@Before
public void setup() throws IOException {
    path = new Path();
    finalBackupPath = new Path();
    mkdirsErrno = -1;
    renameErrno = -1;
    FilesFacade ff = new FilesFacadeImpl() {

        private int nextErrno = -1;

        @Override
        public int errno() {
            if (nextErrno != -1) {
                int errno = nextErrno;
                nextErrno = -1;
                return errno;
            }
            return super.errno();
        }

        @Override
        public int mkdirs(LPSZ path, int mode) {
            if (mkdirsErrno != -1 && --mkdirsErrnoCountDown < 1) {
                nextErrno = mkdirsErrno;
                mkdirsErrno = -1;
                mkdirsErrnoCountDown = 0;
                return -1;
            }
            return super.mkdirs(path, mode);
        }

        @Override
        public boolean rename(LPSZ from, LPSZ to) {
            if (renameErrno != -1) {
                nextErrno = renameErrno;
                renameErrno = -1;
                return false;
            }
            return super.rename(from, to);
        }
    };
    CharSequence root = temp.newFolder(String.format("dbRoot%c%s", Files.SEPARATOR, PropServerConfiguration.DB_DIRECTORY)).getAbsolutePath();
    backupRoot = temp.newFolder("dbBackupRoot").getAbsolutePath();
    mainConfiguration = new DefaultCairoConfiguration(root) {

        @Override
        public FilesFacade getFilesFacade() {
            return ff;
        }

        @Override
        public CharSequence getBackupRoot() {
            return backupRoot;
        }

        @Override
        public DateFormat getBackupDirTimestampFormat() {
            return new TimestampFormatCompiler().compile("ddMMMyyyy");
        }
    };
    mainEngine = new CairoEngine(mainConfiguration);
    mainCompiler = new SqlCompiler(mainEngine);
    mainSqlExecutionContext = new SqlExecutionContextImpl(mainEngine, 1).with(AllowAllCairoSecurityContext.INSTANCE, new BindVariableServiceImpl(mainConfiguration), null, -1, null);
    // dummy configuration
    File confRoot = new File(PropServerConfiguration.confRoot(root));
    Assert.assertTrue(confRoot.mkdirs());
    Assert.assertTrue(new File(confRoot, "server.conf").createNewFile());
    Assert.assertTrue(new File(confRoot, "mime.types").createNewFile());
    Assert.assertTrue(new File(confRoot, "log-file.conf").createNewFile());
    Assert.assertTrue(new File(confRoot, "date.formats").createNewFile());
}
Also used : FilesFacadeImpl(io.questdb.std.FilesFacadeImpl) FilesFacade(io.questdb.std.FilesFacade) TimestampFormatCompiler(io.questdb.std.datetime.microtime.TimestampFormatCompiler) DateFormat(io.questdb.std.datetime.DateFormat) BindVariableServiceImpl(io.questdb.griffin.engine.functions.bind.BindVariableServiceImpl) File(java.io.File)

Example 34 with FilesFacadeImpl

use of io.questdb.std.FilesFacadeImpl in project questdb by bluestreak01.

the class O3FailureTest method testPartitionedOOPrefixesExistingPartitionsCreateDirsContended.

@Test
public void testPartitionedOOPrefixesExistingPartitionsCreateDirsContended() throws Exception {
    counter.set(2);
    executeWithPool(0, O3FailureTest::testPartitionedOOPrefixesExistingPartitionsFailRetry0, new FilesFacadeImpl() {

        @Override
        public int mkdirs(LPSZ path, int mode) {
            if (Chars.contains(path, "1970-01-01") && counter.decrementAndGet() == 0) {
                return -1;
            }
            return super.mkdirs(path, mode);
        }
    });
}
Also used : LPSZ(io.questdb.std.str.LPSZ) FilesFacadeImpl(io.questdb.std.FilesFacadeImpl) Test(org.junit.Test)

Example 35 with FilesFacadeImpl

use of io.questdb.std.FilesFacadeImpl in project questdb by bluestreak01.

the class O3FailureTest method testColumnTopLastDataOOODataFailRetryMapRo.

@Test
public void testColumnTopLastDataOOODataFailRetryMapRo() throws Exception {
    counter.set(1);
    executeWithoutPool((compiler, sqlExecutionContext, sqlExecutionContext2) -> testColumnTopLastDataOOODataFailRetry0(sqlExecutionContext, sqlExecutionContext2), new FilesFacadeImpl() {

        long theFd = 0;

        @Override
        public long mmap(long fd, long len, long offset, int flags, int memoryTag) {
            if (fd == theFd && flags == Files.MAP_RO) {
                theFd = 0;
                return -1;
            }
            return super.mmap(fd, len, offset, flags, memoryTag);
        }

        @Override
        public long openRW(LPSZ name) {
            long fd = super.openRW(name);
            if (Chars.endsWith(name, "1970-01-07" + Files.SEPARATOR + "v11.d") && counter.decrementAndGet() == 0) {
                theFd = fd;
            }
            return fd;
        }
    });
}
Also used : LPSZ(io.questdb.std.str.LPSZ) FilesFacadeImpl(io.questdb.std.FilesFacadeImpl) Test(org.junit.Test)

Aggregations

FilesFacadeImpl (io.questdb.std.FilesFacadeImpl)48 Test (org.junit.Test)46 LPSZ (io.questdb.std.str.LPSZ)35 FilesFacade (io.questdb.std.FilesFacade)14 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 Path (io.questdb.std.str.Path)4 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)3 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)3 SqlCompiler (io.questdb.griffin.SqlCompiler)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 MemoryMARW (io.questdb.cairo.vm.api.MemoryMARW)1 LineTcpSender (io.questdb.cutlass.line.LineTcpSender)1 SqlException (io.questdb.griffin.SqlException)1 BindVariableServiceImpl (io.questdb.griffin.engine.functions.bind.BindVariableServiceImpl)1 Rnd (io.questdb.std.Rnd)1 DateFormat (io.questdb.std.datetime.DateFormat)1 TimestampFormatCompiler (io.questdb.std.datetime.microtime.TimestampFormatCompiler)1 File (java.io.File)1