Skip to content

Commit

Permalink
test with rowlevel lock based on ST_Intersects, step 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars Aksel Opsahl committed May 22, 2020
1 parent 08f98d0 commit 7d71dbe
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 8 deletions.
7 changes: 2 additions & 5 deletions src/main/sql/function_resolve_overlap_gap_run.sql
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,8 @@ BEGIN
RAISE NOTICE 'Start to run overlap for % stmts_final and gap for table % cell_job_type % at loop_number %',
Array_length(stmts_final, 1), (_input).table_to_resolve, cell_job_type, loop_number;

IF cell_job_type = 3 THEN
SELECT execute_parallel (stmts_final, 1,true) INTO call_result;
ELSE
SELECT execute_parallel (stmts_final, _max_parallel_jobs,true) INTO call_result;
END IF;
SELECT execute_parallel (stmts_final, _max_parallel_jobs,true) INTO call_result;

IF (call_result = FALSE AND last_run_stmts = Array_length(stmts, 1)) THEN
RAISE EXCEPTION 'FFailed to run overlap and gap for % at loop_number % for the following statement list %',
(_input).table_to_resolve, loop_number, stmts_final;
Expand Down
51 changes: 48 additions & 3 deletions src/main/sql/function_resolve_overlap_gap_single_cell.sql
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ DECLARE
heal_edge_status int;
heal_edge_retry_num int;

num_locked int;


BEGIN
Expand Down Expand Up @@ -464,16 +465,60 @@ BEGIN
RETURN;
END IF;





border_topo_info.topology_name := _topology_name;

command_string := Format('CREATE TEMP table temp_left_over_borders as select geo FROM
(select geo from topo_update.get_left_over_borders(%1$L,%2$L,%3$L,%4$L) as r) as r',
overlapgap_grid, input_table_geo_column_name, _bb, _table_name_result_prefix,_topology_snap_tolerance*inner_cell_distance);
EXECUTE command_string;


-- add rowlevel lock based info from Sandro https://trac.osgeo.org/postgis/ticket/4684
--A pessimistic approach might lock:
--EVERY FACE whos MBR intersects the input line
--EVERY EDGE having any of those faces on its right or left side
--EVERY ISOLATED NODE within tolerance distance from the input line

command_string := Format('SELECT count(r.*) FROM
(
SELECT f.*
FROM temp_left_over_borders i, %1$s.face f
where ST_intersects(i.geo,f.mbr)
for update
) as r;',
_topology_name);
EXECUTE command_string INTO num_locked;
RAISE NOTICE 'Locked % faces for update top toplogy % and _cell_job_type %, for area_to_block % ',
num_locked, _topology_name, _cell_job_type, area_to_block;

command_string := Format('SELECT count(r.*) FROM
(
SELECT e.*
FROM temp_left_over_borders i, %1$s.face f, %1$s.edge_data e
WHERE ST_intersects(i.geo,f.mbr) AND
(e.left_face = f.face_id OR e.right_face = f.face_id)
for update
) as r;',
_topology_name);
EXECUTE command_string INTO num_locked;
RAISE NOTICE 'Locked % edge_data for update top toplogy % and _cell_job_type %, for area_to_block % ',
num_locked, _topology_name, _cell_job_type, area_to_block;


command_string := Format('SELECT count(r.*) FROM
(
SELECT n.*
FROM temp_left_over_borders i, %1$s.node n
where ST_DWithin(i.geo,n.geom,%2$s)
for update
) as r;',
_topology_name,snap_tolerance_fixed);
EXECUTE command_string INTO num_locked;
RAISE NOTICE 'Locked % nodes for update toplogy % and _cell_job_type %, for area_to_block % ',
num_locked, _topology_name, _cell_job_type, area_to_block;




-- add border smale border lines
Expand Down

0 comments on commit 7d71dbe

Please sign in to comment.