@Test public void testSimplePut() { File directory = null; try { directory = makeTemporaryDirectory(); ByteStore externalStore = new ConcurrentByteStoreBDB(directory, "db"); NonConcurrentPageCache<Integer, DBIntValue> cache = new NonConcurrentPageCache.Builder<>(new SimpleIntKeyCoder(), externalStore, 25).build(); for (int i = 0; i < 10000; i++) { assertEquals(null, cache.put(i, new DBIntValue(10000 - i))); } for (int i = 0; i < 10000; i++) { assertEquals(new Integer(10000 - i), cache.get(i).getVal()); } cache.doClose(false, CloseOperation.NONE); } catch (IOException ex) { ex.printStackTrace(); fail(); } finally { if (directory != null) { if (!LessFiles.deleteDir(directory)) { fail(); } } } }
@VisibleForTesting protected int doClose(boolean cleanLog, CloseOperation operation) { int status = 0; if (!shutdownGuard.getAndSet(true)) { pushAllPagesToDisk(); if (operation != null && operation.testIntegrity()) { int failedPages = testIntegrity(operation.repairIntegrity()); status = (failedPages > 0) ? 1 : 0; } closeExternalStore(cleanLog); assert (status == 0); log.info("pages: encoded=" + numPagesEncoded.get() + " decoded=" + numPagesDecoded.get() + " split=" + numPagesSplit.get()); if (trackEncodingByteUsage) { log.info(MetricsUtil.histogramToString("encodeFirstKeySize", metrics.encodeFirstKeySize)); log.info(MetricsUtil.histogramToString("encodeNextFirstKeySize", metrics.encodeNextFirstKeySize)); log.info(MetricsUtil.histogramToString("encodeKeySize", metrics.encodeKeySize)); log.info(MetricsUtil.histogramToString("encodeValueSize", metrics.encodeValueSize)); log.info(MetricsUtil.histogramToString("encodePageSize (final)", metrics.encodePageSize)); log.info(MetricsUtil.histogramToString("numberKeysPerPage", metrics.numberKeysPerPage)); } } return status; }
NonConcurrentPageCache extends AbstractPageCache<K, V> { @VisibleForTesting protected int doClose(boolean cleanLog, CloseOperation operation) { int status = 0; if (!shutdownGuard.getAndSet(true)) { pushAllPagesToDisk(); if (operation != null && operation.testIntegrity()) { int failedPages = testIntegrity(operation.repairIntegrity()); status = (failedPages > 0) ? 1 : 0; } closeExternalStore(cleanLog); assert (status == 0); log.info("pages: encoded=" + numPagesEncoded.get() + " decoded=" + numPagesDecoded.get() + " split=" + numPagesSplit.get()); if (trackEncodingByteUsage) { log.info(MetricsUtil.histogramToString("encodeFirstKeySize", metrics.encodeFirstKeySize)); log.info(MetricsUtil.histogramToString("encodeNextFirstKeySize", metrics.encodeNextFirstKeySize)); log.info(MetricsUtil.histogramToString("encodeKeySize", metrics.encodeKeySize)); log.info(MetricsUtil.histogramToString("encodeValueSize", metrics.encodeValueSize)); log.info(MetricsUtil.histogramToString("encodePageSize (final)", metrics.encodePageSize)); log.info(MetricsUtil.histogramToString("numberKeysPerPage", metrics.numberKeysPerPage)); } } return status; } }
NonConcurrentPageCache extends AbstractPageCache<K, V> { @VisibleForTesting protected int doClose(boolean cleanLog, CloseOperation operation) { int status = 0; if (!shutdownGuard.getAndSet(true)) { pushAllPagesToDisk(); if (operation != null && operation.testIntegrity()) { int failedPages = testIntegrity(operation.repairIntegrity()); status = (failedPages > 0) ? 1 : 0; } closeExternalStore(cleanLog); assert (status == 0); log.info("pages: encoded=" + numPagesEncoded.get() + " decoded=" + numPagesDecoded.get() + " split=" + numPagesSplit.get()); if (trackEncodingByteUsage) { log.info(MetricsUtil.histogramToString("encodeFirstKeySize", metrics.encodeFirstKeySize)); log.info(MetricsUtil.histogramToString("encodeNextFirstKeySize", metrics.encodeNextFirstKeySize)); log.info(MetricsUtil.histogramToString("encodeKeySize", metrics.encodeKeySize)); log.info(MetricsUtil.histogramToString("encodeValueSize", metrics.encodeValueSize)); log.info(MetricsUtil.histogramToString("encodePageSize (final)", metrics.encodePageSize)); log.info(MetricsUtil.histogramToString("numberKeysPerPage", metrics.numberKeysPerPage)); } } return status; } NonConcurrentPageCache(KeyCoder<K, V> keyCoder, ByteStore externalStore, int maxPageSize,
                                  int maxPages, PageFactory<K, V> pageFactory); }
