ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ptupit...@apache.org
Subject ignite git commit: IGNITE-5730 .NET: Fix ignite.jni.dll temp dir race
Date Wed, 27 Sep 2017 11:57:55 GMT
Repository: ignite
Updated Branches:
  refs/heads/master 690694cad -> fca47345f


IGNITE-5730 .NET: Fix ignite.jni.dll temp dir race

This closes #2755


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

Branch: refs/heads/master
Commit: fca47345fae7adf80a1d40cc6c4c711924df2de2
Parents: 690694c
Author: Pavel Tupitsyn <ptupitsyn@apache.org>
Authored: Wed Sep 27 14:57:47 2017 +0300
Committer: Pavel Tupitsyn <ptupitsyn@apache.org>
Committed: Wed Sep 27 14:57:47 2017 +0300

----------------------------------------------------------------------
 .../Apache.Ignite.Core/Impl/IgniteUtils.cs      | 30 ++++++++++----------
 .../Impl/Unmanaged/UnmanagedUtils.cs            |  4 +++
 2 files changed, 19 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/fca47345/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteUtils.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteUtils.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteUtils.cs
index f3bdd2b..d55960a 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteUtils.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/IgniteUtils.cs
@@ -82,16 +82,6 @@ namespace Apache.Ignite.Core.Impl
         private static Random _rnd;
 
         /// <summary>
-        /// Initializes the <see cref="IgniteUtils"/> class.
-        /// </summary>
-        [SuppressMessage("Microsoft.Performance", "CA1810:InitializeReferenceTypeStaticFieldsInline",
-            Justification = "Readability.")]
-        static IgniteUtils()
-        {
-            TryCleanTempDirectories();
-        }
-
-        /// <summary>
         /// Gets thread local random.
         /// </summary>
         /// <value>Thread local random.</value>
@@ -388,10 +378,20 @@ namespace Apache.Ignite.Core.Impl
         /// <summary>
         /// Tries to clean temporary directories created with <see cref="GetTempDirectoryName"/>.
         /// </summary>
-        private static void TryCleanTempDirectories()
+        internal static void TryCleanTempDirectories()
         {
-            foreach (var dir in Directory.GetDirectories(Path.GetTempPath(), DirIgniteTmp
+ "*"))
+            var dt = DateTime.Now;
+
+            foreach (var dir in Directory.EnumerateDirectories(Path.GetTempPath(), DirIgniteTmp
+ "*"))
             {
+                if ((dt - Directory.GetCreationTime(dir)).TotalMinutes < 1)
+                {
+                    // Do not clean up recently created temp directories:
+                    // they may be used by currently starting up nodes.
+                    // This is a workaround for multiple node startup problem, see IGNITE-5730.
+                    continue;
+                }
+
                 try
                 {
                     Directory.Delete(dir, true);
@@ -413,13 +413,13 @@ namespace Apache.Ignite.Core.Impl
         /// <returns>The full path of the temporary directory.</returns>
         internal static string GetTempDirectoryName()
         {
+            var baseDir = Path.Combine(Path.GetTempPath(), DirIgniteTmp);
+
             while (true)
             {
-                var dir = Path.Combine(Path.GetTempPath(), DirIgniteTmp + Path.GetRandomFileName());
-
                 try
                 {
-                    return Directory.CreateDirectory(dir).FullName;
+                    return Directory.CreateDirectory(baseDir + Path.GetRandomFileName()).FullName;
                 }
                 catch (IOException)
                 {

http://git-wip-us.apache.org/repos/asf/ignite/blob/fca47345/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedUtils.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedUtils.cs
b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedUtils.cs
index b6e6582..511bb7a 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedUtils.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Unmanaged/UnmanagedUtils.cs
@@ -21,6 +21,7 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
     using System.Diagnostics;
     using System.Diagnostics.CodeAnalysis;
     using System.Runtime.InteropServices;
+    using System.Threading.Tasks;
     using Apache.Ignite.Core.Common;
     using JNI = IgniteJniNativeMethods;
 
@@ -57,6 +58,9 @@ namespace Apache.Ignite.Core.Impl.Unmanaged
             AppDomain.CurrentDomain.DomainUnload += CurrentDomain_DomainUnload;
 
             JNI.SetConsoleHandler(UnmanagedCallbacks.ConsoleWriteHandler);
+
+            // Clean directories in background to avoid extra work on start.
+            Task.Factory.StartNew(IgniteUtils.TryCleanTempDirectories);
         }
 
         /// <summary>


Mime
View raw message