Skip to content

[SPARK-2103][Streaming] Change to ClassTag for KafkaInputDStream and fix reflection issue - #1508

Closed
jerryshao wants to merge 2 commits into
apache:masterfrom
jerryshao:SPARK-2103
Closed

jerryshao wants to merge 2 commits into
apache:masterfrom
jerryshao:SPARK-2103

Conversation

@jerryshao

Copy link
Copy Markdown
Contributor

This PR updates previous Manifest for KafkaInputDStream's Decoder to ClassTag, also fix the problem addressed in SPARK-2103.

Previous Java interface cannot actually get the type of Decoder, so when using this Manifest to reconstruct the decode object will meet reflection exception.

Also for other two Java interfaces, ClassTag[String] is useless because calling Scala API will get the right implicit ClassTag.

Current Kafka unit test cannot actually verify the interface. I've tested these interfaces in my local and distribute settings.

@SparkQA

SparkQA commented Jul 21, 2014

Copy link
Copy Markdown

QA tests have started for PR 1508. This patch merges cleanly.
View progress: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/16900/consoleFull

@srowen

srowen commented Jul 21, 2014

Copy link
Copy Markdown
Member

Nice one Jerry! this actually enables using Kafka with non-String data in Java.

@SparkQA

SparkQA commented Jul 21, 2014

Copy link
Copy Markdown

QA results for PR 1508:
- This patch FAILED unit tests.
- This patch merges cleanly
- This patch adds no public classes

For more information see test ouptut:
https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/16900/consoleFull

@srowen

srowen commented Jul 21, 2014

Copy link
Copy Markdown
Member

It's the MIMA test that fails, since the method signature is changed. It's possible to keep and deprecate the existing method of course. Should we just do that, or OK to remove the method on the grounds that the API doesn't quite work?

@jerryshao

Copy link
Copy Markdown
Contributor Author

Hi @srowen , thanks for your advice. I've also noticed that seems MIMA cannot allow me to change the method signature. But I think it is meaningful and will not change the user's code, only need to recompile.

@tdas, would you mind giving me some suggestions, thanks a lot.

@tdas

tdas commented Jul 30, 2014

Copy link
Copy Markdown
Contributor

Jenkins, test this please.

@SparkQA

SparkQA commented Jul 30, 2014

Copy link
Copy Markdown

QA tests have started for PR 1508. This patch merges cleanly.
View progress: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17484/consoleFull

@tdas

tdas commented Jul 30, 2014

Copy link
Copy Markdown
Contributor

LGTM. I am okay with the binary compatibility change, since it is really wrong that we were using manifest instead of classtags.

But I am not sure I really understand what is the reason behind the failure of the
val keyDecoder = manifest[U].runtimeClass.getConstructor(classOf[VerifiableProperties])
Why could the manifest not get the runtimeClass correctly?

@tdas

tdas commented Jul 30, 2014

Copy link
Copy Markdown
Contributor

Oh, please add the appropriate exclude in the Mima exclusions
https://github.com/apache/spark/blob/master/project/MimaExcludes.scala

See the error in the jenkins console output for the exact exception string that you need to add.

@SparkQA

SparkQA commented Jul 30, 2014

Copy link
Copy Markdown

QA results for PR 1508:
- This patch FAILED unit tests.
- This patch merges cleanly
- This patch adds no public classes

For more information see test ouptut:
https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17484/consoleFull

@tdas

tdas commented Jul 30, 2014

Copy link
Copy Markdown
Contributor

This failure is unrelated to this patch. Its a current known issue in Jenkins, will run the test again when this error gets cleared.

@jerryshao

Copy link
Copy Markdown
Contributor Author

Hi TD, thanks for your review. I think the previous issue is that:

implicit val keyCmd: Manifest[U] = implicitly[Manifest[AnyRef]].asInstanceOf[Manifest[U]]

This line of code cannot actually get the correct runtime class, the runtime class of keyCmd is Object as SPARK-2103 mentioned.

Because we only got Object, so create through reflection will get exception is this line:

