Search in sources :

Example 21 with Trace

use of org.h2.message.Trace in project h2database by h2database.

the class TestAll method testEverything.

/**
 * Run all tests in all possible combinations.
 */
private void testEverything() throws SQLException {
    for (int c = 0; c < 2; c++) {
        if (c == 0) {
            cipher = null;
        } else {
            cipher = "AES";
        }
        for (int a = 0; a < 64; a++) {
            smallLog = (a & 1) != 0;
            big = (a & 2) != 0;
            networked = (a & 4) != 0;
            memory = (a & 8) != 0;
            ssl = (a & 16) != 0;
            diskResult = (a & 32) != 0;
            for (int trace = 0; trace < 3; trace++) {
                traceLevelFile = trace;
                test();
            }
        }
    }
}
Also used : TestCheckpoint(org.h2.test.db.TestCheckpoint)

Example 22 with Trace

use of org.h2.message.Trace in project h2database by h2database.

the class TestBenchmark method testConcurrency.

private void testConcurrency(String fileName, int concurrency, final int count) throws Exception {
    Thread.sleep(1000);
    final MVStore store = new MVStore.Builder().cacheSize(256).cacheConcurrency(concurrency).fileName(fileName).open();
    int threadCount = 128;
    final CountDownLatch wait = new CountDownLatch(1);
    final AtomicInteger counter = new AtomicInteger();
    final AtomicBoolean stopped = new AtomicBoolean();
    Task[] tasks = new Task[threadCount];
    // Profiler prof = new Profiler().startCollecting();
    for (int i = 0; i < threadCount; i++) {
        final int x = i;
        Task t = new Task() {

            @Override
            public void call() throws Exception {
                MVMap<Integer, byte[]> map = store.openMap("test");
                Random random = new Random(x);
                wait.await();
                while (!stopped.get()) {
                    int key = random.nextInt(count);
                    byte[] data = map.get(key);
                    if (data.length > 1) {
                        counter.incrementAndGet();
                    }
                }
            }
        };
        t.execute("t" + i);
        tasks[i] = t;
    }
    wait.countDown();
    try {
        Thread.sleep(3000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    stopped.set(true);
    for (Task t : tasks) {
        t.get();
    }
    // System.out.println(prof.getTop(5));
    String msg = "concurrency " + concurrency + " threads " + threadCount + " requests: " + counter;
    System.out.println(msg);
    trace(msg);
    store.close();
}
Also used : Task(org.h2.util.Task) CountDownLatch(java.util.concurrent.CountDownLatch) MVStore(org.h2.mvstore.MVStore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Random(java.util.Random) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 23 with Trace

use of org.h2.message.Trace in project h2database by h2database.

the class TestMVStore method testLargerThan2G.

private void testLargerThan2G() {
    if (!config.big) {
        return;
    }
    String fileName = getBaseDir() + "/" + getTestName();
    FileUtils.delete(fileName);
    MVStore store = new MVStore.Builder().cacheSize(16).fileName(fileName).open();
    try {
        MVMap<Integer, String> map = store.openMap("test");
        long last = System.nanoTime();
        String data = new String(new char[2500]).replace((char) 0, 'x');
        for (int i = 0; ; i++) {
            map.put(i, data);
            if (i % 10000 == 0) {
                store.commit();
                long time = System.nanoTime();
                if (time - last > TimeUnit.SECONDS.toNanos(2)) {
                    long mb = store.getFileStore().size() / 1024 / 1024;
                    trace(mb + "/4500");
                    if (mb > 4500) {
                        break;
                    }
                    last = time;
                }
            }
        }
        store.commit();
        store.close();
    } finally {
        store.closeImmediately();
    }
    FileUtils.delete(fileName);
}
Also used : MVStore(org.h2.mvstore.MVStore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 24 with Trace

use of org.h2.message.Trace in project h2database by h2database.

the class Recover method dumpPageBtreeNode.

private void dumpPageBtreeNode(PrintWriter writer, Data s, long pageId, boolean positionOnly) {
    int rowCount = s.readInt();
    int entryCount = s.readShortInt();
    int[] children = new int[entryCount + 1];
    int[] offsets = new int[entryCount];
    children[entryCount] = s.readInt();
    checkParent(writer, pageId, children, entryCount);
    int empty = Integer.MAX_VALUE;
    for (int i = 0; i < entryCount; i++) {
        children[i] = s.readInt();
        checkParent(writer, pageId, children, i);
        int off = s.readShortInt();
        empty = Math.min(off, empty);
        offsets[i] = off;
    }
    empty = empty - s.length();
    if (!trace) {
        return;
    }
    writer.println("--   empty: " + empty);
    for (int i = 0; i < entryCount; i++) {
        int off = offsets[i];
        s.setPos(off);
        long key = s.readVarLong();
        Value data;
        if (positionOnly) {
            data = ValueLong.get(key);
        } else {
            try {
                data = s.readValue();
            } catch (Throwable e) {
                writeDataError(writer, "exception " + e, s.getBytes());
                continue;
            }
        }
        writer.println("-- [" + i + "] child: " + children[i] + " key: " + key + " data: " + data);
    }
    writer.println("-- [" + entryCount + "] child: " + children[entryCount] + " rowCount: " + rowCount);
}
Also used : Value(org.h2.value.Value)

Example 25 with Trace

use of org.h2.message.Trace in project h2database by h2database.

the class FtpServer method startTask.

/**
 * Start a task.
 *
 * @param path the name of the task file
 */
void startTask(String path) throws IOException {
    stopTask(path);
    if (path.endsWith(".zip.task")) {
        trace("expand: " + path);
        Process p = Runtime.getRuntime().exec("jar -xf " + path, null, new File(root));
        new StreamRedirect(path, p.getInputStream(), null).start();
        return;
    }
    Properties prop = SortedProperties.loadProperties(path);
    String command = prop.getProperty("command");
    String outFile = path.substring(0, path.length() - TASK_SUFFIX.length());
    String errorFile = root + "/" + prop.getProperty("error", outFile + ".err.txt");
    String outputFile = root + "/" + prop.getProperty("output", outFile + ".out.txt");
    trace("start process: " + path + " / " + command);
    Process p = Runtime.getRuntime().exec(command, null, new File(root));
    new StreamRedirect(path, p.getErrorStream(), errorFile).start();
    new StreamRedirect(path, p.getInputStream(), outputFile).start();
    tasks.put(path, p);
}
Also used : SortedProperties(org.h2.util.SortedProperties) Properties(java.util.Properties) File(java.io.File)

Aggregations

SQLException (java.sql.SQLException)16 DbException (org.h2.message.DbException)14 Connection (java.sql.Connection)11 ResultSet (java.sql.ResultSet)10 PreparedStatement (java.sql.PreparedStatement)9 Statement (java.sql.Statement)8 IOException (java.io.IOException)7 Savepoint (java.sql.Savepoint)7 Random (java.util.Random)7 ArrayList (java.util.ArrayList)5 Properties (java.util.Properties)5 TraceSystem (org.h2.message.TraceSystem)5 Server (org.h2.tools.Server)5 ValueString (org.h2.value.ValueString)5 SQLClientInfoException (java.sql.SQLClientInfoException)4 SysProperties (org.h2.engine.SysProperties)4 JdbcConnection (org.h2.jdbc.JdbcConnection)4 SortedProperties (org.h2.util.SortedProperties)4 Value (org.h2.value.Value)4 Socket (java.net.Socket)3