Skip to content

Commit

Permalink
Allow host:port specification for MemcacheD storage backend (#369)
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
hummeltech authored Jan 10, 2024
1 parent a346728 commit 09e7fa1
Show file tree
Hide file tree
Showing 6 changed files with 282 additions and 83 deletions.
6 changes: 5 additions & 1 deletion etc/apache2/renderd-example-map.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ Redirect /renderd-example-map/leaflet/leaflet.min.js https://unpkg.com/leaflet/d

Listen 8081
<VirtualHost *:8081>

# Specify the location under which (meta)tiles are stored.
# This can be a directory path, or, when using storage backends other than "file", a URI.
#
# I.E.:
# "memcached://{memcached_host}:{memcached_port}" for MemcacheD
ModTileTileDir /var/cache/renderd/tiles

# You can manually configure each tile set with AddTileConfig or AddTileMimeConfig.
Expand Down
26 changes: 25 additions & 1 deletion etc/renderd/renderd.conf.examples
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ tile_dir=/var/cache/renderd/tiles
;iphostname=::1
;ipport=7654
;num_threads=8
;tile_dir=memcached://
;tile_dir=memcached:// ; Defaults to "localhost:11211" when host:port is not specified
;pid_file=/run/renderd/renderd_memcached.pid
;stats_file=/run/renderd/renderd.stats

;[renderd]
;iphostname=::1
;ipport=7654
;num_threads=8
;tile_dir=memcached://memcached_host:11212 ; You may also specify a custom host:port
;pid_file=/run/renderd/renderd_memcached.pid
;stats_file=/run/renderd/renderd.stats

Expand Down Expand Up @@ -70,3 +78,19 @@ XML=/var/www/example-map/mapnik.xml
;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>
;SERVER_ALIAS=http://localhost/
;CORS=*

;[style3]
;URI=/osm_tiles3/
;TILEDIR=memcached://
;TILESIZE=512
;XML=/usr/share/renderd/openstreetmap/osm-local3.xml
;HOST=tile.openstreetmap.org
;HTCPHOST=proxy.openstreetmap.org
;** config options used by mod_tile, but not renderd **
;MINZOOM=0
;MAXZOOM=22
;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)
;DESCRIPTION=This is a description of the tile layer used in the tile json request
;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>
;SERVER_ALIAS=http://localhost/
;CORS=*
12 changes: 12 additions & 0 deletions src/store_memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,20 @@ struct storage_backend * init_storage_memcached(const char * connection_string)
return NULL;
}

if (strcmp(connection_string, "memcached://")) {
int connection_string_len = strnlen(connection_string, PATH_MAX);
connection_str = malloc(sizeof(char) * connection_string_len);
// The length of the string "memcached://" is 12
snprintf(connection_str, connection_string_len - 2, "--server=%.*s", connection_string_len - 12, connection_string + 12);
}

g_logger(G_LOG_LEVEL_DEBUG, "init_storage_memcached: Creating memcached ctx with options '%s'", connection_str);
ctx = memcached(connection_str, strlen(connection_str));

if (strcmp(connection_string, "memcached://")) {
free(connection_str);
}

if (ctx == NULL) {
g_logger(G_LOG_LEVEL_ERROR, "init_storage_memcached: Failed to create memcached ctx");
free(store);
Expand Down
Loading

0 comments on commit 09e7fa1

Please sign in to comment.