public class BulkLoader<K,V>
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
(package private) static class |
BulkLoader.LevelEnum |
private static class |
BulkLoader.SortedFile
A private class used to store the temporary sorted file.
|
| Modifier | Constructor and Description |
|---|---|
private |
BulkLoader() |
| Modifier and Type | Method and Description |
|---|---|
private static <K,V> BTree<K,V> |
bulkLoad(BTree<K,V> btree,
java.util.Iterator<Tuple<K,java.util.Set<V>>> dataIterator,
int nbElems)
Construct the target BTree from the sorted data.
|
private static <K,V> BTree<K,V> |
bulkLoadSinglePage(BTree<K,V> btree,
java.util.Iterator<Tuple<K,java.util.Set<V>>> dataIterator,
int nbElems) |
static BTree<?,?> |
compact(BTree<?,?> btree)
Compact a given in-memory BTree, making it dense.
|
static void |
compact(RecordManager recordManager,
BTree<?,?> btree)
Compact a given persisted BTree, making it dense.
|
(package private) static <K,V> LevelInfo<K,V> |
computeLevel(BTree<K,V> btree,
int nbElems,
BulkLoader.LevelEnum levelType)
Creates a node leaf LevelInfo based on the number of elements in the lower level.
|
(package private) static <K,V> java.util.List<LevelInfo<K,V>> |
computeLevels(BTree<K,V> btree,
int nbElems)
Compute the number of pages necessary to store all the elements per level.
|
private static <K,V> int |
computeNbElemsLeaf(BTree<K,V> btree,
LevelInfo<K,V> levelInfo) |
(package private) int |
computeNbElemsNode(BTree<K,V> btree,
LevelInfo<K,V> levelInfo)
Compute the number of nodes necessary to store all the elements.
|
private static <K,V> java.util.Iterator<Tuple<K,java.util.Set<V>>> |
createIterator(BTree<K,V> btree,
java.io.FileInputStream[] streams)
Build an iterator over an array of sorted tuples, from files on the disk
|
private static <K,V> java.util.Iterator<Tuple<K,java.util.Set<V>>> |
createTupleIterator(BTree<K,V> btree,
java.util.List<Tuple<K,V>> tuples)
Build an iterator over an array of sorted tuples, in memory
|
private static <K,V> java.util.Iterator<Tuple<K,java.util.Set<V>>> |
createUniqueFileIterator(BTree<K,V> btree,
java.io.FileInputStream stream)
Build an iterator over an array of sorted tuples, from files on the disk
|
private static <K,V> Tuple<K,java.util.Set<V>> |
fetchTuple(BTree<K,V> btree,
java.io.FileInputStream fis) |
private static <K,V> java.io.File |
flushToDisk(int fileNb,
java.util.List<Tuple<K,V>> tuples,
BTree<K,V> btree)
Flush a list of tuples to disk after having sorted them.
|
private static <K,V> void |
injectInLeaf(BTree<K,V> btree,
Tuple<K,java.util.Set<V>> tuple,
LevelInfo<K,V> leafLevel)
Inject a tuple into a leaf
|
private static <K,V> void |
injectInNode(BTree<K,V> btree,
Page<K,V> page,
java.util.List<LevelInfo<K,V>> levels,
int levelIndex)
Inject a page reference into a Node.
|
private static <K,V> void |
injectInRoot(BTree<K,V> btree,
Page<K,V> page,
PageHolder<K,V> pageHolder,
LevelInfo<K,V> level)
Inject a page reference into the root page.
|
static <K,V> BTree<K,V> |
load(BTree<K,V> btree,
java.util.Iterator<Tuple<K,V>> iterator,
int chunkSize)
Bulk Load data into a persisted BTree
|
private static <K,V> Tuple<java.util.Iterator<Tuple<K,java.util.Set<V>>>,BulkLoader.SortedFile> |
processFiles(BTree<K,V> btree,
java.util.Iterator<Tuple<K,java.util.Set<V>>> dataIterator)
Read all the sorted files, and inject them into one single big file containing all the
sorted and merged elements.
|
private static <K,V> int |
readElements(BTree<K,V> btree,
java.util.Iterator<Tuple<K,V>> iterator,
java.util.List<java.io.File> sortedFiles,
java.util.List<Tuple<K,V>> tuples,
int chunkSize)
Process the data, and creates files to store them sorted if necessary, or store them
TODO readElements.
|
private static <K,V> Tuple<K,java.util.Set<V>>[] |
sort(BTree<K,V> btree,
java.util.List<Tuple<K,V>> tuples)
Sort a list of tuples, eliminating the duplicate keys and storing the values in a set when we
have a duplicate key
|
private static <K,V> int readElements(BTree<K,V> btree, java.util.Iterator<Tuple<K,V>> iterator, java.util.List<java.io.File> sortedFiles, java.util.List<Tuple<K,V>> tuples, int chunkSize) throws java.io.IOException
btree - iterator - sortedFiles - tuples - chunkSize - java.io.IOExceptionprivate static <K,V> Tuple<java.util.Iterator<Tuple<K,java.util.Set<V>>>,BulkLoader.SortedFile> processFiles(BTree<K,V> btree, java.util.Iterator<Tuple<K,java.util.Set<V>>> dataIterator) throws java.io.IOException
java.io.IOExceptionpublic static <K,V> BTree<K,V> load(BTree<K,V> btree, java.util.Iterator<Tuple<K,V>> iterator, int chunkSize) throws java.io.IOException
btree - The persisted BTree in which we want to load the dataiterator - The iterator over the data to bulkloadchunkSize - The number of elements we may store in memory at each iterationjava.io.IOException - If there is a problem while processing the datastatic <K,V> LevelInfo<K,V> computeLevel(BTree<K,V> btree, int nbElems, BulkLoader.LevelEnum levelType)
static <K,V> java.util.List<LevelInfo<K,V>> computeLevels(BTree<K,V> btree, int nbElems)
private static <K,V> void injectInLeaf(BTree<K,V> btree, Tuple<K,java.util.Set<V>> tuple, LevelInfo<K,V> leafLevel)
private static <K,V> int computeNbElemsLeaf(BTree<K,V> btree, LevelInfo<K,V> levelInfo)
int computeNbElemsNode(BTree<K,V> btree, LevelInfo<K,V> levelInfo)
private static <K,V> void injectInRoot(BTree<K,V> btree, Page<K,V> page, PageHolder<K,V> pageHolder, LevelInfo<K,V> level) throws java.io.IOException
java.io.IOExceptionprivate static <K,V> void injectInNode(BTree<K,V> btree, Page<K,V> page, java.util.List<LevelInfo<K,V>> levels, int levelIndex) throws java.io.IOException
java.io.IOExceptionprivate static <K,V> BTree<K,V> bulkLoadSinglePage(BTree<K,V> btree, java.util.Iterator<Tuple<K,java.util.Set<V>>> dataIterator, int nbElems) throws java.io.IOException
java.io.IOExceptionprivate static <K,V> BTree<K,V> bulkLoad(BTree<K,V> btree, java.util.Iterator<Tuple<K,java.util.Set<V>>> dataIterator, int nbElems) throws java.io.IOException
java.io.IOExceptionprivate static <K,V> java.io.File flushToDisk(int fileNb,
java.util.List<Tuple<K,V>> tuples,
BTree<K,V> btree)
throws java.io.IOException
java.io.IOExceptionprivate static <K,V> Tuple<K,java.util.Set<V>>[] sort(BTree<K,V> btree, java.util.List<Tuple<K,V>> tuples)
private static <K,V> java.util.Iterator<Tuple<K,java.util.Set<V>>> createTupleIterator(BTree<K,V> btree, java.util.List<Tuple<K,V>> tuples)
private static <K,V> Tuple<K,java.util.Set<V>> fetchTuple(BTree<K,V> btree, java.io.FileInputStream fis)
private static <K,V> java.util.Iterator<Tuple<K,java.util.Set<V>>> createIterator(BTree<K,V> btree, java.io.FileInputStream[] streams) throws java.io.FileNotFoundException
java.io.FileNotFoundExceptionprivate static <K,V> java.util.Iterator<Tuple<K,java.util.Set<V>>> createUniqueFileIterator(BTree<K,V> btree, java.io.FileInputStream stream) throws java.io.FileNotFoundException
java.io.FileNotFoundExceptionpublic static void compact(RecordManager recordManager, BTree<?,?> btree)
recordManager - The associated recordManagerbtree - The BTree to compactpublic static BTree<?,?> compact(BTree<?,?> btree) throws java.io.IOException, KeyNotFoundException
btree - The BTree to compactKeyNotFoundExceptionjava.io.IOException