Skip to content
This repository has been archived by the owner on Mar 3, 2024. It is now read-only.

Commit

Permalink
stage-6: add javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
vitekkor committed Dec 31, 2023
1 parent 8763657 commit a4e6dd9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;

/**
* Base class for implementing the sstable reader.
*
* @author vitekkor
* @see BaseSSTableReader
* @see CompressedSSTableReader
*/
public abstract class AbstractSSTableReader {
protected final MemorySegment mappedSSTable;
protected final MemorySegment mappedIndexFile;
Expand All @@ -26,6 +33,12 @@ protected AbstractSSTableReader(
this.index = index;
}

/**
* Returns entry by key.
* @param key entry`s key
* @return entry
* @throws IOException if an I/O error occurs.
*/
public Entry<MemorySegment> get(MemorySegment key) throws IOException {
try {
long entryOffset = getEntryOffset(key, SearchOption.EQ);
Expand All @@ -38,12 +51,38 @@ public Entry<MemorySegment> get(MemorySegment key) throws IOException {
}
}

/**
* Returns ordered iterator of entries with keys between from (inclusive) and to (exclusive).
* @param from lower bound of range (inclusive)
* @param to upper bound of range (exclusive)
* @return entries [from;to)
* @throws IOException if an I/O error occurs.
*/
public abstract LSMPointerIterator iterator(MemorySegment from, MemorySegment to) throws IOException;

/**
* Returns entry by index.
* @param index entry`s index from index file.
* @return entry
* @throws IOException if an I/O error occurs.
*/
protected abstract Entry<MemorySegment> getByIndex(long index) throws IOException;

/**
* Returns entry's index by key.
* @param key entry`s key
* @param searchOption Entity search parameter. {@link SearchOption#EQ} find equal by key,
* {@link SearchOption#GTE} find greater than or equal to,
* {@link SearchOption#LT} strictly less than
* @return offset (index)
* @throws IOException if an I/O error occurs.
*/
protected abstract long getEntryOffset(MemorySegment key, SearchOption searchOption) throws IOException;

/**
* SSTable has no tombstones.
* @return false if sstable has tombstones.
*/
public boolean hasNoTombstones() {
return mappedIndexFile.get(ValueLayout.JAVA_BOOLEAN, 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
import java.lang.foreign.ValueLayout;
import java.util.NoSuchElementException;

/**
* SSTable reader without compression.
*
* @author vitekkor
*/
public class BaseSSTableReader extends AbstractSSTableReader {
private static final long METADATA_SIZE = Long.BYTES + 1L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import ru.vk.itmo.viktorkorotkikh.LSMPointerIterator;
import ru.vk.itmo.viktorkorotkikh.MemorySegmentComparator;
import ru.vk.itmo.viktorkorotkikh.Utils;
import ru.vk.itmo.viktorkorotkikh.compressor.Compressor;
import ru.vk.itmo.viktorkorotkikh.decompressor.Decompressor;
import ru.vk.itmo.viktorkorotkikh.decompressor.LZ4Decompressor;
import ru.vk.itmo.viktorkorotkikh.decompressor.ZstdDecompressor;
Expand All @@ -19,6 +20,10 @@
import java.util.NoSuchElementException;

/**
* SSTable reader implementation with compression.
* Implementations of the {@link Decompressor} interface are used for decompression.
* <br/>
* <br/>
* <B>compression info</B>:
* isCompressed|algorithm|blocksCount|uncompressedBlockSize|block1Offset|block2Offset|blockNOffset
* <p/>
Expand Down

0 comments on commit a4e6dd9

Please # to comment.