Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 089B61748D for ; Tue, 7 Apr 2015 11:53:53 +0000 (UTC) Received: (qmail 2277 invoked by uid 500); 7 Apr 2015 11:53:50 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 2248 invoked by uid 500); 7 Apr 2015 11:53:49 -0000 Mailing-List: contact commits-help@ignite.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.incubator.apache.org Delivered-To: mailing list commits@ignite.incubator.apache.org Received: (qmail 2237 invoked by uid 99); 7 Apr 2015 11:53:49 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Apr 2015 11:53:49 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Tue, 07 Apr 2015 11:53:27 +0000 Received: (qmail 73660 invoked by uid 99); 7 Apr 2015 11:43:00 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Apr 2015 11:43:00 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 48626E2F24; Tue, 7 Apr 2015 11:42:59 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sboikov@apache.org To: commits@ignite.incubator.apache.org Date: Tue, 07 Apr 2015 11:43:13 -0000 Message-Id: <25c0e195ae7843138a0bfff4aae6f689@git.apache.org> In-Reply-To: <0998388a0a464889b9fbf101e576cae4@git.apache.org> References: <0998388a0a464889b9fbf101e576cae4@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [15/16] incubator-ignite git commit: # IGNITE-679: Applied patch from Ivan V. X-Virus-Checked: Checked by ClamAV on apache.org # IGNITE-679: Applied patch from Ivan V. Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/bed567f9 Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/bed567f9 Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/bed567f9 Branch: refs/heads/ignite-665 Commit: bed567f9e468b2aa6b752475cc2936cb6c0dc6a3 Parents: f0bcbc9 Author: vozerov-gridgain Authored: Tue Apr 7 14:37:36 2015 +0300 Committer: vozerov-gridgain Committed: Tue Apr 7 14:37:36 2015 +0300 ---------------------------------------------------------------------- .../ipc/shmem/IpcSharedMemoryNativeLoader.java | 48 ++++++++++++++------ 1 file changed, 35 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/bed567f9/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryNativeLoader.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryNativeLoader.java b/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryNativeLoader.java index ef9f46a..dc00ca6 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryNativeLoader.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryNativeLoader.java @@ -33,18 +33,15 @@ import static org.apache.ignite.internal.IgniteVersionUtils.*; */ @SuppressWarnings("ErrorNotRethrown") public class IpcSharedMemoryNativeLoader { - /** Loaded flag. */ - private static volatile boolean loaded; - /** Library name base. */ private static final String LIB_NAME_BASE = "igniteshmem"; - /** Lock file path. */ - private static final File LOCK_FILE = new File(System.getProperty("java.io.tmpdir"), "igniteshmem.lock"); - /** Library name. */ static final String LIB_NAME = LIB_NAME_BASE + "-" + VER_STR; + /** Loaded flag. */ + private static volatile boolean loaded; + /** * @return Operating system name to resolve path to library. */ @@ -121,16 +118,20 @@ public class IpcSharedMemoryNativeLoader { errs.add(e); } + File tmpDir = getUserSpecificTempDir(); + + File lockFile = new File(tmpDir, "igniteshmem.lock"); + // Obtain lock on file to prevent concurrent extracts. - try (RandomAccessFile randomAccessFile = new RandomAccessFile(LOCK_FILE, "rws"); + try (RandomAccessFile randomAccessFile = new RandomAccessFile(lockFile, "rws"); FileLock ignored = randomAccessFile.getChannel().lock()) { - if (extractAndLoad(errs, platformSpecificResourcePath())) + if (extractAndLoad(errs, tmpDir, platformSpecificResourcePath())) return; - if (extractAndLoad(errs, osSpecificResourcePath())) + if (extractAndLoad(errs, tmpDir, osSpecificResourcePath())) return; - if (extractAndLoad(errs, resourcePath())) + if (extractAndLoad(errs, tmpDir, resourcePath())) return; // Failed to find the library. @@ -139,11 +140,32 @@ public class IpcSharedMemoryNativeLoader { throw new IgniteCheckedException("Failed to load native IPC library: " + errs); } catch (IOException e) { - throw new IgniteCheckedException("Failed to obtain file lock: " + LOCK_FILE, e); + throw new IgniteCheckedException("Failed to obtain file lock: " + lockFile, e); } } /** + * Gets temporary directory unique for each OS user. + * The directory guaranteed to exist, though may not be empty. + */ + private static File getUserSpecificTempDir() throws IgniteCheckedException { + String tmp = System.getProperty("java.io.tmpdir"); + + String userName = System.getProperty("user.name"); + + File tmpDir = new File(tmp, userName); + + if (!tmpDir.exists()) + //noinspection ResultOfMethodCallIgnored + tmpDir.mkdirs(); + + if (!(tmpDir.exists() && tmpDir.isDirectory())) + throw new IgniteCheckedException("Failed to create temporary directory [dir=" + tmpDir + ']'); + + return tmpDir; + } + + /** * @return OS resource path. */ private static String osSpecificResourcePath() { @@ -181,13 +203,13 @@ public class IpcSharedMemoryNativeLoader { * @param rsrcPath Path. * @return {@code True} if library was found and loaded. */ - private static boolean extractAndLoad(Collection errs, String rsrcPath) { + private static boolean extractAndLoad(Collection errs, File tmpDir, String rsrcPath) { ClassLoader clsLdr = U.detectClassLoader(IpcSharedMemoryNativeLoader.class); URL rsrc = clsLdr.getResource(rsrcPath); if (rsrc != null) - return extract(errs, rsrc, new File(System.getProperty("java.io.tmpdir"), mapLibraryName(LIB_NAME))); + return extract(errs, rsrc, new File(tmpDir, mapLibraryName(LIB_NAME))); else { errs.add(new IllegalStateException("Failed to find resource with specified class loader " + "[rsrc=" + rsrcPath + ", clsLdr=" + clsLdr + ']'));