Skip to content
Merged
Changes from 2 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
Comment thread
sumitagrawl marked this conversation as resolved.
for (UnhealthyContainers rec : recs) {
Comment thread
ArafatKhan2198 marked this conversation as resolved.
Outdated
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);
Comment thread
sumitagrawl marked this conversation as resolved.
Outdated
LOG.debug("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);
Comment thread
sumitagrawl marked this conversation as resolved.
Outdated
throw new RuntimeException("Recon failed to insert " + recs.size() + " num of unhealthy container records.", e);
}
}

}