ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ptupit...@apache.org
Subject [3/8] ignite git commit: IGNITE-3197 - OverlappingFileLockException in marshaller context
Date Tue, 23 Aug 2016 11:24:48 GMT
IGNITE-3197 - OverlappingFileLockException in marshaller context


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/a0c7c44f
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/a0c7c44f
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/a0c7c44f

Branch: refs/heads/master
Commit: a0c7c44fc864aa965fd4d14e5362a4f6356c01ab
Parents: fa13832
Author: AndreVel <andrey4vel@gmail.com>
Authored: Mon Aug 22 20:50:57 2016 -0700
Committer: Valentin Kulichenko <valentin.lulichenko@gmail.com>
Committed: Mon Aug 22 20:50:57 2016 -0700

----------------------------------------------------------------------
 .../ignite/internal/MarshallerContextImpl.java  |   9 +-
 .../continuous/CacheContinuousQueryManager.java |   2 +-
 .../MarshallerContextLockingSelfTest.java       | 139 +++++++++++++++++++
 .../ignite/testsuites/IgniteBasicTestSuite.java |   3 +
 4 files changed, 150 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/a0c7c44f/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java
b/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java
index 504ea6e..0420e18 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/MarshallerContextImpl.java
@@ -27,6 +27,7 @@ import java.io.OutputStreamWriter;
 import java.io.Writer;
 import java.nio.channels.FileChannel;
 import java.nio.channels.FileLock;
