@@ -21,7 +21,7 @@ CREATE FUNCTION smp_agent_test_protocol_schema.on_rcv_queue_delete() RETURNS tri
2121 AS $$
2222BEGIN
2323 IF OLD .rcv_service_assoc != 0 AND OLD .deleted = 0 THEN
24- PERFORM update_aggregates(OLD .user_id , OLD .host , OLD .port , - 1 , OLD .rcv_id );
24+ PERFORM update_aggregates(OLD .conn_id , OLD .host , OLD .port , - 1 , OLD .rcv_id );
2525 END IF;
2626 RETURN OLD;
2727END;
@@ -34,7 +34,7 @@ CREATE FUNCTION smp_agent_test_protocol_schema.on_rcv_queue_insert() RETURNS tri
3434 AS $$
3535BEGIN
3636 IF NEW .rcv_service_assoc != 0 AND NEW .deleted = 0 THEN
37- PERFORM update_aggregates(NEW .user_id , NEW .host , NEW .port , 1 , NEW .rcv_id );
37+ PERFORM update_aggregates(NEW .conn_id , NEW .host , NEW .port , 1 , NEW .rcv_id );
3838 END IF;
3939 RETURN NEW;
4040END;
@@ -48,58 +48,57 @@ CREATE FUNCTION smp_agent_test_protocol_schema.on_rcv_queue_update() RETURNS tri
4848BEGIN
4949 IF OLD .rcv_service_assoc != 0 AND OLD .deleted = 0 THEN
5050 IF NOT (NEW .rcv_service_assoc != 0 AND NEW .deleted = 0 ) THEN
51- PERFORM update_aggregates(OLD .user_id , OLD .host , OLD .port , - 1 , OLD .rcv_id );
51+ PERFORM update_aggregates(OLD .conn_id , OLD .host , OLD .port , - 1 , OLD .rcv_id );
5252 END IF;
5353 ELSIF NEW .rcv_service_assoc != 0 AND NEW .deleted = 0 THEN
54- PERFORM update_aggregates(NEW .user_id , NEW .host , NEW .port , 1 , NEW .rcv_id );
54+ PERFORM update_aggregates(NEW .conn_id , NEW .host , NEW .port , 1 , NEW .rcv_id );
5555 END IF;
5656 RETURN NEW;
5757END;
5858$$;
5959
6060
6161
62- CREATE FUNCTION smp_agent_test_protocol_schema .update_aggregates(p_user_id bigint , p_host text , p_port text , p_change bigint , p_rcv_id bytea ) RETURNS void
62+ CREATE FUNCTION smp_agent_test_protocol_schema .update_aggregates(p_conn_id bytea , p_host text , p_port text , p_change bigint , p_rcv_id bytea ) RETURNS void
6363 LANGUAGE plpgsql
6464 AS $$
65+ DECLARE q_user_id BIGINT ;
6566BEGIN
67+ SELECT user_id INTO q_user_id FROM connections WHERE conn_id = p_conn_id;
6668 UPDATE client_services
6769 SET service_queue_count = service_queue_count + p_change,
6870 service_queue_ids_hash = xor_combine(service_queue_ids_hash, public .digest (p_rcv_id, ' md5' ))
69- WHERE user_id = p_user_id AND host = p_host AND port = p_port;
71+ WHERE user_id = q_user_id AND host = p_host AND port = p_port;
7072END;
7173$$;
7274
7375
76+ SET default_table_access_method = heap;
7477
75- CREATE FUNCTION smp_agent_test_protocol_schema .xor_combine(state bytea , value bytea ) RETURNS bytea
76- LANGUAGE plpgsql IMMUTABLE STRICT
77- AS $$
78- DECLARE
79- result BYTEA := state;
80- i INTEGER ;
81- len INTEGER := octet_length(value);
82- BEGIN
83- IF octet_length(state) != len THEN
84- RAISE EXCEPTION ' Inputs must be equal length (% != %)' , octet_length(state), len;
85- END IF;
86- FOR i IN 0 ..len- 1 LOOP
87- result := set_byte(result, i, get_byte(state, i) # get_byte(value, i));
88- END LOOP;
89- RETURN result;
90- END;
91- $$;
9278
79+ CREATE TABLE smp_agent_test_protocol_schema .client_notices (
80+ client_notice_id bigint NOT NULL ,
81+ protocol text NOT NULL ,
82+ host text NOT NULL ,
83+ port text NOT NULL ,
84+ entity_id bytea NOT NULL ,
85+ server_key_hash bytea ,
86+ notice_ttl bigint ,
87+ created_at bigint NOT NULL ,
88+ updated_at bigint NOT NULL
89+ );
9390
9491
95- CREATE AGGREGATE smp_agent_test_protocol_schema .xor_aggregate(bytea ) (
96- SFUNC = smp_agent_test_protocol_schema .xor_combine ,
97- STYPE = bytea ,
98- INITCOND = ' \x 00000000000000000000000000000000'
99- );
10092
93+ ALTER TABLE smp_agent_test_protocol_schema .client_notices ALTER COLUMN client_notice_id ADD GENERATED ALWAYS AS IDENTITY (
94+ SEQUENCE NAME smp_agent_test_protocol_schema .client_notices_client_notice_id_seq
95+ START WITH 1
96+ INCREMENT BY 1
97+ NO MINVALUE
98+ NO MAXVALUE
99+ CACHE 1
100+ );
101101
102- SET default_table_access_method = heap;
103102
104103
105104CREATE TABLE smp_agent_test_protocol_schema .client_services (
@@ -535,6 +534,8 @@ CREATE TABLE smp_agent_test_protocol_schema.rcv_queues (
535534 link_priv_sig_key bytea ,
536535 link_enc_fixed_data bytea ,
537536 queue_mode text ,
537+ to_subscribe smallint DEFAULT 0 NOT NULL ,
538+ client_notice_id bigint ,
538539 rcv_service_assoc smallint DEFAULT 0 NOT NULL
539540);
540541
@@ -816,6 +817,11 @@ ALTER TABLE smp_agent_test_protocol_schema.xftp_servers ALTER COLUMN xftp_server
816817
817818
818819
820+ ALTER TABLE ONLY smp_agent_test_protocol_schema .client_notices
821+ ADD CONSTRAINT client_notices_pkey PRIMARY KEY (client_notice_id);
822+
823+
824+
819825ALTER TABLE ONLY smp_agent_test_protocol_schema .commands
820826 ADD CONSTRAINT commands_pkey PRIMARY KEY (command_id);
821827
@@ -996,6 +1002,10 @@ ALTER TABLE ONLY smp_agent_test_protocol_schema.xftp_servers
9961002
9971003
9981004
1005+ CREATE UNIQUE INDEX idx_client_notices_entity ON smp_agent_test_protocol_schema .client_notices USING btree (protocol, host, port, entity_id);
1006+
1007+
1008+
9991009CREATE INDEX idx_commands_conn_id ON smp_agent_test_protocol_schema .commands USING btree (conn_id);
10001010
10011011
@@ -1124,6 +1134,10 @@ CREATE UNIQUE INDEX idx_rcv_queue_id ON smp_agent_test_protocol_schema.rcv_queue
11241134
11251135
11261136
1137+ CREATE INDEX idx_rcv_queues_client_notice_id ON smp_agent_test_protocol_schema .rcv_queues USING btree (client_notice_id);
1138+
1139+
1140+
11271141CREATE UNIQUE INDEX idx_rcv_queues_link_id ON smp_agent_test_protocol_schema .rcv_queues USING btree (host, port, link_id);
11281142
11291143
@@ -1132,6 +1146,10 @@ CREATE UNIQUE INDEX idx_rcv_queues_ntf ON smp_agent_test_protocol_schema.rcv_que
11321146
11331147
11341148
1149+ CREATE INDEX idx_rcv_queues_to_subscribe ON smp_agent_test_protocol_schema .rcv_queues USING btree (to_subscribe);
1150+
1151+
1152+
11351153CREATE INDEX idx_server_certs_host_port ON smp_agent_test_protocol_schema .client_services USING btree (host, port);
11361154
11371155
@@ -1345,6 +1363,11 @@ ALTER TABLE ONLY smp_agent_test_protocol_schema.rcv_messages
13451363
13461364
13471365
1366+ ALTER TABLE ONLY smp_agent_test_protocol_schema .rcv_queues
1367+ ADD CONSTRAINT rcv_queues_client_notice_id_fkey FOREIGN KEY (client_notice_id) REFERENCES smp_agent_test_protocol_schema .client_notices (client_notice_id) ON UPDATE RESTRICT ON DELETE SET NULL ;
1368+
1369+
1370+
13481371ALTER TABLE ONLY smp_agent_test_protocol_schema .rcv_queues
13491372 ADD CONSTRAINT rcv_queues_conn_id_fkey FOREIGN KEY (conn_id) REFERENCES smp_agent_test_protocol_schema .connections (conn_id) ON DELETE CASCADE ;
13501373
0 commit comments