Skip to content

Commit

Permalink
off heap indexing fix
Browse files Browse the repository at this point in the history
Signed-off-by: Bharathwaj G <bharath78910@gmail.com>
  • Loading branch information
bharath-techie committed Feb 9, 2024
1 parent 13c5f7b commit c0c8a28
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,13 @@ private byte[] serializeStarTreeRecord(Record starTreeRecord) {
private Record deserializeStarTreeRecord(RandomAccessInput buffer, long offset) throws IOException {
long[] dimensions = new long[_numDimensions];
for (int i = 0; i < _numDimensions; i++) {
dimensions[i] = buffer.readLong(offset);
try {
dimensions[i] = buffer.readLong(offset);
} catch(Exception e) {
logger.info("Error reading dimension value at offset " + offset + " for dimension"
+ " " + i + " : _numReadableStarTreeRecords = " + _numReadableStarTreeRecords);
throw e;
}
offset += Long.BYTES;
}
Object[] metrics = new Object[_numMetrics];
Expand Down Expand Up @@ -367,6 +373,8 @@ public Record getSegmentRecord(int docID, long recordBytes) throws IOException {

@Override
Iterator<Record> generateRecordsForStarNode(int startDocId, int endDocId, int dimensionId) throws IOException {
// End doc id is not inclusive but start doc is inclusive
// Hence we need to check if buffer is readable till endDocId - 1
ensureBufferReadable(endDocId, true);

// Sort all records using an int array
Expand Down Expand Up @@ -453,10 +461,20 @@ private void ensureBufferReadable(int docId, boolean endDocCheck) throws IOExcep
return;
}
IndexInput in = null;
/**
* If docId is less then the _numDocs , then we need to find a previous file associated with doc id
* The fileToByteSizeMap is in the following format
* file1 -> 521
* file2 -> 780
*
* which represents that file1 contains all docs till "520".
* "prevStartDocId" essentially tracks the "start doc id" of the range in the present file
* "_numReadableStarTreeRecords" tracks the "end doc id + 1" of the range in the present file
*/
if (docId < _numDocs) {
int prevStartDocId = 0;
for (Map.Entry<String, Integer> entry : fileToByteSizeMap.entrySet()) {
if (docId < entry.getValue() - 1) {
if (docId < entry.getValue()) {
in = state.directory.openInput(entry.getKey(), state.context);
starTreeRecordRandomInput = in.randomAccessSlice(in.getFilePointer(), in.length() - in.getFilePointer());
_numReadableStarTreeRecords = entry.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.opensearch.index.codec.freshstartree.query;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.index.DocValues;
import org.apache.lucene.index.NumericDocValues;
import org.apache.lucene.index.SortedNumericDocValues;
Expand All @@ -41,6 +43,8 @@

/** Filter operator for star tree data structure. */
public class StarTreeFilter {
private static final Logger logger = LogManager.getLogger(StarTreeFilter.class);


/** Helper class to wrap the result from traversing the star tree. */
static class StarTreeResult {
Expand Down Expand Up @@ -125,6 +129,7 @@ private StarTreeResult traverseStarTree() throws IOException {

StarTree starTree = _starTree;
List<String> dimensionNames = starTree.getDimensionNames();
logger.info("Dimension names {}", dimensionNames);
StarTreeNode starTreeRootNode = starTree.getRoot();

// Track whether we have found a leaf node added to the queue. If we have found a leaf node, and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

package org.opensearch.index.codec.freshstartree.query;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.search.Query;
import org.opensearch.core.ParseField;
import org.opensearch.core.common.ParsingException;
Expand All @@ -16,6 +18,7 @@
import org.opensearch.core.xcontent.ObjectParser;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.core.xcontent.XContentParser;
import org.opensearch.index.codec.freshstartree.builder.BaseSingleTreeBuilder;
import org.opensearch.index.query.AbstractQueryBuilder;
import org.opensearch.index.query.BoolQueryBuilder;
import org.opensearch.index.query.QueryBuilder;
Expand All @@ -38,6 +41,7 @@ public class StarTreeQueryBuilder extends AbstractQueryBuilder<StarTreeQueryBuil

private final Set<String> groupBy = new HashSet<>();
Map<String, List<Predicate<Long>>> predicateMap = new HashMap<>();
private static final Logger logger = LogManager.getLogger(StarTreeQueryBuilder.class);

public StarTreeQueryBuilder() {}

Expand Down Expand Up @@ -140,8 +144,10 @@ public static StarTreeQueryBuilder fromXContent(XContentParser parser) {
protected Query doToQuery(QueryShardContext context) {
// TODO : star tree supports either group by or filter
if (predicateMap.size() > 0) {
logger.info("Predicates: {} ", this.groupBy.toString() );
return new StarTreeQuery(predicateMap, new HashSet<>());
}
logger.info("Group by : {} ", this.groupBy.toString() );
return new StarTreeQuery(new HashMap<>(), this.groupBy);
}

Expand Down

0 comments on commit c0c8a28

Please sign in to comment.