mirror of https://github.com/citusdata/citus.git
v1.2
parent
2b4c930e33
commit
eb0dc48f17
|
@ -55,7 +55,7 @@ static void
|
|||
RunHintAI(void)
|
||||
{
|
||||
elog(NOTICE, "Running the HintAI code...");
|
||||
system("psql -p 9700 -f /tmp/hint_ai_code.txt --single-transaction 2> /tmp/hint_ai_code_error.txt");
|
||||
system("psql -p 9700 -X -f /tmp/hint_ai_code.txt --single-transaction 2> /tmp/hint_ai_code_error.txt 1> /tmp/hint_ai_code_output.txt");
|
||||
|
||||
// read the first ERROR-DETAIL-HINT block from the error file
|
||||
FILE *fp = fopen("/tmp/hint_ai_code_error.txt", "r");
|
||||
|
@ -105,6 +105,8 @@ RunHintAI(void)
|
|||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
||||
if (error)
|
||||
{
|
||||
ereport(ERROR, (errmsg("%s", error),
|
||||
|
@ -112,6 +114,33 @@ RunHintAI(void)
|
|||
hint ? errhint("%s", hint) : 0));
|
||||
}
|
||||
|
||||
// else, print lines from /tmp/hint_ai_code_output.txt
|
||||
fp = fopen("/tmp/hint_ai_code_output.txt", "r");
|
||||
if (fp == NULL)
|
||||
{
|
||||
elog(ERROR, "Failed to open file");
|
||||
}
|
||||
|
||||
StringInfo outBuf = makeStringInfo();
|
||||
|
||||
while (true)
|
||||
{
|
||||
char *line = NULL;
|
||||
size_t len = 0;
|
||||
ssize_t read = getline(&line, &len, fp);
|
||||
if (read == -1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
appendStringInfoString(outBuf, line);
|
||||
}
|
||||
|
||||
if (outBuf->len > 0)
|
||||
{
|
||||
ereport(NOTICE, (errmsg("The output of \"RUN HINT\":\n%s", outBuf->data)));
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,16 +8,36 @@ AS $$
|
|||
DECLARE
|
||||
cluster_stats text;
|
||||
BEGIN
|
||||
WITH citus_tables_arr AS (
|
||||
SELECT array_agg(row_to_json(t.*)) d FROM public.citus_tables t
|
||||
WITH
|
||||
citus_tables_arr AS (
|
||||
SELECT array_agg(row_to_json(t.*)) d FROM (
|
||||
SELECT table_name, distribution_column FROM public.citus_tables
|
||||
) t
|
||||
),
|
||||
all_tables_arr AS (
|
||||
SELECT array_agg(tablename) d from pg_tables where schemaname='public'
|
||||
),
|
||||
citus_nodes_arr AS (
|
||||
SELECT array_agg(row_to_json(t.*)) d FROM pg_catalog.pg_dist_node t
|
||||
SELECT array_agg(row_to_json(t.*)) d FROM (
|
||||
SELECT nodename, nodeport FROM pg_catalog.pg_dist_node
|
||||
) t
|
||||
),
|
||||
key_values AS (
|
||||
SELECT unnest(ARRAY['citus_tables', 'citus_nodes']) AS key,
|
||||
unnest(ARRAY[to_json(citus_tables_arr.d), to_json(citus_nodes_arr.d)]::json[]) AS value
|
||||
FROM citus_tables_arr, citus_nodes_arr
|
||||
SELECT
|
||||
unnest(ARRAY[
|
||||
'citus_tables',
|
||||
'all_tables',
|
||||
'citus_nodes'
|
||||
]) AS key,
|
||||
unnest(ARRAY[
|
||||
to_json(citus_tables_arr.d),
|
||||
to_json(all_tables_arr.d),
|
||||
to_json(citus_nodes_arr.d)
|
||||
]::json[]) AS value
|
||||
FROM
|
||||
citus_tables_arr,
|
||||
all_tables_arr,
|
||||
citus_nodes_arr
|
||||
)
|
||||
SELECT json_object_agg(key, value)::text INTO cluster_stats
|
||||
FROM key_values;
|
||||
|
|
Loading…
Reference in New Issue