Skip to content
Merged
Show file tree
Hide file tree
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 @@ -37,13 +37,16 @@
public class ListContainers extends AbstractSubcommand implements Callable<Void> {

@CommandLine.Option(names = {"--state"},
description = "Life cycle state of the container.",
required = true)
description = "Life cycle state of the container.")
private HddsProtos.LifeCycleState state;

@CommandLine.Mixin
private ListOptions listOptions;

@CommandLine.Option(names = {"--duplicate-open"},
description = "List all the containers which have duplicate open states.")
private boolean duplicateOpen;

@CommandLine.ParentCommand
private ContainerLogController parent;

Expand All @@ -57,7 +60,13 @@ public Void call() throws Exception {

ContainerDatanodeDatabase cdd = new ContainerDatanodeDatabase(dbPath.toString());

cdd.listContainersByState(state.name(), listOptions.getLimit());
if (duplicateOpen) {
cdd.findDuplicateOpenContainer();
} else if (state != null) {
cdd.listContainersByState(state.name(), listOptions.getLimit());
} else {
err().println("Please provide either a container state or use --double-open.");
}

return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,5 +541,44 @@ private List<DatanodeContainerInfo> getContainerLogData(Long containerID, Connec

return logEntries;
}

private void createIdxContainerlogContainerId(Connection conn) throws SQLException {
String sql = SQLDBConstants.CREATE_CONTAINER_ID_INDEX;
try (Statement stmt = conn.createStatement()) {
stmt.execute(sql);
}
}

public void findDuplicateOpenContainer() throws SQLException {
String sql = SQLDBConstants.SELECT_DISTINCT_CONTAINER_IDS_QUERY;

try (Connection connection = getConnection()) {

createIdxContainerlogContainerId(connection);

try (PreparedStatement statement = connection.prepareStatement(sql);
ResultSet resultSet = statement.executeQuery()) {
int count = 0;

while (resultSet.next()) {
Long containerID = resultSet.getLong("container_id");
List<DatanodeContainerInfo> logEntries = getContainerLogData(containerID, connection);
logEntries.sort(Comparator.comparing(DatanodeContainerInfo::getTimestamp));
boolean hasIssue = checkForMultipleOpenStates(logEntries);
if (hasIssue) {
count++;
out.println("Container ID: " + containerID);
}
}

out.println("Total containers that might have duplicate OPEN state : " + count);

}
} catch (SQLException e) {
throw new SQLException("Error while retrieving containers.");
} catch (Exception e) {
throw new RuntimeException("Unexpected error: " + e);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public final class SQLDBConstants {
"WHERE d.container_id = ? ORDER BY d.datanode_id ASC, d.timestamp ASC;";
public static final String CREATE_DCL_CONTAINER_STATE_TIME_INDEX = "CREATE INDEX IF NOT EXISTS " +
"idx_dcl_container_state_time ON DatanodeContainerLogTable(container_id, container_state, timestamp);";
public static final String CREATE_CONTAINER_ID_INDEX = "CREATE INDEX IF NOT EXISTS idx_containerlog_container_id " +
"ON ContainerLogTable(container_id);";
public static final String SELECT_DISTINCT_CONTAINER_IDS_QUERY =
"SELECT DISTINCT container_id FROM ContainerLogTable";

private SQLDBConstants() {
//Never constructed
Expand Down