yashmayya commented on code in PR #18615: URL: https://github.com/apache/pinot/pull/18615#discussion_r3331091443
########## pinot-controller/src/main/resources/app/utils/requestLimiter.ts: ########## @@ -0,0 +1,45 @@ +/** + * 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. + */ + +export const runWithConcurrencyLimit = async <T>( + tasks: (() => Promise<T>)[], + limit: number +): Promise<T[]> => { + if (tasks.length === 0) { + return []; + } + + const concurrency = Math.max(1, Math.floor(limit)); + const results = new Array<T>(tasks.length); + let nextIndex = 0; + + const worker = async () => { + while (nextIndex < tasks.length) { + const currentIndex = nextIndex++; + results[currentIndex] = await tasks[currentIndex](); Review Comment: If a task rejects, this `await` throws and the worker's while-loop exits — so that worker stops pulling tasks. After a handful of failures the whole pool is dead and the remaining tables never get their requests fired (rows stuck on 'Loading'). The old per-table forEach isolated failures. Maybe wrap the task call in try/catch here so one bad request doesn't starve the rest? ########## pinot-controller/src/main/resources/app/components/AsyncPinotTables.tsx: ########## @@ -189,7 +192,10 @@ export const AsyncPinotTables = ({ }); } ); + + await Promise.all([segmentDetails, tableSizes]); Review Comment: `getTableSizes`/`getSegmentCountAndStatus` reject when there's no response (e.g. a timeout — `result.data` is undefined), so this `Promise.all` rejects and bubbles all the way up to `runWithConcurrencyLimit` uncaught. That's exactly the large-cluster case this PR is meant to help. Probably want a `.catch` per request so a failing table just keeps its placeholder instead of taking down the rest. ########## pinot-controller/src/main/resources/app/utils/requestLimiter.test.ts: ########## @@ -0,0 +1,53 @@ +/** + * 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. + */ + +import assert from 'node:assert/strict'; +import test from 'node:test'; +import { runWithConcurrencyLimit } from './requestLimiter'; + +const nextTick = () => new Promise((resolve) => setTimeout(resolve, 0)); + +test('runWithConcurrencyLimit caps in-flight tasks', async () => { Review Comment: This only covers the all-resolve path — since a rejection kills the worker, a test where one task rejects is the valuable one to add. Also worth flagging: `npm test` is still the no-op stub, so this spec doesn't actually run in CI yet. -- 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]
