Search in sources :

Example 1 with PagingStoreFactoryNIO

use of org.apache.activemq.artemis.core.paging.impl.PagingStoreFactoryNIO in project activemq-artemis by apache.

the class ReplicationEndpoint method start.

@Override
public synchronized void start() throws Exception {
    Configuration config = server.getConfiguration();
    try {
        storageManager = server.getStorageManager();
        storageManager.start();
        server.getManagementService().setStorageManager(storageManager);
        journalsHolder.put(JournalContent.BINDINGS, storageManager.getBindingsJournal());
        journalsHolder.put(JournalContent.MESSAGES, storageManager.getMessageJournal());
        for (JournalContent jc : EnumSet.allOf(JournalContent.class)) {
            filesReservedForSync.put(jc, new HashMap<Long, JournalSyncFile>());
            // We only need to load internal structures on the backup...
            journalLoadInformation[jc.typeByte] = journalsHolder.get(jc).loadSyncOnly(JournalState.SYNCING);
        }
        pageManager = new PagingManagerImpl(new PagingStoreFactoryNIO(storageManager, config.getPagingLocation(), config.getJournalBufferTimeout_NIO(), server.getScheduledPool(), server.getIOExecutorFactory(), config.isJournalSyncNonTransactional(), criticalErrorListener), server.getAddressSettingsRepository());
        pageManager.start();
        started = true;
    } catch (Exception e) {
        if (server.isStarted())
            throw e;
    }
}
Also used : Configuration(org.apache.activemq.artemis.core.config.Configuration) PagingStoreFactoryNIO(org.apache.activemq.artemis.core.paging.impl.PagingStoreFactoryNIO) JournalContent(org.apache.activemq.artemis.core.persistence.impl.journal.AbstractJournalStorageManager.JournalContent) PagingManagerImpl(org.apache.activemq.artemis.core.paging.impl.PagingManagerImpl) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) IOException(java.io.IOException)

Example 2 with PagingStoreFactoryNIO

use of org.apache.activemq.artemis.core.paging.impl.PagingStoreFactoryNIO in project activemq-artemis by apache.

the class DBOption method initializeJournal.

protected void initializeJournal(Configuration configuration) throws Exception {
    this.config = configuration;
    executor = Executors.newFixedThreadPool(5, ActiveMQThreadFactory.defaultThreadFactory());
    executorFactory = new OrderedExecutorFactory(executor);
    scheduledExecutorService = new ScheduledThreadPoolExecutor(configuration.getScheduledThreadPoolMaxSize(), new ThreadFactory() {

        @Override
        public Thread newThread(Runnable r) {
            return new Thread(r);
        }
    });
    HierarchicalRepository<AddressSettings> addressSettingsRepository = new HierarchicalObjectRepository<>(config.getWildcardConfiguration());
    addressSettingsRepository.setDefault(new AddressSettings());
    if (configuration.isJDBC()) {
        storageManager = new JDBCJournalStorageManager(config, null, scheduledExecutorService, executorFactory, executorFactory, null);
        PagingStoreFactory pageStoreFactory = new PagingStoreFactoryDatabase((DatabaseStorageConfiguration) configuration.getStoreConfiguration(), storageManager, 1000L, scheduledExecutorService, executorFactory, false, null);
        pagingmanager = new PagingManagerImpl(pageStoreFactory, addressSettingsRepository);
    } else {
        storageManager = new JournalStorageManager(config, EmptyCriticalAnalyzer.getInstance(), executorFactory, executorFactory);
        PagingStoreFactory pageStoreFactory = new PagingStoreFactoryNIO(storageManager, config.getPagingLocation(), 1000L, scheduledExecutorService, executorFactory, true, null);
        pagingmanager = new PagingManagerImpl(pageStoreFactory, addressSettingsRepository);
    }
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) ActiveMQThreadFactory(org.apache.activemq.artemis.utils.ActiveMQThreadFactory) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) JDBCJournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JDBCJournalStorageManager) OrderedExecutorFactory(org.apache.activemq.artemis.utils.actors.OrderedExecutorFactory) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) PagingStoreFactoryDatabase(org.apache.activemq.artemis.core.paging.impl.PagingStoreFactoryDatabase) HierarchicalObjectRepository(org.apache.activemq.artemis.core.settings.impl.HierarchicalObjectRepository) JDBCJournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JDBCJournalStorageManager) JournalStorageManager(org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager) PagingStoreFactoryNIO(org.apache.activemq.artemis.core.paging.impl.PagingStoreFactoryNIO) PagingStoreFactory(org.apache.activemq.artemis.core.paging.PagingStoreFactory) PagingManagerImpl(org.apache.activemq.artemis.core.paging.impl.PagingManagerImpl)

