diff options
-rw-r--r-- | src/datacache/Makefile.am | 3 | ||||
-rw-r--r-- | src/namecache/Makefile.am | 10 | ||||
-rw-r--r-- | src/namecache/namecache-0001.sql | 42 | ||||
-rw-r--r-- | src/namecache/namecache-drop.sql | 25 | ||||
-rw-r--r-- | src/namecache/plugin_namecache_postgres.c | 85 | ||||
-rw-r--r-- | src/namestore/Makefile.am | 5 |
6 files changed, 109 insertions, 61 deletions
diff --git a/src/datacache/Makefile.am b/src/datacache/Makefile.am index 2d112b4ca..14778e0a3 100644 --- a/src/datacache/Makefile.am +++ b/src/datacache/Makefile.am | |||
@@ -202,4 +202,5 @@ EXTRA_DIST = \ | |||
202 | test_datacache_data_heap.conf \ | 202 | test_datacache_data_heap.conf \ |
203 | perf_datacache_data_heap.conf \ | 203 | perf_datacache_data_heap.conf \ |
204 | test_datacache_data_postgres.conf \ | 204 | test_datacache_data_postgres.conf \ |
205 | perf_datacache_data_postgres.conf | 205 | perf_datacache_data_postgres.conf \ |
206 | $(sql_DATA) | ||
diff --git a/src/namecache/Makefile.am b/src/namecache/Makefile.am index 272f16b77..f283d3f64 100644 --- a/src/namecache/Makefile.am +++ b/src/namecache/Makefile.am | |||
@@ -10,6 +10,13 @@ libexecdir= $(pkglibdir)/libexec/ | |||
10 | pkgcfg_DATA = \ | 10 | pkgcfg_DATA = \ |
11 | namecache.conf | 11 | namecache.conf |
12 | 12 | ||
13 | sqldir = $(prefix)/share/gnunet/sql/ | ||
14 | |||
15 | sql_DATA = \ | ||
16 | namecache-0001.sql \ | ||
17 | namecache-drop.sql | ||
18 | |||
19 | |||
13 | if USE_COVERAGE | 20 | if USE_COVERAGE |
14 | AM_CFLAGS = --coverage -O0 | 21 | AM_CFLAGS = --coverage -O0 |
15 | XLIBS = -lgcov | 22 | XLIBS = -lgcov |
@@ -168,4 +175,5 @@ EXTRA_DIST = \ | |||
168 | test_namecache_api.conf \ | 175 | test_namecache_api.conf \ |
169 | test_plugin_namecache_sqlite.conf \ | 176 | test_plugin_namecache_sqlite.conf \ |
170 | test_plugin_namecache_postgres.conf \ | 177 | test_plugin_namecache_postgres.conf \ |
171 | test_plugin_namecache_flat.conf | 178 | test_plugin_namecache_flat.conf \ |
179 | $(sql_DATA) | ||
diff --git a/src/namecache/namecache-0001.sql b/src/namecache/namecache-0001.sql new file mode 100644 index 000000000..8509b078f --- /dev/null +++ b/src/namecache/namecache-0001.sql | |||
@@ -0,0 +1,42 @@ | |||
1 | -- | ||
2 | -- This file is part of GNUnet | ||
3 | -- Copyright (C) 2014--2022 GNUnet e.V. | ||
4 | -- | ||
5 | -- GNUnet is free software; you can redistribute it and/or modify it under the | ||
6 | -- terms of the GNU General Public License as published by the Free Software | ||
7 | -- Foundation; either version 3, or (at your option) any later version. | ||
8 | -- | ||
9 | -- GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY | ||
10 | -- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||
11 | -- A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
12 | -- | ||
13 | -- You should have received a copy of the GNU General Public License along with | ||
14 | -- GNUnet; see the file COPYING. If not, see <http://www.gnu.org/licenses/> | ||
15 | -- | ||
16 | |||
17 | -- Everything in one big transaction | ||
18 | BEGIN; | ||
19 | |||
20 | -- Check patch versioning is in place. | ||
21 | SELECT _v.register_patch('namecache-0001', NULL, NULL); | ||
22 | |||
23 | -------------------- Schema ---------------------------- | ||
24 | |||
25 | CREATE SCHEMA datacache; | ||
26 | COMMENT ON SCHEMA datacache IS 'gnunet-datacache data'; | ||
27 | |||
28 | SET search_path TO datacache; | ||
29 | |||
30 | CREATE TABLE IF NOT EXISTS ns096blocks ( | ||
31 | query BYTEA NOT NULL DEFAULT '', | ||
32 | block BYTEA NOT NULL DEFAULT '', | ||
33 | expiration_time BIGINT NOT NULL DEFAULT 0); | ||
34 | |||
35 | CREATE INDEX ir_query_hash | ||
36 | ON ns096blocks (query,expiration_time); | ||
37 | |||
38 | CREATE INDEX ir_block_expiration | ||
39 | ON ns096blocks (expiration_time); | ||
40 | |||
41 | |||
42 | COMMIT; | ||
diff --git a/src/namecache/namecache-drop.sql b/src/namecache/namecache-drop.sql new file mode 100644 index 000000000..197ee78c1 --- /dev/null +++ b/src/namecache/namecache-drop.sql | |||
@@ -0,0 +1,25 @@ | |||
1 | -- | ||
2 | -- This file is part of GNUnet | ||
3 | -- Copyright (C) 2014--2022 GNUnet e.V. | ||
4 | -- | ||
5 | -- GNUnet is free software; you can redistribute it and/or modify it under the | ||
6 | -- terms of the GNU General Public License as published by the Free Software | ||
7 | -- Foundation; either version 3, or (at your option) any later version. | ||
8 | -- | ||
9 | -- GNUnet is distributed in the hope that it will be useful, but WITHOUT ANY | ||
10 | -- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||
11 | -- A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
12 | -- | ||
13 | -- You should have received a copy of the GNU General Public License along with | ||
14 | -- GNUnet; see the file COPYING. If not, see <http://www.gnu.org/licenses/> | ||
15 | -- | ||
16 | |||
17 | -- Everything in one big transaction | ||
18 | BEGIN; | ||
19 | |||
20 | |||
21 | SELECT _v.unregister_patch('namecache-0001'); | ||
22 | |||
23 | DROP SCHEMA namecache CASCADE; | ||
24 | |||
25 | COMMIT; | ||
diff --git a/src/namecache/plugin_namecache_postgres.c b/src/namecache/plugin_namecache_postgres.c index d6d1730ce..cdbe248b6 100644 --- a/src/namecache/plugin_namecache_postgres.c +++ b/src/namecache/plugin_namecache_postgres.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | * This file is part of GNUnet | 2 | * This file is part of GNUnet |
3 | * Copyright (C) 2009-2013, 2016, 2017 GNUnet e.V. | 3 | * Copyright (C) 2009-2013, 2016, 2017, 2022 GNUnet e.V. |
4 | * | 4 | * |
5 | * GNUnet is free software: you can redistribute it and/or modify it | 5 | * GNUnet is free software: you can redistribute it and/or modify it |
6 | * under the terms of the GNU Affero General Public License as published | 6 | * under the terms of the GNU Affero General Public License as published |
@@ -56,63 +56,34 @@ struct Plugin | |||
56 | * @param plugin the plugin context (state for this module) | 56 | * @param plugin the plugin context (state for this module) |
57 | * @return #GNUNET_OK on success | 57 | * @return #GNUNET_OK on success |
58 | */ | 58 | */ |
59 | static int | 59 | static enum GNUNET_GenericReturnValue |
60 | database_setup (struct Plugin *plugin) | 60 | database_setup (struct Plugin *plugin) |
61 | { | 61 | { |
62 | struct GNUNET_PQ_ExecuteStatement es_temporary = | 62 | struct GNUNET_PQ_PreparedStatement ps[] = { |
63 | GNUNET_PQ_make_execute ("CREATE TEMPORARY TABLE IF NOT EXISTS ns096blocks (" | 63 | GNUNET_PQ_make_prepare ("cache_block", |
64 | " query BYTEA NOT NULL DEFAULT ''," | 64 | "INSERT INTO namecache.ns096blocks" |
65 | " block BYTEA NOT NULL DEFAULT ''," | 65 | " (query, block, expiration_time)" |
66 | " expiration_time BIGINT NOT NULL DEFAULT 0" | 66 | " VALUES" |
67 | ")"); | 67 | " ($1, $2, $3)"), |
68 | struct GNUNET_PQ_ExecuteStatement es_default = | 68 | GNUNET_PQ_make_prepare ("expire_blocks", |
69 | GNUNET_PQ_make_execute ("CREATE TABLE IF NOT EXISTS ns096blocks (" | 69 | "DELETE FROM namecache.ns096blocks" |
70 | " query BYTEA NOT NULL DEFAULT ''," | 70 | " WHERE expiration_time<$1"), |
71 | " block BYTEA NOT NULL DEFAULT ''," | 71 | GNUNET_PQ_make_prepare ("delete_block", |
72 | " expiration_time BIGINT NOT NULL DEFAULT 0" | 72 | "DELETE FROM namecache.ns096blocks" |
73 | ")"); | 73 | " WHERE query=$1 AND expiration_time<=$2"), |
74 | const struct GNUNET_PQ_ExecuteStatement *cr; | 74 | GNUNET_PQ_make_prepare ("lookup_block", |
75 | 75 | "SELECT block" | |
76 | if (GNUNET_YES == | 76 | " FROM namecache.ns096blocks" |
77 | GNUNET_CONFIGURATION_get_value_yesno (plugin->cfg, | 77 | " WHERE query=$1" |
78 | " ORDER BY expiration_time DESC LIMIT 1"), | ||
79 | GNUNET_PQ_PREPARED_STATEMENT_END | ||
80 | }; | ||
81 | |||
82 | plugin->dbh = GNUNET_PQ_connect_with_cfg (plugin->cfg, | ||
78 | "namecache-postgres", | 83 | "namecache-postgres", |
79 | "TEMPORARY_TABLE")) | 84 | "namecache-", |
80 | { | 85 | NULL, |
81 | cr = &es_temporary; | 86 | ps); |
82 | } | ||
83 | else | ||
84 | { | ||
85 | cr = &es_default; | ||
86 | } | ||
87 | { | ||
88 | struct GNUNET_PQ_ExecuteStatement es[] = { | ||
89 | *cr, | ||
90 | GNUNET_PQ_make_try_execute ( | ||
91 | "CREATE INDEX ir_query_hash ON ns096blocks (query,expiration_time)"), | ||
92 | GNUNET_PQ_make_try_execute ( | ||
93 | "CREATE INDEX ir_block_expiration ON ns096blocks (expiration_time)"), | ||
94 | GNUNET_PQ_EXECUTE_STATEMENT_END | ||
95 | }; | ||
96 | struct GNUNET_PQ_PreparedStatement ps[] = { | ||
97 | GNUNET_PQ_make_prepare ("cache_block", | ||
98 | "INSERT INTO ns096blocks (query, block, expiration_time) VALUES " | ||
99 | "($1, $2, $3)"), | ||
100 | GNUNET_PQ_make_prepare ("expire_blocks", | ||
101 | "DELETE FROM ns096blocks WHERE expiration_time<$1"), | ||
102 | GNUNET_PQ_make_prepare ("delete_block", | ||
103 | "DELETE FROM ns096blocks WHERE query=$1 AND expiration_time<=$2"), | ||
104 | GNUNET_PQ_make_prepare ("lookup_block", | ||
105 | "SELECT block FROM ns096blocks WHERE query=$1" | ||
106 | " ORDER BY expiration_time DESC LIMIT 1"), | ||
107 | GNUNET_PQ_PREPARED_STATEMENT_END | ||
108 | }; | ||
109 | |||
110 | plugin->dbh = GNUNET_PQ_connect_with_cfg (plugin->cfg, | ||
111 | "namecache-postgres", | ||
112 | NULL, | ||
113 | es, | ||
114 | ps); | ||
115 | } | ||
116 | if (NULL == plugin->dbh) | 87 | if (NULL == plugin->dbh) |
117 | return GNUNET_SYSERR; | 88 | return GNUNET_SYSERR; |
118 | return GNUNET_OK; | 89 | return GNUNET_OK; |
@@ -174,7 +145,7 @@ delete_old_block (struct Plugin *plugin, | |||
174 | * @param block block to cache | 145 | * @param block block to cache |
175 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | 146 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR |
176 | */ | 147 | */ |
177 | static int | 148 | static enum GNUNET_GenericReturnValue |
178 | namecache_postgres_cache_block (void *cls, | 149 | namecache_postgres_cache_block (void *cls, |
179 | const struct GNUNET_GNSRECORD_Block *block) | 150 | const struct GNUNET_GNSRECORD_Block *block) |
180 | { | 151 | { |
@@ -222,7 +193,7 @@ namecache_postgres_cache_block (void *cls, | |||
222 | * @param iter_cls closure for @a iter | 193 | * @param iter_cls closure for @a iter |
223 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error | 194 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error |
224 | */ | 195 | */ |
225 | static int | 196 | static enum GNUNET_GenericReturnValue |
226 | namecache_postgres_lookup_block (void *cls, | 197 | namecache_postgres_lookup_block (void *cls, |
227 | const struct GNUNET_HashCode *query, | 198 | const struct GNUNET_HashCode *query, |
228 | GNUNET_NAMECACHE_BlockCallback iter, | 199 | GNUNET_NAMECACHE_BlockCallback iter, |
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am index b4d2b0ff2..98ee228e1 100644 --- a/src/namestore/Makefile.am +++ b/src/namestore/Makefile.am | |||
@@ -538,5 +538,6 @@ EXTRA_DIST = \ | |||
538 | test_plugin_namestore_sqlite.conf \ | 538 | test_plugin_namestore_sqlite.conf \ |
539 | test_plugin_namestore_postgres.conf \ | 539 | test_plugin_namestore_postgres.conf \ |
540 | test_hostkey \ | 540 | test_hostkey \ |
541 | example_zonefile \ | 541 | example_zonefile \ |
542 | $(check_SCRIPTS) | 542 | $(check_SCRIPTS) \ |
543 | $(sql_DATA) | ||