val keyDecoder = manifest[U].runtimeClass.getConstructor(classOf[VerifiableProperties])

The right way is like this:

implicit val keyCmd: Manifest[U] = Manifest.classType(keyDecodeClass)

Manifest can also do the same thing if we correctly feed it with class info. But I think it would be better to change Manifest to ClassTag to keep align with other code, so I changed to use ClassTag.

I will add this to Mima exclude.

Thanks a lot.

@tdas

tdas commented Jul 31, 2014

Copy link
Copy Markdown
Contributor

I get it now. Let me try to run the Jenkins once again, to figure out what needs to be added to Mima

@tdas

tdas commented Jul 31, 2014

Copy link
Copy Markdown
Contributor

Jenkins, test this please.

@SparkQA

SparkQA commented Jul 31, 2014

Copy link
Copy Markdown

QA tests have started for PR 1508. This patch merges cleanly.
View progress: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17533/consoleFull

@SparkQA

SparkQA commented Jul 31, 2014

Copy link
Copy Markdown

QA results for PR 1508:
- This patch FAILED unit tests.
- This patch merges cleanly
- This patch adds no public classes

For more information see test ouptut:
https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17533/consoleFull

@tdas

tdas commented Jul 31, 2014

Copy link
Copy Markdown
Contributor

Again, this is an unrelated failure. Running it again.

@tdas

tdas commented Jul 31, 2014

Copy link
Copy Markdown
Contributor

Jenkins, test this please.

@SparkQA

SparkQA commented Jul 31, 2014

Copy link
Copy Markdown

QA tests have started for PR 1508. This patch merges cleanly.
View progress: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17584/consoleFull

@SparkQA

SparkQA commented Jul 31, 2014

Copy link
Copy Markdown

QA results for PR 1508:
- This patch FAILED unit tests.
- This patch merges cleanly
- This patch adds no public classes

For more information see test ouptut:
https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17584/consoleFull

@tdas

tdas commented Jul 31, 2014

Copy link
Copy Markdown
Contributor

Can you add these to the Mima excludes.

ProblemFilters.exclude[IncompatibleMethTypeProblem]("org.apache.spark.streaming.kafka.KafkaUtils.createStream")

ProblemFilters.exclude[IncompatibleMethTypeProblem]("org.apache.spark.streaming.kafka.KafkaReceiver.this")

The last one should not be necessary as it is not a public class. Let me look into this. No harm in adding the exclusion though.

@SparkQA

SparkQA commented Aug 1, 2014

Copy link
Copy Markdown

QA tests have started for PR 1508. This patch DID NOT merge cleanly!
View progress: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17627/consoleFull

@tdas

tdas commented Aug 1, 2014

Copy link
Copy Markdown
Contributor

@jerryshao Oops, not sure how that is possible given what this patch touches. Can you merge with master nonetheless.

@jerryshao

Copy link
Copy Markdown
Contributor Author

Ok, I will update the code.

@SparkQA

SparkQA commented Aug 1, 2014

Copy link
Copy Markdown

QA tests have started for PR 1508. This patch merges cleanly.
View progress: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17629/consoleFull

@SparkQA

SparkQA commented Aug 1, 2014

Copy link
Copy Markdown

QA results for PR 1508:
- This patch FAILED unit tests.
- This patch merges cleanly
- This patch adds no public classes

For more information see test ouptut:
https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17629/consoleFull

@SparkQA

SparkQA commented Aug 1, 2014

Copy link
Copy Markdown

QA results for PR 1508:
- This patch PASSES unit tests.

For more information see test ouptut:
https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17627/consoleFull

@tdas

tdas commented Aug 1, 2014

Copy link
Copy Markdown
Contributor

OK, this is very confusing, sequence of two results is very confusing. Let me run the tests again.

@tdas

tdas commented Aug 1, 2014

Copy link
Copy Markdown
Contributor

Jenkins, test this again.

@tdas

tdas commented Aug 1, 2014

Copy link
Copy Markdown
Contributor

