Skip to content

Commit

Permalink
mk-sql: fix clusters section
Browse files Browse the repository at this point in the history
- correct function call
- added '\n' between lines
- more correctly processed the final output
- nvarchar maxed

SUP-21423
SUP-20138

Change-Id: I9eda2f8209cb6abeeca7afe9d462ffb513f21677
  • Loading branch information
s-kipnis committed Dec 12, 2024
1 parent 2322b59 commit fbae112
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions packages/host/mk-sql/src/ms_sql/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ impl SqlInstance {
self.generate_datafiles_section(endpoint, chunk, query, sep),
),
names::CLUSTERS => rt.block_on(
self.generate_transaction_logs_section(endpoint, chunk, query, sep),
self.generate_clusters_section(endpoint, chunk, query, sep),
),
_ => format!("{} not implemented\n", section.name()).to_string(),
}
Expand Down Expand Up @@ -1001,7 +1001,7 @@ impl SqlInstance {
}
let (nodes, active_node) = self.get_cluster_nodes(client, query).await?;
Ok(Some(format!(
"{}{sep}{}{sep}{}{sep}{}",
"{}{sep}{}{sep}{}{sep}{}\n",
self.name,
database.replace(' ', "_"),
active_node,
Expand All @@ -1022,7 +1022,7 @@ impl SqlInstance {
query: &str,
) -> Result<(String, String)> {
let answers = &run_custom_query(client, query).await?;
if answers.len() > 2 && !answers[0].is_empty() && !answers[1].is_empty() {
if answers.len() >= 2 && !answers[1].is_empty() {
return Ok((answers[0].get_node_names(), answers[1].get_active_node()));
}
Ok((String::default(), String::default()))
Expand Down
7 changes: 4 additions & 3 deletions packages/host/mk-sql/src/ms_sql/sqls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,12 @@ cast(DATABASEPROPERTYEX(name, 'Status') as nvarchar(max)) AS Status, \
FROM master.dbo.sysdatabases";

pub const IS_CLUSTERED: &str =
"SELECT cast( SERVERPROPERTY('IsClustered') as nvarchar) AS is_clustered";
"SELECT cast( SERVERPROPERTY('IsClustered') as nvarchar(max)) AS is_clustered";
pub const CLUSTER_NODES: &str =
"SELECT cast(nodename as NVARCHAR) as nodename FROM sys.dm_os_cluster_nodes";
"SELECT cast(nodename as NVARCHAR(max)) as nodename FROM sys.dm_os_cluster_nodes";

pub const CLUSTER_ACTIVE_NODES: &str =
"SELECT cast(SERVERPROPERTY('ComputerNamePhysicalNetBIOS') as nvarchar) AS active_node";
"SELECT cast(SERVERPROPERTY('ComputerNamePhysicalNetBIOS') as nvarchar(max)) AS active_node";

pub const CONNECTIONS: &str = "SELECT name AS DbName, \
cast((SELECT COUNT(dbid) AS Num_Of_Connections FROM sys.sysprocesses WHERE dbid > 0 AND name = DB_NAME(dbid) GROUP BY dbid ) as bigint) AS NumberOfConnections \
Expand Down

0 comments on commit fbae112

Please sign in to comment.