-
Notifications
You must be signed in to change notification settings - Fork 9.1k
[HDDS-1200] Add support for checksum verification in data scrubber #1154
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,11 @@ | |
import com.google.common.primitives.Longs; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos; | ||
import org.apache.hadoop.hdfs.util.Canceler; | ||
import org.apache.hadoop.hdfs.util.DataTransferThrottler; | ||
import org.apache.hadoop.ozone.common.Checksum; | ||
import org.apache.hadoop.ozone.common.ChecksumData; | ||
import org.apache.hadoop.ozone.common.OzoneChecksumException; | ||
import org.apache.hadoop.ozone.container.common.helpers.BlockData; | ||
import org.apache.hadoop.ozone.container.common.helpers.ChunkInfo; | ||
import org.apache.hadoop.ozone.container.common.helpers.ContainerUtils; | ||
|
@@ -30,12 +35,15 @@ | |
import org.apache.hadoop.ozone.container.keyvalue.helpers.BlockUtils; | ||
import org.apache.hadoop.ozone.container.keyvalue.helpers.ChunkUtils; | ||
import org.apache.hadoop.ozone.container.keyvalue.helpers.KeyValueContainerLocationUtil; | ||
import org.apache.hadoop.ozone.container.common.utils.ReferenceCountedDB; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.io.InputStream; | ||
import java.util.Arrays; | ||
|
||
import org.apache.hadoop.ozone.container.common.utils.ReferenceCountedDB; | ||
import org.apache.ratis.thirdparty.com.google.protobuf.ByteString; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
@@ -101,13 +109,13 @@ public boolean fastCheck() { | |
* | ||
* @return true : integrity checks pass, false : otherwise. | ||
*/ | ||
public boolean fullCheck() { | ||
public boolean fullCheck(DataTransferThrottler throttler, Canceler canceler) { | ||
boolean valid = false; | ||
|
||
try { | ||
valid = fastCheck(); | ||
if (valid) { | ||
checkBlockDB(); | ||
scanData(throttler, canceler); | ||
} | ||
} catch (IOException e) { | ||
handleCorruption(e); | ||
|
@@ -194,7 +202,8 @@ private void checkContainerFile() throws IOException { | |
} | ||
} | ||
|
||
private void checkBlockDB() throws IOException { | ||
private void scanData(DataTransferThrottler throttler, Canceler canceler) | ||
throws IOException { | ||
/** | ||
* Check the integrity of the DB inside each container. | ||
* In Scope: | ||
|
@@ -220,43 +229,67 @@ private void checkBlockDB() throws IOException { | |
throw new IOException(dbFileErrorMsg); | ||
} | ||
|
||
|
||
onDiskContainerData.setDbFile(dbFile); | ||
try(ReferenceCountedDB db = | ||
BlockUtils.getDB(onDiskContainerData, checkConfig)) { | ||
iterateBlockDB(db); | ||
} | ||
} | ||
BlockUtils.getDB(onDiskContainerData, checkConfig); | ||
KeyValueBlockIterator kvIter = new KeyValueBlockIterator(containerID, | ||
new File(onDiskContainerData.getContainerPath()))) { | ||
|
||
private void iterateBlockDB(ReferenceCountedDB db) | ||
throws IOException { | ||
Preconditions.checkState(db != null); | ||
|
||
// get "normal" keys from the Block DB | ||
try(KeyValueBlockIterator kvIter = new KeyValueBlockIterator(containerID, | ||
new File(onDiskContainerData.getContainerPath()))) { | ||
|
||
// ensure there is a chunk file for each key in the DB | ||
while (kvIter.hasNext()) { | ||
while(kvIter.hasNext()) { | ||
BlockData block = kvIter.nextBlock(); | ||
|
||
List<ContainerProtos.ChunkInfo> chunkInfoList = block.getChunks(); | ||
for (ContainerProtos.ChunkInfo chunk : chunkInfoList) { | ||
File chunkFile; | ||
chunkFile = ChunkUtils.getChunkFile(onDiskContainerData, | ||
for(ContainerProtos.ChunkInfo chunk : block.getChunks()) { | ||
File chunkFile = ChunkUtils.getChunkFile(onDiskContainerData, | ||
ChunkInfo.getFromProtoBuf(chunk)); | ||
|
||
if (!chunkFile.exists()) { | ||
// concurrent mutation in Block DB? lookup the block again. | ||
byte[] bdata = db.getStore().get( | ||
Longs.toByteArray(block.getBlockID().getLocalID())); | ||
if (bdata == null) { | ||
LOG.trace("concurrency with delete, ignoring deleted block"); | ||
break; // skip to next block from kvIter | ||
} else { | ||
String errorStr = "Missing chunk file " | ||
+ chunkFile.getAbsolutePath(); | ||
throw new IOException(errorStr); | ||
if (bdata != null) { | ||
throw new IOException("Missing chunk file " | ||
+ chunkFile.getAbsolutePath()); | ||
} | ||
} else if (chunk.getChecksumData().getType() | ||
!= ContainerProtos.ChecksumType.NONE){ | ||
anuengineer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
int length = chunk.getChecksumData().getChecksumsList().size(); | ||
ChecksumData cData = new ChecksumData( | ||
chunk.getChecksumData().getType(), | ||
chunk.getChecksumData().getBytesPerChecksum(), | ||
chunk.getChecksumData().getChecksumsList()); | ||
long bytesRead = 0; | ||
byte[] buffer = new byte[cData.getBytesPerChecksum()]; | ||
try (InputStream fs = new FileInputStream(chunkFile)) { | ||
int i = 0, v = 0; | ||
for (; i < length; i++) { | ||
v = fs.read(buffer); | ||
if (v == -1) { | ||
break; | ||
} | ||
bytesRead += v; | ||
throttler.throttle(v, canceler); | ||
Checksum cal = new Checksum(cData.getChecksumType(), | ||
cData.getBytesPerChecksum()); | ||
ByteString expected = cData.getChecksums().get(i); | ||
ByteString actual = cal.computeChecksum(buffer) | ||
.getChecksums().get(0); | ||
if (!Arrays.equals(expected.toByteArray(), | ||
actual.toByteArray())) { | ||
throw new OzoneChecksumException(String | ||
.format("Inconsistent read for chunk=%s len=%d expected" + | ||
" checksum %s actual checksum %s for block %s", | ||
chunk.getChunkName(), chunk.getLen(), | ||
Arrays.toString(expected.toByteArray()), | ||
Arrays.toString(actual.toByteArray()), | ||
block.getBlockID())); | ||
} | ||
|
||
} | ||
if (v == -1 && i < length) { | ||
throw new OzoneChecksumException(String | ||
.format("Inconsistent read for chunk=%s expected length=%d" | ||
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. It might be a good idea to log the blockId as well in the exception msg. 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. done. |
||
+ " actual length=%d for block %s", | ||
chunk.getChunkName(), | ||
chunk.getLen(), bytesRead, block.getBlockID())); | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can you please run this in a profiler mode -- and make sure there are no memory leaks in this code path. Nothing to do with your patch at all. Just that we have found some issues here earlier. Just run it under something like VisualVM and see if we release all memory when get out of the loop.
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.
Done