protected IndexSegmentCheckpoint doBuildAndDiscardCache(final BTree btree, final int m)
      throws IOException, Exception {

    final long commitTime = System.currentTimeMillis();

    final IndexSegmentCheckpoint checkpoint =
        IndexSegmentBuilder.newInstance(
                outFile,
                tmpDir,
                btree.getEntryCount(),
                btree.rangeIterator(),
                m,
                btree.getIndexMetadata(),
                commitTime,
                true /* compactingMerge */,
                bufferNodes)
            .call();

    //      @see BLZG-1501 (remove LRUNexus)
    //        if (LRUNexus.INSTANCE != null) {
    //
    //            /*
    //             * Clear the records for the index segment from the cache so we will
    //             * read directly from the file. This is necessary to ensure that the
    //             * data on the file is good rather than just the data in the cache.
    //             */
    //
    //            LRUNexus.INSTANCE.deleteCache(checkpoint.segmentUUID);
    //
    //        }

    return checkpoint;
  }
Beispiel #2
0
  /**
   * Tests the ability to store a <code>null</code> in a tuple of a {@link BTree}, to reload the
   * {@link BTree} and find the <code>null</code> value still under the tuple, and to build an
   * {@link IndexSegmentBuilder} from the {@link BTree} and find the <code>null</code> value under
   * the tuple.
   *
   * @throws IOException
   * @throws Exception
   */
  public void test_nullValues() throws IOException, Exception {

    final IRawStore store = new SimpleMemoryRawStore();

    final IndexMetadata metadata = new IndexMetadata(UUID.randomUUID());

    BTree btree = BTree.create(store, metadata);

    final byte[] k1 = new byte[] {1};

    assertNull(btree.lookup(k1));
    assertFalse(btree.contains(k1));

    assertNull(btree.insert(k1, null));

    assertNull(btree.lookup(k1));
    assertTrue(btree.contains(k1));

    final long addrCheckpoint1 = btree.writeCheckpoint();

    btree = BTree.load(store, addrCheckpoint1, true /*readOnly*/);

    assertNull(btree.lookup(k1));
    assertTrue(btree.contains(k1));

    File outFile = null;
    File tmpDir = null;

    try {

      outFile = new File(getName() + ".seg");

      if (outFile.exists() && !outFile.delete()) {

        throw new RuntimeException("Could not delete file: " + outFile);
      }

      tmpDir = outFile.getAbsoluteFile().getParentFile();

      final long commitTime = System.currentTimeMillis();

      @SuppressWarnings("unused")
      final IndexSegmentCheckpoint checkpoint =
          IndexSegmentBuilder.newInstance(
                  outFile,
                  tmpDir,
                  btree.getEntryCount(),
                  btree.rangeIterator(),
                  3 /* m */,
                  btree.getIndexMetadata(),
                  commitTime,
                  true /* compactingMerge */,
                  bufferNodes)
              .call();

      //          @see BLZG-1501 (remove LRUNexus)
      //            if (LRUNexus.INSTANCE != null) {
      //
      //                /*
      //                 * Clear the records for the index segment from the cache so we will
      //                 * read directly from the file. This is necessary to ensure that the
      //                 * data on the file is good rather than just the data in the cache.
      //                 */
      //
      //                LRUNexus.INSTANCE.deleteCache(checkpoint.segmentUUID);
      //
      //            }

      /*
       * Verify can load the index file and that the metadata associated
       * with the index file is correct (we are only checking those
       * aspects that are easily defined by the test case and not, for
       * example, those aspects that depend on the specifics of the length
       * of serialized nodes or leaves).
       */

      final IndexSegmentStore segStore = new IndexSegmentStore(outFile);

      final IndexSegment seg = segStore.loadIndexSegment();

      try {

        assertNull(seg.lookup(k1));
        assertTrue(seg.contains(k1));

      } finally {

        seg.close();
      }

    } finally {

      if (outFile != null && outFile.exists() && !outFile.delete()) {

        log.warn("Could not delete file: " + outFile);
      }
    }
  }