Example 3 with PagingStoreFactoryNIO

use of org.apache.activemq.artemis.core.paging.impl.PagingStoreFactoryNIO in project activemq-artemis by apache.

the class FileMoveManagerTest method testMoveOverPaging.

@Test
public void testMoveOverPaging() throws Exception {
    AssertionLoggerHandler.startCapture();
    ExecutorService threadPool = Executors.newCachedThreadPool();
    try {
        manager.setMaxFolders(3);
        for (int i = 1; i <= 10; i++) {
            HierarchicalRepository<AddressSettings> addressSettings = new HierarchicalObjectRepository<>();
            AddressSettings settings = new AddressSettings();
            settings.setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE);
            addressSettings.setDefault(settings);
            final StorageManager storageManager = new NullStorageManager();
            PagingStoreFactoryNIO storeFactory = new PagingStoreFactoryNIO(storageManager, dataLocation, 100, null, new OrderedExecutorFactory(threadPool), true, null);
            PagingManagerImpl managerImpl = new PagingManagerImpl(storeFactory, addressSettings, -1);
            managerImpl.start();
            PagingStore store = managerImpl.getPageStore(new SimpleString("simple-test"));
            store.startPaging();
            store.stop();
            managerImpl.stop();
            manager.doMove();
            Assert.assertEquals(Math.min(i, manager.getMaxFolders()), manager.getNumberOfFolders());
        }
        Assert.assertFalse("The loggers are complaining about address.txt", AssertionLoggerHandler.findText("address.txt"));
    } finally {
        AssertionLoggerHandler.stopCapture();
        threadPool.shutdown();
    }
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) NullStorageManager(org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager) OrderedExecutorFactory(org.apache.activemq.artemis.utils.actors.OrderedExecutorFactory) PagingStoreFactoryNIO(org.apache.activemq.artemis.core.paging.impl.PagingStoreFactoryNIO) ExecutorService(java.util.concurrent.ExecutorService) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) NullStorageManager(org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) PagingManagerImpl(org.apache.activemq.artemis.core.paging.impl.PagingManagerImpl) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) HierarchicalObjectRepository(org.apache.activemq.artemis.core.settings.impl.HierarchicalObjectRepository) Test(org.junit.Test)

Example 4 with PagingStoreFactoryNIO

use of org.apache.activemq.artemis.core.paging.impl.PagingStoreFactoryNIO in project activemq-artemis by apache.

the class PagingTest method testRestartWithComplete.

