Skip to content

Commit

Permalink
GEOS-8837 get rid of hazelcast cache
Browse files Browse the repository at this point in the history
  • Loading branch information
NielsCharlier committed Jul 20, 2018
1 parent 445625c commit 60c985d
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
<property name="rawCatalog" ref="rawCatalog"/>
</bean>

<bean id="hzCacheProvider" class="org.geoserver.cluster.hazelcast.HzCacheProvider">
<!-- <bean id="hzCacheProvider" class="org.geoserver.cluster.hazelcast.HzCacheProvider">
<constructor-arg ref="xstreamPersisterFactory"/>
</bean>
</bean>
<bean id="hzExtensionFilter" class="org.geoserver.cluster.hazelcast.HzExtensionFilter">
</bean>
</bean> -->

<bean id="hzLockProvider" class="org.geoserver.cluster.hazelcast.HzLockProvider">
<property name="cluster" ref="hzCluster"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ public void setLockProvider(LockProvider lockProvider) {
*
* @param resourceWatcher
*/
public void setResourceNotificationDispatcher(ResourceNotificationDispatcher resourceWatcher) {
this.resourceNotificationDispatcher = resourceWatcher;
public void setResourceNotificationDispatcher(ResourceNotificationDispatcher resourceNotDis) {
this.resourceNotificationDispatcher = resourceNotDis;
dir.setResourceNotificationDispatcher(resourceNotDis);
}

public JDBCResourceStore(JDBCDirectoryStructure dir) {
Expand All @@ -85,6 +86,7 @@ public JDBCResourceStore(JDBCDirectoryStructure dir) {

public JDBCResourceStore(DataSource ds, JDBCResourceStoreProperties config) {
this(new JDBCDirectoryStructure(ds, config));
dir.setResourceNotificationDispatcher(resourceNotificationDispatcher);
}

public JDBCResourceStore(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sql.DataSource;
import org.geoserver.jdbcstore.internal.JDBCQueryHelper.*;
import org.geoserver.platform.resource.Paths;
import org.geoserver.platform.resource.ResourceListener;
import org.geoserver.platform.resource.ResourceNotification;
import org.geoserver.platform.resource.ResourceNotificationDispatcher;
import org.geoserver.util.CacheProvider;
import org.geoserver.util.DefaultCacheProvider;

Expand Down Expand Up @@ -60,6 +62,8 @@ public class JDBCDirectoryStructure {

Cache<ArrayList<String>, EntryMetaData> entryCache;

private ResourceNotificationDispatcher resourceNotificationDispatcher;

private static class EntryMetaData implements Serializable {
private static final long serialVersionUID = 4442694295286861328L;

Expand Down Expand Up @@ -220,7 +224,7 @@ public InputStream getContent() {
}

public void setContent(InputStream is) {
md.lastModified = new Timestamp(new java.util.Date().getTime());
md.lastModified = new Timestamp(System.currentTimeMillis());
if (helper.updateQuery(
TABLE_RESOURCES,
new PathSelector(path),
Expand Down Expand Up @@ -302,7 +306,7 @@ public boolean createResource() {
}

ByteArrayInputStream is = new ByteArrayInputStream(new byte[0]);
/*Integer*/ md.oid =
md.oid =
helper.insertQuery(
TABLE_RESOURCES,
new Assignment<String>(NAME, getName()),
Expand All @@ -326,14 +330,7 @@ public boolean createResource() {
}

public String toString() {
StringBuilder buf = new StringBuilder();
for (int i = 0; i < path.size(); i++) {
if (i > 0) { // no leading slash
buf.append("/");
}
buf.append(path.get(i));
}
return buf.toString();
return mergePath(path);
}

@Override
Expand Down Expand Up @@ -365,6 +362,17 @@ protected JDBCDirectoryStructure getStructure() {
}
}

protected String mergePath(List<String> path) {
StringBuilder buf = new StringBuilder();
for (int i = 0; i < path.size(); i++) {
if (i > 0) { // no leading slash
buf.append("/");
}
buf.append(path.get(i));
}
return buf.toString();
}

public JDBCDirectoryStructure(DataSource ds, JDBCResourceStoreProperties config) {
this.helper = new JDBCQueryHelper(ds);
this.config = config;
Expand Down Expand Up @@ -419,6 +427,19 @@ public EntryMetaData call() throws Exception {
LAST_MODIFIED
.getFieldName());
}
resourceNotificationDispatcher.addListener(
mergePath(path),
new ResourceListener() {

@Override
public void changed(
ResourceNotification notify) {
entryCache().invalidate(path);
resourceNotificationDispatcher
.removeListener(
md.toString(), this);
}
});
return md;
}
}));
Expand Down Expand Up @@ -532,4 +553,8 @@ public QueryBuilder appendCondition(QueryBuilder qb) {
return qb;
}
}

public void setResourceNotificationDispatcher(ResourceNotificationDispatcher resourceNotDis) {
this.resourceNotificationDispatcher = resourceNotDis;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,29 @@ public void testCache() throws Exception {
}
}

@Test
public void testDelete() throws Exception {
standardData();
cache.create();

JDBCResourceStoreProperties config = getConfig(true, false);

ResourceStore fileStore = new FileSystemResourceStore(cache.getRoot());
ResourceStore jdbcStore = new JDBCResourceStore(support.getDataSource(), config, fileStore);

((JDBCResourceStore) jdbcStore).setCache(new SimpleResourceCache(cache.getRoot()));
// Initialize FileA in cache
Resource jdbcResource = jdbcStore.get("FileA");

// Update the Resource in the JDBCStore
jdbcResource.delete();

// Verify this update actually occurs
Resource fileResource = fileStore.get("FileA");

assertThat(fileResource.getType(), equalTo(Resource.Type.UNDEFINED));
}

@Test
public void testIgnoreDir() throws Exception {
support.initialize();
Expand Down

0 comments on commit 60c985d

Please sign in to comment.