Jenkins, test this please.

@SparkQA

SparkQA commented Aug 1, 2014

Copy link
Copy Markdown

QA tests have started for PR 1508. This patch merges cleanly.
View progress: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17670/consoleFull

@srowen

srowen commented Aug 1, 2014

Copy link
Copy Markdown
Member

A bunch of tests have been failing spuriously with "java.net.BindException: Address already in use". It's not the PR. I wonder what recent change could have made this happen? Is something being stricter about assigning a fixed port? did a config change to let multiple tests run on the same virtual machine?

@tdas

tdas commented Aug 1, 2014

Copy link
Copy Markdown
Contributor

Also, a number of them have been failing for spurious python mllib issues. At least was the case yesterday.

@SparkQA

SparkQA commented Aug 1, 2014

Copy link
Copy Markdown

QA results for PR 1508:
- This patch PASSES unit tests.
- This patch merges cleanly
- This patch adds no public classes

For more information see test ouptut:
https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17670/consoleFull

@tdas

tdas commented Aug 1, 2014

Copy link
Copy Markdown
Contributor

Heyyyaa, it finally passed. I am merging this. Thanks @jerryshao

@asfgit asfgit closed this in a32f0fb Aug 1, 2014
xiliu82 pushed a commit to xiliu82/spark that referenced this pull request Sep 4, 2014
…fix reflection issue

This PR updates previous Manifest for KafkaInputDStream's Decoder to ClassTag, also fix the problem addressed in [SPARK-2103](https://issues.apache.org/jira/browse/SPARK-2103).

Previous Java interface cannot actually get the type of Decoder, so when using this Manifest to reconstruct the decode object will meet reflection exception.

Also for other two Java interfaces, ClassTag[String] is useless because calling Scala API will get the right implicit ClassTag.

Current Kafka unit test cannot actually verify the interface. I've tested these interfaces in my local and distribute settings.

Author: jerryshao <saisai.shao@intel.com>

Closes apache#1508 from jerryshao/SPARK-2103 and squashes the following commits:

e90c37b [jerryshao] Add Mima excludes
7529810 [jerryshao] Change Manifest to ClassTag for KafkaInputDStream's Decoder and fix Decoder construct issue when using Java API
@salex89

salex89 commented Feb 16, 2015

Copy link
Copy Markdown

I'm not sure if this is the exactly same issue, but I am experience this with Spark 1.2.1 and Scala 2.10.4 also.

ERROR ReceiverTracker: Deregistered receiver for stream 0: Error starting receiver 0 -   java.lang.NoSuchMethodException: UserLocationEventDecoder.<init>(kafka.utils.VerifiableProperties)
at java.lang.Class.getConstructor0(Class.java:2971)
at java.lang.Class.getConstructor(Class.java:1812)
at org.apache.spark.streaming.kafka.KafkaReceiver.onStart(KafkaInputDStream.scala:106)
at   org.apache.spark.streaming.receiver.ReceiverSupervisor.startReceiver(ReceiverSupervisor.scala:121)
at org.apache.spark.streaming.receiver.ReceiverSupervisor.start(ReceiverSupervisor.scala:106)
at   org.apache.spark.streaming.scheduler.ReceiverTracker$ReceiverLauncher$$anonfun$8.apply(ReceiverTracker.scala:288)
at   org.apache.spark.streaming.scheduler.ReceiverTracker$ReceiverLauncher$$anonfun$8.apply(ReceiverTracker.scala:280)
at org.apache.spark.SparkContext$$anonfun$runJob$4.apply(SparkContext.scala:1353)
at org.apache.spark.SparkContext$$anonfun$runJob$4.apply(SparkContext.scala:1353)
at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:61)
at org.apache.spark.scheduler.Task.run(Task.scala:56)
at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:200)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

@jerryshao

Copy link
Copy Markdown
Contributor Author

Hi @salex89 , seems your exception is a little different to this PR, maybe I need a careful look at this exception, thanks for your reporting.

@salex89