// The pages are complete, and this is simulating a scenario where the server crashed before deleting the pages.
@Test
public void testRestartWithComplete() throws Exception {
    clearDataRecreateServerDirs();
    Configuration config = createDefaultInVMConfig();
    final AtomicBoolean mainCleanup = new AtomicBoolean(true);
    class InterruptedCursorProvider extends PageCursorProviderImpl {

        InterruptedCursorProvider(PagingStore pagingStore, StorageManager storageManager, ArtemisExecutor executor, int maxCacheSize) {
            super(pagingStore, storageManager, executor, maxCacheSize);
        }

        @Override
        public void cleanup() {
            if (mainCleanup.get()) {
                super.cleanup();
            } else {
                try {
                    pagingStore.unlock();
                } catch (Throwable ignored) {
                }
            }
        }
    }
    server = new ActiveMQServerImpl(config, ManagementFactory.getPlatformMBeanServer(), new ActiveMQSecurityManagerImpl()) {

        @Override
        protected PagingStoreFactoryNIO getPagingStoreFactory() {
            return new PagingStoreFactoryNIO(this.getStorageManager(), this.getConfiguration().getPagingLocation(), this.getConfiguration().getJournalBufferTimeout_NIO(), this.getScheduledPool(), this.getExecutorFactory(), this.getConfiguration().isJournalSyncNonTransactional(), null) {

                @Override
                public PageCursorProvider newCursorProvider(PagingStore store, StorageManager storageManager, AddressSettings addressSettings, ArtemisExecutor executor) {
                    return new InterruptedCursorProvider(store, storageManager, executor, addressSettings.getPageCacheMaxSize());
                }
            };
        }
    };
    addServer(server);
    AddressSettings defaultSetting = new AddressSettings().setPageSizeBytes(PagingTest.PAGE_SIZE).setMaxSizeBytes(PagingTest.PAGE_MAX).setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE);
    server.getAddressSettingsRepository().addMatch("#", defaultSetting);
    server.start();
    locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true);
    sf = createSessionFactory(locator);
    ClientSession session = sf.createSession(true, true, 0);
    session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS, null, true);
    Queue queue = server.locateQueue(ADDRESS);
    queue.getPageSubscription().getPagingStore().startPaging();
    ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
    ClientMessage message;
    for (int i = 0; i < 20; i++) {
        message = session.createMessage(true);
        ActiveMQBuffer bodyLocal = message.getBodyBuffer();
        bodyLocal.writeBytes(new byte[100 * 4]);
        message.putIntProperty(new SimpleString("idi"), i);
        producer.send(message);
        session.commit();
        if (i < 19) {
            queue.getPageSubscription().getPagingStore().forceAnotherPage();
        }
    }
    Assert.assertEquals(20, queue.getPageSubscription().getPagingStore().getCurrentWritingPage());
    // This will force a scenario where the pages are cleaned up. When restarting we need to check if the current page is complete
    // if it is complete we must move to another page avoiding races on cleanup
    // which could happen during a crash / restart
    long tx = server.getStorageManager().generateID();
    for (int i = 1; i <= 20; i++) {
        server.getStorageManager().storePageCompleteTransactional(tx, queue.getID(), new PagePositionImpl(i, 1));
    }
    server.getStorageManager().commit(tx);
    session.close();
    sf.close();
    server.stop();
    mainCleanup.set(false);
    logger.trace("Server restart");
    server.start();
    queue = server.locateQueue(ADDRESS);
    locator = createInVMNonHALocator();
    sf = createSessionFactory(locator);
    session = sf.createSession(null, null, false, false, true, false, 0);
    producer = session.createProducer(PagingTest.ADDRESS);
    for (int i = 0; i < 10; i++) {
        message = session.createMessage(true);
        ActiveMQBuffer bodyLocal = message.getBodyBuffer();
        bodyLocal.writeBytes(new byte[100 * 4]);
        message.putIntProperty(new SimpleString("newid"), i);
        producer.send(message);
        session.commit();
        if (i == 5) {
            queue.getPageSubscription().getPagingStore().forceAnotherPage();
        }
    }
    mainCleanup.set(true);
    queue = server.locateQueue(ADDRESS);
    queue.getPageSubscription().cleanupEntries(false);
    queue.getPageSubscription().getPagingStore().getCursorProvider().cleanup();
    ClientConsumer consumer = session.createConsumer(ADDRESS);
    session.start();
    for (int i = 0; i < 10; i++) {
        message = consumer.receive(5000);
        Assert.assertNotNull(message);
        Assert.assertEquals(i, message.getIntProperty("newid").intValue());
        message.acknowledge();
    }
    server.stop();
