From 2e894554ca8d0e518f254b22ff3f4cccc9a59475 Mon Sep 17 00:00:00 2001 From: Clebert Suconic Date: Thu, 7 Apr 2016 15:53:52 -0400 Subject: [PATCH] ARTEMIS-474 fixing page.close() deadlock with replica --- .../paging/cursor/impl/PageCursorProviderImpl.java | 6 +++--- .../apache/activemq/artemis/core/paging/impl/Page.java | 10 ++++++++-- .../artemis/core/paging/impl/PagingStoreImpl.java | 8 ++++---- .../artemis/core/replication/ReplicationEndpoint.java | 4 ++-- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/cursor/impl/PageCursorProviderImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/cursor/impl/PageCursorProviderImpl.java index 5f5e1b32e7..7dad12be82 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/cursor/impl/PageCursorProviderImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/cursor/impl/PageCursorProviderImpl.java @@ -174,7 +174,7 @@ public class PageCursorProviderImpl implements PageCursorProvider { finally { try { if (page != null) { - page.close(); + page.close(false); } } catch (Throwable ignored) { @@ -448,14 +448,14 @@ public class PageCursorProviderImpl implements PageCursorProvider { } finally { try { - depagedPage.close(); + depagedPage.close(false); } catch (Exception e) { } storageManager.afterPageRead(); } - depagedPage.close(); + depagedPage.close(false); pgdMessages = pgdMessagesList.toArray(new PagedMessage[pgdMessagesList.size()]); } else { diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/Page.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/Page.java index b2373c92ad..07579a29d7 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/Page.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/Page.java @@ -216,8 +216,14 @@ public final class Page implements Comparable { file.position(0); } - public synchronized void close() throws Exception { - if (storageManager != null) { + public void close() throws Exception { + close(false); + } + + /** sendEvent means it's a close happening from a major event such moveNext. + * While reading the cache we don't need (and shouldn't inform the backup */ + public synchronized void close(boolean sendEvent) throws Exception { + if (sendEvent && storageManager != null) { storageManager.pageClosed(storeName, pageId); } if (pageCache != null) { diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PagingStoreImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PagingStoreImpl.java index 9a0af15d9b..85a2dc2b2b 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PagingStoreImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PagingStoreImpl.java @@ -348,7 +348,7 @@ public class PagingStoreImpl implements PagingStore { flushExecutors(); if (currentPage != null) { - currentPage.close(); + currentPage.close(false); currentPage = null; } } @@ -390,7 +390,7 @@ public class PagingStoreImpl implements PagingStore { currentPageId = 0; if (currentPage != null) { - currentPage.close(); + currentPage.close(false); } currentPage = null; @@ -589,7 +589,7 @@ public class PagingStoreImpl implements PagingStore { } returnPage = currentPage; - returnPage.close(); + returnPage.close(false); currentPage = null; // The current page is empty... which means we reached the end of the pages @@ -1021,7 +1021,7 @@ public class PagingStoreImpl implements PagingStore { int tmpCurrentPageId = currentPageId + 1; if (currentPage != null) { - currentPage.close(); + currentPage.close(true); } currentPage = createPage(tmpCurrentPageId); diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/replication/ReplicationEndpoint.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/replication/ReplicationEndpoint.java index dabe9fd700..7cf5450130 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/replication/ReplicationEndpoint.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/replication/ReplicationEndpoint.java @@ -306,7 +306,7 @@ public final class ReplicationEndpoint implements ChannelHandler, ActiveMQCompon for (Page page : map.values()) { try { page.sync(); - page.close(); + page.close(false); } catch (Exception e) { ActiveMQServerLogger.LOGGER.errorClosingPageOnReplication(e); @@ -698,7 +698,7 @@ public final class ReplicationEndpoint implements ChannelHandler, ActiveMQCompon } } else { - page.close(); + page.close(false); } }