Search in sources :

Example 6 with StorageManager

use of org.apache.activemq.artemis.core.persistence.StorageManager in project activemq-artemis by apache.

the class SendAckFailTest method startServer.

public ActiveMQServer startServer(boolean fail) {
    try {
        // ActiveMQServerImpl server = (ActiveMQServerImpl) createServer(true, true);
        AtomicInteger count = new AtomicInteger(0);
        ActiveMQSecurityManager securityManager = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), new SecurityConfiguration());
        Configuration configuration = createDefaultConfig(true);
        ActiveMQServer server = new ActiveMQServerImpl(configuration, ManagementFactory.getPlatformMBeanServer(), securityManager) {

            @Override
            public StorageManager createStorageManager() {
                StorageManager original = super.createStorageManager();
                return new StorageManagerDelegate(original) {

                    @Override
                    public void storeMessage(Message message) throws Exception {
                        if (fail) {
                            if (count.incrementAndGet() == 110) {
                                System.out.println("Failing " + message);
                                System.out.flush();
                                Thread.sleep(100);
                                Runtime.getRuntime().halt(-1);
                            }
                        }
                        super.storeMessage(message);
                    }
                };
            }
        };
        System.out.println("Location::" + server.getConfiguration().getJournalLocation().getAbsolutePath());
        server.start();
        return server;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) Configuration(org.apache.activemq.artemis.core.config.Configuration) SecurityConfiguration(org.apache.activemq.artemis.core.config.impl.SecurityConfiguration) LargeServerMessage(org.apache.activemq.artemis.core.server.LargeServerMessage) PagedMessage(org.apache.activemq.artemis.core.paging.PagedMessage) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(org.apache.activemq.artemis.api.core.Message) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ActiveMQJAASSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) InVMLoginModule(org.apache.activemq.artemis.spi.core.security.jaas.InVMLoginModule) SecurityConfiguration(org.apache.activemq.artemis.core.config.impl.SecurityConfiguration) ActiveMQServerImpl(org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl) ActiveMQSecurityManager(org.apache.activemq.artemis.spi.core.security.ActiveMQSecurityManager)

Example 7 with StorageManager

use of org.apache.activemq.artemis.core.persistence.StorageManager in project activemq-artemis by apache.

the class PersistMultiThreadTest method testMultipleWrites.

@Test
public void testMultipleWrites() throws Exception {
    deleteDirectory(new File(DIRECTORY));
    ActiveMQServer server = createServer(true);
    server.getConfiguration().setJournalCompactMinFiles(ActiveMQDefaultConfiguration.getDefaultJournalCompactMinFiles());
    server.getConfiguration().setJournalCompactPercentage(ActiveMQDefaultConfiguration.getDefaultJournalCompactPercentage());
    server.getConfiguration().setJournalDirectory(DIRECTORY + "/journal");
    server.getConfiguration().setBindingsDirectory(DIRECTORY + "/bindings");
    server.getConfiguration().setPagingDirectory(DIRECTORY + "/paging");
    server.getConfiguration().setLargeMessagesDirectory(DIRECTORY + "/largemessage");
    server.getConfiguration().setJournalFileSize(10 * 1024 * 1024);
    server.getConfiguration().setJournalMinFiles(2);
    server.getConfiguration().setJournalType(JournalType.ASYNCIO);
    server.start();
    StorageManager storage = server.getStorageManager();
    long msgID = storage.generateID();
    System.out.println("msgID=" + msgID);
    int NUMBER_OF_THREADS = 50;
    int NUMBER_OF_MESSAGES = 5000;
    MyThread[] threads = new MyThread[NUMBER_OF_THREADS];
    final CountDownLatch alignFlag = new CountDownLatch(NUMBER_OF_THREADS);
    final CountDownLatch startFlag = new CountDownLatch(1);
    final CountDownLatch finishFlag = new CountDownLatch(NUMBER_OF_THREADS);
    MyDeleteThread deleteThread = new MyDeleteThread("deleteThread", storage, NUMBER_OF_MESSAGES * NUMBER_OF_THREADS * 10);
    deleteThread.start();
    for (int i = 0; i < threads.length; i++) {
        threads[i] = new MyThread("writer::" + i, storage, NUMBER_OF_MESSAGES, alignFlag, startFlag, finishFlag);
    }
    for (MyThread t : threads) {
        t.start();
    }
    alignFlag.await();
    long startTime = System.currentTimeMillis();
    startFlag.countDown();
    // I'm using a countDown to avoid measuring time spent on thread context from join.
    // i.e. i want to measure as soon as the loops are done
    finishFlag.await();
    long endtime = System.currentTimeMillis();
    System.out.println("Time:: " + (endtime - startTime));
    for (MyThread t : threads) {
        t.join();
        Assert.assertEquals(0, t.errors.get());
    }
    deleteThread.join();
    Assert.assertEquals(0, deleteThread.errors.get());
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) CountDownLatch(java.util.concurrent.CountDownLatch) File(java.io.File) Test(org.junit.Test)

