mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Align persisted Chronicle Map creation with Size Prefixed Blob and Self-Bootstrapping Header specifications
This commit is contained in:
@@ -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;
|
||||
|
||||
public final class SizePrefixedBlob {
|
||||
|
||||
public static final int HEADER_OFFSET = 0;
|
||||
public static final int SIZE_WORD_OFFSET = 8;
|
||||
public static final int SELF_BOOTSTRAPPING_HEADER_OFFSET = 12;
|
||||
|
||||
public static final int READY = 0;
|
||||
public static final int NOT_READY = 0x80000000;
|
||||
|
||||
public static final int DATA = 0;
|
||||
public static final int META_DATA = 0x40000000;
|
||||
|
||||
public static final int SIZE_MASK = (1 << 30) - 1;
|
||||
|
||||
public static boolean isReady(int sizeWord) {
|
||||
return sizeWord > 0;
|
||||
}
|
||||
|
||||
public static int extractSize(int sizeWord) {
|
||||
return sizeWord & SIZE_MASK;
|
||||
}
|
||||
|
||||
private SizePrefixedBlob() {}
|
||||
}
|
||||
@@ -378,9 +378,9 @@ public abstract class VanillaChronicleHash<K,
|
||||
}
|
||||
}
|
||||
|
||||
public final void initBeforeMapping(File file, FileChannel ch, long headerSize)
|
||||
public final void initBeforeMapping(File file, FileChannel ch, long headerEnd)
|
||||
throws IOException {
|
||||
this.headerSize = roundUpMapHeaderSize(headerSize);
|
||||
this.headerSize = roundUpMapHeaderSize(headerEnd);
|
||||
if (!createdOrInMemory) {
|
||||
// This block is for reading segmentHeadersOffset before main mapping
|
||||
// After the mapping globalMutableState value's bytes are reassigned
|
||||
@@ -774,6 +774,10 @@ public abstract class VanillaChronicleHash<K,
|
||||
globalMutableState.setFirstFreeTierIndex(firstTierIndex);
|
||||
}
|
||||
|
||||
public void msync(RandomAccessFile raf) throws IOException {
|
||||
msync(raf, bsAddress(), bs.capacity());
|
||||
}
|
||||
|
||||
private static void msync(RandomAccessFile raf, long address, long length) throws IOException {
|
||||
// address should be a multiple of page size
|
||||
if (OS.pageAlign(address) != address) {
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
|
||||
public final class FileIOUtils {
|
||||
|
||||
private FileIOUtils() {}
|
||||
|
||||
public static void readFully(FileChannel fileChannel, long filePosition, ByteBuffer buffer)
|
||||
throws IOException {
|
||||
int startBufferPosition = buffer.position();
|
||||
while (buffer.remaining() > 0 &&
|
||||
buffer.position() < fileChannel.size()) {
|
||||
int bytesRead = fileChannel.read(buffer,
|
||||
filePosition + buffer.position() - startBufferPosition);
|
||||
if (bytesRead == -1)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeFully(FileChannel fileChannel, long filePosition, ByteBuffer buffer)
|
||||
throws IOException {
|
||||
int startBufferPosition = buffer.position();
|
||||
while (buffer.remaining() > 0) {
|
||||
fileChannel.write(buffer, filePosition + buffer.position() - startBufferPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user