当前位置: 首页>>代码示例>>Java>>正文


Java MVMap.remove方法代码示例

本文整理汇总了Java中org.h2.mvstore.MVMap.remove方法的典型用法代码示例。如果您正苦于以下问题:Java MVMap.remove方法的具体用法?Java MVMap.remove怎么用?Java MVMap.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.h2.mvstore.MVMap的用法示例。


在下文中一共展示了MVMap.remove方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: rollbackTo

import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
/**
 * Rollback to an old savepoint.
 *
 * @param t the transaction
 * @param maxLogId the last log id
 * @param toLogId the log id to roll back to
 */
void rollbackTo(Transaction t, long maxLogId, long toLogId) {
    // TODO could synchronize on blocks (100 at a time or so)
    synchronized (undoLog) {
        for (long logId = maxLogId - 1; logId >= toLogId; logId--) {
            Long undoKey = getOperationId(t.getId(), logId);
            Object[] op = undoLog.get(undoKey);
            if (op == null) {
                // partially rolled back: load previous
                undoKey = undoLog.floorKey(undoKey);
                if (undoKey == null ||
                        getTransactionId(undoKey) != t.getId()) {
                    break;
                }
                logId = getLogId(undoKey) + 1;
                continue;
            }
            int mapId = ((Integer) op[0]).intValue();
            MVMap<Object, VersionedValue> map = openMap(mapId);
            if (map != null) {
                Object key = op[1];
                VersionedValue oldValue = (VersionedValue) op[2];
                if (oldValue == null) {
                    // this transaction added the value
                    map.remove(key);
                } else {
                    // this transaction updated the value
                    map.put(key, oldValue);
                }
            }
            undoLog.remove(undoKey);
        }
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:41,代码来源:TransactionStore.java

示例2: testConcurrentIterate

import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
private void testConcurrentIterate() {
    MVStore s = new MVStore.Builder().pageSplitSize(3).open();
    s.setVersionsToKeep(100);
    final MVMap<Integer, Integer> map = s.openMap("test");
    final int len = 10;
    final Random r = new Random();
    Task t = new Task() {
        @Override
        public void call() throws Exception {
            while (!stop) {
                int x = r.nextInt(len);
                if (r.nextBoolean()) {
                    map.remove(x);
                } else {
                    map.put(x, r.nextInt(100));
                }
            }
        }
    };
    t.execute();
    for (int k = 0; k < 10000; k++) {
        Iterator<Integer> it = map.keyIterator(r.nextInt(len));
        long old = s.getCurrentVersion();
        s.commit();
        while (map.getVersion() == old) {
            Thread.yield();
        }
        while (it.hasNext()) {
            it.next();
        }
    }
    t.get();
    s.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:35,代码来源:TestConcurrent.java

示例3: testTruncateFile

import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
private void testTruncateFile() {
    String fileName = getBaseDir() + "/testTruncate.h3";
    FileUtils.delete(fileName);
    MVStore s;
    MVMap<Integer, String> m;
    s = openStore(fileName);
    m = s.openMap("data");
    String data = new String(new char[10000]).replace((char) 0, 'x');
    for (int i = 1; i < 10; i++) {
        m.put(i, data);
        s.commit();
    }
    s.close();
    long len = FileUtils.size(fileName);
    s = openStore(fileName);
    s.setRetentionTime(0);
    // remove 75%
    m = s.openMap("data");
    for (int i = 0; i < 10; i++) {
        if (i % 4 != 0) {
            m.remove(i);
        }
    }
    s.commit();
    assertTrue(s.compact(100, 50 * 1024));
    s.close();
    long len2 = FileUtils.size(fileName);
    assertTrue("len2: " + len2 + " len: " + len, len2 < len);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:30,代码来源:TestMVStore.java

示例4: commit

import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
/**
 * Commit a transaction.
 *
 * @param t the transaction
 * @param maxLogId the last log id
 */
void commit(Transaction t, long maxLogId) {
    if (store.isClosed()) {
        return;
    }
    // TODO could synchronize on blocks (100 at a time or so)
    synchronized (undoLog) {
        t.setStatus(Transaction.STATUS_COMMITTING);
        for (long logId = 0; logId < maxLogId; logId++) {
            Long undoKey = getOperationId(t.getId(), logId);
            Object[] op = undoLog.get(undoKey);
            if (op == null) {
                // partially committed: load next
                undoKey = undoLog.ceilingKey(undoKey);
                if (undoKey == null ||
                        getTransactionId(undoKey) != t.getId()) {
                    break;
                }
                logId = getLogId(undoKey) - 1;
                continue;
            }
            int mapId = (Integer) op[0];
            MVMap<Object, VersionedValue> map = openMap(mapId);
            if (map == null) {
                // map was later removed
            } else {
                Object key = op[1];
                VersionedValue value = map.get(key);
                if (value == null) {
                    // nothing to do
                } else if (value.value == null) {
                    // remove the value
                    map.remove(key);
                } else {
                    VersionedValue v2 = new VersionedValue();
                    v2.value = value.value;
                    map.put(key, v2);
                }
            }
            undoLog.remove(undoKey);
        }
    }
    endTransaction(t);
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:50,代码来源:TransactionStore.java

示例5: testConcurrentMap

import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
/**
 * Test the concurrent map implementation.
 */
private void testConcurrentMap() throws InterruptedException {
    final MVStore s = openStore(null);
    final MVMap<Integer, Integer> m = s.openMap("data");
    final int size = 20;
    final Random rand = new Random(1);
    Task task = new Task() {
        @Override
        public void call() throws Exception {
            try {
                while (!stop) {
                    if (rand.nextBoolean()) {
                        m.put(rand.nextInt(size), 1);
                    } else {
                        m.remove(rand.nextInt(size));
                    }
                    m.get(rand.nextInt(size));
                    m.firstKey();
                    m.lastKey();
                    m.ceilingKey(5);
                    m.floorKey(5);
                    m.higherKey(5);
                    m.lowerKey(5);
                    for (Iterator<Integer> it = m.keyIterator(null);
                            it.hasNext();) {
                        it.next();
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    task.execute();
    Thread.sleep(1);
    for (int j = 0; j < 100; j++) {
        for (int i = 0; i < 100; i++) {
            if (rand.nextBoolean()) {
                m.put(rand.nextInt(size), 2);
            } else {
                m.remove(rand.nextInt(size));
            }
            m.get(rand.nextInt(size));
        }
        s.commit();
        Thread.sleep(1);
    }
    task.get();
    s.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:53,代码来源:TestConcurrent.java

示例6: write

import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
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;
    }
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:56,代码来源:TestKillProcessWhileWriting.java

示例7: testExampleMvcc

import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
private void testExampleMvcc() {
    String fileName = getBaseDir() + "/testExampleMvcc.h3";
    FileUtils.delete(fileName);

    // open the store (in-memory if fileName is null)
    MVStore s = MVStore.open(fileName);

    // create/get the map named "data"
    MVMap<Integer, String> map = s.openMap("data");

    // add some data
    map.put(1, "Hello");
    map.put(2, "World");

    // get the current version, for later use
    long oldVersion = s.getCurrentVersion();

    // from now on, the old version is read-only
    s.commit();

    // more changes, in the new version
    // changes can be rolled back if required
    // changes always go into "head" (the newest version)
    map.put(1, "Hi");
    map.remove(2);

    // access the old data (before the commit)
    MVMap<Integer, String> oldMap =
            map.openVersion(oldVersion);

    // print the old version (can be done
    // concurrently with further modifications)
    // this will print "Hello" and "World":
    // System.out.println(oldMap.get(1));
    assertEquals("Hello", oldMap.get(1));
    // System.out.println(oldMap.get(2));
    assertEquals("World", oldMap.get(2));

    // print the newest version ("Hi")
    // System.out.println(map.get(1));
    assertEquals("Hi", map.get(1));

    // close the store
    s.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:46,代码来源:TestMVStore.java

示例8: testBtreeStore

import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
private void testBtreeStore() {
    String fileName = getBaseDir() + "/testBtreeStore.h3";
    FileUtils.delete(fileName);
    MVStore s = openStore(fileName);
    s.close();

    s = openStore(fileName);
    MVMap<Integer, String> m = s.openMap("data");
    int count = 2000;
    // Profiler p = new Profiler();
    // p.startCollecting();
    // long t = System.currentTimeMillis();
    for (int i = 0; i < count; i++) {
        assertNull(m.put(i, "hello " + i));
        assertEquals("hello " + i, m.get(i));
    }
    // System.out.println("put: " + (System.currentTimeMillis() - t));
    // System.out.println(p.getTop(5));
    // p = new Profiler();
    //p.startCollecting();
    // t = System.currentTimeMillis();
    s.commit();
    // System.out.println("store: " + (System.currentTimeMillis() - t));
    // System.out.println(p.getTop(5));
    assertEquals("hello 0", m.remove(0));
    assertNull(m.get(0));
    for (int i = 1; i < count; i++) {
        assertEquals("hello " + i, m.get(i));
    }
    s.close();

    s = openStore(fileName);
    m = s.openMap("data");
    assertNull(m.get(0));
    for (int i = 1; i < count; i++) {
        assertEquals("hello " + i, m.get(i));
    }
    for (int i = 1; i < count; i++) {
        m.remove(i);
    }
    s.commit();
    assertNull(m.get(0));
    for (int i = 0; i < count; i++) {
        assertNull(m.get(i));
    }
    s.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:48,代码来源:TestMVStore.java

示例9: testRandom

import org.h2.mvstore.MVMap; //导入方法依赖的package包/类
private void testRandom() {
    String fileName = getBaseDir() + "/testRandom.h3";
    FileUtils.delete(fileName);
    MVStore s = openStore(fileName);
    MVMap<Integer, Integer> m = s.openMap("data");
    TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
    Random r = new Random(1);
    int operationCount = 1000;
    int maxValue = 30;
    Integer expected, got;
    for (int i = 0; i < operationCount; i++) {
        int k = r.nextInt(maxValue);
        int v = r.nextInt();
        boolean compareAll;
        switch (r.nextInt(3)) {
        case 0:
            log(i + ": put " + k + " = " + v);
            expected = map.put(k, v);
            got = m.put(k, v);
            if (expected == null) {
                assertNull(got);
            } else {
                assertEquals(expected, got);
            }
            compareAll = true;
            break;
        case 1:
            log(i + ": remove " + k);
            expected = map.remove(k);
            got = m.remove(k);
            if (expected == null) {
                assertNull(got);
            } else {
                assertEquals(expected, got);
            }
            compareAll = true;
            break;
        default:
            Integer a = map.get(k);
            Integer b = m.get(k);
            if (a == null || b == null) {
                assertTrue(a == b);
            } else {
                assertEquals(a.intValue(), b.intValue());
            }
            compareAll = false;
            break;
        }
        if (compareAll) {
            Iterator<Integer> it = m.keyIterator(null);
            Iterator<Integer> itExpected = map.keySet().iterator();
            while (itExpected.hasNext()) {
                assertTrue(it.hasNext());
                expected = itExpected.next();
                got = it.next();
                assertEquals(expected, got);
            }
            assertFalse(it.hasNext());
        }
    }
    s.close();
}
 
开发者ID:vdr007,项目名称:ThriftyPaxos,代码行数:63,代码来源:TestMVStore.java


注:本文中的org.h2.mvstore.MVMap.remove方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。