Repository: nifi Updated Branches: refs/heads/master 0876cf12b -> 701597775
NIFI-1547: DistributedMapCacheServer: Ambiguous error on misconfiguration Updated PersistentMapCache constructor in PersistentMapCache.java to catch an OverlappingFileLockException and present a more useful error message before propagating the exception forward. The log message alerts user to possible duplicated persistencePath in call to PersistentMapCache. Created a test method to verify the exception is thrown as expected. Signed-off-by: Matthew Burgess <mattyb...@apache.org> This closes #2192 Project: http://git-wip-us.apache.org/repos/asf/nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/70159777 Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/70159777 Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/70159777 Branch: refs/heads/master Commit: 701597775fd2e98d7c577c5c1c683ac15d42098c Parents: 0876cf1 Author: Mark Owens <jmark...@gmail.com> Authored: Tue Oct 3 10:48:42 2017 -0400 Committer: Matthew Burgess <mattyb...@apache.org> Committed: Thu Oct 5 16:44:43 2017 -0400 ---------------------------------------------------------------------- .../cache/server/map/PersistentMapCache.java | 14 ++++++- .../server/map/TestPersistentMapCache.java | 42 ++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/nifi/blob/70159777/nifi-nar-bundles/nifi-standard-services/nifi-distributed-cache-services-bundle/nifi-distributed-cache-server/src/main/java/org/apache/nifi/distributed/cache/server/map/PersistentMapCache.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-distributed-cache-services-bundle/nifi-distributed-cache-server/src/main/java/org/apache/nifi/distributed/cache/server/map/PersistentMapCache.java b/nifi-nar-bundles/nifi-standard-services/nifi-distributed-cache-services-bundle/nifi-distributed-cache-server/src/main/java/org/apache/nifi/distributed/cache/server/map/PersistentMapCache.java index 9f1375c..28861ea 100644 --- a/nifi-nar-bundles/nifi-standard-services/nifi-distributed-cache-services-bundle/nifi-distributed-cache-server/src/main/java/org/apache/nifi/distributed/cache/server/map/PersistentMapCache.java +++ b/nifi-nar-bundles/nifi-standard-services/nifi-distributed-cache-services-bundle/nifi-distributed-cache-server/src/main/java/org/apache/nifi/distributed/cache/server/map/PersistentMapCache.java @@ -21,12 +21,15 @@ import java.io.EOFException; import java.io.File; import java.io.IOException; import java.nio.ByteBuffer; +import java.nio.channels.OverlappingFileLockException; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicLong; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.wali.MinimalLockingWriteAheadLog; import org.wali.SerDe; @@ -34,13 +37,22 @@ import org.wali.UpdateType; import org.wali.WriteAheadRepository; public class PersistentMapCache implements MapCache { + + private static final Logger logger = LoggerFactory.getLogger(PersistentMapCache.class); + private final MapCache wrapped; private final WriteAheadRepository<MapWaliRecord> wali; private final AtomicLong modifications = new AtomicLong(0L); public PersistentMapCache(final String serviceIdentifier, final File persistencePath, final MapCache cacheToWrap) throws IOException { - wali = new MinimalLockingWriteAheadLog<>(persistencePath.toPath(), 1, new Serde(), null); + try { + wali = new MinimalLockingWriteAheadLog<>(persistencePath.toPath(), 1, new Serde(), null); + } catch (OverlappingFileLockException ex) { + logger.error("OverlappingFileLockException thrown: Check lock location - possible duplicate persistencePath conflict in PersistentMapCache."); + // Propagate the exception + throw ex; + } wrapped = cacheToWrap; } http://git-wip-us.apache.org/repos/asf/nifi/blob/70159777/nifi-nar-bundles/nifi-standard-services/nifi-distributed-cache-services-bundle/nifi-distributed-cache-server/src/test/java/org/apache/nifi/distributed/cache/server/map/TestPersistentMapCache.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-services/nifi-distributed-cache-services-bundle/nifi-distributed-cache-server/src/test/java/org/apache/nifi/distributed/cache/server/map/TestPersistentMapCache.java b/nifi-nar-bundles/nifi-standard-services/nifi-distributed-cache-services-bundle/nifi-distributed-cache-server/src/test/java/org/apache/nifi/distributed/cache/server/map/TestPersistentMapCache.java new file mode 100644 index 0000000..55fb470 --- /dev/null +++ b/nifi-nar-bundles/nifi-standard-services/nifi-distributed-cache-services-bundle/nifi-distributed-cache-server/src/test/java/org/apache/nifi/distributed/cache/server/map/TestPersistentMapCache.java @@ -0,0 +1,42 @@ +/* + * 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.nifi.distributed.cache.server.map; + +import java.io.File; +import java.io.IOException; +import java.nio.channels.OverlappingFileLockException; +import org.apache.nifi.distributed.cache.server.EvictionPolicy; +import static org.junit.Assert.fail; +import org.junit.Test; + +public class TestPersistentMapCache { + + /** + * Test OverlappingFileLockException is caught when persistent path is duplicated. + */ + @Test(expected=OverlappingFileLockException.class) + public void testDuplicatePersistenceDirectory() { + try { + File duplicatedFilePath = new File("/tmp/path1"); + final MapCache cache = new SimpleMapCache("simpleCache", 2, EvictionPolicy.FIFO); + PersistentMapCache pmc1 = new PersistentMapCache("id1", duplicatedFilePath, cache); + PersistentMapCache pmc2 = new PersistentMapCache("id2", duplicatedFilePath, cache); + } catch (IOException ex) { + fail("Unexpected IOException thrown: " + ex.getMessage()); + } + } +} \ No newline at end of file