Search in sources :

Example 6 with PageCache

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;
    }
}
Also used : PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) NonExistentPage(org.apache.activemq.artemis.core.paging.cursor.NonExistentPage) Page(org.apache.activemq.artemis.core.paging.impl.Page) PageCache(org.apache.activemq.artemis.core.paging.cursor.PageCache)

Example 7 with PageCache

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());
}
Also used : PageCursorProviderImpl(org.apache.activemq.artemis.core.paging.cursor.impl.PageCursorProviderImpl) PageCache(org.apache.activemq.artemis.core.paging.cursor.PageCache) Test(org.junit.Test)

Aggregations

PageCache (org.apache.activemq.artemis.core.paging.cursor.PageCache)7 PagedMessage (org.apache.activemq.artemis.core.paging.PagedMessage)2 Test (org.junit.Test)2 NonExistentPage (org.apache.activemq.artemis.core.paging.cursor.NonExistentPage)1 PageCursorProvider (org.apache.activemq.artemis.core.paging.cursor.PageCursorProvider)1 PagePosition (org.apache.activemq.artemis.core.paging.cursor.PagePosition)1 PageCursorProviderImpl (org.apache.activemq.artemis.core.paging.cursor.impl.PageCursorProviderImpl)1 Page (org.apache.activemq.artemis.core.paging.impl.Page)1