Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HCOLL-397 msync before pointing to newly created tier bulk in the header
- Loading branch information
Showing
4 changed files
with
170 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/java/net/openhft/chronicle/hash/impl/PosixMsync.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (C) 2015 higherfrequencytrading.com | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package net.openhft.chronicle.hash.impl; | ||
|
||
import com.sun.jna.Native; | ||
import com.sun.jna.Platform; | ||
|
||
import java.io.IOException; | ||
|
||
final class PosixMsync { | ||
|
||
private static final int MS_SYNC = 4; | ||
|
||
public static void msync(long addr, long length) throws IOException { | ||
if (msync(addr, length, MS_SYNC) == -1) | ||
throw new IOException(strerror_r(Native.getLastError(), null, 0)); | ||
} | ||
|
||
private static native String strerror_r(int errnum, char[] buf, int buflen); | ||
|
||
private static native int msync(long addr, long length, int flags); | ||
|
||
static { | ||
Native.register(PosixMsync.class, Platform.C_LIBRARY_NAME); | ||
} | ||
|
||
private PosixMsync() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/java/net/openhft/chronicle/hash/impl/WindowsMsync.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (C) 2015 higherfrequencytrading.com | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package net.openhft.chronicle.hash.impl; | ||
|
||
import com.sun.jna.Native; | ||
import com.sun.jna.platform.win32.Kernel32Util; | ||
|
||
import java.io.IOException; | ||
import java.io.RandomAccessFile; | ||
|
||
import static com.sun.jna.platform.win32.WinError.ERROR_LOCK_VIOLATION; | ||
|
||
final class WindowsMsync { | ||
|
||
public static void msync(RandomAccessFile raf, long addr, long length) | ||
throws IOException { | ||
int retry = 0; | ||
boolean success; | ||
int lastError = 0; | ||
// FlushViewOfFile can fail with ERROR_LOCK_VIOLATION if the memory system is writing dirty | ||
// pages to disk. As there is no way to synchronize the flushing then we retry a limited | ||
// number of times. | ||
do { | ||
if ((success = FlushViewOfFile(addr, length)) || | ||
(lastError = GetLastError()) != ERROR_LOCK_VIOLATION) | ||
break; | ||
retry++; | ||
} while (retry < 3); | ||
|
||
if (success) { | ||
// Finally calls FlushFileBuffers | ||
raf.getChannel().force(false); | ||
} else { | ||
throw new IOException(Kernel32Util.formatMessage(lastError)); | ||
} | ||
} | ||
|
||
private static native boolean FlushViewOfFile(long addr, long length); | ||
|
||
private static native int GetLastError(); | ||
|
||
static { | ||
Native.register(WindowsMsync.class, "kernel32"); | ||
} | ||
|
||
private WindowsMsync() {} | ||
} |