+import java.nio.channels.OverlappingFileLockException;
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ThreadLocalRandom;
@@ -258,7 +259,7 @@ public class MarshallerContextImpl extends MarshallerContextAdapter {
 
     /**
      */
-    private static class ContinuousQueryListener implements CacheEntryUpdatedListener<Integer,
String> {
+    public static class ContinuousQueryListener implements CacheEntryUpdatedListener<Integer,
String> {
         /** */
         private final IgniteLogger log;
 
@@ -269,7 +270,7 @@ public class MarshallerContextImpl extends MarshallerContextAdapter {
          * @param log Logger.
          * @param workDir Work directory.
          */
-        private ContinuousQueryListener(IgniteLogger log, File workDir) {
+        public ContinuousQueryListener(IgniteLogger log, File workDir) {
             this.log = log;
             this.workDir = workDir;
         }
@@ -306,6 +307,10 @@ public class MarshallerContextImpl extends MarshallerContextAdapter {
                             U.error(log, "Failed to write class name to file [id=" + evt.getKey()
+
                                 ", clsName=" + evt.getValue() + ", file=" + file.getAbsolutePath()
+ ']', e);
                         }
+                        catch(OverlappingFileLockException ignored) {
+                            if (log.isDebugEnabled())
+                                log.debug("File already locked (will ignore): " + file.getAbsolutePath());
+                        }
                         catch (IgniteInterruptedCheckedException e) {
                             U.error(log, "Interrupted while waiting for acquiring file lock:
" + file, e);
                         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/a0c7c44f/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java
index a8e5a6b..2863f3d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/continuous/CacheContinuousQueryManager.java
@@ -1204,7 +1204,7 @@ public class CacheContinuousQueryManager extends GridCacheManagerAdapter
{
     /**
      *
      */
-    private static class CacheEntryEventImpl extends CacheQueryEntryEvent {
+    public static class CacheEntryEventImpl extends CacheQueryEntryEvent {
         /** */
         private static final long serialVersionUID = 0L;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/a0c7c44f/modules/core/src/test/java/org/apache/ignite/internal/MarshallerContextLockingSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/MarshallerContextLockingSelfTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/MarshallerContextLockingSelfTest.java
new file mode 100644
index 0000000..e549336
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/MarshallerContextLockingSelfTest.java
@@ -0,0 +1,139 @@
+/*
+ * 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.ignite.internal;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentLinkedDeque;
+import java.util.concurrent.atomic.AtomicInteger;
+import javax.cache.event.CacheEntryEvent;
+import javax.cache.event.EventType;
+import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
+import org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryManager;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.testframework.GridTestClassLoader;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.testframework.junits.logger.GridTestLog4jLogger;
+
+/**
+ * Test marshaller context.
+ */
+public class MarshallerContextLockingSelfTest extends GridCommonAbstractTest {
+    /** Inner logger. */
+    private InnerLogger innerLog = null;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        innerLog = new InnerLogger();
+
+        log = innerLog;
+    }
+
+    /**
+     * Mumtithread test, used custom class loader
+     */
+    public void testMultithreadedUpdate() throws Exception {
+        multithreaded(new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                GridTestClassLoader classLoader = new GridTestClassLoader(
+                    InternalExecutor.class.getName(),
+                    MarshallerContextImpl.class.getName(),
+                    MarshallerContextImpl.ContinuousQueryListener.class.getName()
+                );
+
+                Thread.currentThread().setContextClassLoader(classLoader);
+
+                Class clazz = classLoader.loadClass(InternalExecutor.class.getName());
+
+                Object internelExecutor = clazz.newInstance();
+
+                clazz.getMethod("executeTest", GridTestLog4jLogger.class).invoke(internelExecutor,
log);
+
+                return null;
+            }
+        }, 4);
+
+        assertTrue(InternalExecutor.counter.get() == 0);
+
+        assertTrue(innerLog.contains("File already locked"));
+
+        assertTrue(!innerLog.contains("Exception"));
+    }
+
+    /**
+     * Internal test executor
+     */
+    public static class InternalExecutor {
+        /** Counter. */
+        public static AtomicInteger counter = new AtomicInteger();
+
+        /**
+        * Executes onUpdated
+        */
+        public void executeTest(GridTestLog4jLogger log) throws Exception {
+            counter.incrementAndGet();
+
+            File workDir = U.resolveWorkDirectory("marshaller", false);
+
+            final MarshallerContextImpl.ContinuousQueryListener queryListener = new MarshallerContextImpl.ContinuousQueryListener(log,
workDir);
+
+            final ArrayList evts = new ArrayList<CacheEntryEvent<Integer, String>>();
+
+            IgniteCacheProxy cache = new IgniteCacheProxy();
+
+            evts.add(new CacheContinuousQueryManager.CacheEntryEventImpl(cache, EventType.CREATED,
1, String.class.getName()));
+
+            for (int i = 0; i < 100; i++)
+                queryListener.onUpdated(evts);
+        }
+    }
+
+    /**
+     * Internal logger
+     */
+    public static class InnerLogger extends GridTestLog4jLogger {
+        /** */
+        private Collection<String> logs = new ConcurrentLinkedDeque<>();
+
+        /**
+         * Returns true if and only if this string contains the specified
+         * sequence of char values.
+         *
+         * @param str String.
+         */
+        public boolean contains(String str) {
+            for (String text : logs)
+                if (text != null && text.contains(str))
+                    return true;
+
+            return false;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void debug(String msg) {
+            logs.add(msg);
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean isDebugEnabled() {
+            return true;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/a0c7c44f/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
index 6611500..d56c29d 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
@@ -33,6 +33,7 @@ import org.apache.ignite.internal.GridSelfTest;
 import org.apache.ignite.internal.GridStartStopSelfTest;
 import org.apache.ignite.internal.GridStopWithCancelSelfTest;
 import org.apache.ignite.internal.IgniteSlowClientDetectionSelfTest;
+import org.apache.ignite.internal.MarshallerContextLockingSelfTest;
 import org.apache.ignite.internal.processors.affinity.GridAffinityProcessorRendezvousSelfTest;
 import org.apache.ignite.internal.processors.cache.GridProjectionForCachesOnDaemonNodeSelfTest;
 import org.apache.ignite.internal.processors.cache.IgniteDaemonNodeMarshallerCacheTest;
@@ -136,6 +137,8 @@ public class IgniteBasicTestSuite extends TestSuite {
         suite.addTestSuite(ConfigVariationsTestSuiteBuilderTest.class);
         suite.addTestSuite(NotStringSystemPropertyTest.class);
 
+        suite.addTestSuite(MarshallerContextLockingSelfTest.class);
+
         return suite;
     }
 }


Mime
View raw message