Repository: james-project Updated Branches: refs/heads/master af726bbb9 -> eeca3b563
MAILBOX-322 Add a Cassandra mailbox listener logger This will help diagnose Ghost mailbox bug. Note the possibility to filter per mailbox and per event type. Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/dd2ef3aa Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/dd2ef3aa Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/dd2ef3aa Branch: refs/heads/master Commit: dd2ef3aa3f778e70bc60d8c69edca36e24c40dfd Parents: 73e9333 Author: benwa <btell...@linagora.com> Authored: Thu Dec 14 10:32:13 2017 +0700 Committer: Antoine Duprat <adup...@linagora.com> Committed: Fri Dec 15 16:45:42 2017 +0100 ---------------------------------------------------------------------- .../james/mailbox/cassandra/GhostMailbox.java | 42 ++++++++++++ .../MailboxOperationLoggingListener.java | 72 ++++++++++++++++++++ .../modules/mailbox/CassandraMailboxModule.java | 5 ++ 3 files changed, 119 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/dd2ef3aa/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/GhostMailbox.java ---------------------------------------------------------------------- diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/GhostMailbox.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/GhostMailbox.java new file mode 100644 index 0000000..b3bd17b --- /dev/null +++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/GhostMailbox.java @@ -0,0 +1,42 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.mailbox.cassandra; + +import org.apache.james.util.MDCStructuredLogger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * See https://issues.apache.org/jira/browse/MAILBOX-322 for reading about the Ghost mailbox bug. + * + * This class intend to introduce a dedicated logger for the ghost mailbox bug. + */ +public class GhostMailbox { + private static final Logger LOGGER = LoggerFactory.getLogger(GhostMailbox.class); + + public static String MAILBOX_NAME = "mailboxName"; + public static String TYPE = "type"; + public static String MAILBOX_ID = "mailboxId"; + + public static MDCStructuredLogger logger() { + return MDCStructuredLogger.forLogger(LOGGER); + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/dd2ef3aa/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/MailboxOperationLoggingListener.java ---------------------------------------------------------------------- diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/MailboxOperationLoggingListener.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/MailboxOperationLoggingListener.java new file mode 100644 index 0000000..f0b7226 --- /dev/null +++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/MailboxOperationLoggingListener.java @@ -0,0 +1,72 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ + +package org.apache.james.mailbox.cassandra; + +import static org.apache.james.mailbox.cassandra.GhostMailbox.MAILBOX_NAME; +import static org.apache.james.mailbox.cassandra.GhostMailbox.TYPE; + +import org.apache.james.mailbox.MailboxListener; + +/** + * See https://issues.apache.org/jira/browse/MAILBOX-322 for reading about the Ghost mailbox bug. + * + * This class logs mailboxes writes in order to give context to analyse ghost mailbox bug. + */ +public class MailboxOperationLoggingListener implements MailboxListener { + public static final String ADDED = "Added"; + public static final String REMOVED = "Removed"; + + @Override + public ListenerType getType() { + return ListenerType.ONCE; + } + + @Override + public ExecutionMode getExecutionMode() { + return ExecutionMode.SYNCHRONOUS; + } + + @Override + public void event(Event event) { + if (event instanceof MailboxRenamed) { + MailboxRenamed mailboxRenamed = (MailboxRenamed) event; + GhostMailbox.logger() + .addField(MAILBOX_NAME, mailboxRenamed.getNewPath()) + .addField(TYPE, ADDED) + .log(logger -> logger.info("Mailbox renamed event")); + GhostMailbox.logger() + .addField(MAILBOX_NAME, mailboxRenamed.getMailboxPath()) + .addField(TYPE, REMOVED) + .log(logger -> logger.info("Mailbox renamed event")); + } + if (event instanceof MailboxDeletion) { + GhostMailbox.logger() + .addField(MAILBOX_NAME, event.getMailboxPath()) + .addField(TYPE, REMOVED) + .log(logger -> logger.info("Mailbox deleted event")); + } + if (event instanceof MailboxAdded) { + GhostMailbox.logger() + .addField(MAILBOX_NAME, event.getMailboxPath()) + .addField(TYPE, ADDED) + .log(logger -> logger.info("Mailbox added event")); + } + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/dd2ef3aa/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java index 35e524c..18789c6 100644 --- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java +++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java @@ -25,6 +25,7 @@ import org.apache.james.adapter.mailbox.store.UserRepositoryAuthorizator; import org.apache.james.backends.cassandra.components.CassandraModule; import org.apache.james.mailbox.AttachmentManager; import org.apache.james.mailbox.BlobManager; +import org.apache.james.mailbox.MailboxListener; import org.apache.james.mailbox.MailboxManager; import org.apache.james.mailbox.MailboxPathLocker; import org.apache.james.mailbox.MessageIdManager; @@ -33,6 +34,7 @@ import org.apache.james.mailbox.SubscriptionManager; import org.apache.james.mailbox.cassandra.CassandraMailboxManager; import org.apache.james.mailbox.cassandra.CassandraMailboxSessionMapperFactory; import org.apache.james.mailbox.cassandra.CassandraSubscriptionManager; +import org.apache.james.mailbox.cassandra.MailboxOperationLoggingListener; import org.apache.james.mailbox.cassandra.ids.CassandraId; import org.apache.james.mailbox.cassandra.ids.CassandraMessageId; import org.apache.james.mailbox.cassandra.mail.CassandraACLMapper; @@ -130,6 +132,9 @@ public class CassandraMailboxModule extends AbstractModule { bind(AttachmentManager.class).to(StoreAttachmentManager.class); bind(RightManager.class).to(StoreRightManager.class); + Multibinder<MailboxListener> mailboxListeners = Multibinder.newSetBinder(binder(), MailboxListener.class); + mailboxListeners.addBinding().to(MailboxOperationLoggingListener.class); + Multibinder<CassandraModule> cassandraDataDefinitions = Multibinder.newSetBinder(binder(), CassandraModule.class); cassandraDataDefinitions.addBinding().to(org.apache.james.mailbox.cassandra.modules.CassandraAclModule.class); cassandraDataDefinitions.addBinding().to(org.apache.james.mailbox.cassandra.modules.CassandraMailboxCounterModule.class); --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org