Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug where changes to GWC layers won't be propagated to other pods. #570

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
import java.util.Set;
import java.util.stream.Stream;

/**
* {@link TileLayerInfoRepository} decorator cache {@link TileLayerInfo}s on demand, alleviating the
* load on the delegate, especially under load.
*/
@RequiredArgsConstructor
@Slf4j(topic = "org.geoserver.cloud.gwc.backend.pgconfig.caching")
public class CachingTileLayerInfoRepository implements TileLayerInfoRepository {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.geoserver.cloud.backend.pgconfig.catalog.repository.LoggingTemplate;
import org.geoserver.gwc.layer.CatalogConfiguration;
import org.geoserver.gwc.layer.GeoServerTileLayerInfo;
import org.geoserver.gwc.layer.TileLayerCatalog;
import org.geoserver.platform.resource.ResourceStore;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.EmptyResultDataAccessException;
Expand All @@ -26,8 +25,8 @@
import java.util.stream.Stream;

/**
* Implementation of {@link TileLayerCatalog} for {@link CatalogConfiguration} to manage {@link
* GeoServerTileLayerInfo}s directly from the database instead of going through {@link
* Implementation of {@link TileLayerInfoRepository} for {@link CatalogConfiguration} to manage
* {@link GeoServerTileLayerInfo}s directly from the database instead of going through {@link
* ResourceStore}.
*
* @since 1.7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
import java.util.Set;
import java.util.stream.Stream;

/**
* {@code TileLayerInfoRepository} defines CRUD operations on {@link TileLayerInfo}.
*
* @see PgconfigTileLayerCatalog
*/
public interface TileLayerInfoRepository {

void add(TileLayerInfo pgInfo) throws DataAccessException;
Expand Down
10 changes: 10 additions & 0 deletions src/gwc/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,15 @@
<artifactId>gs-web-gwc</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-assertj</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import org.geoserver.GeoServerConfigurationLock;
import org.geoserver.catalog.Catalog;
import org.geoserver.cloud.gwc.event.TileLayerEvent;
import org.geoserver.cloud.gwc.repository.CachingTileLayerCatalog;
import org.geoserver.cloud.gwc.repository.CloudCatalogConfiguration;
import org.geoserver.cloud.gwc.repository.GeoServerTileLayerConfiguration;
Expand All @@ -16,8 +15,10 @@
import org.geoserver.gwc.config.GWCConfigPersister;
import org.geoserver.gwc.config.GWCInitializer;
import org.geoserver.gwc.layer.CatalogConfiguration;
import org.geoserver.gwc.layer.GeoServerTileLayer;
import org.geoserver.gwc.layer.TileLayerCatalog;
import org.geoserver.platform.resource.ResourceStore;
import org.geowebcache.config.TileLayerConfiguration;
import org.geowebcache.grid.GridSetBroker;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cache.CacheManager;
Expand All @@ -29,7 +30,6 @@
import org.springframework.web.context.WebApplicationContext;

import java.util.Optional;
import java.util.function.Consumer;

/**
* @since 1.0
Expand Down Expand Up @@ -57,6 +57,20 @@ DefaultGwcInitializer gwcInitializer(
return new DefaultGwcInitializer(configPersister, blobStore, geoseverTileLayers, lock);
}

/**
* In vanilla GeoServer, {@link CatalogConfiguration} is the {@link TileLayerConfiguration}
* contributed to the app context to serve {@code TileLayer}s ({@link GeoServerTileLayer}) out
* of the GeoServer {@link Catalog} by means of a {@link TileLayerCatalog}.
*
* <p>Here we contribute a different {@code TileLayerConfiguration} for the same purpose, {@link
* GeoServerTileLayerConfiguration}, which is a distributed-event aware decorator over the
* actual {@link CloudCatalogConfiguration} implementation of {@code TileLayerCatalog}.
*
* <p>Since the {@code CloudCatalogConfiguration} isn't hence a spring bean, in order to avoid
* registering as a delegate to {@link TileLayerDispatcher}, {@link TileLayerEvents} will need
* to be relayed from {@code GeoServerTileLayerConfiguration} to {@link
* CloudCatalogConfiguration#onTileLayerEventEvict()}.
*/
@SuppressWarnings("java:S6830")
@Bean(name = "gwcCatalogConfiguration")
GeoServerTileLayerConfiguration gwcCatalogConfiguration( //
Expand All @@ -66,8 +80,12 @@ GeoServerTileLayerConfiguration gwcCatalogConfiguration( //
ApplicationEventPublisher eventPublisher) {

var config = new CloudCatalogConfiguration(catalog, tld, gsb);
Consumer<TileLayerEvent> gwcEventPublisher = eventPublisher::publishEvent;
return new GeoServerTileLayerConfiguration(config, gwcEventPublisher);
var eventAwareConfig =
new GeoServerTileLayerConfiguration(config, eventPublisher::publishEvent);
// tell GeoServerTileLayerConfiguration to relay TileLayerEvents to
// CloudCatalogConfiguration, since it's not a spring bean can't listen itself.
eventAwareConfig.setEventListener(config::onTileLayerEventEvict);
return eventAwareConfig;
}

@Primary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ public TileLayerEvent(
this.name = layerName;
}

public static TileLayerEvent ofId(
@NonNull Object source, @NonNull Type eventType, @NonNull String layerId) {
return new TileLayerEvent(source, eventType, layerId, layerId);
}

public static TileLayerEvent created(
@NonNull Object source, @NonNull String publishedId, @NonNull String layerName) {
return valueOf(source, Type.CREATED, publishedId, layerName, null);
Expand Down Expand Up @@ -77,8 +72,20 @@ private static TileLayerEvent valueOf(

@Override
public String toString() {
return "%s[%s id: %s, name: %s]"
.formatted(getClass().getSimpleName(), getEventType(), getPublishedId(), getName());
if (null == getOldName())
return "%s[%s id: %s, name: %s]"
.formatted(
getClass().getSimpleName(),
getEventType(),
getPublishedId(),
getName());
return "%s[%s id: %s, name: %s, oldname: %s]"
.formatted(
getClass().getSimpleName(),
getEventType(),
getPublishedId(),
getName(),
getOldName());
}

protected @Override String getObjectId() {
Expand Down
Loading
Loading