mridulm commented on code in PR #38781:
URL: https://github.com/apache/spark/pull/38781#discussion_r1045404199
##########
core/src/main/scala/org/apache/spark/SparkContext.scala:
##########
@@ -2570,10 +2570,23 @@ class SparkContext(config: SparkConf) extends Logging {
private[spark] def newShuffleId(): Int = nextShuffleId.getAndIncrement()
- private val nextRddId = new AtomicInteger(0)
+ private var nextRddId = new AtomicInteger(0)
Review Comment:
You dont need to make this a `var` - see below.
##########
core/src/main/scala/org/apache/spark/SparkContext.scala:
##########
@@ -2570,10 +2570,20 @@ class SparkContext(config: SparkConf) extends Logging {
private[spark] def newShuffleId(): Int = nextShuffleId.getAndIncrement()
- private val nextRddId = new AtomicInteger(0)
+ private var nextRddId = new AtomicInteger(0)
/** Register a new RDD, returning its RDD ID */
- private[spark] def newRddId(): Int = nextRddId.getAndIncrement()
+ private[spark] def newRddId(): Int = {
+ var id = nextRddId.getAndIncrement()
+ if (id >= 0) {
+ return id
+ }
+ this.synchronized {
+ nextRddId = new AtomicInteger(0)
+ id = nextRddId.getAndIncrement()
+ }
+ id
+ }
Review Comment:
Something like this would remove the need for synchronization, etc
```suggestion
private[spark] def newRddId(): Int = {
nextRddId.getAndUpdate { i =>
var nextValue = i + 1
if (nextValue < 0) {
nextValue = 0
}
nextValue
}
}
```
--
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]