diff options
author | Harald Musum <musum@oath.com> | 2018-02-13 13:56:07 +0100 |
---|---|---|
committer | Harald Musum <musum@oath.com> | 2018-02-13 13:56:07 +0100 |
commit | f013f24874f77c45b792522fc488cb1c848ed71b (patch) | |
tree | 9ac5732c03e2a27e703dfe558553d72ec821c7be /configserver | |
parent | 8daccb7a9396d1ffa5fffb9d7bba04e3f15aca8e (diff) |
Remove dead code
Diffstat (limited to 'configserver')
2 files changed, 0 insertions, 203 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDistributionLock.java b/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDistributionLock.java deleted file mode 100644 index 547c4a1bc2a..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDistributionLock.java +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.config.server.filedistribution; - -import com.yahoo.vespa.config.server.TimeoutBudget; -import com.yahoo.vespa.curator.Curator; -import com.yahoo.vespa.curator.recipes.CuratorLock; -import com.yahoo.vespa.curator.recipes.CuratorLockException; - -import java.time.Clock; -import java.time.Duration; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.locks.Condition; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; - -/** - * Global filedistribution lock to ensure only one configserver may work on filedistribution. - * The implementation uses a combination of a {@link java.util.concurrent.locks.ReentrantLock} and - * a {@link CuratorLock} to ensure both mutual exclusion within the JVM and - * across JVMs via ZooKeeper. - * - * @author lulf - */ -public class FileDistributionLock implements Lock { - private final Lock processLock; - private final CuratorLock curatorLock; - - public FileDistributionLock(Curator curator, String zkPath) { - this.processLock = new ReentrantLock(); - this.curatorLock = new CuratorLock(curator, zkPath); - } - - @Override - public void lock() { - processLock.lock(); - try { - curatorLock.lock(); - } catch (CuratorLockException e) { - processLock.unlock(); - throw e; - } - } - - @Override - public void lockInterruptibly() throws InterruptedException { - throw new UnsupportedOperationException(); - - } - - @Override - public boolean tryLock() { - if (processLock.tryLock()) { - if (curatorLock.tryLock()) { - return true; - } else { - processLock.unlock(); - return false; - } - } else { - return false; - } - } - - @Override - public boolean tryLock(long timeout, TimeUnit unit) throws InterruptedException { - TimeoutBudget budget = new TimeoutBudget(Clock.systemUTC(), Duration.ofMillis(unit.toMillis(timeout))); - if (processLock.tryLock(budget.timeLeft().toMillis(), TimeUnit.MILLISECONDS)) { - if (curatorLock.tryLock(budget.timeLeft().toMillis(), TimeUnit.MILLISECONDS)) { - return true; - } else { - processLock.unlock(); - return false; - } - } else { - return false; - } - } - - @Override - public void unlock() { - try { - curatorLock.unlock(); - } finally { - processLock.unlock(); - } - } - - @Override - public Condition newCondition() { - throw new UnsupportedOperationException(); - } -} - diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/FileDistributionLockTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/FileDistributionLockTest.java deleted file mode 100644 index 362934b7898..00000000000 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/filedistribution/FileDistributionLockTest.java +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.vespa.config.server.filedistribution; - -import com.yahoo.vespa.config.server.TestWithCurator; -import com.yahoo.vespa.curator.recipes.CuratorLockException; -import com.yahoo.vespa.curator.mock.MockCurator; -import org.junit.Before; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.*; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; - -/** - * @author lulf - */ -public class FileDistributionLockTest extends TestWithCurator { - - FileDistributionLock lock; - private int value = 0; - - @Before - public void setupLock() { - lock = new FileDistributionLock(curator, "/lock"); - value = 0; - } - - @Test - public void testDistributedLock() throws InterruptedException, TimeoutException, ExecutionException { - ExecutorService executor = Executors.newFixedThreadPool(20); - - List<Future<?>> futureList = new ArrayList<>(); - for (int i = 0; i < 20; i++) { - futureList.add(executor.submit(() -> { - lock.lock(); - value++; - lock.unlock(); - })); - } - - for (Future<?> future : futureList) { - future.get(600, TimeUnit.SECONDS); - } - assertThat(value, is(20)); - } - - @Test - public void testDistributedTryLockFailure() throws InterruptedException { - MockCurator mockCurator = new MockCurator(); - lock = new FileDistributionLock(mockCurator, "/mocklock"); - mockCurator.timeoutOnLock = true; - assertFalse(lock.tryLock(600, TimeUnit.SECONDS)); - mockCurator.timeoutOnLock = false; - // Second time should not be blocking - Thread t = new Thread(() -> { - try { - if (lock.tryLock(6, TimeUnit.SECONDS)) { - value = 1; - lock.unlock(); - } - } catch (InterruptedException e) { - } - }); - assertThat(value, is(0)); - t.start(); - t.join(); - assertThat(value, is(1)); - } - - @Test - public void testDistributedLockExceptionFailure() throws InterruptedException { - MockCurator mockCurator = new MockCurator(); - lock = new FileDistributionLock(mockCurator, "/mocklock"); - mockCurator.throwExceptionOnLock = true; - try { - lock.lock(); - fail("Lock call should not succeed"); - } catch (CuratorLockException e) { - // ignore - } - mockCurator.throwExceptionOnLock = false; - // Second time should not be blocking - Thread t = new Thread(() -> { - try { - lock.lock(); - value = 1; - lock.unlock(); - } catch (Exception e) { - fail("Should not fail"); - } - }); - assertThat(value, is(0)); - t.start(); - t.join(); - assertThat(value, is(1)); - } - - @Test(expected = UnsupportedOperationException.class) - public void testConditionNotSupported() { - lock.newCondition(); - } - - @Test(expected = UnsupportedOperationException.class) - public void testLockInterruptiblyNotSupported() throws InterruptedException { - lock.lockInterruptibly(); - } -} |