@NotThreadSafe public class ExternalSpillableMap<T extends Serializable,R extends Serializable> extends Object implements Map<T,R>, Serializable
This map holds 2 types of data structures :
(1) Key-Value pairs in a in-memory map (2) Key-ValueMetadata pairs in an in-memory map which keeps a marker to the values spilled to disk
NOTE : Values are only appended to disk. If a remove() is called, the entry is marked removed from the in-memory key-valueMetadata map but it's values will be lying around in the temp file on disk until the file is cleaned.
The setting of the spill threshold faces the following trade-off: If the spill threshold is too high, the in-memory map may occupy more memory than is available, resulting in OOM. However, if the spill threshold is too low, we spill frequently and incur unnecessary disk writes.
| Modifier and Type | Class and Description |
|---|---|
static class |
ExternalSpillableMap.DiskMapType
The type of map to use for storing the Key, values on disk after it spills
from memory in the
ExternalSpillableMap. |
| Constructor and Description |
|---|
ExternalSpillableMap(Long maxInMemorySizeInBytes,
String baseFilePath,
SizeEstimator<T> keySizeEstimator,
SizeEstimator<R> valueSizeEstimator) |
ExternalSpillableMap(Long maxInMemorySizeInBytes,
String baseFilePath,
SizeEstimator<T> keySizeEstimator,
SizeEstimator<R> valueSizeEstimator,
ExternalSpillableMap.DiskMapType diskMapType) |
ExternalSpillableMap(Long maxInMemorySizeInBytes,
String baseFilePath,
SizeEstimator<T> keySizeEstimator,
SizeEstimator<R> valueSizeEstimator,
ExternalSpillableMap.DiskMapType diskMapType,
boolean isCompressionEnabled) |
| Modifier and Type | Method and Description |
|---|---|
void |
clear() |
void |
close() |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
Set<Map.Entry<T,R>> |
entrySet() |
R |
get(Object key) |
long |
getCurrentInMemoryMapSize()
Approximate memory footprint of the in-memory map.
|
int |
getDiskBasedMapNumEntries()
Number of entries in BitCaskDiskMap.
|
int |
getInMemoryMapNumEntries()
Number of entries in InMemoryMap.
|
long |
getSizeOfFileOnDiskInBytes()
Number of bytes spilled to disk.
|
boolean |
inDiskContainsKey(Object key) |
boolean |
inMemoryContainsKey(Object key) |
boolean |
isEmpty() |
Iterator<R> |
iterator()
A custom iterator to wrap over iterating in-memory + disk spilled data.
|
Set<T> |
keySet() |
R |
put(T key,
R value) |
void |
putAll(Map<? extends T,? extends R> m) |
R |
remove(Object key) |
int |
size() |
Collection<R> |
values() |
Stream<R> |
valueStream() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcompute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAllpublic ExternalSpillableMap(Long maxInMemorySizeInBytes, String baseFilePath, SizeEstimator<T> keySizeEstimator, SizeEstimator<R> valueSizeEstimator) throws IOException
IOExceptionpublic ExternalSpillableMap(Long maxInMemorySizeInBytes, String baseFilePath, SizeEstimator<T> keySizeEstimator, SizeEstimator<R> valueSizeEstimator, ExternalSpillableMap.DiskMapType diskMapType) throws IOException
IOExceptionpublic ExternalSpillableMap(Long maxInMemorySizeInBytes, String baseFilePath, SizeEstimator<T> keySizeEstimator, SizeEstimator<R> valueSizeEstimator, ExternalSpillableMap.DiskMapType diskMapType, boolean isCompressionEnabled) throws IOException
IOExceptionpublic Iterator<R> iterator()
public int getDiskBasedMapNumEntries()
public long getSizeOfFileOnDiskInBytes()
public int getInMemoryMapNumEntries()
public long getCurrentInMemoryMapSize()
public int size()
size in interface Map<T extends Serializable,R extends Serializable>public boolean isEmpty()
isEmpty in interface Map<T extends Serializable,R extends Serializable>public boolean containsKey(Object key)
containsKey in interface Map<T extends Serializable,R extends Serializable>public boolean containsValue(Object value)
containsValue in interface Map<T extends Serializable,R extends Serializable>public boolean inMemoryContainsKey(Object key)
public boolean inDiskContainsKey(Object key)
public R get(Object key)
get in interface Map<T extends Serializable,R extends Serializable>public R put(T key, R value)
put in interface Map<T extends Serializable,R extends Serializable>public R remove(Object key)
remove in interface Map<T extends Serializable,R extends Serializable>public void putAll(Map<? extends T,? extends R> m)
putAll in interface Map<T extends Serializable,R extends Serializable>public void clear()
clear in interface Map<T extends Serializable,R extends Serializable>public void close()
public Set<T> keySet()
keySet in interface Map<T extends Serializable,R extends Serializable>public Collection<R> values()
values in interface Map<T extends Serializable,R extends Serializable>public Set<Map.Entry<T,R>> entrySet()
entrySet in interface Map<T extends Serializable,R extends Serializable>Copyright © 2024 The Apache Software Foundation. All rights reserved.