How to fix Ambari topology tables
In case of a Blueprint based deployment Ambari stores deployment tasks in topology tables: topology_request, topology_logical_request, topology_host_request, topology_host_task, topology_logical_task.
In case of some errors during deployment task creation these tables could be left in an inconsistent state, which has been fixed in 2.5.0 (AMBARI-19929).
Ambari 2.5.0 introduced (removed in 2.5.2) two DB consistency checks related to topology tables:
1. Check topology_request, topology_logical_request tables are consistent, by comparing the row counts returned:
select count(tpr.id) from topology_request tpr;
select count(DISTINCT tpr.id) from topology_request tpr join topology_logical_request tlr on tpr.id = tlr.request_id;
- get next available: next_topology_logical_request_id = select max(id) + 1 from topology_logical_request;
- insert new row:
insert into topology_logical_request select <next_topology_logical_request_id>, id, 'Logical Request: ' || description from topology_request where id not in (select request_id from topology_logical_request);
select count(thr.id) from topology_host_request thr;
select count(DISTINCT thr.id) from topology_host_request thr join topology_host_task tht on thr.id = tht.host_request_id join topology_logical_task tlt on tht.id = tlt.host_task_id;
delete from topology_host_task where not id in (select host_task_id from topology_logical_task);delete from topology_host_request where not id in (select host_request_id from topology_host_task);

