Commit 94b1507f authored by Jean-Benoist Leger's avatar Jean-Benoist Leger

separation de l'update d'osmosis et de rv

parent 40c2811f
......@@ -19,9 +19,15 @@ BEGIN;
-- rv_edges
DROP TABLE IF EXISTS rv_edges;
CREATE TABLE rv_edges (from_id BIGINT, to_id BIGINT, way_id BIGINT);
ALTER TABLE rv_edges ADD CONSTRAINT pk_rv_edges PRIMARY KEY (from_id,to_id,way_id);
CREATE INDEX idx_rv_edges_from_id ON rv_edges USING btree (from_id);
CREATE INDEX idx_rv_edges_way_id ON rv_edges USING btree (way_id);
-- rv_to_update
DROP TABLE IF EXISTS rv_to_update;
CREATE TABLE rv_to_update (data_type character(1) NOT NULL, action character(1) NOT NULL, id bigint NOT NULL);
ALTER TABLE rv_to_update ADD CONSTRAINT pk_rv_to_update PRIMARY KEY (data_type, id);
......
......@@ -6,8 +6,8 @@ DECLARE
n_n integer;
t timestamp;
BEGIN
SELECT count(*) FROM actions WHERE data_type='N' INTO n_n;
SELECT count(*) FROM actions WHERE data_type='W' INTO n_w;
SELECT count(*) FROM rv_to_update WHERE data_type='N' INTO n_n;
SELECT count(*) FROM rv_to_update WHERE data_type='W' INTO n_w;
SELECT timeofday()::TIMESTAMP INTO t;
......
......@@ -17,7 +17,7 @@ BEGIN
SELECT
id
FROM
actions
rv_to_update
WHERE
data_type='W'
AND
......@@ -36,7 +36,7 @@ BEGIN
FROM
ways
INNER JOIN
actions ON ways.id=actions.id
rv_to_update ON ways.id=rv_to_update.id
WHERE
data_type='W'
AND
......@@ -60,7 +60,7 @@ BEGIN
SELECT
id
FROM
actions
rv_to_update
WHERE
data_type='W'
AND
......@@ -80,7 +80,7 @@ BEGIN
FROM
rv_ways
INNER JOIN
actions ON rv_ways.id=actions.id
rv_to_update ON rv_ways.id=rv_to_update.id
WHERE
data_type='W'
AND
......@@ -93,7 +93,7 @@ BEGIN
-- etape 1: on considère que tous les nodes apparenants à des ways modifiés
-- ont été potentiellement modifés (la ways peut avoir été marqué comme
-- interdite au cyclistes)
INSERT INTO actions
INSERT INTO rv_to_update
(
SELECT
'N' AS data_type,
......@@ -105,9 +105,9 @@ BEGIN
SELECT DISTINCT
node_id AS id
FROM
actions
rv_to_update
INNER JOIN
way_nodes ON way_nodes.way_id=actions.id
way_nodes ON way_nodes.way_id=rv_to_update.id
WHERE
data_type='W'
)
......@@ -116,7 +116,7 @@ BEGIN
SELECT
id
FROM
actions
rv_to_update
WHERE
data_type='N'
)
......@@ -133,7 +133,7 @@ BEGIN
SELECT
id AS node_id
FROM
actions
rv_to_update
WHERE
data_type='N'
) AS sub
......@@ -154,11 +154,11 @@ BEGIN
FROM
(
SELECT DISTINCT
actions.id AS id
rv_to_update.id AS id
FROM
actions
rv_to_update
INNER JOIN
way_nodes ON way_nodes.node_id=actions.id
way_nodes ON way_nodes.node_id=rv_to_update.id
INNER JOIN
rv_ways ON way_nodes.way_id=rv_ways.id
WHERE
......
......@@ -4,6 +4,6 @@
DROP FUNCTION IF EXISTS osmosisUpdate();
CREATE FUNCTION osmosisUpdate() RETURNS VOID AS $$
BEGIN
PERFORM updateRV();
PERFORM rv_fill_to_update();
END;
$$ LANGUAGE plpgsql;
--
-- modifs
DROP FUNCTION IF EXISTS rv_fill_to_update();
CREATE FUNCTION rv_fill_to_update() RETURNS VOID AS $$
BEGIN
DELETE
FROM
rv_to_update
USING
actions
WHERE
actions.data_type = rv_to_update.data_type
AND
actions.id = rv_to_update.id;
INSERT INTO rv_to_update (SELECT * FROM actions);
END;
$$ LANGUAGE plpgsql;
BEGIN;
-- locks only for wrinting this is not blocking reading
LOCK TABLE nodes IN EXCLUSIVE MODE;
LOCK TABLE ways IN EXCLUSIVE MODE;
LOCK TABLE way_nodes IN EXCLUSIVE MODE;
LOCK TABLE actions IN EXCLUSIVE MODE;
LOCK TABLE rv_nodes IN EXCLUSIVE MODE;
LOCK TABLE rv_ways IN EXCLUSIVE MODE;
LOCK TABLE rv_edges IN EXCLUSIVE MODE;
-- this is blocking reading and wrinting
LOCK TABLE rv_to_update IN ACCESS EXCLUSIVE MODE;
INSERT INTO rv_ways
(
......
BEGIN;
-- locks only for wrinting this is not blocking reading
LOCK TABLE nodes IN EXCLUSIVE MODE;
LOCK TABLE ways IN EXCLUSIVE MODE;
LOCK TABLE way_nodes IN EXCLUSIVE MODE;
LOCK TABLE actions IN EXCLUSIVE MODE;
LOCK TABLE rv_nodes IN EXCLUSIVE MODE;
LOCK TABLE rv_ways IN EXCLUSIVE MODE;
LOCK TABLE rv_edges IN EXCLUSIVE MODE;
-- this is blocking reading and wrinting
LOCK TABLE rv_to_update IN ACCESS EXCLUSIVE MODE;
-- we are alone to write, mouhahahahaha
SELECT updateRV();
TRUNCATE rv_to_update;
-- we write and release locks
COMMIT;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment