Search in sources :

Example 86 with MVStore

use of org.h2.mvstore.MVStore in project h2database by h2database.

the class TestTransactionStore method testGetModifiedMaps.

private void testGetModifiedMaps() {
    MVStore s = MVStore.open(null);
    TransactionStore ts = new TransactionStore(s);
    ts.init();
    Transaction tx;
    TransactionMap<String, String> m1, m2, m3;
    long sp;
    tx = ts.begin();
    m1 = tx.openMap("m1");
    m2 = tx.openMap("m2");
    m3 = tx.openMap("m3");
    assertFalse(tx.getChanges(0).hasNext());
    tx.commit();
    tx = ts.begin();
    m1 = tx.openMap("m1");
    m2 = tx.openMap("m2");
    m3 = tx.openMap("m3");
    m1.put("1", "100");
    sp = tx.setSavepoint();
    m2.put("1", "100");
    m3.put("1", "100");
    Iterator<Change> it = tx.getChanges(sp);
    assertTrue(it.hasNext());
    Change c;
    c = it.next();
    assertEquals("m3", c.mapName);
    assertEquals("1", c.key.toString());
    assertNull(c.value);
    assertTrue(it.hasNext());
    c = it.next();
    assertEquals("m2", c.mapName);
    assertEquals("1", c.key.toString());
    assertNull(c.value);
    assertFalse(it.hasNext());
    it = tx.getChanges(0);
    assertTrue(it.hasNext());
    c = it.next();
    assertEquals("m3", c.mapName);
    assertEquals("1", c.key.toString());
    assertNull(c.value);
    assertTrue(it.hasNext());
    c = it.next();
    assertEquals("m2", c.mapName);
    assertEquals("1", c.key.toString());
    assertNull(c.value);
    assertTrue(it.hasNext());
    c = it.next();
    assertEquals("m1", c.mapName);
    assertEquals("1", c.key.toString());
    assertNull(c.value);
    assertFalse(it.hasNext());
    tx.rollbackToSavepoint(sp);
    it = tx.getChanges(0);
    assertTrue(it.hasNext());
    c = it.next();
    assertEquals("m1", c.mapName);
    assertEquals("1", c.key.toString());
    assertNull(c.value);
    assertFalse(it.hasNext());
    tx.commit();
    s.close();
}
Also used : MVStore(org.h2.mvstore.MVStore) TransactionStore(org.h2.mvstore.db.TransactionStore) Transaction(org.h2.mvstore.db.TransactionStore.Transaction) Change(org.h2.mvstore.db.TransactionStore.Change)

Example 87 with MVStore

use of org.h2.mvstore.MVStore in project h2database by h2database.

the class TestKillProcessWhileWriting method write.

private int write() {
    MVStore s;
    MVMap<Integer, byte[]> m;
    s = new MVStore.Builder().fileName(fileName).pageSplitSize(50).autoCommitDisabled().open();
    m = s.openMap("data");
    Random r = new Random(seed);
    int op = 0;
    try {
        for (; op < 100; op++) {
            int k = r.nextInt(100);
            byte[] v = new byte[r.nextInt(100) * 100];
            int type = r.nextInt(10);
            switch(type) {
                case 0:
                case 1:
                case 2:
                case 3:
                    m.put(k, v);
                    break;
                case 4:
                case 5:
                    m.remove(k);
                    break;
                case 6:
                    s.commit();
                    break;
                case 7:
                    s.compact(80, 1024);
                    break;
                case 8:
                    m.clear();
                    break;
                case 9:
                    s.close();
                    s = new MVStore.Builder().fileName(fileName).pageSplitSize(50).autoCommitDisabled().open();
                    m = s.openMap("data");
                    break;
            }
        }
        s.close();
        return 0;
    } catch (Exception e) {
        s.closeImmediately();
        return op;
    }
}
Also used : MVStore(org.h2.mvstore.MVStore) Random(java.util.Random)

Example 88 with MVStore

use of org.h2.mvstore.MVStore in project h2database by h2database.

the class TestMVStore method testRenameMapRollback.

private void testRenameMapRollback() {
    MVStore s = openStore(null);
    MVMap<Integer, Integer> map;
    map = s.openMap("hello");
    map.put(1, 10);
    long old = s.commit();
    s.renameMap(map, "world");
    map.put(2, 20);
    assertEquals("world", map.getName());
    s.rollbackTo(old);
    assertEquals("hello", map.getName());
    s.rollbackTo(0);
    assertTrue(map.isClosed());
    s.close();
}
Also used : MVStore(org.h2.mvstore.MVStore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 89 with MVStore

use of org.h2.mvstore.MVStore in project h2database by h2database.

the class TestMVStore method testIterateOldVersion.

private void testIterateOldVersion() {
    MVStore s;
    Map<Integer, Integer> map;
    s = new MVStore.Builder().open();
    map = s.openMap("test");
    int len = 100;
    for (int i = 0; i < len; i++) {
        map.put(i, 10 * i);
    }
    Iterator<Integer> it = map.keySet().iterator();
    s.commit();
    for (int i = 0; i < len; i += 2) {
        map.remove(i);
    }
    int count = 0;
    while (it.hasNext()) {
        it.next();
        count++;
    }
    assertEquals(len, count);
    s.close();
}
Also used : MVStore(org.h2.mvstore.MVStore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 90 with MVStore

use of org.h2.mvstore.MVStore in project h2database by h2database.

the class TestMVStore method testRollback.

private void testRollback() {
    MVStore s = MVStore.open(null);
    MVMap<Integer, Integer> m = s.openMap("m");
    m.put(1, -1);
    s.commit();
    for (int i = 0; i < 10; i++) {
        m.put(1, i);
        s.rollback();
        assertEquals(i - 1, m.get(1).intValue());
        m.put(1, i);
        s.commit();
    }
}
Also used : MVStore(org.h2.mvstore.MVStore) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Aggregations

MVStore (org.h2.mvstore.MVStore)123 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)69 Random (java.util.Random)23 Task (org.h2.util.Task)20 TransactionStore (org.h2.mvstore.db.TransactionStore)19 Transaction (org.h2.mvstore.db.TransactionStore.Transaction)17 MVRTreeMap (org.h2.mvstore.rtree.MVRTreeMap)8 SpatialKey (org.h2.mvstore.rtree.SpatialKey)8 IOException (java.io.IOException)6 Connection (java.sql.Connection)5 Statement (java.sql.Statement)5 FileStore (org.h2.mvstore.FileStore)5 StreamStore (org.h2.mvstore.StreamStore)5 ArrayList (java.util.ArrayList)4 TreeMap (java.util.TreeMap)4 Store (org.h2.mvstore.db.MVTableEngine.Store)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 FileOutputStream (java.io.FileOutputStream)3 OutputStream (java.io.OutputStream)3 PreparedStatement (java.sql.PreparedStatement)3