Skip to content

Pluggable BlobStores

Gabriel Roldan edited this page May 12, 2015 · 21 revisions

Introduction

BlobStore is the interface that handles the actual storage and retrieval of tile images. The only realization is currently FileBlobStore, which stores tiles as single files following a legacy filesystem layout.

There can be one single instance of FileBlobStore and the location of the stored tiles is tied to the location of the geowebcache.xml configuration file.

This proposal aims to incorporate the following enhancements while maintaining behavioral backwards compatibility with GWC versions prior to 1.8, and minimal API changes:

  • Decouple the location of the cache directory and the geowebcache.xml configuration file;
  • Allow for multiple cache base directories;
  • Allow for alternate storage mechanisms than the current FileBlobStore;
  • Allow for different storage mechanisms to coexist;
  • Allow to chose which "blob store" to save tiles to on a per "tile layer" basis.

Status

Work is being conducted on groldan's pluggable_blobstores branch.

Code is almost complete pending more unit tests for the new functionality and documentation.

See the full set of changes.

Strategy

Given BlobStore is an interface, we can obviously create implementations that store tiles in a different format and/or storage backend. Problem is GWC is designed to work with only one, defined in the Spring configuration. The easiest path forward to have multiple BlobStores coexisting is to keep that assumption but use a composite blob store instead, that merely multiplexes tile operations to the actual blobstores configured in the geowebcache.xml configuration file. This gives the flexibility necessary for the administrator to easily configure several blob stores without messing with the spring configuration.

To do so, instead of changing BlobStores API, we'll define a base configuration bean that defines the basic properties (unique id, enabled flag, etc) of a blob store, and concrete subclasses specialized in configuring and creating instances of different blob store types.

With this in place, the only missing piece to glue everything together is TileLayer's ability to define which blob store its tiles shall be stored to, so adding a blobStoreId property to TileLayer. This property can be undefined (i.e. null), meaning the "default" blob store shall be used instead. The "deafult" blob store is by default the same FileBlobStore than for versions prior to 1.8, and created automatically following the same cache directory lookup mechanism. But it can also be overridden by configuring a blob store in geowebcache.xml and settings its boolean default flag to true.

Changes

API

Add getBlobStoreId():String method to TileLayer, allow it to return null, meaning its tiles are handled by the default blob store.

public abstract class TileLayer{
/**
 * @return the identifier for the blob store that manages this layer tiles,
 *         or {@code null} if the default blob store shall be used
 */
public String getBlobStoreId();
...
}
public class GeoWebCacheConfiguration {
    private List<BlobStoreConfig> blobStores;
 ...
    public List<? extends BlobStoreConfig> getBlobStores(){
    	return blobStores;
    }
 ...
}

public class XMLConfiguration implements Configuration {
    public List<? extends BlobStoreConfig> getBlobStores() {
        return gwcConfig.getBlobStores();
    }
 ...
}
### Implementation

Decouple blob store configuration from application components weaving, defining a base bean class for blob store configuration and delegating blob store construction to a factory method:

public abstract class BlobStoreConfig { /** * @return the unique identifier for the blob store; which * {@link TileLayer#getBlobStoreId()} refers to. / public String getId(); /* * @return whether the blob store is enabled ({@code true}) or not. / public boolean isEnabled(); /* * Sets whether the blob store is enabled ({@code true}) or not. / public void setEnabled(boolean enabled); /* * @return whether the blob store defined by these settings is the default * one (i.e. the one used when * {@code TileLayer#getBlobStoreId() == null}, and hence used to * preserve backwards compatibility). / public boolean isDefault(); /* * Sets whether the blob store defined by these settings is the default one * (i.e. the one used when {@code TileLayer#getBlobStoreId() == null}, and * hence used to preserve backwards compatibility). / public void setDefault(boolean def); /* * Factory method for this class of blobstore, configured as per this * configuration object properties. *

* May only be called if {@link #isEnabled() == true}. * * @throws StorageException * if the blob store can't be created with this configuration * settings * @throws IllegalStateException * if {@link #isEnabled() isEnabled() == false} or * {@link #getId() getId() == null} */ public abstract BlobStore createInstance() throws StorageException; }

And have concrete config beans for each kind of blob store:

public class FileBlobStoreConfig extends BlobStoreConfig { public String getBaseDirectory() { ... }


Introduce `CompositeBlobStore`, a `BlobStore` implementation that rece

### Configuration
Clone this wiki locally