public class InMemoryCompactionMap extends Object implements PartialCompactionMap
SegmentId instances of the old,
compacted segments.
The data structure used by this class consists of four parts:
recent map of recently compacted entries is maintained
while the compaction is in progress and new entries need to be added.
These entries are periodically compressed into the more
memory-efficient structure described below.
msbs and lsbs arrays store the identifiers
of all old, compacted segments. The identifiers are stored in
increasing order, with the i'th identifier stored in the
msbs[i] and lsbs[i] slots. Interpolation search
is used to quickly locate any given identifier.
entryIndex array is used to to locate these lists within
the larger entry arrays described below. The list of entries for
the i'th identifier consists of entries from entryIndex[i]
(inclusive) to entryIndex[i+1] (exclusive). An extra
sentinel slot is added at the end of the array to make the above
rule work also for the last compacted segment identifier.
beforeOffsets,
afterSegmentIds and afterOffsets arrays. Once the
list of entries for a given compacted segment is found, the
before record offsets are scanned to find a match. If a match is
found, the corresponding compacted record will be identified by the
respective after segment identifier and offset.
Assuming each compacted segment contains n compacted records on
average, the amortized size of each entry in this mapping is about
20/n + 8 bytes, assuming compressed pointers.
| Modifier and Type | Method and Description |
|---|---|
void |
compress()
Compressing this map ensures it takes up as little heap as possible.
|
RecordId |
get(RecordId before)
Retrieve the record id
before maps to or null
if no such id exists. |
long |
getEstimatedWeight()
The weight of the compaction map is its heap memory consumption in bytes.
|
long |
getRecordCount()
Number of records referenced by the keys in this map.
|
long |
getSegmentCount()
Number of segments referenced by the keys in this map.
|
boolean |
isEmpty()
Determine whether this map contains keys at all.
|
void |
put(RecordId before,
RecordId after)
Adds a new entry to the compaction map.
|
void |
remove(Set<UUID> uuids)
Remove all keys from this map where
keys.contains(key.asUUID()). |
boolean |
wasCompacted(UUID id)
Checks whether content in the segment with the given identifier was
compacted to new segments.
|
boolean |
wasCompactedTo(RecordId before,
RecordId after)
Checks whether the record with the given
before identifier was
compacted to a new record with the given after identifier. |
public boolean wasCompactedTo(@Nonnull RecordId before, @Nonnull RecordId after)
PartialCompactionMapbefore identifier was
compacted to a new record with the given after identifier.wasCompactedTo in interface PartialCompactionMapbefore - before record identifierafter - after record identifierbefore was compacted to afterpublic boolean wasCompacted(@Nonnull UUID id)
PartialCompactionMapwasCompacted in interface PartialCompactionMapid - segment identifierpublic RecordId get(@Nonnull RecordId before)
PartialCompactionMapbefore maps to or null
if no such id exists.get in interface PartialCompactionMapbefore - before record idnullpublic void put(@Nonnull RecordId before, @Nonnull RecordId after)
PartialCompactionMapput in interface PartialCompactionMapbefore - before record idafter - after record idpublic void remove(@Nonnull Set<UUID> uuids)
PartialCompactionMapkeys.contains(key.asUUID()).remove in interface PartialCompactionMapuuids - uuids of the keys to removepublic void compress()
PartialCompactionMapcompress in interface PartialCompactionMappublic long getSegmentCount()
PartialCompactionMapgetSegmentCount in interface PartialCompactionMappublic long getRecordCount()
PartialCompactionMapgetRecordCount in interface PartialCompactionMappublic boolean isEmpty()
PartialCompactionMapisEmpty in interface PartialCompactionMaptrue iff this map is emptypublic long getEstimatedWeight()
PartialCompactionMapgetEstimatedWeight in interface PartialCompactionMapCopyright © 2012-2016 The Apache Software Foundation. All Rights Reserved.