Jackie-Jiang commented on code in PR #12345: URL: https://github.com/apache/pinot/pull/12345#discussion_r1473572509
########## 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: Directly set `_prevLeaderOfTables` to `currentLeaderOfTables`? ########## 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 Review Comment: No need to make a set for all tables. List should be good and more performant ########## 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: Get the diff of `_prevLeaderOfTables` and `currentLeaderOfTables` should be good. No need to do union -- 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