// Thread.sleep(5000);
}
Also used : ActiveMQSecurityManagerImpl(org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManagerImpl) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) StoreConfiguration(org.apache.activemq.artemis.core.config.StoreConfiguration) Configuration(org.apache.activemq.artemis.core.config.Configuration) DatabaseStorageConfiguration(org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration) ArtemisExecutor(org.apache.activemq.artemis.utils.actors.ArtemisExecutor) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) PageCursorProviderImpl(org.apache.activemq.artemis.core.paging.cursor.impl.PageCursorProviderImpl) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) PagePositionImpl(org.apache.activemq.artemis.core.paging.cursor.impl.PagePositionImpl) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PagingStoreFactoryNIO(org.apache.activemq.artemis.core.paging.impl.PagingStoreFactoryNIO) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) PageCursorProvider(org.apache.activemq.artemis.core.paging.cursor.PageCursorProvider) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) Queue(org.apache.activemq.artemis.core.server.Queue) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer) Test(org.junit.Test)

Example 5 with PagingStoreFactoryNIO

use of org.apache.activemq.artemis.core.paging.impl.PagingStoreFactoryNIO in project activemq-artemis by apache.

the class PrintData method printPages.

private static void printPages(File pageDirectory, DescribeJournal describeJournal, PrintStream out, boolean safe) {
    try {
        ScheduledExecutorService scheduled = Executors.newScheduledThreadPool(1, ActiveMQThreadFactory.defaultThreadFactory());
        final ExecutorService executor = Executors.newFixedThreadPool(10, ActiveMQThreadFactory.defaultThreadFactory());
        ExecutorFactory execfactory = new ExecutorFactory() {

            @Override
            public ArtemisExecutor getExecutor() {
                return ArtemisExecutor.delegate(executor);
            }
        };
        final StorageManager sm = new NullStorageManager();
        PagingStoreFactory pageStoreFactory = new PagingStoreFactoryNIO(sm, pageDirectory, 1000L, scheduled, execfactory, false, null);
        HierarchicalRepository<AddressSettings> addressSettingsRepository = new HierarchicalObjectRepository<>();
        addressSettingsRepository.setDefault(new AddressSettings());
        PagingManager manager = new PagingManagerImpl(pageStoreFactory, addressSettingsRepository);
        printPages(describeJournal, sm, manager, out, safe);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) PagingManager(org.apache.activemq.artemis.core.paging.PagingManager) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) NullStorageManager(org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager) HierarchicalObjectRepository(org.apache.activemq.artemis.core.settings.impl.HierarchicalObjectRepository) NullStorageManager(org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager) PagingStoreFactoryNIO(org.apache.activemq.artemis.core.paging.impl.PagingStoreFactoryNIO) ExecutorFactory(org.apache.activemq.artemis.utils.ExecutorFactory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ExecutorService(java.util.concurrent.ExecutorService) PagingStoreFactory(org.apache.activemq.artemis.core.paging.PagingStoreFactory) PagingManagerImpl(org.apache.activemq.artemis.core.paging.impl.PagingManagerImpl)

Aggregations

PagingStoreFactoryNIO (org.apache.activemq.artemis.core.paging.impl.PagingStoreFactoryNIO)7 PagingManagerImpl (org.apache.activemq.artemis.core.paging.impl.PagingManagerImpl)6 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)5 StorageManager (org.apache.activemq.artemis.core.persistence.StorageManager)4 HierarchicalObjectRepository (org.apache.activemq.artemis.core.settings.impl.HierarchicalObjectRepository)4 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 PagingStore (org.apache.activemq.artemis.core.paging.PagingStore)3 NullStorageManager (org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager)3 Test (org.junit.Test)3 ExecutorService (java.util.concurrent.ExecutorService)2 Configuration (org.apache.activemq.artemis.core.config.Configuration)2 PagingManager (org.apache.activemq.artemis.core.paging.PagingManager)2 PagingStoreFactory (org.apache.activemq.artemis.core.paging.PagingStoreFactory)2 OrderedExecutorFactory (org.apache.activemq.artemis.utils.actors.OrderedExecutorFactory)2 IOException (java.io.IOException)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)1