Jackie-Jiang commented on code in PR #9802: URL: https://github.com/apache/pinot/pull/9802#discussion_r1029878916
########## pinot-core/src/main/java/org/apache/pinot/core/data/manager/offline/MemoryOptimizedDimensionTable.java: ########## @@ -0,0 +1,71 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.pinot.core.data.manager.offline; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.pinot.spi.data.FieldSpec; +import org.apache.pinot.spi.data.Schema; +import org.apache.pinot.spi.data.readers.GenericRow; +import org.apache.pinot.spi.data.readers.PrimaryKey; + + +class MemoryOptimizedDimensionTable implements DimensionTable { + + private final Map<PrimaryKey, LookupRecordLocation> _lookupTable; + private final Schema _tableSchema; + private final List<String> _primaryKeyColumns; + private final GenericRow _reuse = new GenericRow(); + + MemoryOptimizedDimensionTable(Schema tableSchema, List<String> primaryKeyColumns) { Review Comment: (minor) Do we need this constructor? ########## pinot-core/src/main/java/org/apache/pinot/core/data/manager/offline/DimensionTableDataManager.java: ########## @@ -125,13 +142,18 @@ private void loadLookupTable() { DimensionTable replacement; do { snapshot = _dimensionTable; - replacement = createDimensionTable(); + if (_disablePreload) { + replacement = createMemOptimisedDimensionTable(); + } else { + replacement = createDimensionTable(); + } } while (!UPDATER.compareAndSet(this, snapshot, replacement)); } private DimensionTable createDimensionTable() { Review Comment: (minor) Rename this method ########## pinot-core/src/main/java/org/apache/pinot/core/data/manager/offline/DimensionTableDataManager.java: ########## @@ -156,7 +178,43 @@ private DimensionTable createDimensionTable() { } } } - return new DimensionTable(schema, primaryKeyColumns, lookupTable); + return new FastLookupDimensionTable(schema, primaryKeyColumns, lookupTable); Review Comment: (minor) Reformat ########## pinot-core/src/main/java/org/apache/pinot/core/data/manager/offline/DimensionTableDataManager.java: ########## @@ -156,7 +178,43 @@ private DimensionTable createDimensionTable() { } } } - return new DimensionTable(schema, primaryKeyColumns, lookupTable); + return new FastLookupDimensionTable(schema, primaryKeyColumns, lookupTable); + } finally { + for (SegmentDataManager segmentManager : segmentManagers) { + releaseSegment(segmentManager); + } + } + } + + private DimensionTable createMemOptimisedDimensionTable() { + Schema schema = ZKMetadataProvider.getTableSchema(_propertyStore, _tableNameWithType); + Preconditions.checkState(schema != null, "Failed to find schema for dimension table: %s", _tableNameWithType); + + List<String> primaryKeyColumns = schema.getPrimaryKeyColumns(); + Preconditions.checkState(CollectionUtils.isNotEmpty(primaryKeyColumns), + "Primary key columns must be configured for dimension table: %s", _tableNameWithType); + + Map<PrimaryKey, LookupRecordLocation> lookupTable = new HashMap<>(); + List<SegmentDataManager> segmentManagers = acquireAllSegments(); + try { + for (SegmentDataManager segmentManager : segmentManagers) { + IndexSegment indexSegment = segmentManager.getSegment(); + int numTotalDocs = indexSegment.getSegmentMetadata().getTotalDocs(); + if (numTotalDocs > 0) { + try (PinotSegmentRecordReader recordReader = new PinotSegmentRecordReader()) { Review Comment: (MAJOR) This will close the record reader, which makes the record not readable from the record location. We need to figure out a way to close the record reader though (probably add a `close()` in `DimensionTable`) ########## pinot-core/src/main/java/org/apache/pinot/core/data/manager/offline/DimensionTableDataManager.java: ########## @@ -156,7 +178,43 @@ private DimensionTable createDimensionTable() { } } } - return new DimensionTable(schema, primaryKeyColumns, lookupTable); + return new FastLookupDimensionTable(schema, primaryKeyColumns, lookupTable); + } finally { + for (SegmentDataManager segmentManager : segmentManagers) { + releaseSegment(segmentManager); + } + } + } + + private DimensionTable createMemOptimisedDimensionTable() { + Schema schema = ZKMetadataProvider.getTableSchema(_propertyStore, _tableNameWithType); + Preconditions.checkState(schema != null, "Failed to find schema for dimension table: %s", _tableNameWithType); + + List<String> primaryKeyColumns = schema.getPrimaryKeyColumns(); + Preconditions.checkState(CollectionUtils.isNotEmpty(primaryKeyColumns), + "Primary key columns must be configured for dimension table: %s", _tableNameWithType); + + Map<PrimaryKey, LookupRecordLocation> lookupTable = new HashMap<>(); + List<SegmentDataManager> segmentManagers = acquireAllSegments(); + try { + for (SegmentDataManager segmentManager : segmentManagers) { + IndexSegment indexSegment = segmentManager.getSegment(); + int numTotalDocs = indexSegment.getSegmentMetadata().getTotalDocs(); + if (numTotalDocs > 0) { + try (PinotSegmentRecordReader recordReader = new PinotSegmentRecordReader()) { Review Comment: Since we need to access the segment within the `DimensionTable`, there is another corner case we need to handle. Currently when a segment is removed, we release the segment before reloading the lookup table. This will cause on-the-fly query to fail. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org