Skip to content
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

HDDS-12585. Ozone Recon - ContainerHealthTask ConstraintViolationException error handling. #8070

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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 @@ -17,13 +17,15 @@

package org.apache.hadoop.ozone.recon.persistence;

import static org.apache.ozone.recon.schema.ContainerSchemaDefinition.UNHEALTHY_CONTAINERS_TABLE_NAME;
import static org.apache.ozone.recon.schema.ContainerSchemaDefinition.UnHealthyContainerStates.ALL_REPLICAS_BAD;
import static org.apache.ozone.recon.schema.ContainerSchemaDefinition.UnHealthyContainerStates.UNDER_REPLICATED;
import static org.apache.ozone.recon.schema.generated.tables.UnhealthyContainersTable.UNHEALTHY_CONTAINERS;
import static org.jooq.impl.DSL.count;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.sql.Connection;
import java.util.List;
import org.apache.hadoop.ozone.recon.api.types.UnhealthyContainersSummary;
import org.apache.ozone.recon.schema.ContainerSchemaDefinition;
Expand All @@ -35,6 +37,7 @@
import org.jooq.DSLContext;
import org.jooq.Record;
import org.jooq.SelectQuery;
import org.jooq.exception.DataAccessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -123,7 +126,26 @@ public void insertUnhealthyContainerRecords(List<UnhealthyContainers> recs) {
rec.getContainerState());
});
}
unhealthyContainersDao.insert(recs);

try (Connection connection = containerSchemaDefinition.getDataSource().getConnection()) {
connection.setAutoCommit(false); // Turn off auto-commit for transactional control
for (UnhealthyContainers rec : recs) {
try {
unhealthyContainersDao.insert(rec);
} catch (DataAccessException dataAccessException) {
// Log the error and just update other fields of the existing record
// in case of ConstraintViolationException being actually thrown.
unhealthyContainersDao.update(rec);
LOG.error("Error while inserting unhealthy container record: {}", rec,
dataAccessException);
}
}
// Commit all the records inserted and updated.
connection.commit();
} catch (Exception e) {
LOG.error("Failed to get connection over {} ", UNHEALTHY_CONTAINERS_TABLE_NAME, e);
throw new RuntimeException("Recon failed to insert " + recs.size() + " num of unhealthy container records.", e);
}
}

}