diff --git a/server/src/main/java/org/opensearch/index/codec/freshstartree/builder/OffHeapBufferedSingleTreeBuilder.java b/server/src/main/java/org/opensearch/index/codec/freshstartree/builder/OffHeapBufferedSingleTreeBuilder.java index 58c4cbde6455d..c95778584bd97 100644 --- a/server/src/main/java/org/opensearch/index/codec/freshstartree/builder/OffHeapBufferedSingleTreeBuilder.java +++ b/server/src/main/java/org/opensearch/index/codec/freshstartree/builder/OffHeapBufferedSingleTreeBuilder.java @@ -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]; @@ -367,6 +373,8 @@ public Record getSegmentRecord(int docID, long recordBytes) throws IOException { @Override Iterator 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 @@ -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 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(); diff --git a/server/src/main/java/org/opensearch/index/codec/freshstartree/query/StarTreeFilter.java b/server/src/main/java/org/opensearch/index/codec/freshstartree/query/StarTreeFilter.java index 90e98fae89275..3f754f9286b6e 100644 --- a/server/src/main/java/org/opensearch/index/codec/freshstartree/query/StarTreeFilter.java +++ b/server/src/main/java/org/opensearch/index/codec/freshstartree/query/StarTreeFilter.java @@ -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; @@ -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 { @@ -125,6 +129,7 @@ private StarTreeResult traverseStarTree() throws IOException { StarTree starTree = _starTree; List 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 diff --git a/server/src/main/java/org/opensearch/index/codec/freshstartree/query/StarTreeQueryBuilder.java b/server/src/main/java/org/opensearch/index/codec/freshstartree/query/StarTreeQueryBuilder.java index 1c5aa1632cfbf..540d8a9e2e0bc 100644 --- a/server/src/main/java/org/opensearch/index/codec/freshstartree/query/StarTreeQueryBuilder.java +++ b/server/src/main/java/org/opensearch/index/codec/freshstartree/query/StarTreeQueryBuilder.java @@ -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; @@ -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; @@ -38,6 +41,7 @@ public class StarTreeQueryBuilder extends AbstractQueryBuilder groupBy = new HashSet<>(); Map>> predicateMap = new HashMap<>(); + private static final Logger logger = LogManager.getLogger(StarTreeQueryBuilder.class); public StarTreeQueryBuilder() {} @@ -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); }