Example 8 with StorageManager

use of org.apache.activemq.artemis.core.persistence.StorageManager 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 9 with StorageManager

use of org.apache.activemq.artemis.core.persistence.StorageManager in project activemq-artemis by apache.

the class PagingTest method testPurge.

@Test
public void testPurge() throws Exception {
    clearDataRecreateServerDirs();
    Configuration config = createDefaultNettyConfig().setJournalSyncNonTransactional(false);
    server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
    server.start();
    String queue = "purgeQueue";
    SimpleString ssQueue = new SimpleString(queue);
    server.addAddressInfo(new AddressInfo(ssQueue, RoutingType.ANYCAST));
    QueueImpl purgeQueue = (QueueImpl) server.createQueue(ssQueue, RoutingType.ANYCAST, ssQueue, null, true, false, 1, true, false);
    ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory();
    Connection connection = cf.createConnection();
    Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
    javax.jms.Queue jmsQueue = session.createQueue(queue);
    MessageProducer producer = session.createProducer(jmsQueue);
    for (int i = 0; i < 100; i++) {
        producer.send(session.createTextMessage("hello" + i));
    }
    session.commit();
    Wait.assertEquals(0, purgeQueue::getMessageCount);
    Assert.assertEquals(0, purgeQueue.getPageSubscription().getPagingStore().getAddressSize());
    MessageConsumer consumer = session.createConsumer(jmsQueue);
    for (int i = 0; i < 100; i++) {
        producer.send(session.createTextMessage("hello" + i));
        if (i == 10) {
            purgeQueue.getPageSubscription().getPagingStore().startPaging();
        }
    }
    session.commit();
    consumer.close();
    Wait.assertEquals(0, purgeQueue::getMessageCount);
    Wait.assertFalse(purgeQueue.getPageSubscription()::isPaging);
    Wait.assertEquals(0, purgeQueue.getPageSubscription().getPagingStore()::getAddressSize);
    purgeQueue.getPageSubscription().getPagingStore().startPaging();
    Wait.assertTrue(purgeQueue.getPageSubscription()::isPaging);
    consumer = session.createConsumer(jmsQueue);
    for (int i = 0; i < 100; i++) {
        purgeQueue.getPageSubscription().getPagingStore().startPaging();
        Assert.assertTrue(purgeQueue.getPageSubscription().isPaging());
        producer.send(session.createTextMessage("hello" + i));
        if (i % 2 == 0) {
            session.commit();
        }
    }
    session.commit();
    connection.start();
    server.getStorageManager().getMessageJournal().scheduleCompactAndBlock(50000);
    Assert.assertNotNull(consumer.receive(5000));
    session.commit();
    consumer.close();
    Wait.assertEquals(0, purgeQueue::getMessageCount);
    Wait.assertEquals(0, purgeQueue.getPageSubscription().getPagingStore()::getAddressSize);
    Wait.assertFalse(purgeQueue.getPageSubscription()::isPaging);
    StorageManager sm = server.getStorageManager();
    for (int i = 0; i < 1000; i++) {
        long tx = sm.generateID();
        PageTransactionInfoImpl txinfo = new PageTransactionInfoImpl(tx);
        sm.storePageTransaction(tx, txinfo);
        sm.commit(tx);
        tx = sm.generateID();
        sm.updatePageTransaction(tx, txinfo, 1);
        sm.commit(tx);
    }
    server.stop();
    server.start();
    Assert.assertEquals(0, server.getPagingManager().getTransactions().size());
}
Also used : MessageConsumer(javax.jms.MessageConsumer) 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) PageTransactionInfoImpl(org.apache.activemq.artemis.core.paging.impl.PageTransactionInfoImpl) Connection(javax.jms.Connection) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Test(org.junit.Test)

Example 10 with StorageManager

use of org.apache.activemq.artemis.core.persistence.StorageManager 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)

Aggregations

StorageManager (org.apache.activemq.artemis.core.persistence.StorageManager)22 Test (org.junit.Test)17 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)15 Queue (org.apache.activemq.artemis.core.server.Queue)9 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)7 Transaction (org.apache.activemq.artemis.core.transaction.Transaction)7 PageSubscription (org.apache.activemq.artemis.core.paging.cursor.PageSubscription)6 PagingStoreFactoryNIO (org.apache.activemq.artemis.core.paging.impl.PagingStoreFactoryNIO)6 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)6 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)6 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)5 Configuration (org.apache.activemq.artemis.core.config.Configuration)5 PagingManagerImpl (org.apache.activemq.artemis.core.paging.impl.PagingManagerImpl)5 NullStorageManager (org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager)5 HierarchicalObjectRepository (org.apache.activemq.artemis.core.settings.impl.HierarchicalObjectRepository)5 ExecutorService (java.util.concurrent.ExecutorService)4 DivertConfiguration (org.apache.activemq.artemis.core.config.DivertConfiguration)4 StoreConfiguration (org.apache.activemq.artemis.core.config.StoreConfiguration)4