DRY out shouldNotBeTrackedAnymoreOnGlobalRefDb The method shouldNotBeTrackedAnymoreOnGlobalRefDb() is to be shared across replication filters: DRY the method and introduce a common package-protected abstract class AbstractMultisiteRepicationFilter to share the method between the two filters. This is a follow-up of changes I83313884 and I8b938675f. Change-Id: Ic83f1979a10d7b2c1a57dcafa892b7de49fba40d
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/AbstractMultisiteReplicationFilter.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/AbstractMultisiteReplicationFilter.java new file mode 100644 index 0000000..bf4a0f9 --- /dev/null +++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/AbstractMultisiteReplicationFilter.java
@@ -0,0 +1,33 @@ +// Copyright (C) 2024 The Android Open Source Project +// +// Licensed 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 com.googlesource.gerrit.plugins.multisite.validation; + +import static com.googlesource.gerrit.plugins.multisite.validation.ProjectVersionRefUpdate.MULTI_SITE_VERSIONING_REF; + +abstract class AbstractMultisiteReplicationFilter { + + /* + * Since ac43a5f94c773c9db7a73d44035961d69d13fa53 the 'refs/multi-site/version' is + * not updated anymore on the global-refdb; however, the values stored already + * on the global-refdb could get in the way and prevent replication from happening + * as expected. + * + * Exclude the 'refs/multi-site/version' from local vs. global refdb checking + * pretending that the global-refdb for that ref did not exist. + */ + protected boolean shouldNotBeTrackedAnymoreOnGlobalRefDb(String ref) { + return MULTI_SITE_VERSIONING_REF.equals(ref); + } +}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/MultisiteReplicationFetchFilter.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/MultisiteReplicationFetchFilter.java index d851420..c97b636 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/MultisiteReplicationFetchFilter.java +++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/MultisiteReplicationFetchFilter.java
@@ -14,7 +14,6 @@ package com.googlesource.gerrit.plugins.multisite.validation; -import static com.googlesource.gerrit.plugins.multisite.validation.ProjectVersionRefUpdate.MULTI_SITE_VERSIONING_REF; import static com.googlesource.gerrit.plugins.replication.pull.PullReplicationLogger.repLog; import com.gerritforge.gerrit.globalrefdb.GlobalRefDbLockException; @@ -38,7 +37,8 @@ import org.eclipse.jgit.lib.Repository; @Singleton -public class MultisiteReplicationFetchFilter implements ReplicationFetchFilter { +public class MultisiteReplicationFetchFilter extends AbstractMultisiteReplicationFilter + implements ReplicationFetchFilter { private static final String ZERO_ID_NAME = ObjectId.zeroId().name(); private static final FluentLogger logger = FluentLogger.forEnclosingClass(); @@ -91,19 +91,6 @@ } } - /* - * Since ac43a5f94c773c9db7a73d44035961d69d13fa53 the 'refs/multi-site/version' is - * not updated anymore on the global-refdb; however, the values stored already - * on the global-refdb could get in the way and prevent replication from happening - * as expected. - * - * Exclude the 'refs/multi-site/version' from local vs. global refdb checking - * pretending that the global-refdb for that ref did not exist. - */ - private boolean shouldNotBeTrackedAnymoreOnGlobalRefDb(String ref) { - return MULTI_SITE_VERSIONING_REF.equals(ref); - } - /* If the ref to fetch has been set to all zeros on the global-refdb, it means * that whatever is the situation locally, we do not need to fetch it: * - If the remote still has it, fetching it will be useless because the global
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/MultisiteReplicationPushFilter.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/MultisiteReplicationPushFilter.java index 777886d..1cb9621 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/MultisiteReplicationPushFilter.java +++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/MultisiteReplicationPushFilter.java
@@ -14,8 +14,6 @@ package com.googlesource.gerrit.plugins.multisite.validation; -import static com.googlesource.gerrit.plugins.multisite.validation.ProjectVersionRefUpdate.MULTI_SITE_VERSIONING_REF; - import com.gerritforge.gerrit.globalrefdb.GlobalRefDbLockException; import com.gerritforge.gerrit.globalrefdb.validation.SharedRefDatabaseWrapper; import com.google.common.base.Preconditions; @@ -42,7 +40,8 @@ import org.slf4j.LoggerFactory; @Singleton -public class MultisiteReplicationPushFilter implements ReplicationPushFilter { +public class MultisiteReplicationPushFilter extends AbstractMultisiteReplicationFilter + implements ReplicationPushFilter { private static final FluentLogger logger = FluentLogger.forEnclosingClass(); private static final String REF_META_SUFFIX = "/meta"; @@ -152,19 +151,6 @@ } } - /* - * Since ac43a5f94c773c9db7a73d44035961d69d13fa53 the 'refs/multi-site/version' is - * not updated anymore on the global-refdb; however, the values stored already - * on the global-refdb could get in the way and prevent replication from happening - * as expected. - * - * Exclude the 'refs/multi-site/version' from local vs. global refdb checking - * pretending that the global-refdb for that ref did not exist. - */ - private boolean shouldNotBeTrackedAnymoreOnGlobalRefDb(String ref) { - return MULTI_SITE_VERSIONING_REF.equals(ref); - } - private RemoteRefUpdate newRemoteRefUpdateWithObjectId( Repository localDb, RemoteRefUpdate refUpdate, ObjectId reloadedNewObjectId) throws IOException {