You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/11/27 02:24:29 UTC

[GitHub] [spark] vinodkc commented on a diff in pull request #38781: [SPARK-41246][core] Solve the problem of RddId negative

vinodkc commented on code in PR #38781:
URL: https://github.com/apache/spark/pull/38781#discussion_r1032832334


##########
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)
 
   /** 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 {
+      id = nextRddId.getAndIncrement()
+      if (id < 0) {

Review Comment:
   Instead of this `if (id < 0)` condition, else part of the previous `if (id >= 0)` can be used 



##########
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)
 
   /** 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 {
+      id = nextRddId.getAndIncrement()

Review Comment:
   Can we avoid the duplicate call of 'nextRddId.getAndIncrement()'?



##########
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)
 
   /** 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 {
+      id = nextRddId.getAndIncrement()
+      if (id < 0) {
+        nextRddId = new AtomicInteger(0)
+        id = nextRddId.getAndIncrement()

Review Comment:
   Can we use this?
   ``` 
   nextRddId = new AtomicInteger(1)
   id = nextRddId 
   ```



-- 
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: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org