Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -35,18 +35,26 @@
description = "Finds containers from the database based on the option provided."
)
public class ListContainers extends AbstractSubcommand implements Callable<Void> {

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

@CommandLine.ArgGroup(multiplicity = "1")
private ExclusiveOptions exclusiveOptions;

@CommandLine.Mixin
private ListOptions listOptions;

@CommandLine.ParentCommand
private ContainerLogController parent;

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

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

@Override
public Void call() throws Exception {

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

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

cdd.listContainersByState(state.name(), listOptions.getLimit());
if (exclusiveOptions.duplicateOpen) {
cdd.findDuplicateOpenContainer();
} else if (exclusiveOptions.state != null) {
cdd.listContainersByState(exclusiveOptions.state.name(), listOptions.getLimit());
}

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
Loading