mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
introduced NativeBytesI to allow us to checks if the buffer has been closed, if the buffer is accessed after it is closed an exception is thrown, This class should be used to investigate JVM crashes, it should not be used in production code ( as its slow )
This commit is contained in:
@@ -21,7 +21,7 @@ package net.openhft.chronicle.map;
|
||||
import net.openhft.lang.Maths;
|
||||
import net.openhft.lang.collection.ATSDirectBitSet;
|
||||
import net.openhft.lang.io.DirectStore;
|
||||
import net.openhft.lang.io.NativeBytes;
|
||||
import net.openhft.lang.io.NativeBytesI;
|
||||
|
||||
import static net.openhft.lang.Maths.isPowerOf2;
|
||||
import static net.openhft.lang.MemoryUnit.*;
|
||||
@@ -39,7 +39,7 @@ enum MultiMapFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiMap create(NativeBytes bytes, NativeBytes bitSetBytes) {
|
||||
public MultiMap create(NativeBytesI bytes, NativeBytesI bitSetBytes) {
|
||||
return new ShortShortMultiMap(bytes, bitSetBytes);
|
||||
}
|
||||
},
|
||||
@@ -50,7 +50,7 @@ enum MultiMapFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiMap create(NativeBytes bytes, NativeBytes bitSetBytes) {
|
||||
public MultiMap create(NativeBytesI bytes, NativeBytesI bitSetBytes) {
|
||||
return new Int24Int24MultiMap(bytes, bitSetBytes);
|
||||
}
|
||||
},
|
||||
@@ -61,7 +61,7 @@ enum MultiMapFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiMap create(NativeBytes bytes, NativeBytes bitSetBytes) {
|
||||
public MultiMap create(NativeBytesI bytes, NativeBytesI bitSetBytes) {
|
||||
return new IntIntMultiMap(bytes, bitSetBytes);
|
||||
}
|
||||
};
|
||||
@@ -104,5 +104,5 @@ enum MultiMapFactory {
|
||||
|
||||
public abstract long sizeInBytes(long minCapacity);
|
||||
|
||||
public abstract MultiMap create(NativeBytes bytes, NativeBytes bitSetBytes);
|
||||
public abstract MultiMap create(NativeBytesI bytes, NativeBytesI bitSetBytes);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import net.openhft.lang.Maths;
|
||||
import net.openhft.lang.collection.ATSDirectBitSet;
|
||||
import net.openhft.lang.io.Bytes;
|
||||
import net.openhft.lang.io.MultiStoreBytes;
|
||||
import net.openhft.lang.io.NativeBytes;
|
||||
import net.openhft.lang.io.NativeBytesI;
|
||||
import net.openhft.lang.threadlocal.ThreadLocalCopies;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -126,7 +126,7 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
|
||||
|
||||
@Override
|
||||
VanillaChronicleMap<K, KI, MKI, V, VI, MVI>.Segment createSegment(
|
||||
NativeBytes segmentHeader, NativeBytes bytes, int index) {
|
||||
NativeBytesI segmentHeader, NativeBytesI bytes, int index) {
|
||||
return new Segment(segmentHeader, bytes, index);
|
||||
}
|
||||
|
||||
@@ -678,7 +678,7 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
|
||||
|
||||
class Segment extends VanillaChronicleMap<K, KI, MKI, V, VI, MVI>.Segment {
|
||||
|
||||
Segment(NativeBytes segmentHeader, NativeBytes bytes, int index) {
|
||||
Segment(NativeBytesI segmentHeader, NativeBytesI bytes, int index) {
|
||||
super(segmentHeader, bytes, index);
|
||||
}
|
||||
|
||||
@@ -993,7 +993,7 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
|
||||
* @param identifier the unique identifier relating to this map
|
||||
* @return true if the entry should not be processed
|
||||
*/
|
||||
private boolean shouldIgnore(@NotNull final NativeBytes entry, final long timestamp,
|
||||
private boolean shouldIgnore(@NotNull final NativeBytesI entry, final long timestamp,
|
||||
final byte identifier) {
|
||||
final long lastModifiedTimeStamp = entry.readLong();
|
||||
|
||||
@@ -1262,7 +1262,7 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
|
||||
hashLookup().forEach(new MultiMap.EntryConsumer() {
|
||||
@Override
|
||||
public void accept(long hash, long pos) {
|
||||
final NativeBytes entry = reuse(tmpBytes, offsetFromPos(pos));
|
||||
final NativeBytesI entry = reuse(tmpBytes, offsetFromPos(pos));
|
||||
long keySize = keySizeMarshaller.readSize(entry);
|
||||
entry.skip(keySize);
|
||||
|
||||
@@ -1335,7 +1335,7 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
|
||||
Segment segment = (Segment) seg;
|
||||
|
||||
final long offset = segment.offsetFromPos(pos);
|
||||
final NativeBytes entry = segment.reuse(this.entry, offset);
|
||||
final NativeBytesI entry = segment.reuse(this.entry, offset);
|
||||
|
||||
final long keySize = keySizeMarshaller.readSize(entry);
|
||||
long keyPosition = entry.position();
|
||||
@@ -1490,7 +1490,7 @@ final class ReplicatedChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? supe
|
||||
entryCallback.onBeforeEntry();
|
||||
|
||||
final long segmentPos = position & posMask;
|
||||
final NativeBytes entry =
|
||||
final NativeBytesI entry =
|
||||
segment.reuse(tmpBytes, segment.offsetFromPos(segmentPos));
|
||||
|
||||
// if the entry should be ignored, we'll move the next entry
|
||||
|
||||
@@ -230,7 +230,9 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
}
|
||||
|
||||
final long createMappedStoreAndSegments(BytesStore bytesStore) throws IOException {
|
||||
this.ms = bytesStore;
|
||||
// checks the the store has not been closed
|
||||
// todo remove the CheckedBytesStore before the release
|
||||
this.ms = new CheckedBytesStore(bytesStore);
|
||||
|
||||
onHeaderCreated();
|
||||
|
||||
@@ -242,9 +244,9 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
long segmentSize = segmentSize();
|
||||
long headerOffset = 0;
|
||||
for (int i = 0; i < this.segments.length; i++) {
|
||||
NativeBytes segmentHeader =
|
||||
(NativeBytes) segmentHeaders.bytes(headerOffset, segmentHeaderSize);
|
||||
NativeBytes segmentData = (NativeBytes) ms.bytes(offset, segmentSize);
|
||||
NativeBytesI segmentHeader =
|
||||
(NativeBytesI) segmentHeaders.bytes(headerOffset, segmentHeaderSize);
|
||||
NativeBytesI segmentData = (NativeBytesI) ms.bytes(offset, segmentSize);
|
||||
this.segments[i] = createSegment(segmentHeader, segmentData, i);
|
||||
headerOffset += segmentHeaderSize;
|
||||
offset += segmentSize;
|
||||
@@ -306,7 +308,7 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
return segmentHeaderSize;
|
||||
}
|
||||
|
||||
Segment createSegment(NativeBytes segmentHeader, NativeBytes bytes, int index) {
|
||||
Segment createSegment(NativeBytesI segmentHeader, NativeBytesI bytes, int index) {
|
||||
return new Segment(segmentHeader, bytes, index);
|
||||
}
|
||||
|
||||
@@ -1411,8 +1413,8 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
*/
|
||||
static final long LOCK_OFFSET = 0L; // 64-bit
|
||||
static final long SIZE_OFFSET = LOCK_OFFSET + 8L; // 32-bit
|
||||
final NativeBytes segmentHeader;
|
||||
final NativeBytes bytes;
|
||||
final NativeBytesI segmentHeader;
|
||||
final NativeBytesI bytes;
|
||||
final long entriesOffset;
|
||||
private final int index;
|
||||
private final SingleThreadedDirectBitSet freeList;
|
||||
@@ -1426,7 +1428,7 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
/**
|
||||
* @param index the index of this segment held by the map
|
||||
*/
|
||||
Segment(NativeBytes segmentHeader, NativeBytes bytes, int index) {
|
||||
Segment(NativeBytesI segmentHeader, NativeBytesI bytes, int index) {
|
||||
this.segmentHeader = segmentHeader;
|
||||
this.bytes = bytes;
|
||||
this.index = index;
|
||||
@@ -1435,7 +1437,7 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
hashLookup = createMultiMap(start);
|
||||
start += CACHE_LINES.align(sizeOfMultiMap() + sizeOfMultiMapBitSet(), BYTES)
|
||||
* multiMapsPerSegment();
|
||||
final NativeBytes bsBytes = new NativeBytes(ms.objectSerializer(),
|
||||
final NativeBytesI bsBytes = new NativeBytes(ms.objectSerializer(),
|
||||
start,
|
||||
start + MultiMapFactory.sizeOfBitSetInBytes(actualChunksPerSegment),
|
||||
null);
|
||||
@@ -1453,11 +1455,11 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
}
|
||||
|
||||
private MultiMap createMultiMap(long start) {
|
||||
final NativeBytes multiMapBytes =
|
||||
final NativeBytesI multiMapBytes =
|
||||
new NativeBytes((ObjectSerializer) null, start,
|
||||
start = start + sizeOfMultiMap(), null);
|
||||
|
||||
final NativeBytes sizeOfMultiMapBitSetBytes =
|
||||
final NativeBytesI sizeOfMultiMapBitSetBytes =
|
||||
new NativeBytes((ObjectSerializer) null, start,
|
||||
start + sizeOfMultiMapBitSet(), null);
|
||||
// multiMapBytes.load();
|
||||
@@ -2574,7 +2576,7 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
// of returnedEntry.getKey(), but it seems rather wasteful to workaround so rare
|
||||
// case.
|
||||
final long offset = segment.offsetFromPos(pos);
|
||||
final NativeBytes entry = segment.reuse(this.entry, offset);
|
||||
final NativeBytesI entry = segment.reuse(this.entry, offset);
|
||||
|
||||
final long keySize = keySizeMarshaller.readSize(entry);
|
||||
long position = entry.position();
|
||||
@@ -2583,7 +2585,7 @@ class VanillaChronicleMap<K, KI, MKI extends MetaBytesInterop<K, ? super KI>,
|
||||
removePresent(segment, pos, entry, keySize, segmentHash, true);
|
||||
}
|
||||
|
||||
final void removePresent(Segment segment, long pos, NativeBytes entry, long keySize,
|
||||
final void removePresent(Segment segment, long pos, NativeBytesI entry, long keySize,
|
||||
long segmentHash, boolean removeFromMultiMap) {
|
||||
entry.skip(keySize);
|
||||
segment.manageReplicationBytes(entry, true, true);
|
||||
|
||||
Reference in New Issue
Block a user