From 6f0e3ae6830355ec2b7672e12283491cb68f4f8c Mon Sep 17 00:00:00 2001 From: Edwin Kempin Date: Tue, 11 Jun 2019 13:21:44 +0200 Subject: [PATCH] RepoSequence: Remove unused increaseTo(int) method This method was only used to update the sequence in NoteDb when the sequence was read from ReviewDb. The ReviewDb code is gone and hence this method is no longer used. Signed-off-by: Edwin Kempin Change-Id: I34d78ee0237f1b215c8f304fa72760b469e2cd72 --- .../gerrit/server/notedb/RepoSequence.java | 57 ------------ .../server/notedb/RepoSequenceTest.java | 90 ------------------- 2 files changed, 147 deletions(-) diff --git a/java/com/google/gerrit/server/notedb/RepoSequence.java b/java/com/google/gerrit/server/notedb/RepoSequence.java index 3919622aca..7429aa5c12 100644 --- a/java/com/google/gerrit/server/notedb/RepoSequence.java +++ b/java/com/google/gerrit/server/notedb/RepoSequence.java @@ -238,31 +238,6 @@ public class RepoSequence { } } - public void increaseTo(int val) { - counterLock.lock(); - try { - try (Repository repo = repoManager.openRepository(projectName); - RevWalk rw = new RevWalk(repo)) { - TryIncreaseTo attempt = new TryIncreaseTo(repo, rw, val); - RefUpdate ru = retryer.call(attempt); - // Null update is a sentinel meaning nothing to do. - if (ru != null) { - RefUpdateUtil.checkResult(ru); - } - counter = limit; - } catch (ExecutionException | RetryException e) { - if (e.getCause() != null) { - Throwables.throwIfInstanceOf(e.getCause(), StorageException.class); - } - throw new StorageException(e); - } catch (IOException e) { - throw new StorageException(e); - } - } finally { - counterLock.unlock(); - } - } - private void acquire(int count) { try (Repository repo = repoManager.openRepository(projectName); RevWalk rw = new RevWalk(repo)) { @@ -311,38 +286,6 @@ public class RepoSequence { } } - private class TryIncreaseTo implements Callable { - private final Repository repo; - private final RevWalk rw; - private final int value; - - private TryIncreaseTo(Repository repo, RevWalk rw, int value) { - this.repo = repo; - this.rw = rw; - this.value = value; - } - - @Override - public RefUpdate call() throws Exception { - Optional blob = IntBlob.parse(repo, refName, rw); - afterReadRef.run(); - ObjectId oldId; - if (!blob.isPresent()) { - oldId = ObjectId.zeroId(); - } else { - oldId = blob.get().id(); - int next = blob.get().value(); - if (next >= value) { - // A concurrent write updated the ref already to this or a higher value; return null as a - // sentinel meaning nothing to do. Returning RefUpdate doesn't give us the flexibility to - // return any other kind of sentinel, since it's a fairly thick object. - return null; - } - } - return IntBlob.tryStore(repo, rw, projectName, refName, oldId, value, gitRefUpdated); - } - } - public static ReceiveCommand storeNew(ObjectInserter ins, String name, int val) throws IOException { ObjectId newId = ins.insert(OBJ_BLOB, Integer.toString(val).getBytes(UTF_8)); diff --git a/javatests/com/google/gerrit/server/notedb/RepoSequenceTest.java b/javatests/com/google/gerrit/server/notedb/RepoSequenceTest.java index b409b9d3ec..f088a79164 100644 --- a/javatests/com/google/gerrit/server/notedb/RepoSequenceTest.java +++ b/javatests/com/google/gerrit/server/notedb/RepoSequenceTest.java @@ -251,96 +251,6 @@ public class RepoSequenceTest { assertThat(s2.acquireCount).isEqualTo(1); } - @Test - public void increaseTo() throws Exception { - // Seed existing ref value. - writeBlob("id", "1"); - - RepoSequence s = newSequence("id", 1, 10); - - s.increaseTo(2); - assertThat(s.next()).isEqualTo(2); - } - - @Test - public void increaseToLowerValueIsIgnored() throws Exception { - // Seed existing ref value. - writeBlob("id", "2"); - - RepoSequence s = newSequence("id", 1, 10); - - s.increaseTo(1); - assertThat(s.next()).isEqualTo(2); - } - - @Test - public void increaseToRetryOnLockFailureV1() throws Exception { - // Seed existing ref value. - writeBlob("id", "1"); - - AtomicBoolean doneBgUpdate = new AtomicBoolean(false); - Runnable bgUpdate = - () -> { - if (!doneBgUpdate.getAndSet(true)) { - writeBlob("id", "2"); - } - }; - - RepoSequence s = newSequence("id", 1, 10, bgUpdate, RETRYER); - assertThat(doneBgUpdate.get()).isFalse(); - - // Increase the value to 3. The background thread increases the value to 2, which makes the - // increase to value 3 fail once with LockFailure. The increase to 3 is then retried and is - // expected to succeed. - s.increaseTo(3); - assertThat(s.next()).isEqualTo(3); - - assertThat(doneBgUpdate.get()).isTrue(); - } - - @Test - public void increaseToRetryOnLockFailureV2() throws Exception { - // Seed existing ref value. - writeBlob("id", "1"); - - AtomicBoolean doneBgUpdate = new AtomicBoolean(false); - Runnable bgUpdate = - () -> { - if (!doneBgUpdate.getAndSet(true)) { - writeBlob("id", "3"); - } - }; - - RepoSequence s = newSequence("id", 1, 10, bgUpdate, RETRYER); - assertThat(doneBgUpdate.get()).isFalse(); - - // Increase the value to 2. The background thread increases the value to 3, which makes the - // increase to value 2 fail with LockFailure. The increase to 2 is then not retried because the - // current value is already higher and it should be preserved. - s.increaseTo(2); - assertThat(s.next()).isEqualTo(3); - - assertThat(doneBgUpdate.get()).isTrue(); - } - - @Test - public void increaseToFailAfterRetryerGivesUp() throws Exception { - AtomicInteger bgCounter = new AtomicInteger(1234); - RepoSequence s = - newSequence( - "id", - 1, - 10, - () -> writeBlob("id", Integer.toString(bgCounter.getAndAdd(1000))), - RetryerBuilder.newBuilder() - .withStopStrategy(StopStrategies.stopAfterAttempt(3)) - .build()); - StorageException thrown = assertThrows(StorageException.class, () -> s.increaseTo(2)); - assertThat(thrown) - .hasMessageThat() - .contains("Failed to update refs/sequences/id: LOCK_FAILURE"); - } - private RepoSequence newSequence(String name, int start, int batchSize) { return newSequence(name, start, batchSize, Runnables.doNothing(), RETRYER); }