gortiz commented on code in PR #12345:
URL: https://github.com/apache/pinot/pull/12345#discussion_r1474244132
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/periodictask/ControllerPeriodicTask.java:
##########
@@ -63,29 +69,25 @@ protected final void runTask(Properties
periodicTaskProperties) {
// Check if we have a specific table against which this task needs to be
run.
String propTableNameWithType = (String)
periodicTaskProperties.get(PeriodicTask.PROPERTY_KEY_TABLE_NAME);
// Process the tables that are managed by this controller
- List<String> tablesToProcess = new ArrayList<>();
- List<String> nonLeaderForTables = new ArrayList<>();
- if (propTableNameWithType == null) {
- // Table name is not available, so task should run on all tables for
which this controller is the lead.
- for (String tableNameWithType :
_pinotHelixResourceManager.getAllTables()) {
- if (_leadControllerManager.isLeaderForTable(tableNameWithType)) {
- tablesToProcess.add(tableNameWithType);
- } else {
- nonLeaderForTables.add(tableNameWithType);
- }
- }
- } else {
- // Table name is available, so task should run only on the specified
table.
- if (_leadControllerManager.isLeaderForTable(propTableNameWithType)) {
- tablesToProcess.add(propTableNameWithType);
- }
- }
+ Set<String> allTables = propTableNameWithType == null
+ ? new HashSet<>(_pinotHelixResourceManager.getAllTables())
+ : Collections.singleton(propTableNameWithType);
+
+ Set<String> currentLeaderOfTables = allTables.stream()
+ .filter(_leadControllerManager::isLeaderForTable)
+ .collect(Collectors.toSet());
- if (!tablesToProcess.isEmpty()) {
- processTables(tablesToProcess, periodicTaskProperties);
+ if (!currentLeaderOfTables.isEmpty()) {
+ processTables(new ArrayList<>(currentLeaderOfTables),
periodicTaskProperties);
}
+
+ Sets.SetView<String> allKnownTables = Sets.union(_prevLeaderOfTables,
allTables);
+ Set<String> nonLeaderForTables = Sets.difference(allKnownTables,
currentLeaderOfTables);
Review Comment:
Changed
##########
pinot-controller/src/main/java/org/apache/pinot/controller/helix/core/periodictask/ControllerPeriodicTask.java:
##########
@@ -63,29 +69,25 @@ protected final void runTask(Properties
periodicTaskProperties) {
// Check if we have a specific table against which this task needs to be
run.
String propTableNameWithType = (String)
periodicTaskProperties.get(PeriodicTask.PROPERTY_KEY_TABLE_NAME);
// Process the tables that are managed by this controller
- List<String> tablesToProcess = new ArrayList<>();
- List<String> nonLeaderForTables = new ArrayList<>();
- if (propTableNameWithType == null) {
- // Table name is not available, so task should run on all tables for
which this controller is the lead.
- for (String tableNameWithType :
_pinotHelixResourceManager.getAllTables()) {
- if (_leadControllerManager.isLeaderForTable(tableNameWithType)) {
- tablesToProcess.add(tableNameWithType);
- } else {
- nonLeaderForTables.add(tableNameWithType);
- }
- }
- } else {
- // Table name is available, so task should run only on the specified
table.
- if (_leadControllerManager.isLeaderForTable(propTableNameWithType)) {
- tablesToProcess.add(propTableNameWithType);
- }
- }
+ Set<String> allTables = propTableNameWithType == null
+ ? new HashSet<>(_pinotHelixResourceManager.getAllTables())
+ : Collections.singleton(propTableNameWithType);
+
+ Set<String> currentLeaderOfTables = allTables.stream()
+ .filter(_leadControllerManager::isLeaderForTable)
+ .collect(Collectors.toSet());
- if (!tablesToProcess.isEmpty()) {
- processTables(tablesToProcess, periodicTaskProperties);
+ if (!currentLeaderOfTables.isEmpty()) {
+ processTables(new ArrayList<>(currentLeaderOfTables),
periodicTaskProperties);
}
+
+ Sets.SetView<String> allKnownTables = Sets.union(_prevLeaderOfTables,
allTables);
+ Set<String> nonLeaderForTables = Sets.difference(allKnownTables,
currentLeaderOfTables);
if (!nonLeaderForTables.isEmpty()) {
- nonLeaderCleanup(nonLeaderForTables);
+ nonLeaderCleanup(new ArrayList<>(nonLeaderForTables));
+ }
+ if (!_prevLeaderOfTables.equals(currentLeaderOfTables)) {
Review Comment:
Changed
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]