salex89 commented Feb 20, 2015

Copy link
Copy Markdown

@jerryshao
OK, sorry for necroposting then. Should I open an issue on JIRA with the snippet?

@jerryshao

Copy link
Copy Markdown
Contributor Author

Yeah, please do it and describe it in detail so we can easily reproduce it.

sunchao pushed a commit to sunchao/spark that referenced this pull request Jun 2, 2023
…locks.enabled` by default (apache#1508)

### What changes were proposed in this pull request?

rdar://99068608 (SPARK-40198 Enable `spark.storage.decommission.(rdd|shuffle)Blocks.enabled` by default)

This PR aims to enable the following two configurations by default. Note that these storage configurations are disabled by default by the parent configuration, `spark.storage.decommission.enabled`, still. In addition, all decommission features including this storage decommissioning are disabled by `spark.decommission.enabled` by default.
- `spark.storage.decommission.rddBlocks.enabled`
- `spark.storage.decommission.shuffleBlocks.enabled`

### Why are the changes needed?

This will help users use the storage decommissioning feature more easily.

### Does this PR introduce _any_ user-facing change?

Yes, this will reduce the number of required configurations for decommission users.
However, these two configurations are disabled by two configurations still.

### How was this patch tested?

Pass the CIs.
MaxGekk added a commit to MaxGekk/spark that referenced this pull request Nov 12, 2026
### What changes were proposed in this pull request?

Two new cells in the operator census (`VarkaOperatorCensusCatalog`, `VarkaOperatorCensusProbe`), at 128 bits only. The census forks one JVM per operator and width and reads, from C2's inlining decisions, whether the operator's loop compiles to vector code (`I`), compiles but allocates (`I+A`), or falls back to the Vector API's Java implementation (`F`).

- `int.I2B_store64_masked` is the store Varka's emitter writes for a `TINYINT` result in a kernel driven at four int lanes. A byte has no 32-bit species, so each int group's `I2B` fills the low half of a `ByteVector.SPECIES_64` vector. That vector is stored with `intoMemorySegment` under `SPECIES_64.indexInRange(0, lanes)`, because its upper four lanes belong to the next group, and the last group has no next group to write over them. `lanes` is read at run time, as the kernel holds it in a local, so C2 cannot fold the mask to a constant. The cell is anchored on `VectorSupport::storeMasked`.
- `int.I2B_store64_combined` is the control, and the store form a fix would use. Two groups' `I2B` results, at parts 0 and -1, are OR-ed into one 64-bit byte vector and stored whole with no mask. It is anchored on `VectorSupport::store`.

Both loops write into a native byte buffer mapped once a call, as a kernel maps its output once a batch. The laptop's `sql/varka/operator_census.json` is regenerated at its own flags. The only other changes in it are the JDK line (25.0.4.1 to 25.0.5) and, in three decimal-store cells at two widths, `binaryOp` and `broadcastInt` swapping places in the intrinsics list; no verdict or allocation figure of an existing cell moved. The cells' reading under `-XX:UseAVX=2` comes from a one-off fork of the probe with the suite's own flags and is recorded in `sql/varka/plans/m8/results/VARKA-603-census-avx2.txt`. The operator census table in `sql/varka/skills/vector-api-and-width.md` gains a row for the cells. Row 603 of `m8/PLAN.md` is marked started.

| cell | laptop, own flags (AVX-512BW), 128 bits | laptop, `-XX:UseAVX=2`, 128 bits |
|---|---|---|
| `int.I2B_store64_masked` | `I`, 0.04 bytes a row | `F`, 20.04 bytes a row, `storeMasked failed to inline (intrinsic)` |
| `int.I2B_store64_combined` | `I`, 0.04 bytes a row | `I`, 0.04 bytes a row |

The 0.04 bytes a row is the output segment each call maps, about 40 bytes over 1024 rows.

### Why are the changes needed?

On an AVX2 host such as the EPYC 7763 CI runners, at 128 bits, Varka's checked `TINYINT` multiply (`y1 * y2` under ANSI, `try_multiply(y1, y2)`) runs at about 135 M rows/s. The same host's other `TINYINT` stores run at 19 to 40 G rows/s. The cause is the masked byte store. When C2 intrinsifies `storeMasked`, it asks whether the CPU has `StoreVectorMasked` for 8 byte lanes. HotSpot's x86 backend answers no for every subword element type (byte, short) without AVX-512BW, at every vector size, and a masked store always needs the predicate. So C2 leaves the call in place, and the Vector API's out-of-line Java loop runs instead, boxing the vector and the mask every time. The mask itself (`indexPartiallyInUpperRange`) and everything else in the loop do compile.

No census cell recorded this: the only masked-store cell was a long-lane decimal tail. The laptop has AVX-512BW, so it cannot show the refusal without `-XX:UseAVX=2`. These cells put the fact in the census per host. The emitter fix that follows can then point at a measured `F` for the masked form and a measured `I` for the form it switches to. The masked cell describes the host, not the emitter, so it stays `F` on AVX2 after the fix. The fix's evidence will be that kernels stop calling it.

### Does this PR introduce _any_ user-facing change?

No. Test code, a generated census file, a results text and documentation only.

### How was this patch tested?

- `VARKA_CENSUS_REGEN=true build/sbt 'catalyst/testOnly *VarkaOperatorCensusSuite'`: 8 tests passed (and again without `VARKA_CENSUS_REGEN` after the review fixes, comparing against the committed file), including `everyCellHasAVerdict`, which needs each cell's anchor among its loop's C2 decisions and no second species in a one-species fork. The new cells read `I` at 128 bits and `-` at 256 and 512.
- Direct forks of the probe for both cells at `-XX:MaxVectorSize=16`, at the host's flags and under `-XX:UseAVX=2` (the table above; commands and deciding lines in the results text). In the masked cell's tree, `indexPartiallyInUpperRange` is `(intrinsic)`, so the mask was not constant-folded.
- `dev/varka_regen_generated.sh --all` regenerated nothing. `python3 dev/varka_census.py --check` passes. `python3 dev/varka_push_check.py --lint` passes (pre-commit range, plan lint, quote check, census check, size, Error Prone, scalastyle, `dev/lint-java`).
- Not yet read: the EPYC 7763 column, expected `F` for the masked cell and `I` for the control. It comes from the width-audit workflow's x86 census artifact, which a push touching `VarkaOperatorCensus*.java` triggers.

One `/code-review high` pass: found 9 / fixed 6 / left 3 (fixed: control bound, plan rows, probe placement, runner paragraph, JDK line, row 603 state; left: no AVX2 test, PrintInlining only, segment mapped per call). Fixed: the combined control bounded to exactly 128 bits, since its two hard-coded parts fill the 64-bit vector only at four int lanes; both cells given the same plan rows; the new probe loops moved after the widening loads, not between them; the skills page's runner-difference paragraph now names the expected EPYC reading; its laptop JDK line updated; row 603 of `m8/PLAN.md` marked started with what this step built (the plan lint also requires it). Left, as trade-offs:
- The `UseAVX=2` reading is recorded in a results text, not held by a test. The plan keeps the per-host census file at the host's own flags, and the EPYC run will hold the same fact natively.
- The results text records the probe's `PrintInlining` decisions only. The `PrintIntrinsics`/`PrintCompilation` diagnosis of the emitted kernels belongs to the row's plan document, which lands separately.
- The output segment is mapped once a call (0.04 bytes a row), as the decimal store cells and the kernels do, not cached in a static field. That keeps the cell's allocation comparable to a kernel's.

One departure from the row's plan: it bounds both cells at 0 to 128 bits, and the control is bounded at exactly 128 here, since its two parts are hard-coded. The masked cell keeps 0 to 128: below 128 bits it still models the emitter's store at two int lanes, though the census does not run there today.

Line count: 67 counted lines, by `dev/varka_msg_check.py`.

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 5.5)
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.

5 participants