viirya commented on code in PR #55620:
URL: https://github.com/apache/spark/pull/55620#discussion_r3271406932


##########
common/network-common/src/main/java/org/apache/spark/network/shuffle/streaming/CreditControlMessage.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.network.shuffle.streaming;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.CompositeByteBuf;
+
+/**
+ * Reader → writer control message.
+ *
+ * Current function: serves as a connection-establishment and per-consumption 
"ready"
+ * signal. The writer uses receipt of any CreditControlMessage as the trigger 
that the
+ * reader is ready to receive, and does not act on the numeric value of {@link
+ * #numMessages}. Backpressure today is handled at the TCP layer via channel 
autoRead,
+ * not via this message.
+ *
+ * Future function: this message is reserved as the carrier for a future 
credit-based
+ * flow-control extension. When that extension lands, {@link #numMessages} 
will carry
+ * the number of additional DataMessages the writer may send beyond any
+ * previously-granted credit (i.e., a credit-grant delta).
+ */
+public final class CreditControlMessage extends StreamingShuffleMessage {
+  public final int shuffleWriterId;
+  public final int shuffleReaderId;
+
+  /**
+   * In the current protocol revision the writer ignores this value and treats 
any
+   * CreditControlMessage as a "reader is ready" signal; senders should pass 1.
+   *
+   * Reserved for the future credit-based flow-control extension, in which 
this field

Review Comment:
   This field currently has no semantic meaning (the receiver ignores it 
entirely), yet it occupies 4 bytes on the wire. The javadoc says "senders 
should pass 1" and reserves it for a future credit-based flow-control extension.
   
   The problem: "should pass 1" is only a comment — the constructor does not 
enforce it. Future contributors may pass 0, -1, or some other value out of 
habit or by copy-paste. Tests will still pass and behavior will look correct 
today (since no one reads the value), but once credit semantics are actually 
enabled, these silently drifted call sites will turn into bugs that are hard to 
trace back.
   
   Suggestion: add a if (numMessages != 1) throw ... check in the constructor 
to promote the "reserved" contract from a comment into a code-level constraint. 
Comments are documentation; validation is contract — reserved fields are 
exactly the case where that distinction matters.



-- 
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]

Reply via email to