Skip to content

Fix: store rowCount per-file to prevent cross-file index corruption#32

Open
amitgour1996 wants to merge 1 commit intorollno748:masterfrom
amitgour1996:fix/per-file-rowcount
Open

Fix: store rowCount per-file to prevent cross-file index corruption#32
amitgour1996 wants to merge 1 commit intorollno748:masterfrom
amitgour1996:fix/per-file-rowcount

Conversation

@amitgour1996
Copy link
Copy Markdown

Fixes #31

Problem

rowCount is a private static int — one global value shared across all CSV files. When a Thread Group has multiple CSVs with different row counts, calculateRowCount() overwrites it each time. readRandom() and readUnique() then use the wrong count, generating indices past EOF, which blows up in readIndexed() with NoSuchElementException.

Changes

All in FileServerExtended.java:

  • Added int rowCount field to the FileEntry inner class so each file tracks its own count
  • calculateRowCount() now stores the count in fileEntry.rowCount (still updates the global for backward compat)
  • Added getRowCount(String alias) — looks up the per-file count from FileEntry, falls back to global
  • readRandom() and readUnique() now call getRowCount(alias) instead of using the static directly

Tested

Before fix: ~49% of iterations crash with NoSuchElementException when two CSVs have different row counts.
After fix: 0 crashes across multiple runs with 98 threads, all ExtendedCsvDataSetConfig elements enabled.

The static field 'rowCount' in FileServerExtended was shared across all
CSV files.  When a Thread Group contained multiple ExtendedCsvDataSetConfig
elements with different row counts, whichever called calculateRowCount()
last would overwrite the global value.  readRandom() and readUnique() then
used this incorrect global value, generating line indices beyond the
actual file size, causing NoSuchElementException from Optional.get()
in readIndexed().

Fix: store rowCount per-FileEntry and add getRowCount(alias) to look
up the correct count.  The global static is retained for backward
compatibility but deprecated.
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.

NoSuchElementException in readRandom/readUnique when TG has multiple CSV files with different row counts

1 participant