Skip to content

TEZ-4757: APPROXIMATE_INPUT_RECORDS over-counts the rows an input will deliver - #540

Open
deniskuzZ wants to merge 1 commit into
apache:masterfrom
deniskuzZ:TEZ-approx-input-records
Open

deniskuzZ wants to merge 1 commit into
apache:masterfrom
deniskuzZ:TEZ-approx-input-records

Conversation

@deniskuzZ

Copy link
Copy Markdown
Member
  • An announcement carries the source task's output record count so far, not a per-event delta; keep the latest value per input instead of summing events, so a pipelined input's earlier spills are not counted again
  • Count an input that wrote no rows in the denominator; leaving it out while numInputs keeps it in the multiplier spread the mean of the inputs that had data over the ones that did not
  • Announce from the composite event path too: which path runs depends only on tez.am.shuffle.auxiliary-service.id, so on the Tez shuffle handler the counter was never updated at all
  • Multiply before dividing, the mean was truncated first
  • Saturate the announced count instead of wrapping it through int, and include large records, which bypass OUTPUT_RECORDS -- the VertexManager event already counts both
  • updateApproximateInputRecords takes the input index
  • Measured before the fix: 10 inputs, 2 announcing 1000 rows each, read 10,000 instead of 2,000; 4 pipelined events totalling 600 read 450

@tez-yetus

Copy link
Copy Markdown

🎊 +1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 0m 12s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 0s No case conflicting files found.
+0 🆗 detsecrets 0m 0s detect-secrets was not available.
+1 💚 @author 0m 0s The patch does not contain any @author tags.
+1 💚 test4tests 0m 0s The patch appears to include 2 new or modified test files.
_ master Compile Tests _
+1 💚 mvninstall 4m 50s master passed
+1 💚 compile 4m 0s master passed
+1 💚 checkstyle 0m 36s master passed
+1 💚 javadoc 0m 38s master passed
+0 🆗 spotbugs 1m 14s tez-runtime-library in master has 143 extant spotbugs warnings.
_ Patch Compile Tests _
+1 💚 mvninstall 3m 40s the patch passed
+1 💚 codespell 1m 34s No new issues.
+1 💚 compile 4m 4s the patch passed
+1 💚 javac 4m 4s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
-0 ⚠️ checkstyle 0m 33s /results-checkstyle-tez-runtime-library.txt tez-runtime-library: The patch generated 1 new + 77 unchanged - 1 fixed = 78 total (was 78)
+1 💚 javadoc 0m 38s the patch passed
+1 💚 spotbugs 1m 28s the patch passed
_ Other Tests _
+1 💚 unit 74m 0s root in the patch passed.
+1 💚 asflicense 0m 32s The patch does not generate ASF License warnings.
99m 39s
Subsystem Report/Notes
Docker ClientAPI=1.56 ServerAPI=1.56 base: https://ci-hadoop.apache.org/job/tez-multibranch/job/PR-540/1/artifact/out/Dockerfile
Optional Tests dupname compile unit asflicense javac javadoc spotbugs checkstyle codespell detsecrets
uname Linux c0c85768ffd3 5.15.0-190-generic #200-Ubuntu SMP Fri Aug 7 15:06:04 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality tez-personality.sh
git revision master / 0e9f756
Default Java Eclipse Adoptium-21.0.12+8-LTS
Test Results https://ci-hadoop.apache.org/job/tez-multibranch/job/PR-540/1/testReport/
Max. process+thread count 1405 (vs. ulimit of 5500)
modules C: tez-runtime-library U: tez-runtime-library
Console output https://ci-hadoop.apache.org/job/tez-multibranch/job/PR-540/1/console
versions git=2.43.0 maven=3.9.15 spotbugs=4.9.3 codespell=2.4.1
Powered by Apache Yetus 0.15.1 https://yetus.apache.org

This message was automatically generated.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

One or more issues must be addressed before approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity · 1 Low severity

Open (2)
What changed in this PR

Fixes approximate input record estimation for unordered shuffle inputs.

Changes:

  • Track the latest per-input record total, including empty inputs.
  • Update both regular and composite event paths.
  • Include large records and saturate payload counts.
File Description
tez-runtime-library/​src/​test/​java/​org/​apache/​tez/​runtime/​library/​common/​shuffle/​impl/​TestShuffleManager.java Updated as part of this pull request.
tez-runtime-library/​src/​test/​java/​org/​apache/​tez/​runtime/​library/​common/​shuffle/​impl/​TestShuffleInputEventHandlerImpl.java Updated as part of this pull request.
tez-runtime-library/​src/​main/​java/​org/​apache/​tez/​runtime/​library/​common/​writers/​UnorderedPartitionedKVWriter.java Updated as part of this pull request.
tez-runtime-library/​src/​main/​java/​org/​apache/​tez/​runtime/​library/​common/​shuffle/​impl/​ShuffleManager.java Updated as part of this pull request.
tez-runtime-library/​src/​main/​java/​org/​apache/​tez/​runtime/​library/​common/​shuffle/​impl/​ShuffleInputEventHandlerImpl.java Updated as part of this pull request.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

}
inputRecordsFromEvents += numRecords - reportedSoFar;
recordsPerInput[inputIndex] = numRecords;
approximateInputRecords.setValue((inputRecordsFromEvents * numInputs) / inputsReportingRecords);
Comment on lines +911 to +912
long records = outputRecordsCounter.getValue() + outputLargeRecordsCounter.getValue();
payloadBuilder.setNumRecord((int) Math.min(records, Integer.MAX_VALUE));

