mod_tile 0.9.1
Renders map tiles with Mapnik and serves them using Apache HTTP Server
Loading...
Searching...
No Matches
store_memcached.c File Reference
#include <glib.h>
#include <stdio.h>
#include "config.h"
#include "g_logger.h"
#include "store.h"
#include "store_memcached.h"
#include <libmemcached/memcached.h>
#include <limits.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "metatile.h"
#include "render_config.h"

Functions

static char * memcached_xyzo_to_storagekey (const char *xmlconfig, const char *options, int x, int y, int z, char *key)
 Format the Memcached object key for a metatile given (xmlconfig, options, x, y, z).
static char * memcached_xyz_to_storagekey (const char *xmlconfig, int x, int y, int z, char *key)
 Format the Memcached object key for an unparameterized metatile.
static int memcached_tile_read (struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z, char *buf, size_t sz, int *compressed, char *log_msg)
 Fetch a metatile object from Memcached and extract a single sub-tile payload.
static struct stat_info memcached_tile_stat (struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z)
 Retrieve stored metadata, timestamps, and expiry status for a tile in Memcached.
static char * memcached_tile_storage_id (struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z, char *string)
 Format a human-readable memcached:/// storage URI identifying (x, y, z).
static int memcached_metatile_write (struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z, const char *buf, int sz)
 Store a serialized metatile buffer in Memcached prefixed with struct stat_info.
static int memcached_metatile_delete (struct storage_backend *store, const char *xmlconfig, int x, int y, int z)
 Delete the cached metatile entry containing (x, y, z) from Memcached.
static int memcached_metatile_expire (struct storage_backend *store, const char *xmlconfig, int x, int y, int z)
 Mark a cached metatile entry in Memcached as expired without evicting it.
static int memcached_close_storage (struct storage_backend *store)
 Release the memcached_st client handle associated with a Memcached storage backend.
struct storage_backend * init_storage_memcached (const char *connection_string)
 Allocate and initialize a Memcached metatile storage_backend.

Function Documentation

◆ init_storage_memcached()

struct storage_backend * init_storage_memcached ( const char * connection_string)

Allocate and initialize a Memcached metatile storage_backend.

Parses connection_string of the form "memcached://" (defaulting to "--server=localhost") or "memcached://<host[:port]>" (translated to "--server=<host[:port]>"), constructs a memcached_st handle via memcached(), and wires all backend operation function pointers. Returns NULL if compiled without HAVE_LIBMEMCACHED or if initialization fails.

Parameters
connection_stringBackend URI starting with "memcached://".
Returns
Newly allocated struct storage_backend pointer, or NULL on failure or if unsupported.

◆ memcached_close_storage()

int memcached_close_storage ( struct storage_backend * store)
static

Release the memcached_st client handle associated with a Memcached storage backend.

Parameters
storeStorage backend instance to close.
Returns
Always returns 0.

◆ memcached_metatile_delete()

int memcached_metatile_delete ( struct storage_backend * store,
const char * xmlconfig,
int x,
int y,
int z )
static

Delete the cached metatile entry containing (x, y, z) from Memcached.

Parameters
storeInitialized memcached storage_backend.
xmlconfigLogical map style name.
xTile X coordinate.
yTile Y coordinate.
zTile zoom level.
Returns
0 if deleted successfully, or -1 if memcached_delete() failed.

◆ memcached_metatile_expire()

int memcached_metatile_expire ( struct storage_backend * store,
const char * xmlconfig,
int x,
int y,
int z )
static

Mark a cached metatile entry in Memcached as expired without evicting it.

Fetches the existing cached blob, sets expired = 1 in its leading struct stat_info header, and writes the updated blob back via memcached_replace() so mod_tile can serve stale tiles while triggering background re-rendering.

Parameters
storeInitialized memcached storage_backend.
xmlconfigLogical map style name.
xTile X coordinate.
yTile Y coordinate.
zTile zoom level.
Returns
0 on success, or -1 if the entry was not found or memcached_replace() failed.

◆ memcached_metatile_write()

int memcached_metatile_write ( struct storage_backend * store,
const char * xmlconfig,
const char * options,
int x,
int y,
int z,
const char * buf,
int sz )
static

Store a serialized metatile buffer in Memcached prefixed with struct stat_info.

Prepends a freshly initialized struct stat_info (with expired = 0 and current timestamps) ahead of buf, writes the combined blob via memcached_set() with no expiration (0), and flushes libmemcached client buffers.

