Пример #1
1
 private void init() {
   String s = settings.get(LAST_TRANSACTION_ID);
   if (s != null) {
     lastTransactionId = Long.parseLong(s);
     lastTransactionIdStored = lastTransactionId;
   }
   Long lastKey = openTransactions.lastKey();
   if (lastKey != null && lastKey.longValue() > lastTransactionId) {
     throw DataUtils.newIllegalStateException("Last transaction not stored");
   }
   Cursor<Long> cursor = openTransactions.keyIterator(null);
   while (cursor.hasNext()) {
     long id = cursor.next();
     Object[] data = openTransactions.get(id);
     int status = (Integer) data[0];
     String name = (String) data[1];
     long[] next = {id + 1, -1};
     long[] last = undoLog.floorKey(next);
     if (last == null) {
       // no entry
     } else if (last[0] == id) {
       Transaction t = new Transaction(this, id, status, name, last[1]);
       t.setStored(true);
       openTransactionMap.put(id, t);
     }
   }
 }
Пример #2
0
 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();
 }
Пример #3
0
 /**
  * Get the size of the map as seen by this transaction.
  *
  * @return the size
  */
 public long getSize() {
   // TODO this method is very slow
   long size = 0;
   Cursor<K> cursor = map.keyIterator(null);
   while (cursor.hasNext()) {
     K key = cursor.next();
     if (get(key) != null) {
       size++;
     }
   }
   return size;
 }