Skip to content

Commit

Permalink
use both row level lock and lock based on area
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars Aksel Opsahl committed May 24, 2020
1 parent c69fd07 commit 8ef48c0
Showing 1 changed file with 85 additions and 6 deletions.
91 changes: 85 additions & 6 deletions src/main/sql/function_resolve_overlap_gap_single_cell.sql
Original file line number Diff line number Diff line change
Expand Up @@ -442,23 +442,54 @@ BEGIN

-- Anohter test block base on mbr Sandro https://trac.osgeo.org/postgis/ticket/4684

command_string := Format('SELECT ST_Union(r.geom) FROM

command_string := Format('WITH
face_mbr AS
(
SELECT distinct f2.mbr as geom
FROM temp_left_over_borders i, %1$s.face f, %1$s.edge_data e, %1$s.face f2
WHERE ST_DWithin(i.geo,f.mbr,%2$s) AND
FROM temp_left_over_borders i,
%1$s.face f,
%1$s.edge_data e,
%1$s.face f2
WHERE ST_DWithin(i.geo,e.geom,%2$s) AND
(
(e.left_face = f.face_id AND f2.face_id = e.left_face)
OR
(e.right_face = f.face_id AND f2.face_id = e.right_face)
)
) as r;',
_topology_name,snap_tolerance_fixed);
)
),
edge_line AS
(
SELECT distinct e.geom as geom
FROM temp_left_over_borders i,
%1$s.edge_data e
WHERE ST_DWithin(i.geo,e.geom,%2$s)
),
edge_bb AS
(
SELECT ST_Envelope(e.geom) as geom FROM edge_line e
),
exting_data AS
(
SELECT ST_Union(r.geom,e.geom) as geom FROM face_mbr r, edge_bb e
),
input AS
(
SELECT ST_Union(ST_Envelope(i.geo)) as geom FROM temp_left_over_borders i
),
input_bb AS
(
SELECT ST_Union(geom,%3$L) as geom from input
)
SELECT ST_Union(e.geom,i.geom) FROM exting_data e, input_bb i',
_topology_name,snap_tolerance_fixed,_bb);

EXECUTE command_string INTO area_to_block;


IF area_to_block is NULL or ST_Area(area_to_block) = 0.0 THEN
RAISE NOTICE 'Failed to make block for _cell_job_type %, num_boxes_intersect %, num_boxes_free %',
_cell_job_type, num_boxes_intersect, num_boxes_free;
area_to_block := _bb;
END IF;

Expand All @@ -474,6 +505,54 @@ BEGIN
RETURN;
END IF;





-- 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;

border_topo_info.topology_name := _topology_name;


Expand Down

0 comments on commit 8ef48c0

Please sign in to comment.