예제 #1
0
 /** Clear the map. */
 public void clear() {
   // TODO truncate transactionally
   map.clear();
 }
예제 #2
0
  private void testConcurrentFree() throws InterruptedException {
    String fileName = "memFS:testConcurrentFree.h3";
    for (int test = 0; test < 10; test++) {
      FileUtils.delete(fileName);
      final MVStore s1 = new MVStore.Builder().fileName(fileName).autoCommitDisabled().open();
      s1.setRetentionTime(0);
      final int count = 200;
      for (int i = 0; i < count; i++) {
        MVMap<Integer, Integer> m = s1.openMap("d" + i);
        m.put(1, 1);
        if (i % 2 == 0) {
          s1.commit();
        }
      }
      s1.close();
      final MVStore s = new MVStore.Builder().fileName(fileName).autoCommitDisabled().open();
      s.setRetentionTime(0);
      final ArrayList<MVMap<Integer, Integer>> list = New.arrayList();
      for (int i = 0; i < count; i++) {
        MVMap<Integer, Integer> m = s.openMap("d" + i);
        list.add(m);
      }

      final AtomicInteger counter = new AtomicInteger();
      Task task =
          new Task() {
            @Override
            public void call() throws Exception {
              while (!stop) {
                int x = counter.getAndIncrement();
                if (x >= count) {
                  break;
                }
                MVMap<Integer, Integer> m = list.get(x);
                m.clear();
                s.removeMap(m);
              }
            }
          };
      task.execute();
      Thread.sleep(1);
      while (true) {
        int x = counter.getAndIncrement();
        if (x >= count) {
          break;
        }
        MVMap<Integer, Integer> m = list.get(x);
        m.clear();
        s.removeMap(m);
        if (x % 5 == 0) {
          s.commit();
        }
      }
      task.get();
      s.commit();

      MVMap<String, String> meta = s.getMetaMap();
      int chunkCount = 0;
      for (String k : meta.keyList()) {
        if (k.startsWith("chunk.")) {
          chunkCount++;
        }
      }
      assertEquals(1, chunkCount);
      s.close();
    }
    FileUtils.deleteRecursive("memFS:", false);
  }