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

Classes

 Single-entry cache holding the combined stat_info + meta_layout header of the most recently accessed metatile in a RADOS context. More...
struct  rados_ctx
 Per-backend Ceph RADOS cluster handle, pool I/O context, and metadata cache. More...

Functions

static char * rados_xyzo_to_storagekey (const char *xmlconfig, const char *options, int x, int y, int z, char *key)
 Format the RADOS object key for a metatile given (xmlconfig, options, x, y, z).
static char * read_meta_data (struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z)
 Fetch (or return cached) stat_info + meta_layout header bytes for a metatile.
static int rados_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)
 Read a single sub-tile payload from a metatile object stored in Ceph RADOS.
static struct stat_info rados_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 Ceph RADOS.
static char * rados_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 rados://<pool>/<key> storage URI identifying (x, y, z).
static int rados_metatile_write (struct storage_backend *store, const char *xmlconfig, const char *options, int x, int y, int z, const char *buf, int sz)
 Atomically write a full serialized metatile object to Ceph RADOS prefixed with stat_info.
static int rados_metatile_delete (struct storage_backend *store, const char *xmlconfig, int x, int y, int z)
 Remove the metatile object containing (x, y, z) from the Ceph RADOS pool.
static int rados_metatile_expire (struct storage_backend *store, const char *xmlconfig, int x, int y, int z)
 Mark a RADOS metatile object as expired by updating its leading struct stat_info.
static int rados_close_storage (struct storage_backend *store)
 Tear down the Ceph RADOS I/O context, cluster connection, and metadata cache.
struct storage_backend * init_storage_rados (const char *connection_string)
 Allocate and initialize a Ceph RADOS metatile storage_backend.

Variables

static pthread_mutex_t rados_mutex
 Mutex serializing rados_connect() calls across worker threads during startup.

Function Documentation

◆ init_storage_rados()

struct storage_backend * init_storage_rados ( const char * connection_string)

Allocate and initialize a Ceph RADOS metatile storage_backend.

Parses connection_string of the form "rados://<pool>/<path/to/ceph.conf>", creates a rados_t cluster handle, loads the Ceph configuration file, connects to the cluster (serialized via rados_mutex), opens an I/O context to <pool>, allocates the single-entry metadata_cache buffer, and wires all backend operation function pointers. Returns NULL if compiled without HAVE_LIBRADOS or if any initialization step fails.

Parameters
connection_stringBackend URI of the form "rados://<pool>/<ceph_conf_path>".
Returns
Newly allocated struct storage_backend pointer, or NULL on failure or if unsupported.

◆ rados_close_storage()

int rados_close_storage ( struct storage_backend * store)
static

Tear down the Ceph RADOS I/O context, cluster connection, and metadata cache.

Parameters
storeStorage backend instance to close.
Returns
0 on success, or -1 if store or store->storage_ctx is NULL.

◆ rados_metatile_delete()

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

Remove the metatile object containing (x, y, z) from the Ceph RADOS pool.

Parameters
storeInitialized RADOS storage_backend.
xmlconfigLogical map style name.
xGlobal tile X coordinate.
yGlobal tile Y coordinate.
zTile zoom level.
Returns
0 on success, or -1 on invalid I/O context or rados_remove() error.

◆ rados_metatile_expire()

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

Mark a RADOS metatile object as expired by updating its leading struct stat_info.

Reads the first sizeof(struct stat_info) bytes of the RADOS object, sets expired = 1, and writes those bytes back in place at offset 0 via rados_write() without rewriting the metatile image payloads.

Parameters
storeInitialized RADOS storage_backend.
xmlconfigLogical map style name.
xGlobal tile X coordinate.
yGlobal tile Y coordinate.
zTile zoom level.
Returns
0 on success, -1 if invalid I/O context or object does not exist (ENOENT), -2 if reading stat_info failed, or -3 if writing updated stat_info failed.

◆ rados_metatile_write()

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

Atomically write a full serialized metatile object to Ceph RADOS prefixed with stat_info.

Prepends a freshly initialized struct stat_info (expired = 0, current timestamps) ahead of buf and overwrites the entire RADOS object in a single rados_write_full() operation.

Parameters
storeInitialized RADOS storage_backend.
xmlconfigLogical map style name.
optionsStyle parameterization options string.
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, or -1 on allocation, invalid I/O context, or rados_write_full() failure.

◆ rados_tile_read()

int rados_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

Read a single sub-tile payload from a metatile object stored in Ceph RADOS.

Retrieves the metatile header via read_meta_data(), validates the magic signature and sub-tile count, and performs a ranged rados_read() at file_offset (adjusted for the leading struct stat_info) for tile_size bytes into buf.

Parameters
storeInitialized RADOS storage_backend.
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 read into buf (>= 0) on success, or a negative error code:
  • -1: Header allocation failure or rados_read() error reading sub-tile payload.
  • -3: Metatile object missing or header metadata read failed.
  • -4: Invalid metatile magic bytes.
  • -5: Unexpected tile count (m->count != METATILE * METATILE).
  • -6: Stored sub-tile size exceeds output buffer capacity sz.

◆ rados_tile_stat()

struct stat_info rados_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 Ceph RADOS.

Reads (or hits cache for) the metatile's leading struct stat_info and index table via read_meta_data(), setting tile_stat.size to the individual sub-tile's byte size (or -1 if the RADOS object is missing).

Parameters
storeInitialized RADOS 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 missing object or read error).

◆ rados_tile_storage_id()

char * rados_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 rados://<pool>/<key> storage URI identifying (x, y, z).

Parameters
storeInitialized RADOS storage_backend.
xmlconfigLogical map style name.
optionsStyle parameterization options string.
xGlobal tile X coordinate.
yGlobal tile Y coordinate.
zTile zoom level.
stringCaller-supplied output buffer (PATH_MAX bytes) receiving the formatted URI.
Returns
Pointer to string.

◆ rados_xyzo_to_storagekey()

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

Format the RADOS 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>/<z>/<x>/<y>[.<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 object key.
Returns
Pointer to key.

◆ read_meta_data()

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

Fetch (or return cached) stat_info + meta_layout header bytes for a metatile.

Aligns (x, y) to the metatile origin and checks ctx->metadata_cache. On a cache hit, returns ctx->metadata_cache.data immediately. On a cache miss, reads header_len bytes from offset 0 of the RADOS object into ctx->metadata_cache.data, updates the cache key, and returns the buffer (or invalidates the cache and returns NULL on error).

Parameters
storeInitialized RADOS storage_backend (storage_ctx holds struct rados_ctx *).
xmlconfigLogical map style name.
optionsStyle parameterization options string.
xGlobal tile X coordinate.
yGlobal tile Y coordinate.
zTile zoom level.
Returns
Pointer to ctx->metadata_cache.data containing stat_info followed by meta_layout, or NULL if the RADOS object does not exist or cannot be read.

Variable Documentation

◆ rados_mutex

pthread_mutex_t rados_mutex
static

Mutex serializing rados_connect() calls across worker threads during startup.