NonConcurrentPageCache extends AbstractPageCache<K, V> { @VisibleForTesting protected int doClose(boolean cleanLog, CloseOperation operation) { int status = 0; if (!shutdownGuard.getAndSet(true)) { pushAllPagesToDisk(); if (operation != null && operation.testIntegrity()) { int failedPages = testIntegrity(operation.repairIntegrity()); status = (failedPages > 0) ? 1 : 0; } closeExternalStore(cleanLog); assert (status == 0); log.info("pages: encoded=" + numPagesEncoded.get() + " decoded=" + numPagesDecoded.get() + " split=" + numPagesSplit.get()); if (trackEncodingByteUsage) { log.info(MetricsUtil.histogramToString("encodeFirstKeySize", metrics.encodeFirstKeySize)); log.info(MetricsUtil.histogramToString("encodeNextFirstKeySize", metrics.encodeNextFirstKeySize)); log.info(MetricsUtil.histogramToString("encodeKeySize", metrics.encodeKeySize)); log.info(MetricsUtil.histogramToString("encodeValueSize", metrics.encodeValueSize)); log.info(MetricsUtil.histogramToString("encodePageSize (final)", metrics.encodePageSize)); log.info(MetricsUtil.histogramToString("numberKeysPerPage", metrics.numberKeysPerPage)); } } return status; } NonConcurrentPageCache(KeyCoder<K, V> keyCoder, ByteStore externalStore, int maxPageSize,
                                  int maxPages, PageFactory<K, V> pageFactory); @Override V remove(K key); @Override void close(); @Override int close(boolean cleanLog, CloseOperation operation); }
NonConcurrentPageCache extends AbstractPageCache<K, V> { @VisibleForTesting protected int doClose(boolean cleanLog, CloseOperation operation) { int status = 0; if (!shutdownGuard.getAndSet(true)) { pushAllPagesToDisk(); if (operation != null && operation.testIntegrity()) { int failedPages = testIntegrity(operation.repairIntegrity()); status = (failedPages > 0) ? 1 : 0; } closeExternalStore(cleanLog); assert (status == 0); log.info("pages: encoded=" + numPagesEncoded.get() + " decoded=" + numPagesDecoded.get() + " split=" + numPagesSplit.get()); if (trackEncodingByteUsage) { log.info(MetricsUtil.histogramToString("encodeFirstKeySize", metrics.encodeFirstKeySize)); log.info(MetricsUtil.histogramToString("encodeNextFirstKeySize", metrics.encodeNextFirstKeySize)); log.info(MetricsUtil.histogramToString("encodeKeySize", metrics.encodeKeySize)); log.info(MetricsUtil.histogramToString("encodeValueSize", metrics.encodeValueSize)); log.info(MetricsUtil.histogramToString("encodePageSize (final)", metrics.encodePageSize)); log.info(MetricsUtil.histogramToString("numberKeysPerPage", metrics.numberKeysPerPage)); } } return status; } NonConcurrentPageCache(KeyCoder<K, V> keyCoder, ByteStore externalStore, int maxPageSize,
                                  int maxPages, PageFactory<K, V> pageFactory); @Override V remove(K key); @Override void close(); @Override int close(boolean cleanLog, CloseOperation operation);  }