@abstractdog abstractdog left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nice catch, left minor comments only
check also copilot comments please, if they make sense

Comment on lines +164 to +166
private long approximateInputRecords(InputContext inputContext) {
return inputContext.getCounters().findCounter(TaskCounter.APPROXIMATE_INPUT_RECORDS).getValue();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this method can go below the @Test methods

* in the multiplier. A count the writer could not fit in an int arrives negative; ignore it
* rather than subtract it from the total.
*/
public void updateApproximateInputRecords(int inputIndex, int numRecords) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: this is kind of shuffle internals, a package-protected scope makes more sense to me
I can seen it used to be public, but as the signature is already touched by this PR, maybe make it happen now

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

consider adding a unit test case for negative numRecords

@deniskuzZ
deniskuzZ force-pushed the TEZ-approx-input-records branch 3 times, most recently from a03e61c to 9271332 Compare September 21, 2026 13:24
@tez-yetus

Copy link
Copy Markdown

💔 -1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 0m 8s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 0s No case conflicting files found.
+0 🆗 detsecrets 0m 0s detect-secrets was not available.
+1 💚 @author 0m 0s The patch does not contain any @author tags.
+1 💚 test4tests 0m 0s The patch appears to include 3 new or modified test files.
_ master Compile Tests _
+1 💚 mvninstall 3m 2s master passed
+1 💚 compile 2m 34s master passed
-1 ❌ bufcompat 0m 1s /branch-bufcompat-stderr.txt Error running buf. Please check buf stderr files.
+1 💚 checkstyle 0m 26s master passed
+1 💚 javadoc 0m 24s master passed
+0 🆗 spotbugs 0m 40s tez-runtime-library in master has 143 extant spotbugs warnings.
_ Patch Compile Tests _
+1 💚 mvninstall 2m 14s the patch passed
-1 ❌ codespell 0m 52s /results-codespell.txt The patch generated 1 new + 10 unchanged - 0 fixed = 11 total (was 10)
+1 💚 compile 2m 30s the patch passed
+1 💚 cc 2m 30s the patch passed
-1 ❌ javac 2m 30s /results-compile-javac-root.txt root generated 2 new + 706 unchanged - 0 fixed = 708 total (was 706)
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 buflint 0m 5s No new issues.
-0 ⚠️ checkstyle 0m 18s /results-checkstyle-tez-runtime-library.txt tez-runtime-library: The patch generated 3 new + 183 unchanged - 1 fixed = 186 total (was 184)
+1 💚 javadoc 0m 19s the patch passed
+1 💚 spotbugs 0m 47s the patch passed
_ Other Tests _
+1 💚 unit 59m 41s root in the patch passed.
+1 💚 asflicense 0m 23s The patch does not generate ASF License warnings.
75m 24s
Subsystem Report/Notes
Docker ClientAPI=1.56 ServerAPI=1.56 base: https://ci-hadoop.apache.org/job/tez-multibranch/job/PR-540/4/artifact/out/Dockerfile
Optional Tests dupname compile unit asflicense javac javadoc spotbugs checkstyle codespell detsecrets cc buflint bufcompat
uname Linux 7793c0caf8ad 5.15.0-190-generic #200-Ubuntu SMP Fri Aug 7 15:06:04 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality tez-personality.sh
git revision master / 0e9f756
Default Java Eclipse Adoptium-21.0.12+8-LTS
Test Results https://ci-hadoop.apache.org/job/tez-multibranch/job/PR-540/4/testReport/
Max. process+thread count 1417 (vs. ulimit of 5500)
modules C: tez-runtime-library U: tez-runtime-library
Console output https://ci-hadoop.apache.org/job/tez-multibranch/job/PR-540/4/console
versions git=2.43.0 maven=3.9.15 buf=1.68.2 spotbugs=4.9.3 codespell=2.4.1
Powered by Apache Yetus 0.15.1 https://yetus.apache.org

This message was automatically generated.

@deniskuzZ
deniskuzZ force-pushed the TEZ-approx-input-records branch 3 times, most recently from 8c27407 to 9d712ea Compare September 21, 2026 16:02
…l deliver

- A report carries the source task's output record count so far, not a per-event
  delta; keep the latest value per input instead of summing events, so a pipelined
  input's earlier spills are not counted again
- Ignore a report smaller than that input's last one: spill callbacks read the
  counter and send their event with no lock between, so a stale total can arrive
  last and would otherwise subtract from the sum
- Count an input that wrote no rows in the denominator; leaving it out while
  numInputs keeps it in the multiplier spread the mean of the inputs that had
  data over the ones that did not
- An output that never started reports 0 rather than nothing, so it joins the
  denominator instead of being scaled over
- Flush the record counters before the final pipelined events read them. An
  output small enough for one buffer spills only at close, so its DME and its
  VertexManager event both carried 0
- Report from the composite event path too: which path runs depends only on
  tez.am.shuffle.auxiliary-service.id, so on the Tez shuffle handler the counter
  was never updated at all
- Scale the mean without forming sum * numInputs, so only the true answer has to
  fit in a long
- num_record is int64, matching the VertexManagerEventPayloadProto field it
  mirrors. It was int32 while both are filled from long counters, so a task
  emitting more than 2^31 rows wrapped negative; widening the field alone would
  only move the loss to the consumer, so the per-input array and the update
  method carry a long as well. int32 -> int64 is wire compatible in both
  directions on the same field number
- The count includes OUTPUT_LARGE_RECORDS, which bypass OUTPUT_RECORDS; this is
  what ShuffleUtils.generateVMEvent already sends. Without it a single-partition
  writer reports 0 for a broadcast of large rows
- updateApproximateInputRecords is package-private: it is shuffle internals with
  one caller in the same package
- Measured before the fix: 10 inputs, 2 reporting 1000 rows each, read 10,000
  instead of 2,000; 4 pipelined events totalling 600 read 450; a 5-row
  single-partition pipelined output reported 0
@deniskuzZ
deniskuzZ force-pushed the TEZ-approx-input-records branch from 9d712ea to f2121aa Compare September 21, 2026 16:12
@tez-yetus

Copy link
Copy Markdown

💔 -1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 0m 12s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 0s No case conflicting files found.
+0 🆗 detsecrets 0m 0s detect-secrets was not available.
+1 💚 @author 0m 0s The patch does not contain any @author tags.
+1 💚 test4tests 0m 0s The patch appears to include 4 new or modified test files.
_ master Compile Tests _
+1 💚 mvninstall 5m 4s master passed
+1 💚 compile 4m 4s master passed
-1 ❌ bufcompat 0m 2s /branch-bufcompat-stderr.txt Error running buf. Please check buf stderr files.
+1 💚 checkstyle 0m 41s master passed
+1 💚 javadoc 1m 2s master passed
+0 🆗 spotbugs 1m 18s tez-runtime-library in master has 143 extant spotbugs warnings.
_ Patch Compile Tests _
+1 💚 mvninstall 3m 43s the patch passed
-1 ❌ codespell 1m 34s /results-codespell.txt The patch generated 1 new + 13 unchanged - 0 fixed = 14 total (was 13)
+1 💚 compile 4m 5s the patch passed
+1 💚 cc 4m 5s the patch passed
-1 ❌ javac 4m 5s /results-compile-javac-root.txt root generated 2 new + 706 unchanged - 0 fixed = 708 total (was 706)
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 buflint 0m 9s No new issues.
-0 ⚠️ checkstyle 0m 34s /results-checkstyle-tez-runtime-library.txt tez-runtime-library: The patch generated 6 new + 217 unchanged - 1 fixed = 223 total (was 218)
+1 💚 javadoc 0m 38s the patch passed
+1 💚 spotbugs 1m 26s the patch passed
_ Other Tests _
+1 💚 unit 75m 42s root in the patch passed.
+1 💚 asflicense 0m 33s The patch does not generate ASF License warnings.
102m 24s
Subsystem Report/Notes
Docker ClientAPI=1.56 ServerAPI=1.56 base: https://ci-hadoop.apache.org/job/tez-multibranch/job/PR-540/8/artifact/out/Dockerfile
Optional Tests dupname compile unit asflicense javac javadoc spotbugs checkstyle codespell detsecrets cc buflint bufcompat
uname Linux 9235b2c4fc18 5.15.0-190-generic #200-Ubuntu SMP Fri Aug 7 15:06:04 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality tez-personality.sh
git revision master / 0e9f756
Default Java Eclipse Adoptium-21.0.12+8-LTS
Test Results https://ci-hadoop.apache.org/job/tez-multibranch/job/PR-540/8/testReport/
Max. process+thread count 2124 (vs. ulimit of 5500)
modules C: tez-runtime-library U: tez-runtime-library
Console output https://ci-hadoop.apache.org/job/tez-multibranch/job/PR-540/8/console
versions git=2.43.0 maven=3.9.15 buf=1.68.2 spotbugs=4.9.3 codespell=2.4.1
Powered by Apache Yetus 0.15.1 https://yetus.apache.org

This message was automatically generated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants