Skip to content

[HDDS-1201] Reporting corrupted containers info to SCM #1032

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

Merged
merged 1 commit into from
Jul 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ ContainerReplicaProto getContainerReport()

/**
* check and report the structural integrity of the container.
* @return true if the integrity checks pass
* false otherwise
*/
void check() throws StorageContainerException;
boolean check();
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,12 @@ public EndpointStateMachine.EndPointStates call() throws Exception {
addReports(requestBuilder);
addContainerActions(requestBuilder);
addPipelineActions(requestBuilder);
SCMHeartbeatRequestProto request = requestBuilder.build();
if (LOG.isDebugEnabled()) {
LOG.debug("Sending heartbeat message :: {}", request.toString());
}
SCMHeartbeatResponseProto reponse = rpcEndpoint.getEndPoint()
.sendHeartbeat(requestBuilder.build());
.sendHeartbeat(request);
processResponse(reponse, datanodeDetailsProto);
rpcEndpoint.setLastSuccessfulHeartbeat(ZonedDateTime.now());
rpcEndpoint.zeroMissedCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ public File getContainerDBFile() {
/**
* run integrity checks on the Container metadata.
*/
public void check() throws StorageContainerException {
public boolean check() {
ContainerCheckLevel level = ContainerCheckLevel.NO_CHECK;
long containerId = containerData.getContainerID();

Expand All @@ -671,14 +671,12 @@ public void check() throws StorageContainerException {
containerData.getState());
break;
default:
throw new StorageContainerException(
"Invalid Container state found for Container : " + containerData
.getContainerID(), INVALID_CONTAINER_STATE);
break;
}

if (level == ContainerCheckLevel.NO_CHECK) {
LOG.debug("Skipping integrity checks for Container Id : {}", containerId);
return;
return true;
}

KeyValueContainerCheck checker =
Expand All @@ -687,17 +685,11 @@ public void check() throws StorageContainerException {

switch (level) {
case FAST_CHECK:
checker.fastCheck();
break;
return checker.fastCheck();
case FULL_CHECK:
checker.fullCheck();
break;
case NO_CHECK:
LOG.debug("Skipping integrity checks for Container Id : {}", containerId);
break;
return checker.fullCheck();
default:
// we should not be here at all, scuttle the ship!
Preconditions.checkNotNull(0, "Invalid Containercheck level");
return true;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,37 +72,22 @@ public KeyValueContainerCheck(String metadataPath, Configuration conf,
* These checks do not look inside the metadata files.
* Applicable for OPEN containers.
*
* @return true : corruption detected, false : no corruption.
* @return true : integrity checks pass, false : otherwise.
*/
public boolean fastCheck() {
boolean corruption = false;
LOG.info("Running basic checks for container {};", containerID);
boolean valid = false;
try {
basicChecks();
loadContainerData();
checkLayout();
checkContainerFile();
valid = true;

} catch (IOException e) {
handleCorruption(e);
corruption = true;
}

return corruption;
}

/**
* Checks :
* 1. check directory layout
* 2. check container file
*
* @return void
*/

private void basicChecks() throws IOException {

LOG.trace("Running basic checks for container {};", containerID);

loadContainerData();

checkLayout();
checkContainerFile();
return valid;
}

/**
Expand All @@ -114,21 +99,22 @@ private void basicChecks() throws IOException {
* <p>
* fullCheck is a superset of fastCheck
*
* @return true : corruption detected, false : no corruption.
* @return true : integrity checks pass, false : otherwise.
*/
public boolean fullCheck() {
boolean corruption = false;
boolean valid = false;

try {
basicChecks();
checkBlockDB();

valid = fastCheck();
if (valid) {
checkBlockDB();
}
} catch (IOException e) {
handleCorruption(e);
corruption = true;
valid = false;
}

return corruption;
return valid;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -895,8 +895,17 @@ public void markContainerForClose(Container container)
public void markContainerUnhealthy(Container container)
throws IOException {
if (container.getContainerState() != State.UNHEALTHY) {
container.markContainerUnhealthy();
sendICR(container);
try {
container.markContainerUnhealthy();
} catch (IOException ex) {
// explicitly catch IOException here since the this operation
// will fail if the Rocksdb metadata is corrupted.
long id = container.getContainerData().getContainerID();
LOG.warn("Unexpected error while marking container "
+id+ " as unhealthy", ex);
} finally {
sendICR(container);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ public void markContainerForClose(final long containerId)
}
}

/**
* Marks the container as UNHEALTHY.
*
* @param containerId Id of the container to update
* @throws IOException in case of exception
*/
public void markContainerUnhealthy(final long containerId)
throws IOException {
Container container = containerSet.getContainer(containerId);
getHandler(container).markContainerUnhealthy(container);
}

/**
* Returns the container report.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@

package org.apache.hadoop.ozone.container.ozoneimpl;

import com.google.common.annotations.VisibleForTesting;
import org.apache.commons.net.ntp.TimeStamp;
import org.apache.hadoop.hdds.conf.OzoneConfiguration;
import org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException;
import org.apache.hadoop.ozone.container.common.interfaces.Container;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Iterator;

/**
Expand Down Expand Up @@ -56,11 +57,7 @@ public ContainerScrubber(OzoneConfiguration conf,
LOG.info("Background ContainerScrubber starting up");
while (true) {

try {
scrub();
} catch (StorageContainerException e) {
LOG.error("Scrubber encountered StorageContainerException.");
}
scrub();

if (this.halt) {
break; // stop and exit if requested
Expand Down Expand Up @@ -129,27 +126,33 @@ private void throttleScrubber(TimeStamp startTime) {
}
}

private void scrub() throws StorageContainerException {
private void scrub() {
Iterator<Container> containerIt = controller.getContainers();
long count = 0;

while (containerIt.hasNext() && !halt) {
TimeStamp startTime = new TimeStamp(System.currentTimeMillis());
Container container = containerIt.next();

try {
container.check();
} catch (StorageContainerException e) {
LOG.error("Error unexpected exception {} for Container {}", e,
container.getContainerData().getContainerID());
container.markContainerUnhealthy();
// XXX Action required here
scrub(container);
} catch (IOException e) {
LOG.info("Unexpected error while scrubbing container {}",
container.getContainerData().getContainerID());
}

count++;

throttleScrubber(startTime);
}

LOG.debug("iterator ran integrity checks on {} containers", count);
}

@VisibleForTesting
public void scrub(Container container) throws IOException {
if (!container.check()) {
controller.markContainerUnhealthy(
container.getContainerData().getContainerID());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@

import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_METADATA_STORE_IMPL_LEVELDB;
import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_METADATA_STORE_IMPL_ROCKSDB;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

/**
Expand Down Expand Up @@ -101,7 +100,7 @@ public TestKeyValueContainerCheck(String metadataImpl) {
int deletedBlocks = 1;
int normalBlocks = 3;
int chunksPerBlock = 4;
boolean corruption = false;
boolean valid = false;

// test Closed Container
createContainerWithBlocks(containerID, normalBlocks, deletedBlocks, 65536,
Expand All @@ -115,14 +114,14 @@ public TestKeyValueContainerCheck(String metadataImpl) {
containerID);

// first run checks on a Open Container
corruption = kvCheck.fastCheck();
assertFalse(corruption);
valid = kvCheck.fastCheck();
assertTrue(valid);

container.close();

// next run checks on a Closed Container
corruption = kvCheck.fullCheck();
assertFalse(corruption);
valid = kvCheck.fullCheck();
assertTrue(valid);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public IncrementalContainerReportHandler(
@Override
public void onMessage(final IncrementalContainerReportFromDatanode report,
final EventPublisher publisher) {
LOG.debug("Processing incremental container report from data node {}",
report.getDatanodeDetails().getUuid());

for (ContainerReplicaProto replicaProto :
report.getReport().getReportList()) {
Expand Down
Loading