gaoyajun02 commented on code in PR #3261: URL: https://github.com/apache/celeborn/pull/3261#discussion_r2165467143
########## common/src/main/java/org/apache/celeborn/common/CommitMetadata.java: ########## @@ -0,0 +1,88 @@ +/* + * 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.celeborn.common; + +import java.util.Objects; +import java.util.concurrent.atomic.AtomicLong; + +import io.netty.buffer.ByteBuf; + +public class CommitMetadata { + + private AtomicLong bytes = new AtomicLong(); + private CelebornCRC32 crc = new CelebornCRC32(); + + public CommitMetadata() {} + + public CommitMetadata(long checksum, long numBytes) { Review Comment: ```suggestion public CommitMetadata(int checksum, long numBytes) { ``` ########## common/src/main/java/org/apache/celeborn/common/CommitMetadata.java: ########## @@ -0,0 +1,88 @@ +/* + * 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.celeborn.common; + +import java.util.Objects; +import java.util.concurrent.atomic.AtomicLong; + +import io.netty.buffer.ByteBuf; + +public class CommitMetadata { + + private AtomicLong bytes = new AtomicLong(); Review Comment: ```suggestion private final AtomicLong bytes = new AtomicLong(); ``` ########## client/src/main/scala/org/apache/celeborn/client/commit/ReducePartitionCommitHandler.scala: ########## @@ -268,16 +277,40 @@ class ReducePartitionCommitHandler( numMappers: Int, partitionId: Int, pushFailedBatches: util.Map[String, LocationPushFailedBatches], - recordWorkerFailure: ShuffleFailedWorkers => Unit): (Boolean, Boolean) = { + recordWorkerFailure: ShuffleFailedWorkers => Unit, + numPartitions: Int, + crc32PerPartition: Array[Int], + bytesWrittenPerPartition: Array[Long]): (Boolean, Boolean) = { shuffleMapperAttempts.synchronized { if (getMapperAttempts(shuffleId) == null) { logDebug(s"[handleMapperEnd] $shuffleId not registered, create one.") - initMapperAttempts(shuffleId, numMappers) + initMapperAttempts(shuffleId, numMappers, numPartitions) } val attempts = shuffleMapperAttempts.get(shuffleId) if (attempts(mapId) < 0) { attempts(mapId) = attemptId + if (shuffleIntegrityCheckEnabled) { + val commitMetadataArray = commitMetadataForReducer.get(shuffleId) + checkState( + commitMetadataArray != null, + "commitMetadataArray can only be null if shuffleId %s is not registered!", + shuffleId) + for (i <- 0 until numPartitions) { + if (bytesWrittenPerPartition(i) != 0) { + val commitMetadata = commitMetadataArray(i) + if (commitMetadata == null) { + commitMetadataArray(i) = + new CommitMetadata(crc32PerPartition(i), bytesWrittenPerPartition(i)) + } else { + commitMetadata.addCommitData(new CommitMetadata( + crc32PerPartition(i), + bytesWrittenPerPartition(i))) + } + } + } + } + Review Comment: After we @buska88 preliminary offline discussion, It appears that after the above suggested changes, commitMetadataForReducer supports concurrent updates, so it's recommended to move the shuffleIntegrityCheck logic outside the shuffleMapperAttempts lock for execution. @gauravkm Please take a look. ``` val (mapperAttemptFinishedSuccess, allMapperFinished) = shuffleMapperAttempts.synchronized { .. } if (shuffleIntegrityCheckEnabled && mapperAttemptFinishedSuccess) { // update commitMetadataForReducer } (mapperAttemptFinishedSuccess, allMapperFinished) ``` ########## common/src/main/java/org/apache/celeborn/common/CommitMetadata.java: ########## @@ -0,0 +1,88 @@ +/* + * 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.celeborn.common; + +import java.util.Objects; +import java.util.concurrent.atomic.AtomicLong; + +import io.netty.buffer.ByteBuf; + +public class CommitMetadata { + + private AtomicLong bytes = new AtomicLong(); + private CelebornCRC32 crc = new CelebornCRC32(); + + public CommitMetadata() {} + + public CommitMetadata(long checksum, long numBytes) { + this.bytes = new AtomicLong(numBytes); Review Comment: ```suggestion this.bytes.addAndGet(numBytes); ``` ########## common/src/main/java/org/apache/celeborn/common/CommitMetadata.java: ########## @@ -0,0 +1,88 @@ +/* + * 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.celeborn.common; + +import java.util.Objects; +import java.util.concurrent.atomic.AtomicLong; + +import io.netty.buffer.ByteBuf; + +public class CommitMetadata { + + private AtomicLong bytes = new AtomicLong(); + private CelebornCRC32 crc = new CelebornCRC32(); Review Comment: ```suggestion private final CelebornCRC32 crc = new CelebornCRC32(); ``` ########## common/src/main/java/org/apache/celeborn/common/CommitMetadata.java: ########## @@ -0,0 +1,88 @@ +/* + * 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.celeborn.common; + +import java.util.Objects; +import java.util.concurrent.atomic.AtomicLong; + +import io.netty.buffer.ByteBuf; + +public class CommitMetadata { + + private AtomicLong bytes = new AtomicLong(); + private CelebornCRC32 crc = new CelebornCRC32(); + + public CommitMetadata() {} + + public CommitMetadata(long checksum, long numBytes) { + this.bytes = new AtomicLong(numBytes); + this.crc = new CelebornCRC32((int) checksum); Review Comment: ```suggestion this.crc.addChecksum(checksum); ``` ########## client/src/main/scala/org/apache/celeborn/client/commit/ReducePartitionCommitHandler.scala: ########## @@ -301,19 +334,73 @@ class ReducePartitionCommitHandler( override def registerShuffle( shuffleId: Int, numMappers: Int, - isSegmentGranularityVisible: Boolean): Unit = { - super.registerShuffle(shuffleId, numMappers, isSegmentGranularityVisible) + isSegmentGranularityVisible: Boolean, + numPartitions: Int): Unit = { + super.registerShuffle(shuffleId, numMappers, isSegmentGranularityVisible, numPartitions) getReducerFileGroupRequest.put(shuffleId, new util.HashSet[MultiSerdeVersionRpcContext]()) - initMapperAttempts(shuffleId, numMappers) + initMapperAttempts(shuffleId, numMappers, numPartitions) + } + + override def finishPartition( + shuffleId: Int, + partitionId: Int, + startMapIndex: Int, + endMapIndex: Int, + actualCommitMetadata: CommitMetadata): (Boolean, String) = { + logDebug(s"finish Partition call: shuffleId: $shuffleId, " + + s"partitionId: $partitionId, " + + s"startMapIndex: $startMapIndex " + + s"endMapIndex: $endMapIndex, " + + s"actualCommitMetadata: $actualCommitMetadata") + val map = commitMetadataForReducer.get(shuffleId) + checkState( + map != null, + "CommitMetadata map cannot be null for a registered shuffleId: %d", + shuffleId) + val expectedCommitMetadata = map(partitionId) + if (endMapIndex == Integer.MAX_VALUE) { + // complete partition available + val bool = CommitMetadata.checkCommitMetadata(actualCommitMetadata, expectedCommitMetadata) + var message = "" + if (!bool) { + message = + s"CommitMetadata mismatch for shuffleId: $shuffleId partitionId: $partitionId expected: $expectedCommitMetadata actual: $actualCommitMetadata" + } else { + logInfo( + s"CommitMetadata matched for shuffleID : $shuffleId, partitionId: $partitionId expected: $expectedCommitMetadata actual: $actualCommitMetadata") + } + return (bool, message) + } + + val splitSkewPartitionWithoutMapRange = + ClientUtils.readSkewPartitionWithoutMapRange(conf, startMapIndex, endMapIndex) + + val validator = aqePartitionCompletenessValidator.computeIfAbsent( + shuffleId, + new java.util.function.Function[Int, PartitionCompletenessValidator] { + override def apply(key: Int): PartitionCompletenessValidator = + new PartitionCompletenessValidator() + }) + validator.validateSubPartition( + partitionId, + startMapIndex, + endMapIndex, + actualCommitMetadata, + expectedCommitMetadata, + shuffleMapperAttempts.get(shuffleId).length, + splitSkewPartitionWithoutMapRange) } - private def initMapperAttempts(shuffleId: Int, numMappers: Int): Unit = { + private def initMapperAttempts(shuffleId: Int, numMappers: Int, numPartitions: Int): Unit = { shuffleMapperAttempts.synchronized { if (!shuffleMapperAttempts.containsKey(shuffleId)) { val attempts = new Array[Int](numMappers) 0 until numMappers foreach (idx => attempts(idx) = -1) shuffleMapperAttempts.put(shuffleId, attempts) } + if (shuffleIntegrityCheckEnabled) { + commitMetadataForReducer.put(shuffleId, new Array[CommitMetadata](numPartitions)) Review Comment: ```suggestion commitMetadataForReducer.put(shuffleId, Array.fill(numPartitions)(new CommitMetadata())) ``` -- 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]
