Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id D6D92200C4E for ; Mon, 27 Feb 2017 04:24:29 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id D5945160B78; Mon, 27 Feb 2017 03:24:29 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D6E48160B6E for ; Mon, 27 Feb 2017 04:24:28 +0100 (CET) Received: (qmail 67301 invoked by uid 500); 27 Feb 2017 03:24:28 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 67285 invoked by uid 99); 27 Feb 2017 03:24:27 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Feb 2017 03:24:27 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id CC242DFDA9; Mon, 27 Feb 2017 03:24:27 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: clebertsuconic@apache.org To: commits@activemq.apache.org Date: Mon, 27 Feb 2017 03:24:27 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/4] activemq-artemis git commit: NO-JIRA Database Page Store Improvements archived-at: Mon, 27 Feb 2017 03:24:30 -0000 Repository: activemq-artemis Updated Branches: refs/heads/master 739b8e75b -> c71063d2a NO-JIRA Database Page Store Improvements Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/a3c852eb Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/a3c852eb Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/a3c852eb Branch: refs/heads/master Commit: a3c852eb040a425bd198120a3de3ec4b41b22951 Parents: a101288 Author: Martyn Taylor Authored: Sun Feb 26 20:41:42 2017 +0000 Committer: Martyn Taylor Committed: Sun Feb 26 20:42:04 2017 +0000 ---------------------------------------------------------------------- .../paging/impl/PagingStoreFactoryDatabase.java | 64 ++++++++++++++------ 1 file changed, 44 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/a3c852eb/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PagingStoreFactoryDatabase.java ---------------------------------------------------------------------- diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PagingStoreFactoryDatabase.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PagingStoreFactoryDatabase.java index ee9d7bb..7917165 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PagingStoreFactoryDatabase.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PagingStoreFactoryDatabase.java @@ -45,7 +45,6 @@ import org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFileFactoryDriv import org.apache.activemq.artemis.jdbc.store.sql.GenericSQLProvider; import org.apache.activemq.artemis.jdbc.store.sql.SQLProvider; import org.apache.activemq.artemis.utils.ExecutorFactory; -import org.apache.activemq.artemis.utils.UUIDGenerator; /** * Integration point between Paging and JDBC @@ -80,6 +79,8 @@ public class PagingStoreFactoryDatabase implements PagingStoreFactory { private JDBCSequentialFile directoryList; + private boolean started = false; + public PagingStoreFactoryDatabase(final DatabaseStorageConfiguration dbConf, final StorageManager storageManager, final long syncTimeout, @@ -93,27 +94,33 @@ public class PagingStoreFactoryDatabase implements PagingStoreFactory { this.scheduledExecutor = scheduledExecutor; this.syncTimeout = syncTimeout; this.dbConf = dbConf; + start(); + } - if (dbConf.getDataSource() != null) { - SQLProvider.Factory sqlProviderFactory = dbConf.getSqlProviderFactory(); - if (sqlProviderFactory == null) { - sqlProviderFactory = new GenericSQLProvider.Factory(); + public synchronized void start() throws Exception { + if (!started) { + if (dbConf.getDataSource() != null) { + SQLProvider.Factory sqlProviderFactory = dbConf.getSqlProviderFactory(); + if (sqlProviderFactory == null) { + sqlProviderFactory = new GenericSQLProvider.Factory(); + } + pagingFactoryFileFactory = new JDBCSequentialFileFactory(dbConf.getDataSource(), sqlProviderFactory.create(dbConf.getPageStoreTableName()), executorFactory.getExecutor()); + } else { + String driverClassName = dbConf.getJdbcDriverClassName(); + pagingFactoryFileFactory = new JDBCSequentialFileFactory(dbConf.getJdbcConnectionUrl(), driverClassName, JDBCUtils.getSQLProvider(driverClassName, dbConf.getPageStoreTableName()), executorFactory.getExecutor()); } - pagingFactoryFileFactory = new JDBCSequentialFileFactory(dbConf.getDataSource(), sqlProviderFactory.create(dbConf.getPageStoreTableName()), executorFactory.getExecutor()); - } else { - String driverClassName = dbConf.getJdbcDriverClassName(); - pagingFactoryFileFactory = new JDBCSequentialFileFactory(dbConf.getJdbcConnectionUrl(), driverClassName, JDBCUtils.getSQLProvider(driverClassName, dbConf.getPageStoreTableName()), executorFactory.getExecutor()); + pagingFactoryFileFactory.start(); + started = true; } - pagingFactoryFileFactory.start(); - directoryList = (JDBCSequentialFile) pagingFactoryFileFactory.createSequentialFile(DIRECTORY_NAME); - directoryList.open(); } - // Public -------------------------------------------------------- @Override - public void stop() { - pagingFactoryFileFactory.stop(); + public synchronized void stop() { + if (started) { + pagingFactoryFileFactory.stop(); + started = false; + } } @Override @@ -136,8 +143,8 @@ public class PagingStoreFactoryDatabase implements PagingStoreFactory { @Override public synchronized SequentialFileFactory newFileFactory(final SimpleString address) throws Exception { - String guid = UUIDGenerator.getInstance().generateStringUUID(); - SequentialFileFactory factory = newFileFactory(guid, true); + String tableName = "" + storageManager.generateID(); + SequentialFileFactory factory = newFileFactory(tableName, true); factory.start(); SequentialFile file = factory.createSequentialFile(PagingStoreFactoryDatabase.ADDRESS_FILE); @@ -146,6 +153,7 @@ public class PagingStoreFactoryDatabase implements PagingStoreFactory { ActiveMQBuffer buffer = ActiveMQBuffers.fixedBuffer(SimpleString.sizeofNullableString(address)); buffer.writeSimpleString(address); file.write(buffer, true); + file.close(); return factory; } @@ -157,15 +165,18 @@ public class PagingStoreFactoryDatabase implements PagingStoreFactory { @Override public synchronized List reloadStores(final HierarchicalRepository addressSettingsRepository) throws Exception { // We assume the directory list < Integer.MAX_VALUE (this is only a list of addresses). + JDBCSequentialFile directoryList = (JDBCSequentialFile) pagingFactoryFileFactory.createSequentialFile(DIRECTORY_NAME); + directoryList.open(); + int size = ((Long) directoryList.size()).intValue(); ActiveMQBuffer buffer = readActiveMQBuffer(directoryList, size); ArrayList storesReturn = new ArrayList<>(); while (buffer.readableBytes() > 0) { - SimpleString guid = buffer.readSimpleString(); + SimpleString table = buffer.readSimpleString(); - JDBCSequentialFileFactory factory = (JDBCSequentialFileFactory) newFileFactory(guid.toString(), false); + JDBCSequentialFileFactory factory = (JDBCSequentialFileFactory) newFileFactory(table.toString(), false); factory.start(); JDBCSequentialFile addressFile = (JDBCSequentialFile) factory.createSequentialFile(ADDRESS_FILE); @@ -185,15 +196,28 @@ public class PagingStoreFactoryDatabase implements PagingStoreFactory { storesReturn.add(store); } + directoryList.close(); return storesReturn; } private synchronized SequentialFileFactory newFileFactory(final String directoryName, boolean writeToDirectory) throws Exception { + JDBCSequentialFile directoryList = (JDBCSequentialFile) pagingFactoryFileFactory.createSequentialFile(DIRECTORY_NAME); + directoryList.open(); SimpleString simpleString = SimpleString.toSimpleString(directoryName); ActiveMQBuffer buffer = ActiveMQBuffers.fixedBuffer(simpleString.sizeof()); buffer.writeSimpleString(simpleString); if (writeToDirectory) directoryList.write(buffer, true); - return new JDBCSequentialFileFactory(pagingFactoryFileFactory.getDbDriver().getConnection(), JDBCUtils.getSQLProvider(dbConf.getJdbcDriverClassName(), getTableNameForGUID(directoryName)), executorFactory.getExecutor()); + directoryList.close(); + + SQLProvider sqlProvider = null; + if (dbConf.getDataSource() != null) { + SQLProvider.Factory sqlProviderFactory = dbConf.getSqlProviderFactory() == null ? new GenericSQLProvider.Factory() : dbConf.getSqlProviderFactory(); + sqlProvider = sqlProviderFactory.create(getTableNameForGUID(directoryName)); + } else { + sqlProvider = JDBCUtils.getSQLProvider(dbConf.getJdbcDriverClassName(), getTableNameForGUID(directoryName)); + } + + return new JDBCSequentialFileFactory(pagingFactoryFileFactory.getDbDriver().getConnection(), sqlProvider, executorFactory.getExecutor()); } private String getTableNameForGUID(String guid) {