Revert "Use project versioning ref name from global-refdb library"
This reverts commit ea6677e558f463c1e1b53c22be6c1ec29e2babab.
Reason for revert: This is the wrong fix as we cannot break the v3.2 to v3.3 compatibility, otherwise any upgrade would be impossible without a downtime.
Change-Id: Idef92d8c8bdd809e713299c75e2b0fd0dae1c53c
diff --git a/external_plugin_deps.bzl b/external_plugin_deps.bzl
index a19b0a8..c2f45a0 100644
--- a/external_plugin_deps.bzl
+++ b/external_plugin_deps.bzl
@@ -3,8 +3,8 @@
def external_plugin_deps():
maven_jar(
name = "global-refdb",
- artifact = "com.gerritforge:global-refdb:3.3.0",
- sha1 = "8ef0600757b7468dc023c5030ce2cfeaa8ea0b64",
+ artifact = "com.gerritforge:global-refdb:3.3.0-rc1",
+ sha1 = "1b005b31c27a30ff10de97f903fa2834051bcadf",
)
maven_jar(
diff --git a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/ProjectVersionRefUpdate.java b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/ProjectVersionRefUpdate.java
index 42eb4e2..28eddbb 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/ProjectVersionRefUpdate.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/multisite/validation/ProjectVersionRefUpdate.java
@@ -14,7 +14,6 @@
package com.googlesource.gerrit.plugins.multisite.validation;
-import static com.gerritforge.gerrit.globalrefdb.validation.RefUpdateValidator.SHARED_REF_DB_VERSIONING_REF;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
@@ -52,11 +51,10 @@
private static final Set<RefUpdate.Result> SUCCESSFUL_RESULTS =
ImmutableSet.of(RefUpdate.Result.NEW, RefUpdate.Result.FORCED, RefUpdate.Result.NO_CHANGE);
- public static final String SHARED_REF_DB_VERSIONING_VALUE_REF =
- SHARED_REF_DB_VERSIONING_REF + "/value";
+ public static final String MULTI_SITE_VERSIONING_REF = "refs/multi-site/version";
+ public static final String MULTI_SITE_VERSIONING_VALUE_REF = "refs/multi-site/version/value";
public static final Ref NULL_PROJECT_VERSION_REF =
- new ObjectIdRef.Unpeeled(
- Ref.Storage.NETWORK, SHARED_REF_DB_VERSIONING_REF, ObjectId.zeroId());
+ new ObjectIdRef.Unpeeled(Ref.Storage.NETWORK, MULTI_SITE_VERSIONING_REF, ObjectId.zeroId());
private final GitRepositoryManager gitRepositoryManager;
private final GitReferenceUpdated gitReferenceUpdated;
@@ -93,7 +91,7 @@
private boolean isSpecialRefName(String refName) {
return refName.startsWith(RefNames.REFS_SEQUENCES)
|| refName.startsWith(RefNames.REFS_STARRED_CHANGES)
- || refName.equals(SHARED_REF_DB_VERSIONING_REF);
+ || refName.equals(MULTI_SITE_VERSIONING_REF);
}
private void updateProducerProjectVersionUpdate(RefUpdatedEvent refUpdatedEvent) {
@@ -133,8 +131,7 @@
private RefUpdate getProjectVersionRefUpdate(Repository repository, Long version)
throws IOException {
- RefUpdate refUpdate =
- repository.getRefDatabase().newUpdate(SHARED_REF_DB_VERSIONING_REF, false);
+ RefUpdate refUpdate = repository.getRefDatabase().newUpdate(MULTI_SITE_VERSIONING_REF, false);
refUpdate.setNewObjectId(getNewId(repository, version));
refUpdate.setForceUpdate(true);
return refUpdate;
@@ -153,19 +150,17 @@
Ref sharedRef =
sharedRefDb
- .get(projectNameKey, SHARED_REF_DB_VERSIONING_REF, String.class)
+ .get(projectNameKey, MULTI_SITE_VERSIONING_REF, String.class)
.map(
(String objectId) ->
new ObjectIdRef.Unpeeled(
- Ref.Storage.NEW,
- SHARED_REF_DB_VERSIONING_REF,
- ObjectId.fromString(objectId)))
+ Ref.Storage.NEW, MULTI_SITE_VERSIONING_REF, ObjectId.fromString(objectId)))
.orElse(
new ObjectIdRef.Unpeeled(
- Ref.Storage.NEW, SHARED_REF_DB_VERSIONING_REF, ObjectId.zeroId()));
+ Ref.Storage.NEW, MULTI_SITE_VERSIONING_REF, ObjectId.zeroId()));
Optional<Long> sharedVersion =
sharedRefDb
- .get(projectNameKey, SHARED_REF_DB_VERSIONING_VALUE_REF, String.class)
+ .get(projectNameKey, MULTI_SITE_VERSIONING_VALUE_REF, String.class)
.map(Long::parseLong);
try {
@@ -199,7 +194,7 @@
success =
sharedRefDb.compareAndPut(
projectNameKey,
- SHARED_REF_DB_VERSIONING_VALUE_REF,
+ MULTI_SITE_VERSIONING_VALUE_REF,
sharedVersion.map(Object::toString).orElse(null),
newVersion.toString());
if (!success) {
@@ -228,7 +223,7 @@
public Optional<Long> getProjectLocalVersion(String projectName) {
try (Repository repository =
gitRepositoryManager.openRepository(Project.NameKey.parse(projectName))) {
- Optional<IntBlob> blob = IntBlob.parse(repository, SHARED_REF_DB_VERSIONING_REF);
+ Optional<IntBlob> blob = IntBlob.parse(repository, MULTI_SITE_VERSIONING_REF);
if (blob.isPresent()) {
Long repoVersion = Integer.toUnsignedLong(blob.get().value());
logger.atFine().log("Local project '%s' has version %d", projectName, repoVersion);
@@ -245,7 +240,7 @@
public Optional<Long> getProjectRemoteVersion(String projectName) {
Optional<String> globalVersion =
sharedRefDb.get(
- Project.NameKey.parse(projectName), SHARED_REF_DB_VERSIONING_VALUE_REF, String.class);
+ Project.NameKey.parse(projectName), MULTI_SITE_VERSIONING_VALUE_REF, String.class);
return globalVersion.flatMap(longString -> getLongValueOf(longString));
}
diff --git a/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/ProjectVersionRefUpdateTest.java b/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/ProjectVersionRefUpdateTest.java
index 11ed304..917c6bf 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/ProjectVersionRefUpdateTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/multisite/validation/ProjectVersionRefUpdateTest.java
@@ -14,9 +14,9 @@
package com.googlesource.gerrit.plugins.multisite.validation;
-import static com.gerritforge.gerrit.globalrefdb.validation.RefUpdateValidator.SHARED_REF_DB_VERSIONING_REF;
import static com.google.common.truth.Truth.assertThat;
-import static com.googlesource.gerrit.plugins.multisite.validation.ProjectVersionRefUpdate.SHARED_REF_DB_VERSIONING_VALUE_REF;
+import static com.googlesource.gerrit.plugins.multisite.validation.ProjectVersionRefUpdate.MULTI_SITE_VERSIONING_REF;
+import static com.googlesource.gerrit.plugins.multisite.validation.ProjectVersionRefUpdate.MULTI_SITE_VERSIONING_VALUE_REF;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.atMost;
@@ -93,11 +93,14 @@
@Test
public void producerShouldUpdateProjectVersionUponRefUpdatedEvent() throws IOException {
Context.setForwardedEvent(false);
- when(sharedRefDb.get(A_TEST_PROJECT_NAME_KEY, SHARED_REF_DB_VERSIONING_REF, String.class))
+ when(sharedRefDb.get(
+ A_TEST_PROJECT_NAME_KEY,
+ ProjectVersionRefUpdate.MULTI_SITE_VERSIONING_REF,
+ String.class))
.thenReturn(Optional.of("26f7ee61bf0e470e8393c884526eec8a9b943a63"));
when(sharedRefDb.get(
A_TEST_PROJECT_NAME_KEY,
- ProjectVersionRefUpdate.SHARED_REF_DB_VERSIONING_VALUE_REF,
+ ProjectVersionRefUpdate.MULTI_SITE_VERSIONING_VALUE_REF,
String.class))
.thenReturn(Optional.of("" + (masterCommit.getCommitTime() - 1)));
when(sharedRefDb.compareAndPut(any(Project.NameKey.class), any(Ref.class), any(ObjectId.class)))
@@ -111,7 +114,7 @@
repoManager, sharedRefDb, gitReferenceUpdated, verLogger, projectsFilter)
.onEvent(refUpdatedEvent);
- Ref ref = repo.getRepository().findRef(SHARED_REF_DB_VERSIONING_REF);
+ Ref ref = repo.getRepository().findRef(MULTI_SITE_VERSIONING_REF);
verify(sharedRefDb, atMost(1))
.compareAndPut(any(Project.NameKey.class), any(Ref.class), any(ObjectId.class));
@@ -135,11 +138,14 @@
Thread.sleep(1000L);
repo.branch("master").update(masterCommit);
- when(sharedRefDb.get(A_TEST_PROJECT_NAME_KEY, SHARED_REF_DB_VERSIONING_REF, String.class))
+ when(sharedRefDb.get(
+ A_TEST_PROJECT_NAME_KEY,
+ ProjectVersionRefUpdate.MULTI_SITE_VERSIONING_REF,
+ String.class))
.thenReturn(Optional.of("26f7ee61bf0e470e8393c884526eec8a9b943a63"));
when(sharedRefDb.get(
A_TEST_PROJECT_NAME_KEY,
- ProjectVersionRefUpdate.SHARED_REF_DB_VERSIONING_VALUE_REF,
+ ProjectVersionRefUpdate.MULTI_SITE_VERSIONING_VALUE_REF,
String.class))
.thenReturn(Optional.of("" + (masterCommit.getCommitTime() - 1)));
when(sharedRefDb.compareAndPut(any(Project.NameKey.class), any(Ref.class), any(ObjectId.class)))
@@ -153,7 +159,7 @@
repoManager, sharedRefDb, gitReferenceUpdated, verLogger, projectsFilter)
.onEvent(refUpdatedEvent);
- Ref ref = repo.getRepository().findRef(SHARED_REF_DB_VERSIONING_REF);
+ Ref ref = repo.getRepository().findRef(MULTI_SITE_VERSIONING_REF);
verify(sharedRefDb, atMost(1))
.compareAndPut(any(Project.NameKey.class), any(Ref.class), any(ObjectId.class));
@@ -171,11 +177,14 @@
public void producerShouldCreateNewProjectVersionWhenMissingUponRefUpdatedEvent()
throws IOException {
Context.setForwardedEvent(false);
- when(sharedRefDb.get(A_TEST_PROJECT_NAME_KEY, SHARED_REF_DB_VERSIONING_REF, String.class))
+ when(sharedRefDb.get(
+ A_TEST_PROJECT_NAME_KEY,
+ ProjectVersionRefUpdate.MULTI_SITE_VERSIONING_REF,
+ String.class))
.thenReturn(Optional.empty());
when(sharedRefDb.get(
A_TEST_PROJECT_NAME_KEY,
- ProjectVersionRefUpdate.SHARED_REF_DB_VERSIONING_VALUE_REF,
+ ProjectVersionRefUpdate.MULTI_SITE_VERSIONING_VALUE_REF,
String.class))
.thenReturn(Optional.empty());
@@ -190,7 +199,7 @@
repoManager, sharedRefDb, gitReferenceUpdated, verLogger, projectsFilter)
.onEvent(refUpdatedEvent);
- Ref ref = repo.getRepository().findRef(SHARED_REF_DB_VERSIONING_REF);
+ Ref ref = repo.getRepository().findRef(MULTI_SITE_VERSIONING_REF);
verify(sharedRefDb, atMost(1))
.compareAndPut(any(Project.NameKey.class), isNull(), any(ObjectId.class));
@@ -233,7 +242,7 @@
repoManager, sharedRefDb, gitReferenceUpdated, verLogger, projectsFilter)
.onEvent(refUpdatedEvent);
- Ref ref = repo.getRepository().findRef(SHARED_REF_DB_VERSIONING_REF);
+ Ref ref = repo.getRepository().findRef(MULTI_SITE_VERSIONING_REF);
assertThat(ref).isNull();
verifyZeroInteractions(verLogger);
@@ -249,7 +258,7 @@
repoManager, sharedRefDb, gitReferenceUpdated, verLogger, projectsFilter)
.onEvent(refUpdatedEvent);
- Ref ref = repo.getRepository().findRef(SHARED_REF_DB_VERSIONING_REF);
+ Ref ref = repo.getRepository().findRef(MULTI_SITE_VERSIONING_REF);
assertThat(ref).isNull();
verifyZeroInteractions(verLogger);
@@ -271,7 +280,7 @@
repoManager, sharedRefDb, gitReferenceUpdated, verLogger, projectsFilter)
.onEvent(refUpdatedEvent);
- Ref ref = repo.getRepository().findRef(SHARED_REF_DB_VERSIONING_REF);
+ Ref ref = repo.getRepository().findRef(MULTI_SITE_VERSIONING_REF);
assertThat(ref).isNull();
verifyZeroInteractions(verLogger);
@@ -279,7 +288,7 @@
@Test
public void getRemoteProjectVersionShouldReturnCorrectValue() {
- when(sharedRefDb.get(A_TEST_PROJECT_NAME_KEY, SHARED_REF_DB_VERSIONING_VALUE_REF, String.class))
+ when(sharedRefDb.get(A_TEST_PROJECT_NAME_KEY, MULTI_SITE_VERSIONING_VALUE_REF, String.class))
.thenReturn(Optional.of("123"));
Optional<Long> version =