Parameters
storeInitialized memcached storage_backend.
xmlconfigLogical map style name.
optionsStyle parameterization options string (currently unused in key formatting).
xTop-left tile X coordinate of the metatile.
yTop-left tile Y coordinate of the metatile.
zTile zoom level.
bufSerialized metatile buffer (meta_layout + index table + tile payloads).
szTotal byte length of buf.
Returns
sz on success, -2 on memory allocation failure, or -1 if memcached_set() fails.

◆ memcached_tile_read()

int memcached_tile_read ( struct storage_backend * store,
const char * xmlconfig,
const char * options,
int x,
int y,
int z,
char * buf,
size_t sz,
int * compressed,
char * log_msg )
static

Fetch a metatile object from Memcached and extract a single sub-tile payload.

Retrieves the cached blob (which begins with a struct stat_info prefix followed by struct meta_layout and the sub-tile index/payloads), validates the metatile magic signature and tile count, and copies the requested sub-tile bytes into buf.

Parameters
storeInitialized memcached storage_backend (storage_ctx holds memcached_st *).
xmlconfigLogical map style name.
optionsStyle parameterization options string.
xGlobal tile X coordinate.
yGlobal tile Y coordinate.
zTile zoom level.
bufCaller-supplied output buffer receiving the sub-tile image bytes.
szMaximum capacity of buf in bytes.
compressedOutput flag set to 1 if META_MAGIC_COMPRESSED is present, 0 otherwise.
log_msgCaller-supplied buffer receiving an error message on failure.
Returns
Number of sub-tile bytes copied into buf (>= 0) on success, or a negative error code:
  • -1: Header allocation failure or Memcached cache miss/error.
  • -4: Invalid metatile magic bytes.
  • -5: Unexpected tile count (m->count != METATILE * METATILE).
  • -6: Stored sub-tile size exceeds output buffer capacity sz.

◆ memcached_tile_stat()

struct stat_info memcached_tile_stat ( struct storage_backend * store,
const char * xmlconfig,
const char * options,
int x,
int y,
int z )
static

Retrieve stored metadata, timestamps, and expiry status for a tile in Memcached.

Reads the cached metatile blob from Memcached, unpacks the leading struct stat_info, and sets tile_stat.size to the individual sub-tile's byte size (or -1 on cache miss).

Parameters
storeInitialized memcached storage_backend.
xmlconfigLogical map style name.
optionsStyle parameterization options string.
xGlobal tile X coordinate.
yGlobal tile Y coordinate.
zTile zoom level.
Returns
Populated struct stat_info (size < 0 indicates cache miss or error).

◆ memcached_tile_storage_id()

char * memcached_tile_storage_id ( struct storage_backend * store,
const char * xmlconfig,
const char * options,
int x,
int y,
int z,
char * string )
static

Format a human-readable memcached:/// storage URI identifying (x, y, z).

Parameters
storeInitialized memcached storage_backend (unused).
xmlconfigLogical map style name.
optionsStyle parameterization options string (currently unused).
xTile X coordinate.
yTile Y coordinate.
zTile zoom level.
stringCaller-supplied output buffer (PATH_MAX bytes) receiving the formatted URI.
Returns
Pointer to string.

◆ memcached_xyz_to_storagekey()

char * memcached_xyz_to_storagekey ( const char * xmlconfig,
int x,
int y,
int z,
char * key )
static

Format the Memcached object key for an unparameterized metatile.

Convenience wrapper around memcached_xyzo_to_storagekey() with empty options ("").

Parameters
xmlconfigLogical map style name.
xGlobal tile X coordinate.
yGlobal tile Y coordinate.
zTile zoom level.
keyCaller-supplied output buffer (PATH_MAX bytes) receiving the formatted key.
Returns
Pointer to key.

◆ memcached_xyzo_to_storagekey()

char * memcached_xyzo_to_storagekey ( const char * xmlconfig,
const char * options,
int x,
int y,
int z,
char * key )
static

Format the Memcached object key for a metatile given (xmlconfig, options, x, y, z).

Masks x and y down to the top-left (0, 0) corner of their METATILE x METATILE block and formats key as "<xmlconfig>/<x>/<y>/<z>[.<options>].meta".

Parameters
xmlconfigLogical map style name.
optionsStyle parameterization options string (omitted from key if empty).
xGlobal tile X coordinate.
yGlobal tile Y coordinate.
zTile zoom level.
keyCaller-supplied output buffer (PATH_MAX bytes) receiving the formatted key.
Returns
Pointer to key.