This is an automated email from the ASF dual-hosted git repository. btellier pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-project.git
commit 30255146fc0af9f394c218648a7168d5a5a7f944 Author: Benoit Tellier <[email protected]> AuthorDate: Sun Nov 17 11:01:31 2019 +0700 JAMES-2870 Remove ZooKeeper Uid & ModSeq generators This module allows to generate sequence numbers for things like IMAP modseq or uid. It has been implemented to fulfil the lack of support for this kind of feature in HBase. Cassandra has the same kind of problems, as most distributed database, but we solved the problem without requiring yet another complex middleware. As HBase is no longer part of the codebase and to my knowledge the component is not used anywhere else, I propose to mark it as deprecated for 3.4 in order to target a removal for 3.5 --- mailbox/README.md | 8 - mailbox/pom.xml | 2 - mailbox/zoo-seq-provider/pom.xml | 88 --------- .../james/mailbox/store/mail/ZooUidProvider.java | 111 ------------ .../mailbox/store/mail/ZooUidProviderTest.java | 198 --------------------- 5 files changed, 407 deletions(-) diff --git a/mailbox/README.md b/mailbox/README.md index e76ce0a..0d3c7ea 100644 --- a/mailbox/README.md +++ b/mailbox/README.md @@ -20,7 +20,6 @@ Apache James Mailbox has the following project (Maven) structure: |-- spring -- Spring module - starts a specific mailbox implementation |-- store -- Common base/utility classes used in all mailbox implementations |-- tool -- Database migration/mailbox export tool -|-- zoo-seq-provider -- Distributed unique ID generator using Zookeeper and Curator (Clustering James Mailbox) ~~~ Mailbox JPA @@ -43,13 +42,6 @@ Implements the Maildir standard for email storage (http://en.wikipedia.org/wiki/ *Nix systems. -Zookeeper Sequence Provider -========================== - -Uses Zookeeper and Curator Framework for generating distributed unique ID's, needed for mailbox management from multiple -instances of James (IMAP) servers. - - Building ======== diff --git a/mailbox/pom.xml b/mailbox/pom.xml index d2d85a8..39410b4 100644 --- a/mailbox/pom.xml +++ b/mailbox/pom.xml @@ -72,8 +72,6 @@ <module>tools/indexer</module> <module>tools/jpa-migrator</module> <module>tools/maildir-utils</module> - - <module>zoo-seq-provider</module> </modules> <issueManagement> diff --git a/mailbox/zoo-seq-provider/pom.xml b/mailbox/zoo-seq-provider/pom.xml deleted file mode 100644 index df23980..0000000 --- a/mailbox/zoo-seq-provider/pom.xml +++ /dev/null @@ -1,88 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - 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. ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.apache.james</groupId> - <artifactId>apache-james-mailbox</artifactId> - <version>3.5.0-SNAPSHOT</version> - <relativePath>../pom.xml</relativePath> - </parent> - - <artifactId>zookeeper-sequence-provider</artifactId> - <packaging>jar</packaging> - <name>Apache James :: Mailbox :: Zookeeper Sequence Provider</name> - <description>Deprecated sequence provider based on ZooKeeper</description> - - <properties> - <curator.version>4.0.1</curator.version> - </properties> - - <dependencies> - <dependency> - <groupId>${james.groupId}</groupId> - <artifactId>apache-james-mailbox-api</artifactId> - </dependency> - <dependency> - <groupId>${james.groupId}</groupId> - <artifactId>apache-james-mailbox-store</artifactId> - </dependency> - <dependency> - <groupId>${james.groupId}</groupId> - <artifactId>testing-base</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>com.google.guava</groupId> - <artifactId>guava</artifactId> - <version>13.0</version><!--$NO-MVN-MAN-VER$--> - </dependency> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-lang3</artifactId> - </dependency> - <dependency> - <groupId>org.apache.curator</groupId> - <artifactId>curator-client</artifactId> - <version>${curator.version}</version> - </dependency> - <dependency> - <groupId>org.apache.curator</groupId> - <artifactId>curator-framework</artifactId> - <version>${curator.version}</version> - </dependency> - <dependency> - <groupId>org.apache.curator</groupId> - <artifactId>curator-recipes</artifactId> - <version>${curator.version}</version> - </dependency> - <dependency> - <groupId>org.apache.curator</groupId> - <artifactId>curator-test</artifactId> - <version>${curator.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - </dependency> - </dependencies> -</project> diff --git a/mailbox/zoo-seq-provider/src/main/java/org/apache/james/mailbox/store/mail/ZooUidProvider.java b/mailbox/zoo-seq-provider/src/main/java/org/apache/james/mailbox/store/mail/ZooUidProvider.java deleted file mode 100644 index 05df63c..0000000 --- a/mailbox/zoo-seq-provider/src/main/java/org/apache/james/mailbox/store/mail/ZooUidProvider.java +++ /dev/null @@ -1,111 +0,0 @@ -/**************************************************************** - * 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.store.mail; - -import java.util.Optional; - -import org.apache.commons.lang3.NotImplementedException; -import org.apache.curator.RetryPolicy; -import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.framework.imps.CuratorFrameworkState; -import org.apache.curator.framework.recipes.atomic.AtomicValue; -import org.apache.curator.framework.recipes.atomic.DistributedAtomicLong; -import org.apache.curator.retry.RetryOneTime; -import org.apache.james.mailbox.MailboxSession; -import org.apache.james.mailbox.MessageUid; -import org.apache.james.mailbox.exception.MailboxException; -import org.apache.james.mailbox.model.Mailbox; -import org.apache.james.mailbox.model.MailboxId; - -import com.google.common.base.Preconditions; - -/** - * ZooKeeper based implementation of a distributed sequential UID generator. - * - * This component is deprecated since 3.4. It way initially implemented for HBase backend that is now gone. - * As Others backends have their own solutions to generate sequential ids, we decided to deprecate then remove - * this implementation. - */ -@Deprecated -public class ZooUidProvider implements UidProvider { - // TODO: use ZK paths to store uid and modSeq, etc. - - public static final String UID_PATH_SUFFIX = "-uid"; - public static final String PATH_PREFIX = "/"; - - private final CuratorFramework client; - private final RetryPolicy retryPolicy; - - public ZooUidProvider(CuratorFramework client) { - this(client, new RetryOneTime(1)); - } - - public ZooUidProvider(CuratorFramework client, RetryPolicy retryPolicy) { - Preconditions.checkNotNull(client, "Curator client is null"); - Preconditions.checkNotNull(retryPolicy, "Retry policy is null"); - this.client = client; - this.retryPolicy = retryPolicy; - } - - @Override - public MessageUid nextUid(MailboxSession session, Mailbox mailbox) throws MailboxException { - if (client.getState() == CuratorFrameworkState.STARTED) { - DistributedAtomicLong uid = new DistributedAtomicLong(client, pathForMailbox(mailbox), retryPolicy); - try { - uid.increment(); - AtomicValue<Long> value = uid.get(); - if (value.succeeded()) { - return MessageUid.of(value.postValue()); - } - } catch (Exception e) { - throw new MailboxException("Exception incrementing UID for session " + session, e); - } - } - throw new MailboxException("Curator client is closed."); - } - - @Override - public Optional<MessageUid> lastUid(MailboxSession session, Mailbox mailbox) throws MailboxException { - if (client.getState() == CuratorFrameworkState.STARTED) { - DistributedAtomicLong uid = new DistributedAtomicLong(client, pathForMailbox(mailbox), retryPolicy); - try { - AtomicValue<Long> value = uid.get(); - if (value.succeeded()) { - Long postValue = value.postValue(); - if (postValue == 0) { - return Optional.empty(); - } - return Optional.of(MessageUid.of(value.postValue())); - } - } catch (Exception e) { - throw new MailboxException("Exception getting last UID for session " + session, e); - } - } - throw new MailboxException("Curator client is closed."); - } - - @Override - public MessageUid nextUid(MailboxSession session, MailboxId mailboxId) throws MailboxException { - throw new NotImplementedException("Not implemented"); - } - - public static <E extends MailboxId> String pathForMailbox(Mailbox mailbox) { - return PATH_PREFIX + mailbox.getMailboxId().serialize() + UID_PATH_SUFFIX; - } -} diff --git a/mailbox/zoo-seq-provider/src/test/java/org/apache/james/mailbox/store/mail/ZooUidProviderTest.java b/mailbox/zoo-seq-provider/src/test/java/org/apache/james/mailbox/store/mail/ZooUidProviderTest.java deleted file mode 100644 index 9ef11eb..0000000 --- a/mailbox/zoo-seq-provider/src/test/java/org/apache/james/mailbox/store/mail/ZooUidProviderTest.java +++ /dev/null @@ -1,198 +0,0 @@ -/**************************************************************** - * 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.store.mail; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.io.Serializable; -import java.util.Optional; -import java.util.UUID; - -import org.apache.curator.RetryPolicy; -import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.framework.CuratorFrameworkFactory; -import org.apache.curator.retry.RetryOneTime; -import org.apache.curator.test.TestingServer; -import org.apache.james.core.Username; -import org.apache.james.mailbox.MessageUid; -import org.apache.james.mailbox.model.Mailbox; -import org.apache.james.mailbox.model.MailboxId; -import org.apache.james.mailbox.model.MailboxPath; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - - -/** - * Test for UID provider. - */ -public class ZooUidProviderTest { - - public static class LongId implements MailboxId, Serializable { - - public final Long id; - - public LongId(long id) { - this.id = id; - } - - @Override - public String serialize() { - return String.valueOf(id); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((id == null) ? 0 : id.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - LongId other = (LongId) obj; - if (id == null) { - if (other.id != null) { - return false; - } - } else if (!id.equals(other.id)) { - return false; - } - return true; - } - - } - - public static class UUIDId implements MailboxId, Serializable { - - private final UUID id; - - public static UUIDId of(UUID id) { - return new UUIDId(id); - } - - public UUIDId(UUID id) { - this.id = id; - } - - @Override - public String serialize() { - return id.toString(); - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((id == null) ? 0 : id.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - UUIDId other = (UUIDId) obj; - if (id == null) { - if (other.id != null) { - return false; - } - } else if (!id.equals(other.id)) { - return false; - } - return true; - } - - } - - private static TestingServer testServer; - private static final int ZOO_TEST_PORT = 3123; - private final RetryPolicy retryPolicy = new RetryOneTime(1); - private CuratorFramework client; - private ZooUidProvider uuidProvider; - private ZooUidProvider longProvider; - private Mailbox mailboxUUID; - private Mailbox mailboxLong; - private UUID randomUUID = UUID.randomUUID(); - - @Before - public void setUp() throws Exception { - testServer = new TestingServer(ZOO_TEST_PORT); - client = CuratorFrameworkFactory.builder().connectString("localhost:" + ZOO_TEST_PORT) - .retryPolicy(retryPolicy) - .namespace("JAMES").build(); - client.start(); - uuidProvider = new ZooUidProvider(client, retryPolicy); - longProvider = new ZooUidProvider(client, retryPolicy); - Username namespaceuser = Username.of("namespaceuser"); - MailboxPath path1 = new MailboxPath("namespacetest", namespaceuser, "UUID"); - MailboxPath path2 = new MailboxPath("namespacetest", namespaceuser, "Long"); - mailboxUUID = new Mailbox(path1, 1L); - mailboxUUID.setMailboxId(UUIDId.of(randomUUID)); - mailboxLong = new Mailbox(path2, 2L); - mailboxLong.setMailboxId(new LongId(123L)); - } - - @After - public void tearDown() throws Exception { - client.close(); - testServer.close(); - } - - @Test - public void testNextUid() throws Exception { - MessageUid result = uuidProvider.nextUid(null, mailboxUUID); - assertThat(result.asLong()).describedAs("Next UID is 1").isEqualTo(1); - result = longProvider.nextUid(null, mailboxLong); - assertThat(result.asLong()).describedAs("Next UID is 1").isEqualTo(1); - } - - @Test - public void testLastUid() throws Exception { - Optional<MessageUid> result = uuidProvider.lastUid(null, mailboxUUID); - assertThat(result).describedAs("Next UID is empty").isEqualTo(Optional.empty()); - MessageUid nextResult = uuidProvider.nextUid(null, mailboxUUID); - assertThat(nextResult.asLong()).describedAs("Next UID is 1").isEqualTo(1); - } - - @Test - public void testLongLastUid() throws Exception { - Optional<MessageUid> result = longProvider.lastUid(null, mailboxLong); - assertThat(result).describedAs("Next UID is empty").isEqualTo(Optional.empty()); - MessageUid nextResult = longProvider.nextUid(null, mailboxLong); - assertThat(nextResult.asLong()).describedAs("Next UID is 1").isEqualTo(1); - } -} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
