use of org.apache.activemq.artemis.core.paging.cursor.PageCache in project activemq-artemis by apache.
the class PageCursorProviderImpl method finishCleanup.
// Protected as a way to inject testing
protected void finishCleanup(ArrayList<Page> depagedPages) {
logger.tracef("this(%s) finishing cleanup on %s", this, depagedPages);
try {
for (Page depagedPage : depagedPages) {
PageCache cache;
PagedMessage[] pgdMessages;
synchronized (softCache) {
cache = softCache.get((long) depagedPage.getPageId());
}
if (logger.isTraceEnabled()) {
logger.trace("Removing pageNr=" + depagedPage.getPageId() + " from page-cache");
}
if (cache == null) {
// The page is not on cache any more
// We need to read the page-file before deleting it
// to make sure we remove any large-messages pending
storageManager.beforePageRead();
List<PagedMessage> pgdMessagesList = null;
try {
depagedPage.open();
pgdMessagesList = depagedPage.read(storageManager);
} finally {
try {
depagedPage.close(false);
} catch (Exception e) {
}
storageManager.afterPageRead();
}
depagedPage.close(false);
pgdMessages = pgdMessagesList.toArray(new PagedMessage[pgdMessagesList.size()]);
} else {
pgdMessages = cache.getMessages();
}
depagedPage.delete(pgdMessages);
onDeletePage(depagedPage);
synchronized (softCache) {
softCache.remove((long) depagedPage.getPageId());
}
}
} catch (Exception ex) {
ActiveMQServerLogger.LOGGER.problemCleaningPageAddress(ex, pagingStore.getAddress());
return;
}
}
use of org.apache.activemq.artemis.core.paging.cursor.PageCache in project activemq-artemis by apache.
the class PageCursorStressTest method testReadCache.
// Read more cache than what would fit on the memory, and validate if the memory would be cleared through soft-caches
@Test
public void testReadCache() throws Exception {
final int NUM_MESSAGES = 100;
int numberOfPages = addMessages(NUM_MESSAGES, 1024 * 1024);
System.out.println("NumberOfPages = " + numberOfPages);
PageCursorProviderImpl cursorProvider = new PageCursorProviderImpl(lookupPageStore(ADDRESS), server.getStorageManager(), server.getExecutorFactory().getExecutor(), 5);
for (int i = 0; i < numberOfPages; i++) {
PageCache cache = cursorProvider.getPageCache(i + 1);
System.out.println("Page " + i + " had " + cache.getNumberOfMessages() + " messages");
}
forceGC();
assertTrue(cursorProvider.getCacheSize() < numberOfPages);
System.out.println("Cache size = " + cursorProvider.getCacheSize());
}
Aggregations