Skip to content

Commit 09e7fa1

Browse files
authored
Allow host:port specification for MemcacheD storage backend (#369)
So that MemcacheD hosts and ports other than `localhost` and `11211` can be used. _Also_: - Added `ctest --parallel` execution support - Added tests for custom `MemcacheD` {host}:{port} - Added tests for `AddTileConfig`/`AddTileMimeConfig`
1 parent a346728 commit 09e7fa1

6 files changed

Lines changed: 282 additions & 83 deletions

File tree

etc/apache2/renderd-example-map.conf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ Redirect /renderd-example-map/leaflet/leaflet.min.js https://unpkg.com/leaflet/d
1414

1515
Listen 8081
1616
<VirtualHost *:8081>
17-
17+
# Specify the location under which (meta)tiles are stored.
18+
# This can be a directory path, or, when using storage backends other than "file", a URI.
19+
#
20+
# I.E.:
21+
# "memcached://{memcached_host}:{memcached_port}" for MemcacheD
1822
ModTileTileDir /var/cache/renderd/tiles
1923

2024
# You can manually configure each tile set with AddTileConfig or AddTileMimeConfig.

etc/renderd/renderd.conf.examples

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,15 @@ tile_dir=/var/cache/renderd/tiles
1919
;iphostname=::1
2020
;ipport=7654
2121
;num_threads=8
22-
;tile_dir=memcached://
22+
;tile_dir=memcached:// ; Defaults to "localhost:11211" when host:port is not specified
23+
;pid_file=/run/renderd/renderd_memcached.pid
24+
;stats_file=/run/renderd/renderd.stats
25+
26+
;[renderd]
27+
;iphostname=::1
28+
;ipport=7654
29+
;num_threads=8
30+
;tile_dir=memcached://memcached_host:11212 ; You may also specify a custom host:port
2331
;pid_file=/run/renderd/renderd_memcached.pid
2432
;stats_file=/run/renderd/renderd.stats
2533

@@ -70,3 +78,19 @@ XML=/var/www/example-map/mapnik.xml
7078
;ATTRIBUTION=&copy;<a href=\"http://www.openstreetmap.org/\">OpenStreetMap</a> and <a href=\"http://wiki.openstreetmap.org/wiki/Contributors\">contributors</a>, <a href=\"http://opendatacommons.org/licenses/odbl/\">ODbL</a>
7179
;SERVER_ALIAS=http://localhost/
7280
;CORS=*
81+
82+
;[style3]
83+
;URI=/osm_tiles3/
84+
;TILEDIR=memcached://
85+
;TILESIZE=512
86+
;XML=/usr/share/renderd/openstreetmap/osm-local3.xml
87+
;HOST=tile.openstreetmap.org
88+
;HTCPHOST=proxy.openstreetmap.org
89+
;** config options used by mod_tile, but not renderd **
90+
;MINZOOM=0
91+
;MAXZOOM=22
92+
;TYPE=png image/png png256 ; Values are: <extension> <mime-type> <output-format> (for more information about output format see https://github.com/mapnik/mapnik/wiki/Image-IO)
93+
;DESCRIPTION=This is a description of the tile layer used in the tile json request
94+
;ATTRIBUTION=&copy;<a href=\"http://www.openstreetmap.org/\">OpenStreetMap</a> and <a href=\"http://wiki.openstreetmap.org/wiki/Contributors\">contributors</a>, <a href=\"http://opendatacommons.org/licenses/odbl/\">ODbL</a>
95+
;SERVER_ALIAS=http://localhost/
96+
;CORS=*

src/store_memcached.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,20 @@ struct storage_backend * init_storage_memcached(const char * connection_string)
284284
return NULL;
285285
}
286286

287+
if (strcmp(connection_string, "memcached://")) {
288+
int connection_string_len = strnlen(connection_string, PATH_MAX);
289+
connection_str = malloc(sizeof(char) * connection_string_len);
290+
// The length of the string "memcached://" is 12
291+
snprintf(connection_str, connection_string_len - 2, "--server=%.*s", connection_string_len - 12, connection_string + 12);
292+
}
293+
294+
g_logger(G_LOG_LEVEL_DEBUG, "init_storage_memcached: Creating memcached ctx with options '%s'", connection_str);
287295
ctx = memcached(connection_str, strlen(connection_str));
288296

297+
if (strcmp(connection_string, "memcached://")) {
298+
free(connection_str);
299+
}
300+
289301
if (ctx == NULL) {
290302
g_logger(G_LOG_LEVEL_ERROR, "init_storage_memcached: Failed to create memcached ctx");
291303
free(store);

0 commit comments

Comments
 (0)