-
Notifications
You must be signed in to change notification settings - Fork 28.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP][SPARK-35275][CORE] Add checksum for shuffle blocks and diagnose corruption #32385
Changes from all commits
a7707f6
11cbe38
6c6def7
a8466f8
1bdf396
3ad3b52
38976b7
646f3cf
c09ccd0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* 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.corruption; | ||
|
||
public enum Cause { | ||
DISK, NETWORK, UNKNOWN; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ | |
import org.apache.spark.network.client.RpcResponseCallback; | ||
import org.apache.spark.network.client.TransportClient; | ||
import org.apache.spark.network.client.TransportClientFactory; | ||
import org.apache.spark.network.corruption.Cause; | ||
import org.apache.spark.network.shuffle.protocol.BlockTransferMessage; | ||
import org.apache.spark.network.shuffle.protocol.GetLocalDirsForExecutors; | ||
import org.apache.spark.network.shuffle.protocol.LocalDirsForExecutors; | ||
|
@@ -47,6 +48,15 @@ public abstract class BlockStoreClient implements Closeable { | |
protected volatile TransportClientFactory clientFactory; | ||
protected String appId; | ||
|
||
public Cause diagnoseCorruption( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Include javadoc ? |
||
String host, | ||
int port, | ||
String execId, | ||
String blockId, | ||
long checksum) { | ||
return Cause.UNKNOWN; | ||
} | ||
|
||
/** | ||
* Fetch a sequence of blocks from a remote node asynchronously, | ||
* | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* 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.protocol; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import org.apache.commons.lang3.builder.ToStringBuilder; | ||
import org.apache.commons.lang3.builder.ToStringStyle; | ||
import org.apache.spark.network.corruption.Cause; | ||
|
||
/** Response to the {@link DiagnoseCorruption} */ | ||
public class CorruptionCause extends BlockTransferMessage { | ||
public Cause cause; | ||
|
||
public CorruptionCause(Cause cause) { | ||
this.cause = cause; | ||
} | ||
|
||
@Override | ||
protected Type type() { | ||
return Type.CORRUPTION_CAUSE; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) | ||
.append("cause", cause) | ||
.toString(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
CorruptionCause that = (CorruptionCause) o; | ||
return cause == that.cause; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return cause.hashCode(); | ||
} | ||
|
||
@Override | ||
public int encodedLength() { | ||
return 4; /* encoded length of cause */ | ||
} | ||
|
||
@Override | ||
public void encode(ByteBuf buf) { | ||
buf.writeInt(cause.ordinal()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
public static CorruptionCause decode(ByteBuf buf) { | ||
int ordinal = buf.readInt(); | ||
return new CorruptionCause(Cause.values()[ordinal]); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* 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.protocol; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import org.apache.commons.lang3.builder.ToStringBuilder; | ||
import org.apache.commons.lang3.builder.ToStringStyle; | ||
import org.apache.spark.network.protocol.Encoders; | ||
|
||
/** Request to get the cause of a corrupted block. Returns {@link CorruptionCause} */ | ||
public class DiagnoseCorruption extends BlockTransferMessage { | ||
private final String appId; | ||
private final String execId; | ||
public final String blockId; | ||
public final long checksum; | ||
|
||
public DiagnoseCorruption(String appId, String execId, String blockId, long checksum) { | ||
this.appId = appId; | ||
this.execId = execId; | ||
this.blockId = blockId; | ||
this.checksum = checksum; | ||
} | ||
|
||
@Override | ||
protected Type type() { | ||
return Type.DIAGNOSE_CORRUPTION; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) | ||
.append("appId", appId) | ||
.append("execId", execId) | ||
.append("blockId", blockId) | ||
.append("checksum", checksum) | ||
.toString(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
|
||
DiagnoseCorruption that = (DiagnoseCorruption) o; | ||
|
||
if (!appId.equals(that.appId)) return false; | ||
if (!execId.equals(that.execId)) return false; | ||
if (!blockId.equals(that.blockId)) return false; | ||
return checksum == that.checksum; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. super nit: check |
||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = appId.hashCode(); | ||
result = 31 * result + execId.hashCode(); | ||
result = 31 * result + blockId.hashCode(); | ||
result = 31 * result + (int) checksum; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: checksum -> |
||
return result; | ||
} | ||
|
||
@Override | ||
public int encodedLength() { | ||
return Encoders.Strings.encodedLength(appId) | ||
+ Encoders.Strings.encodedLength(execId) | ||
+ Encoders.Strings.encodedLength(blockId) | ||
+ 8; /* encoded length of checksum */ | ||
} | ||
|
||
@Override | ||
public void encode(ByteBuf buf) { | ||
Encoders.Strings.encode(buf, appId); | ||
Encoders.Strings.encode(buf, execId); | ||
Encoders.Strings.encode(buf, blockId); | ||
buf.writeLong(checksum); | ||
} | ||
|
||
public static DiagnoseCorruption decode(ByteBuf buf) { | ||
String appId = Encoders.Strings.decode(buf); | ||
String execId = Encoders.Strings.decode(buf); | ||
String blockId = Encoders.Strings.decode(buf); | ||
long checksum = buf.readLong(); | ||
return new DiagnoseCorruption(appId, execId, blockId, checksum); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* 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.io; | ||
|
||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
import java.nio.channels.WritableByteChannel; | ||
|
||
import org.apache.spark.annotation.Private; | ||
|
||
/** | ||
* :: Private :: | ||
* A wrapper for {@link java.nio.channels.WritableByteChannel} with the ability of counting | ||
* written bytes. | ||
*/ | ||
@Private | ||
public class CountingWritableChannel implements WritableByteChannel { | ||
|
||
private WritableByteChannel delegate; | ||
|
||
private long count; | ||
|
||
public CountingWritableChannel(WritableByteChannel delegate) { | ||
this.delegate = delegate; | ||
this.count = 0; | ||
} | ||
|
||
public long getCount() { | ||
return this.count; | ||
} | ||
|
||
@Override | ||
public int write(ByteBuffer src) throws IOException { | ||
int written = delegate.write(src); | ||
if (written > 0) { | ||
count += written; | ||
} | ||
return written; | ||
} | ||
|
||
@Override | ||
public boolean isOpen() { | ||
return delegate.isOpen(); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
delegate.close(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.nio.ByteBuffer; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert ? |
||
import java.nio.channels.FileChannel; | ||
import java.util.Optional; | ||
import javax.annotation.Nullable; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UNKNOWN
is handling three cases right now:Anything else ?
For the last, move it to a separate
Cause
?