[mapserver-commits] r12468 - in trunk/mapserver/mapcache: include
src
svn at osgeo.org
svn at osgeo.org
Fri Aug 26 07:29:14 EDT 2011
Author: tbonfort
Date: 2011-08-26 04:29:14 -0700 (Fri, 26 Aug 2011)
New Revision: 12468
Modified:
trunk/mapserver/mapcache/include/geocache.h
trunk/mapserver/mapcache/src/geocache_seed.c
trunk/mapserver/mapcache/src/tileset.c
Log:
Modified: trunk/mapserver/mapcache/include/geocache.h
===================================================================
--- trunk/mapserver/mapcache/include/geocache.h 2011-08-26 11:29:10 UTC (rev 12467)
+++ trunk/mapserver/mapcache/include/geocache.h 2011-08-26 11:29:14 UTC (rev 12468)
@@ -1127,8 +1127,13 @@
void geocache_grid_get_closest_level(geocache_context *ctx, geocache_grid *grid, double resolution, int *level);
void geocache_tileset_tile_get(geocache_context *ctx, geocache_tile *tile);
-void geocache_tileset_tile_delete(geocache_context *ctx, geocache_tile *tile);
+/**
+ * \brief delete tile from cache
+ * @param whole_metatile delete all the other tiles from the metatile to
+ */
+void geocache_tileset_tile_delete(geocache_context *ctx, geocache_tile *tile, int whole_metatile);
+
int geocache_grid_is_bbox_aligned(geocache_context *ctx, geocache_grid *grid, double *bbox);
/**
Modified: trunk/mapserver/mapcache/src/geocache_seed.c
===================================================================
--- trunk/mapserver/mapcache/src/geocache_seed.c 2011-08-26 11:29:10 UTC (rev 12467)
+++ trunk/mapserver/mapcache/src/geocache_seed.c 2011-08-26 11:29:14 UTC (rev 12468)
@@ -38,7 +38,9 @@
typedef enum {
GEOCACHE_CMD_SEED,
- GEOCACHE_CMD_STOP
+ GEOCACHE_CMD_STOP,
+ GEOCACHE_CMD_DELETE,
+ GEOCACHE_CMD_SKIP
} cmd;
struct seed_cmd {
@@ -48,6 +50,7 @@
int z;
};
+cmd mode = GEOCACHE_CMD_SEED; /* the mode the utility will be running in: either seed or delete */
static const apr_getopt_option_t seed_options[] = {
/* long-option, short-option, has-arg flag, description */
@@ -57,6 +60,7 @@
{ "zoom", 'z', TRUE, "min and max zoomlevels to seed, separated by a comma. eg 0,6" },
{ "extent", 'e', TRUE, "extent to seed, format: minx,miny,maxx,maxy" },
{ "nthreads", 'n', TRUE, "number of parallel threads to use" },
+ { "mode", 'm', TRUE, "mode: seed (default) or delete" },
{ "older", 'o', TRUE, "reseed tiles older than supplied date (format: year/month/day hour:minute, eg: 2011/01/31 20:45" },
{ "dimension", 'D', TRUE, "set the value of a dimension (format DIMENSIONNAME=VALUE). Can be used multiple times for multiple dimensions" },
#ifdef USE_CLIPPERS
@@ -184,7 +188,7 @@
while (apr_queue_trypop(work_queue,&entry)!=APR_EAGAIN) {queuedtilestot--;}
break;
}
- int should_seed = 0;
+ cmd action = GEOCACHE_CMD_SKIP;
tile->x = x;
tile->y = y;
tile->z = z;
@@ -195,6 +199,7 @@
if(age_limit) {
if(tileset->cache->tile_get(&cmd_ctx,tile) == GEOCACHE_SUCCESS) {
if(tile->mtime && tile->mtime<age_limit) {
+ /* the tile modification time is older than the specified limit */
#ifdef USE_CLIPPERS
/* check we are in the requested features before deleting the tile */
if(nClippers > 0) {
@@ -202,41 +207,61 @@
}
#endif
if(intersects != 0) {
- /* the tile intersects the ogr features, seed it */
- geocache_tileset_tile_delete(&cmd_ctx,tile);
- should_seed = 1;
+ /* the tile intersects the ogr features, or there was no clipping asked for: seed it */
+ if(mode == GEOCACHE_CMD_SEED) {
+ geocache_tileset_tile_delete(&cmd_ctx,tile,GEOCACHE_TRUE);
+ action = GEOCACHE_CMD_SEED;
+ }
+ else { //if(action == GEOCACHE_CMD_DELETE)
+ action = GEOCACHE_CMD_DELETE;
+ }
} else {
/* the tile does not intersect the ogr features, and already exists, do nothing */
- should_seed = 0;
+ action = GEOCACHE_CMD_SKIP;
}
}
+ } else {
+ //BUG: tile_exists returned true, but tile_get returned a failure. not sure what to do.
+ action = GEOCACHE_CMD_SKIP;
}
+ } else {
+ if(mode == GEOCACHE_CMD_DELETE) {
+ //the tile exists and we are in delete mode: delete it
+ action = GEOCACHE_CMD_DELETE;
+ } else {
+ // the tile exists and we are in seed mode, skip to next one
+ action = GEOCACHE_CMD_SKIP;
+ }
}
} else {
// the tile does not exist
+ if(mode == GEOCACHE_CMD_SEED) {
#ifdef USE_CLIPPERS
/* check we are in the requested features before deleting the tile */
if(nClippers > 0) {
if(ogr_features_intersect_tile(&cmd_ctx,tile)) {
- should_seed = 1;
+ action = GEOCACHE_CMD_SEED;
} else {
- should_seed = 0;
+ action = GEOCACHE_CMD_SKIP;
}
} else {
- should_seed = 1;
+ action = GEOCACHE_CMD_SEED;
}
#else
- should_seed = 1;
+ action = GEOCACHE_CMD_SEED;
#endif
+ } else {
+ action = GEOCACHE_CMD_SKIP;
+ }
}
- if(should_seed){
+ if(action == GEOCACHE_CMD_SEED || action == GEOCACHE_CMD_DELETE){
//current x,y,z needs seeding, add it to the queue
struct seed_cmd *cmd = malloc(sizeof(struct seed_cmd));
cmd->x = x;
cmd->y = y;
cmd->z = z;
- cmd->command = GEOCACHE_CMD_SEED;
+ cmd->command = action;
apr_queue_push(work_queue,cmd);
queuedtilestot++;
progresslog(x,y,z);
@@ -256,6 +281,10 @@
}
}
+ if(error_detected) {
+ printf(ctx.get_error_message(&ctx));
+ }
+
//instruct rendering threads to stop working
int i;
for(i=0;i<nthreads;i++) {
@@ -279,7 +308,11 @@
tile->x = cmd->x;
tile->y = cmd->y;
tile->z = cmd->z;
- geocache_tileset_tile_get(&seed_ctx,tile);
+ if(cmd->command == GEOCACHE_CMD_SEED) {
+ geocache_tileset_tile_get(&seed_ctx,tile);
+ } else { //CMD_DELETE
+ geocache_tileset_tile_delete(&seed_ctx,tile,GEOCACHE_TRUE);
+ }
if(seed_ctx.get_error(&seed_ctx)) {
error_detected++;
ctx.log(&ctx,GEOCACHE_INFO,seed_ctx.get_error_message(&seed_ctx));
@@ -393,6 +426,15 @@
case 't':
tileset_name = optarg;
break;
+ case 'm':
+ if(!strcmp(optarg,"delete")) {
+ mode = GEOCACHE_CMD_DELETE;
+ } else if(strcmp(optarg,"seed")){
+ return usage(argv[0],"invalid mode, expecting \"seed\" or \"delete\"");
+ } else {
+ mode = GEOCACHE_CMD_SEED;
+ }
+ break;
case 'n':
nthreads = (int)strtol(optarg, NULL, 10);
break;
Modified: trunk/mapserver/mapcache/src/tileset.c
===================================================================
--- trunk/mapserver/mapcache/src/tileset.c 2011-08-26 11:29:10 UTC (rev 12467)
+++ trunk/mapserver/mapcache/src/tileset.c 2011-08-26 11:29:14 UTC (rev 12468)
@@ -435,7 +435,7 @@
apr_time_t now = apr_time_now();
apr_time_t stale = tile->mtime + apr_time_from_sec(tile->tileset->auto_expire);
if(stale<now) {
- geocache_tileset_tile_delete(ctx,tile);
+ geocache_tileset_tile_delete(ctx,tile,GEOCACHE_TRUE);
GC_CHECK_ERROR(ctx);
ret = GEOCACHE_CACHE_MISS;
}
@@ -510,23 +510,25 @@
}
}
-void geocache_tileset_tile_delete(geocache_context *ctx, geocache_tile *tile) {
+void geocache_tileset_tile_delete(geocache_context *ctx, geocache_tile *tile, int whole_metatile) {
int i;
/*delete the tile itself*/
tile->tileset->cache->tile_delete(ctx,tile);
GC_CHECK_ERROR(ctx);
- geocache_metatile *mt = geocache_tileset_metatile_get(ctx, tile);
- for(i=0;i<mt->ntiles;i++) {
- geocache_tile *subtile = &mt->tiles[i];
- /* skip deleting the actual tile */
- if(subtile->x == tile->x && subtile->y == tile->y) continue;
- subtile->tileset->cache->tile_delete(ctx,tile);
- /* silently pass failure if the tile was not found */
- if(ctx->get_error(ctx) == 404) {
- ctx->clear_errors(ctx);
+ if(whole_metatile) {
+ geocache_metatile *mt = geocache_tileset_metatile_get(ctx, tile);
+ for(i=0;i<mt->ntiles;i++) {
+ geocache_tile *subtile = &mt->tiles[i];
+ /* skip deleting the actual tile */
+ if(subtile->x == tile->x && subtile->y == tile->y) continue;
+ subtile->tileset->cache->tile_delete(ctx,subtile);
+ /* silently pass failure if the tile was not found */
+ if(ctx->get_error(ctx) == 404) {
+ ctx->clear_errors(ctx);
+ }
+ GC_CHECK_ERROR(ctx);
}
- GC_CHECK_ERROR(ctx);
}
}
More information about the mapserver-commits
mailing list