diff --git a/apache/mod_mapcache.c b/apache/mod_mapcache.c index e69ec7d9..b4fd6be4 100644 --- a/apache/mod_mapcache.c +++ b/apache/mod_mapcache.c @@ -307,11 +307,17 @@ static int write_http_response(mapcache_context_apache_request *ctx, mapcache_ht static void mod_mapcache_child_init(apr_pool_t *pool, server_rec *s) { + mapcache_context *ctx; + ctx = (mapcache_context*)create_apache_server_context(s,pool); for( ; s ; s=s->next) { mapcache_server_cfg* cfg = ap_get_module_config(s->module_config, &mapcache_module); int i,rv; for(i=0;ialiases->nelts;i++) { mapcache_alias_entry *alias_entry = APR_ARRAY_IDX(cfg->aliases,i,mapcache_alias_entry*); + mapcache_cache_child_init(ctx,alias_entry->cfg,pool); + if (GC_HAS_ERROR(ctx)) { + ap_log_error(APLOG_MARK, APLOG_CRIT, 0, s, "%s", ctx->get_error_message(ctx)); + } rv = mapcache_connection_pool_create(alias_entry->cfg, &(alias_entry->cp),pool); ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "creating a child process mapcache connection pool on server %s for alias %s", s->server_hostname, alias_entry->endpoint); if(rv!=APR_SUCCESS) { @@ -320,6 +326,10 @@ static void mod_mapcache_child_init(apr_pool_t *pool, server_rec *s) } for(i=0;iquickaliases->nelts;i++) { mapcache_alias_entry *alias_entry = APR_ARRAY_IDX(cfg->quickaliases,i,mapcache_alias_entry*); + mapcache_cache_child_init(ctx,alias_entry->cfg,pool); + if (GC_HAS_ERROR(ctx)) { + ap_log_error(APLOG_MARK, APLOG_CRIT, 0, s, "%s", ctx->get_error_message(ctx)); + } rv = mapcache_connection_pool_create(alias_entry->cfg, &(alias_entry->cp),pool); ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s, "creating a child process mapcache connection pool on server %s for alias %s", s->server_hostname, alias_entry->endpoint); if(rv!=APR_SUCCESS) { diff --git a/cgi/mapcache.c b/cgi/mapcache.c index 77cba06c..491c8741 100644 --- a/cgi/mapcache.c +++ b/cgi/mapcache.c @@ -213,6 +213,8 @@ static void load_config(mapcache_context *ctx, char *filename) apr_pool_destroy(config_pool); } config_pool = tmp_config_pool; + mapcache_cache_child_init(ctx,cfg,config_pool); + if (GC_HAS_ERROR(ctx)) goto failed_load; mapcache_connection_pool_create(cfg, &ctx->connection_pool, config_pool); return; diff --git a/contrib/mapcache_detail/mapcache_detail.c b/contrib/mapcache_detail/mapcache_detail.c index b16eb26b..7b5d4792 100644 --- a/contrib/mapcache_detail/mapcache_detail.c +++ b/contrib/mapcache_detail/mapcache_detail.c @@ -714,6 +714,8 @@ int main(int argc, char * argv[]) mapcache_context_init(&ctx); ctx.config = mapcache_configuration_create(ctx.pool); ctx.log = mapcache_log; + mapcache_cache_child_init(&ctx,ctx.config,ctx.pool); + if (GC_HAS_ERROR(&ctx)) goto failure; mapcache_connection_pool_create(ctx.config, &ctx.connection_pool, ctx.pool); diff --git a/include/mapcache.h b/include/mapcache.h index 0baeffc1..2792341b 100644 --- a/include/mapcache.h +++ b/include/mapcache.h @@ -369,6 +369,7 @@ struct mapcache_cache { void (*configuration_parse_xml)(mapcache_context *ctx, ezxml_t xml, mapcache_cache * cache, mapcache_cfg *config); void (*configuration_post_config)(mapcache_context *ctx, mapcache_cache * cache, mapcache_cfg *config); + void (*child_init)(mapcache_context *ctx, mapcache_cache *cache, apr_pool_t *pchild); }; MS_DLL_EXPORT int mapcache_cache_tile_get(mapcache_context *ctx, mapcache_cache *cache, mapcache_tile *tile); @@ -377,6 +378,9 @@ MS_DLL_EXPORT int mapcache_cache_tile_exists(mapcache_context *ctx, mapcache_cac MS_DLL_EXPORT void mapcache_cache_tile_set(mapcache_context *ctx, mapcache_cache *cache, mapcache_tile *tile); void mapcache_cache_tile_multi_set(mapcache_context *ctx, mapcache_cache *cache, mapcache_tile *tiles, int ntiles); +MS_DLL_EXPORT void mapcache_cache_child_init(mapcache_context *ctx, mapcache_cfg *config, apr_pool_t *pchild); +static inline void mapcache_cache_child_init_noop(mapcache_context *ctx, mapcache_cache *cache, apr_pool_t *pchild) { +}; /** diff --git a/lib/cache.c b/lib/cache.c index 1b5b515d..c3788bae 100644 --- a/lib/cache.c +++ b/lib/cache.c @@ -174,3 +174,16 @@ void mapcache_cache_tile_multi_set(mapcache_context *ctx, mapcache_cache *cache, } } } + +void mapcache_cache_child_init(mapcache_context *ctx, mapcache_cfg *config, apr_pool_t *pchild) +{ + apr_hash_index_t *cachei = apr_hash_first(pchild,config->caches); + while(cachei) { + mapcache_cache *cache; + const void *key; + apr_ssize_t keylen; + apr_hash_this(cachei,&key,&keylen,(void**)&cache); + cache->child_init(ctx,cache,pchild); + cachei = apr_hash_next(cachei); + } +} diff --git a/lib/cache_bdb.c b/lib/cache_bdb.c index 47a9bbc8..cdc900bb 100644 --- a/lib/cache_bdb.c +++ b/lib/cache_bdb.c @@ -417,6 +417,7 @@ mapcache_cache* mapcache_cache_bdb_create(mapcache_context *ctx) cache->cache._tile_multi_set = _mapcache_cache_bdb_multiset; cache->cache.configuration_post_config = _mapcache_cache_bdb_configuration_post_config; cache->cache.configuration_parse_xml = _mapcache_cache_bdb_configuration_parse_xml; + cache->cache.child_init = mapcache_cache_child_init_noop; cache->basedir = NULL; cache->key_template = NULL; return (mapcache_cache*)cache; diff --git a/lib/cache_composite.c b/lib/cache_composite.c index b29c389f..440c2cb5 100644 --- a/lib/cache_composite.c +++ b/lib/cache_composite.c @@ -262,5 +262,6 @@ mapcache_cache* mapcache_cache_composite_create(mapcache_context *ctx) cache->cache._tile_multi_set = _mapcache_cache_composite_tile_multi_set; cache->cache.configuration_post_config = _mapcache_cache_composite_configuration_post_config; cache->cache.configuration_parse_xml = _mapcache_cache_composite_configuration_parse_xml; + cache->cache.child_init = mapcache_cache_child_init_noop; return (mapcache_cache*)cache; } diff --git a/lib/cache_couchbase.c b/lib/cache_couchbase.c index e81fe608..f0533aee 100644 --- a/lib/cache_couchbase.c +++ b/lib/cache_couchbase.c @@ -466,6 +466,7 @@ mapcache_cache* mapcache_cache_couchbase_create(mapcache_context *ctx) { cache->cache.tile_delete = _mapcache_cache_couchbase_delete; cache->cache.configuration_parse_xml = _mapcache_cache_couchbase_configuration_parse_xml; cache->cache.configuration_post_config = _mapcache_cache_couchbase_configuration_post_config; + cache->cache.child_init = mapcache_cache_child_init_noop; cache->host = NULL; cache->username = NULL; cache->password = NULL; diff --git a/lib/cache_disk.c b/lib/cache_disk.c index 48dfb5b6..719a8f7f 100644 --- a/lib/cache_disk.c +++ b/lib/cache_disk.c @@ -768,6 +768,7 @@ mapcache_cache* mapcache_cache_disk_create(mapcache_context *ctx) cache->cache._tile_set = _mapcache_cache_disk_set; cache->cache.configuration_post_config = _mapcache_cache_disk_configuration_post_config; cache->cache.configuration_parse_xml = _mapcache_cache_disk_configuration_parse_xml; + cache->cache.child_init = mapcache_cache_child_init_noop; return (mapcache_cache*)cache; } diff --git a/lib/cache_fallback.c b/lib/cache_fallback.c index 70edcd3b..a6c29ba5 100644 --- a/lib/cache_fallback.c +++ b/lib/cache_fallback.c @@ -190,6 +190,7 @@ mapcache_cache* mapcache_cache_fallback_create(mapcache_context *ctx) cache->cache._tile_multi_set = _mapcache_cache_fallback_tile_multi_set; cache->cache.configuration_post_config = _mapcache_cache_fallback_configuration_post_config; cache->cache.configuration_parse_xml = _mapcache_cache_fallback_configuration_parse_xml; + cache->cache.child_init = mapcache_cache_child_init_noop; return (mapcache_cache*)cache; } diff --git a/lib/cache_memcache.c b/lib/cache_memcache.c index 3b2c7630..53c33e07 100644 --- a/lib/cache_memcache.c +++ b/lib/cache_memcache.c @@ -370,6 +370,7 @@ mapcache_cache* mapcache_cache_memcache_create(mapcache_context *ctx) cache->cache._tile_delete = _mapcache_cache_memcache_delete; cache->cache.configuration_post_config = _mapcache_cache_memcache_configuration_post_config; cache->cache.configuration_parse_xml = _mapcache_cache_memcache_configuration_parse_xml; + cache->cache.child_init = mapcache_cache_child_init_noop; return (mapcache_cache*)cache; } diff --git a/lib/cache_multitier.c b/lib/cache_multitier.c index 6e68ed66..fb24a91d 100644 --- a/lib/cache_multitier.c +++ b/lib/cache_multitier.c @@ -160,6 +160,7 @@ mapcache_cache* mapcache_cache_multitier_create(mapcache_context *ctx) cache->cache._tile_multi_set = _mapcache_cache_multitier_tile_multi_set; cache->cache.configuration_post_config = _mapcache_cache_multitier_configuration_post_config; cache->cache.configuration_parse_xml = _mapcache_cache_multitier_configuration_parse_xml; + cache->cache.child_init = mapcache_cache_child_init_noop; return (mapcache_cache*)cache; } diff --git a/lib/cache_redis.c b/lib/cache_redis.c index a106e91e..4e43f6d6 100644 --- a/lib/cache_redis.c +++ b/lib/cache_redis.c @@ -297,6 +297,7 @@ mapcache_cache* mapcache_cache_redis_create(mapcache_context *ctx) cache->cache._tile_delete = _mapcache_cache_redis_delete; cache->cache.configuration_post_config = _mapcache_cache_redis_configuration_post_config; cache->cache.configuration_parse_xml = _mapcache_cache_redis_configuration_parse_xml; + cache->cache.child_init = mapcache_cache_child_init_noop; cache->host = NULL; cache->port = 6379; cache->bucket_template = NULL; diff --git a/lib/cache_rest.c b/lib/cache_rest.c index fe0e489a..4c7e9ed2 100644 --- a/lib/cache_rest.c +++ b/lib/cache_rest.c @@ -1441,6 +1441,7 @@ void mapcache_cache_rest_init(mapcache_context *ctx, mapcache_cache_rest *cache) cache->cache._tile_set = _mapcache_cache_rest_set; cache->cache.configuration_post_config = _mapcache_cache_rest_configuration_post_config; cache->cache.configuration_parse_xml = _mapcache_cache_rest_configuration_parse_xml; + cache->cache.child_init = mapcache_cache_child_init_noop; } /** * \brief creates and initializes a mapcache_rest_cache diff --git a/lib/cache_riak.c b/lib/cache_riak.c index f8230d5f..7e2976c9 100644 --- a/lib/cache_riak.c +++ b/lib/cache_riak.c @@ -424,6 +424,7 @@ mapcache_cache* mapcache_cache_riak_create(mapcache_context *ctx) { cache->cache._tile_delete = _mapcache_cache_riak_delete; cache->cache.configuration_parse_xml = _mapcache_cache_riak_configuration_parse_xml; cache->cache.configuration_post_config = _mapcache_cache_riak_configuration_post_config; + cache->cache.child_init = mapcache_cache_child_init_noop; cache->host = NULL; cache->port = 8087; // Default RIAK port used for protobuf cache->bucket_template = NULL; diff --git a/lib/cache_sqlite.c b/lib/cache_sqlite.c index ee72ba7d..0557215a 100644 --- a/lib/cache_sqlite.c +++ b/lib/cache_sqlite.c @@ -1086,6 +1086,7 @@ mapcache_cache* mapcache_cache_sqlite_create(mapcache_context *ctx) cache->cache._tile_multi_set = _mapcache_cache_sqlite_multi_set; cache->cache.configuration_post_config = _mapcache_cache_sqlite_configuration_post_config; cache->cache.configuration_parse_xml = _mapcache_cache_sqlite_configuration_parse_xml; + cache->cache.child_init = mapcache_cache_child_init_noop; cache->create_stmt.sql = apr_pstrdup(ctx->pool, "create table if not exists tiles(tileset text, grid text, x integer, y integer, z integer, data blob, dim text, ctime datetime, primary key(tileset,grid,x,y,z,dim))"); cache->exists_stmt.sql = apr_pstrdup(ctx->pool, @@ -1121,6 +1122,7 @@ mapcache_cache* mapcache_cache_mbtiles_create(mapcache_context *ctx) return NULL; } cache->cache.configuration_post_config = _mapcache_cache_mbtiles_configuration_post_config; + cache->cache.child_init = mapcache_cache_child_init_noop; cache->cache._tile_set = _mapcache_cache_mbtiles_set; cache->cache._tile_multi_set = _mapcache_cache_mbtiles_multi_set; cache->cache._tile_delete = _mapcache_cache_mbtiles_delete; diff --git a/lib/cache_tiff.c b/lib/cache_tiff.c index a5766027..c291be8a 100644 --- a/lib/cache_tiff.c +++ b/lib/cache_tiff.c @@ -1397,6 +1397,7 @@ mapcache_cache* mapcache_cache_tiff_create(mapcache_context *ctx) cache->cache._tile_set = _mapcache_cache_tiff_set; cache->cache.configuration_post_config = _mapcache_cache_tiff_configuration_post_config; cache->cache.configuration_parse_xml = _mapcache_cache_tiff_configuration_parse_xml; + cache->cache.child_init = mapcache_cache_child_init_noop; cache->count_x = 10; cache->count_y = 10; cache->x_fmt = cache->y_fmt = cache->z_fmt diff --git a/lib/cache_tokyocabinet.c b/lib/cache_tokyocabinet.c index 54dc9766..789df810 100644 --- a/lib/cache_tokyocabinet.c +++ b/lib/cache_tokyocabinet.c @@ -219,6 +219,7 @@ mapcache_cache* mapcache_cache_tc_create(mapcache_context *ctx) cache->cache.tile_set = _mapcache_cache_tc_set; cache->cache.configuration_post_config = _mapcache_cache_tc_configuration_post_config; cache->cache.configuration_parse_xml = _mapcache_cache_tc_configuration_parse_xml; + cache->cache.child_init = mapcache_cache_child_init_noop; cache->basedir = NULL; cache->key_template = NULL; return (mapcache_cache*)cache; diff --git a/nginx/ngx_http_mapcache_module.c b/nginx/ngx_http_mapcache_module.c index e04ca4f6..6afa0012 100644 --- a/nginx/ngx_http_mapcache_module.c +++ b/nginx/ngx_http_mapcache_module.c @@ -300,6 +300,11 @@ ngx_http_mapcache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "no mapcache s configured/enabled, no point in continuing."); return NGX_CONF_ERROR; } + mapcache_cache_child_init(ctx,ctx->cfg,ctx->pool); + if(GC_HAS_ERROR(ctx)) { + ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,ctx->get_error_message(ctx)); + return NGX_CONF_ERROR; + } mapcache_connection_pool_create(ctx->config, &ctx->connection_pool,ctx->pool); ctx->config->non_blocking = 1; diff --git a/util/mapcache_seed.c b/util/mapcache_seed.c index dc39e290..08b46ddd 100644 --- a/util/mapcache_seed.c +++ b/util/mapcache_seed.c @@ -1189,6 +1189,9 @@ int main(int argc, const char **argv) mapcache_configuration_post_config(&ctx,cfg); if(ctx.get_error(&ctx)) return usage(argv[0],ctx.get_error_message(&ctx)); + mapcache_cache_child_init(&ctx,cfg,ctx.pool); + if (GC_HAS_ERROR(&ctx)) + return usage(argv[0],ctx.get_error_message(&ctx)); mapcache_connection_pool_create(cfg, &ctx.connection_pool, ctx.pool); }