Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ public static ImmutableSegment load(File indexDir, IndexLoadingConfig indexLoadi
Preconditions.checkArgument(indexDir.isDirectory(), "Index directory: %s does not exist or is not a directory",
indexDir);

SegmentMetadataPreProcessor segmentMetadataPreProcessor = SegmentMetadataPreProcessorRegistry.getInstance();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider simply putting a static variable in this class and add a setter for that. See ForwardIndexConfig for example

if (segmentMetadataPreProcessor != null) {
segmentMetadataPreProcessor.process(indexDir, indexLoadingConfig, zkMetadata);
}

SegmentMetadataImpl segmentMetadata = new SegmentMetadataImpl(indexDir);
if (segmentMetadata.getTotalDocs() == 0) {
return new EmptyIndexSegment(segmentMetadata);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* 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.segment.local.indexsegment.immutable;

import java.io.File;
import javax.annotation.Nullable;
import org.apache.pinot.common.metadata.segment.SegmentZKMetadata;
import org.apache.pinot.segment.local.segment.index.loader.IndexLoadingConfig;

/**
* {@code SegmentMetadataPreProcessor} provides a hook to preprocess a segment's metadata
* before the segment is fully loaded by the server.
*/
public interface SegmentMetadataPreProcessor {
/**
* Preprocesses the metadata for a segment located at the given index directory.
*
* @param indexDir
* The root directory of the segment index containing the segment metadata files.
* @param indexLoadingConfig
* The {@link IndexLoadingConfig} used for loading the segment, which may influence
* preprocessing behavior (e.g. table name, segment type, or server-level settings).
* @param zkMetadata
* Optional {@link SegmentZKMetadata} associated with the segment, if available.
* This may be {@code null} when the segment is loaded outside of Helix or Zookeeper
* context.
*
* @throws Exception
* If preprocessing fails and the segment should not be loaded. Throwing an
* exception will abort the segment loading process.
*/
void process(File indexDir, IndexLoadingConfig indexLoadingConfig,
@Nullable SegmentZKMetadata zkMetadata)
throws Exception;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* 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.segment.local.indexsegment.immutable;

import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class SegmentMetadataPreProcessorRegistry {
private static final Logger LOGGER = LoggerFactory.getLogger(SegmentMetadataPreProcessorRegistry.class);
private static SegmentMetadataPreProcessor _instance = null;

private SegmentMetadataPreProcessorRegistry() {
}

/**
* Get the registered instance of the pre-processor.
*
* @return The registered instance, or null if none registered
*/
@Nullable
public static SegmentMetadataPreProcessor getInstance() {
return _instance;
}

/**
* Register a pre-processor instance.
*
* @param instance The pre-processor instance to register
*/
public static void setInstance(SegmentMetadataPreProcessor instance) {
_instance = instance;
LOGGER.info("Registered SegmentMetadataPreProcessor: {}", instance.getClass().getName());
}
}
Loading