@Test
  public void useOldVSpecInducesExpectedFailure() throws Exception {
    VolumeSpecification volumeSpec;
    final Configuration configuration = _persistit.getConfiguration();
    _persistit.close();
    int remainingJournalFiles = 0;
    configuration.setUseOldVSpec(true);

    for (int i = 5; --i >= 0; ) {
      final Persistit db = new Persistit(_config);
      try {
        volumeSpec =
            new VolumeSpecification(
                DATA_PATH + "/hwdemo" + i, null, 16384, 1, 1000, 1, true, false, false);
        db.loadVolume(volumeSpec);
        final Exchange dbex = db.getExchange("hwdemo" + i, "greetings", true);
        dbex.getKey().append("Hello");
        dbex.getValue().put("World");
        dbex.store();
        dbex.getKey().to(Key.BEFORE);
        db.releaseExchange(dbex);
      } finally {
        if (i == 0) {
          db.copyBackPages();
        }
        remainingJournalFiles = db.getJournalManager().getJournalFileCount();
        db.close();
      }
    }
    assertTrue("Should be only one remaining journal file", remainingJournalFiles > 1);
  }
  /**
   * Test for bug https://bugs.launchpad.net/akiban-persistit/+bug/1045983
   *
   * Truncating a dynamically created volume results in corrupted journal If
   * you dynamically load a volume, truncate it (without adding any trees),
   * and then close it, the next time the database is initialized a fatal
   * exception is thrown:
   *
   * <code><pre>
   *
   * [JOURNAL_COPIER] WARNING Missing volume truncated referenced at journal address 364
   * [main] WARNING Missing volume truncated referenced at journal address 17,004 (6 similar occurrences in 0 seconds)
   * Exception in thread "main" com.persistit.exception.InvalidPageAddressException: Page 1 out of bounds [0-1]
   *  at com.persistit.VolumeStorageV2.readPage(VolumeStorageV2.java:426)
   *  at com.persistit.Buffer.load(Buffer.java:456)
   *  at com.persistit.BufferPool.get(BufferPool.java:780)
   *  at com.persistit.Tree.setRootPageAddress(Tree.java:203)
   *  at com.persistit.VolumeStructure.init(VolumeStructure.java:70)
   *  at com.persistit.VolumeStorageV2.open(VolumeStorageV2.java:217)
   *  at com.persistit.Volume.open(Volume.java:442)
   *  at com.persistit.Persistit.loadVolume(Persistit.java:1066)
   *  at Truncate.main(Truncate.java:30)
   *
   * @throws Exception
   *
   *             </pre></code>
   *
   *             This test is currently disabled pending a fix.
   *
   */
  @Test
  @Ignore
  public void truncateDynamicVolumes() throws Exception {

    VolumeSpecification volumeSpec;
    _persistit.close();

    final Persistit db = new Persistit(_config);

    for (int i = 0; i < 2; i++) {
      try {
        volumeSpec =
            new VolumeSpecification(
                DATA_PATH + "/truncated", null, 16384, 1, 1000, 1, true, false, false);
        final Volume volume = db.loadVolume(volumeSpec);
        volume.truncate();
        // the following may be omitted, and the problem still exhibited
        final Exchange dbex = db.getExchange("truncated", "greetings", true);
        dbex.getKey().append("ave");
        dbex.getValue().put("mundus");
        dbex.store();
        dbex.getKey().to(Key.BEFORE);
        while (dbex.next()) {
          System.out.println(dbex.getKey().reset().decode() + " " + dbex.getValue().get());
        }
        db.releaseExchange(dbex);
        // the preceding may be omitted, and the problem still exhibited
      } finally {
        db.close();
      }
    }
  }
Exemple #3
0
  @Override
  public LogicalRecordCount getLogicalRecordCount(
      final String volumeName,
      final String treeName,
      final String keyFilterString,
      final KeyState fromKey,
      final Key.Direction direction,
      final int maxCount)
      throws RemoteException {
    int count = 0;
    Exchange exchange = null;
    KeyState endKeyState = null;

    try {
      exchange = _persistit.getExchange(volumeName, treeName, false);
      exchange.getAuxiliaryKey2().clear();
      KeyFilter filter = null;
      if (keyFilterString != null && keyFilterString.length() > 0) {
        filter = new KeyFilter(keyFilterString);
      }
      fromKey.copyTo(exchange.getKey());
      for (; count < maxCount; count++) {
        if (!exchange.traverse(direction, filter, 0)) {
          break;
        } else {
          exchange.getKey().copyTo(exchange.getAuxiliaryKey2());
        }
      }
      endKeyState = new KeyState(exchange.getAuxiliaryKey2());
    } catch (final Exception pe) {
      throw new WrappedRemoteException(pe);
    } finally {
      if (exchange != null) _persistit.releaseExchange(exchange);
    }
    return new LogicalRecordCount(endKeyState, count);
  }
 private void releaseExchange(final Exchange ex) {
   _persistit.releaseExchange(ex);
 }