This is an automated email from the ASF dual-hosted git repository.

yashmayya pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git


The following commit(s) were added to refs/heads/master by this push:
     new 2b95c54db85 Provide Segment Operation Task Context (#17623)
2b95c54db85 is described below

commit 2b95c54db8528fd613e56cc3f574ac7b40649d08
Author: Jhow <[email protected]>
AuthorDate: Thu Feb 26 15:47:56 2026 -0800

    Provide Segment Operation Task Context (#17623)
---
 .../core/data/manager/BaseTableDataManager.java    |  8 +-
 .../manager/SegmentOperationsExecutorService.java  | 49 ++++++++++++
 .../data/manager/SegmentOperationsTaskContext.java | 92 ++++++++++++++++++++++
 .../data/manager/SegmentOperationsTaskType.java    | 63 +++++++++++++++
 .../realtime/RealtimeSegmentDataManager.java       |  7 +-
 5 files changed, 216 insertions(+), 3 deletions(-)

diff --git 
a/pinot-core/src/main/java/org/apache/pinot/core/data/manager/BaseTableDataManager.java
 
b/pinot-core/src/main/java/org/apache/pinot/core/data/manager/BaseTableDataManager.java
index df1ddb2fbea..990b6edaac2 100644
--- 
a/pinot-core/src/main/java/org/apache/pinot/core/data/manager/BaseTableDataManager.java
+++ 
b/pinot-core/src/main/java/org/apache/pinot/core/data/manager/BaseTableDataManager.java
@@ -180,8 +180,12 @@ public abstract class BaseTableDataManager implements 
TableDataManager {
     _propertyStore = helixManager.getHelixPropertyStore();
     _segmentLocks = segmentLocks;
     _segmentReloadSemaphore = segmentReloadSemaphore;
-    _segmentReloadRefreshExecutor = segmentReloadRefreshExecutor;
-    _segmentPreloadExecutor = segmentPreloadExecutor;
+    _segmentReloadRefreshExecutor = new 
SegmentOperationsExecutorService(segmentReloadRefreshExecutor,
+        SegmentOperationsTaskType.REFRESH_OR_RELOAD, 
tableConfig.getTableName());
+    _segmentPreloadExecutor = segmentPreloadExecutor != null
+        ? new SegmentOperationsExecutorService(segmentPreloadExecutor, 
SegmentOperationsTaskType.PRELOAD,
+        tableConfig.getTableName())
+        : null;
     _enableAsyncSegmentRefresh = enableAsyncSegmentRefresh;
     _authProvider = 
AuthProviderUtils.extractAuthProvider(instanceDataManagerConfig.getAuthConfig(),
 null);
 
diff --git 
a/pinot-core/src/main/java/org/apache/pinot/core/data/manager/SegmentOperationsExecutorService.java
 
b/pinot-core/src/main/java/org/apache/pinot/core/data/manager/SegmentOperationsExecutorService.java
new file mode 100644
index 00000000000..979fb81c0d2
--- /dev/null
+++ 
b/pinot-core/src/main/java/org/apache/pinot/core/data/manager/SegmentOperationsExecutorService.java
@@ -0,0 +1,49 @@
+/**
+ * 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;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import org.apache.pinot.spi.executor.DecoratorExecutorService;
+
+
+/**
+ * An ExecutorService wrapper that automatically wraps all submitted tasks 
with segment operations context.
+ */
+public class SegmentOperationsExecutorService extends DecoratorExecutorService 
{
+  private final SegmentOperationsTaskType _taskType;
+  private final String _tableNameWithType;
+
+  public SegmentOperationsExecutorService(ExecutorService delegate, 
SegmentOperationsTaskType taskType,
+      String tableNameWithType) {
+    super(delegate);
+    _taskType = taskType;
+    _tableNameWithType = tableNameWithType;
+  }
+
+  @Override
+  protected <T> Callable<T> decorate(Callable<T> task) {
+    return SegmentOperationsTaskContext.wrap(task, _taskType, 
_tableNameWithType);
+  }
+
+  @Override
+  protected Runnable decorate(Runnable task) {
+    return SegmentOperationsTaskContext.wrap(task, _taskType, 
_tableNameWithType);
+  }
+}
diff --git 
a/pinot-core/src/main/java/org/apache/pinot/core/data/manager/SegmentOperationsTaskContext.java
 
b/pinot-core/src/main/java/org/apache/pinot/core/data/manager/SegmentOperationsTaskContext.java
new file mode 100644
index 00000000000..eca2a34ee0d
--- /dev/null
+++ 
b/pinot-core/src/main/java/org/apache/pinot/core/data/manager/SegmentOperationsTaskContext.java
@@ -0,0 +1,92 @@
+/**
+ * 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;
+
+import java.util.concurrent.Callable;
+import javax.annotation.Nullable;
+
+/**
+ * Thread-local task context for segment operations.
+ */
+public final class SegmentOperationsTaskContext {
+  private static final ThreadLocal<Context> CONTEXT = new ThreadLocal<>();
+
+  private SegmentOperationsTaskContext() {
+  }
+
+  public static void set(SegmentOperationsTaskType taskType, String 
tableNameWithType) {
+    CONTEXT.set(new Context(taskType, tableNameWithType));
+  }
+
+  public static void clear() {
+    CONTEXT.remove();
+  }
+
+  @Nullable
+  public static SegmentOperationsTaskType getTaskType() {
+    Context context = CONTEXT.get();
+    return context != null ? context._taskType : null;
+  }
+
+  @Nullable
+  public static String getTableNameWithType() {
+    Context context = CONTEXT.get();
+    return context != null ? context._tableNameWithType : null;
+  }
+
+  /**
+   * Wraps a runnable task with segment operations context.
+   */
+  public static Runnable wrap(Runnable runnable, SegmentOperationsTaskType 
taskType,
+      @Nullable String tableNameWithType) {
+    return () -> {
+      set(taskType, tableNameWithType);
+      try {
+        runnable.run();
+      } finally {
+        clear();
+      }
+    };
+  }
+
+  /**
+   * Wraps a callable task with segment operations context.
+   */
+  public static <T> Callable<T> wrap(Callable<T> callable, 
SegmentOperationsTaskType taskType,
+      @Nullable String tableNameWithType) {
+    return () -> {
+      set(taskType, tableNameWithType);
+      try {
+        return callable.call();
+      } finally {
+        clear();
+      }
+    };
+  }
+
+  private static final class Context {
+    private final SegmentOperationsTaskType _taskType;
+    private final String _tableNameWithType;
+
+    private Context(SegmentOperationsTaskType taskType, String 
tableNameWithType) {
+      _taskType = taskType;
+      _tableNameWithType = tableNameWithType;
+    }
+  }
+}
diff --git 
a/pinot-core/src/main/java/org/apache/pinot/core/data/manager/SegmentOperationsTaskType.java
 
b/pinot-core/src/main/java/org/apache/pinot/core/data/manager/SegmentOperationsTaskType.java
new file mode 100644
index 00000000000..a97248e8bb7
--- /dev/null
+++ 
b/pinot-core/src/main/java/org/apache/pinot/core/data/manager/SegmentOperationsTaskType.java
@@ -0,0 +1,63 @@
+/**
+ * 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;
+
+/**
+ * Labels the task type for segment operations throttler binding.
+ *
+ * <p>This is implemented as a class with static instances (type-safe enum 
pattern) rather than a Java enum
+ * to allow extensibility. Extend this class to define additional custom task 
types while maintaining compatibility
+ * with the base task types defined here.</p>
+ */
+public class SegmentOperationsTaskType {
+  public static final SegmentOperationsTaskType CONSUMER =
+      new SegmentOperationsTaskType("CONSUMER");
+  public static final SegmentOperationsTaskType REFRESH_OR_RELOAD =
+      new SegmentOperationsTaskType("REFRESH_OR_RELOAD");
+  public static final SegmentOperationsTaskType PRELOAD =
+      new SegmentOperationsTaskType("PRELOAD");
+
+  private final String _name;
+
+  protected SegmentOperationsTaskType(String name) {
+    _name = name;
+  }
+
+  @Override
+  public String toString() {
+    return _name;
+  }
+
+  @Override
+  public int hashCode() {
+    return _name.hashCode();
+  }
+
+  @Override
+  public boolean equals(Object obj) {
+    if (this == obj) {
+      return true;
+    }
+    if (obj == null || getClass() != obj.getClass()) {
+      return false;
+    }
+    SegmentOperationsTaskType other = (SegmentOperationsTaskType) obj;
+    return _name.equals(other._name);
+  }
+}
diff --git 
a/pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/RealtimeSegmentDataManager.java
 
b/pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/RealtimeSegmentDataManager.java
index b7122ccff35..d555c13403b 100644
--- 
a/pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/RealtimeSegmentDataManager.java
+++ 
b/pinot-core/src/main/java/org/apache/pinot/core/data/manager/realtime/RealtimeSegmentDataManager.java
@@ -53,6 +53,8 @@ import 
org.apache.pinot.common.restlet.resources.SegmentErrorInfo;
 import org.apache.pinot.common.utils.LLCSegmentName;
 import org.apache.pinot.common.utils.PauselessConsumptionUtils;
 import org.apache.pinot.common.utils.TarCompressionUtils;
+import org.apache.pinot.core.data.manager.SegmentOperationsTaskContext;
+import org.apache.pinot.core.data.manager.SegmentOperationsTaskType;
 import 
org.apache.pinot.core.data.manager.realtime.RealtimeConsumptionRateManager.ConsumptionRateLimiter;
 import org.apache.pinot.segment.local.data.manager.SegmentDataManager;
 import org.apache.pinot.segment.local.dedup.DedupContext;
@@ -1633,7 +1635,10 @@ public class RealtimeSegmentDataManager extends 
SegmentDataManager {
   }
 
   public void startConsumption() {
-    _consumerThread = new Thread(new PartitionConsumer(), _segmentNameStr);
+    Runnable consumer =
+        SegmentOperationsTaskContext.wrap(new PartitionConsumer(), 
SegmentOperationsTaskType.CONSUMER,
+            _tableNameWithType);
+    _consumerThread = new Thread(consumer, _segmentNameStr);
     _segmentLogger.info("Created new consumer thread {} for {}", 
_consumerThread, this);
     _consumerThread.start();
   }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to