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

Jetty 10.0.x 6687 upgrade infinispan #6766

Merged
merged 24 commits into from Sep 21, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion javadoc/pom.xml
Expand Up @@ -414,6 +414,12 @@
<artifactId>infinispan-core</artifactId>
<version>${infinispan.version}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.wildfly.common</groupId>
<artifactId>wildfly-common</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- to make infinispan-common source sane -->
<dependency>
Expand All @@ -426,7 +432,7 @@
<dependency>
<groupId>org.infinispan.protostream</groupId>
<artifactId>protostream</artifactId>
<version>4.2.2.Final</version>
<version>${infinispan.protostream.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
6 changes: 6 additions & 0 deletions jetty-home/pom.xml
Expand Up @@ -750,6 +750,12 @@
<version>${project.version}</version>
<type>pom</type>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>org.wildfly.common</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
Expand Down
9 changes: 6 additions & 3 deletions jetty-infinispan/infinispan-common/pom.xml
Expand Up @@ -37,8 +37,13 @@
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-core</artifactId>
<version>${infinispan.version}</version>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>org.wildfly.common</groupId>
<artifactId>wildfly-common</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.infinispan.protostream</groupId>
Expand All @@ -63,13 +68,11 @@
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-client-hotrod</artifactId>
<version>${infinispan.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-remote-query-client</artifactId>
<version>${infinispan.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
Expand Up @@ -10,6 +10,7 @@
<Set name="infinispanIdleTimeoutSec" property="jetty.session.infinispan.idleTimeout.seconds"/>
<Set name="gracePeriodSec" property="jetty.session.gracePeriod.seconds"/>
<Set name="savePeriodSec" property="jetty.session.savePeriod.seconds"/>
<Set name="serialization" property="jetty.session.infinispan.serialization"/>
</New>
</Arg>
</Call>
Expand Down
Expand Up @@ -13,7 +13,7 @@ lib/infinispan-common-${jetty.version}.jar
lib/infinispan/*.jar

[ini]
infinispan.version?=9.4.8.Final
infinispan.version?=11.0.11.Final

[license]
Infinispan is an open source project hosted on Github and released under the Apache 2.0 license.
Expand Down
@@ -0,0 +1,51 @@
//
// ========================================================================
// Copyright (c) 1995-2021 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//

package org.eclipse.jetty.session.infinispan;

import java.io.UncheckedIOException;

import org.infinispan.protostream.FileDescriptorSource;
import org.infinispan.protostream.SerializationContext;
import org.infinispan.protostream.SerializationContextInitializer;

/**
* Set up the marshaller for InfinispanSessionData serialization
*
*/
public class InfinispanSerializationContextInitializer implements SerializationContextInitializer
{
@Override
public String getProtoFileName()
{
return "session.proto";
}

@Override
public String getProtoFile() throws UncheckedIOException
{
return FileDescriptorSource.getResourceAsString(getClass(), "/" + getProtoFileName());
}

@Override
public void registerSchema(SerializationContext serCtx)
{
serCtx.registerProtoFiles(FileDescriptorSource.fromString(getProtoFileName(), getProtoFile()));
}

@Override
public void registerMarshallers(SerializationContext serCtx)
{
serCtx.registerMarshaller(new SessionDataMarshaller());
}
}
Expand Up @@ -33,7 +33,6 @@
* pool and thus these threads have no knowledge of the correct classloader to
* use.
*/
@SerializeWith(SessionDataMarshaller.class)
public class InfinispanSessionData extends SessionData
{
protected byte[] _serializedAttributes;
Expand Down
Expand Up @@ -44,6 +44,7 @@ public class InfinispanSessionDataStore extends AbstractSessionDataStore
private int _infinispanIdleTimeoutSec;
private QueryManager _queryManager;
private boolean _passivating;
private boolean _serialization;

/**
* Get the clustered cache instance.
Expand Down Expand Up @@ -74,9 +75,8 @@ protected void doStart() throws Exception

try
{
_passivating = false;
Class<?> remoteClass = InfinispanSessionDataStore.class.getClassLoader().loadClass("org.infinispan.client.hotrod.RemoteCache");
if (remoteClass.isAssignableFrom(_cache.getClass()))
if (remoteClass.isAssignableFrom(_cache.getClass()) || _serialization)
_passivating = true;
}
catch (ClassNotFoundException e)
Expand Down Expand Up @@ -105,6 +105,9 @@ public SessionData doLoad(String id) throws Exception
LOG.debug("Loading session {} from infinispan", id);

InfinispanSessionData sd = _cache.get(getCacheKey(id));

//Deserialize the attributes now that we are back in a thread that
//has the correct classloader set on it
if (isPassivating() && sd != null)
{
if (LOG.isDebugEnabled())
Expand Down Expand Up @@ -205,6 +208,15 @@ public void doCleanOrphans(long timeLimit)
@Override
public void doStore(String id, SessionData data, long lastSaveTime) throws Exception
{
//prepare for serialization: we need to convert the attributes now while the context
//classloader is set, because infinispan uses a different thread and classloader to
//perform the serialization
if (isPassivating() && data != null)
{
if (LOG.isDebugEnabled())
LOG.debug("Serializing session attributes for {}", id);
((InfinispanSessionData)data).serializeAttributes();
}
//Put an idle timeout on the cache entry if the session is not immortal -
//if no requests arrive at any node before this timeout occurs, or no node
//scavenges the session before this timeout occurs, the session will be removed.
Expand Down Expand Up @@ -270,6 +282,11 @@ public int getInfinispanIdleTimeoutSec()
{
return _infinispanIdleTimeoutSec;
}

public void setSerialization(boolean serialization)
{
_serialization = serialization;
}

@Override
public String toString()
Expand Down
Expand Up @@ -26,6 +26,7 @@ public class InfinispanSessionDataStoreFactory extends AbstractSessionDataStoreF
int _infinispanIdleTimeoutSec;
BasicCache<String, InfinispanSessionData> _cache;
protected QueryManager _queryManager;
protected boolean _serialization;

/**
* @return the infinispanIdleTimeoutSec
Expand All @@ -52,6 +53,7 @@ public SessionDataStore getSessionDataStore(SessionHandler handler) throws Excep
store.setCache(getCache());
store.setSavePeriodSec(getSavePeriodSec());
store.setQueryManager(getQueryManager());
store.setSerialization(getSerialization());
return store;
}

Expand Down Expand Up @@ -84,4 +86,14 @@ public void setQueryManager(QueryManager queryManager)
{
_queryManager = queryManager;
}

public void setSerialization(boolean serialization)
{
_serialization = serialization;
}

public boolean getSerialization()
{
return _serialization;
}
}
Expand Up @@ -14,10 +14,7 @@
package org.eclipse.jetty.session.infinispan;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;

import org.infinispan.commons.marshall.Externalizer;
import org.infinispan.protostream.FileDescriptorSource;
import org.infinispan.protostream.MessageMarshaller;
import org.infinispan.protostream.ProtobufUtil;
Expand All @@ -31,8 +28,7 @@
* control to ensure that session attributes can be deserialized using either
* the container class loader or the webapp classloader, as appropriate.
*/
public class SessionDataMarshaller
implements MessageMarshaller<InfinispanSessionData>, Externalizer<InfinispanSessionData>
public class SessionDataMarshaller implements MessageMarshaller<InfinispanSessionData>
{
/**
* The version of the serializer.
Expand Down Expand Up @@ -67,39 +63,6 @@ public String getTypeName()
return "org_eclipse_jetty_session_infinispan.InfinispanSessionData";
}

@Override
public InfinispanSessionData readObject(ObjectInput input) throws IOException, ClassNotFoundException
{
if (serializationContext == null)
{
initSerializationContext();
}

// invokes readFrom(ProtoStreamReader)
InfinispanSessionData data = ProtobufUtil.readFrom(serializationContext, new BoundDelegatingInputStream(input),
InfinispanSessionData.class);
if (data != null)
{
data.deserializeAttributes();
}
return data;
}

@Override
public void writeObject(ObjectOutput output, InfinispanSessionData object) throws IOException
{
if (serializationContext == null)
{
initSerializationContext();
}

// invokes writeTo(ProtoStreamWriter, InfinispanSessionData)
byte[] data = ProtobufUtil.toByteArray(serializationContext, object);
int length = data.length;
output.writeInt(length);
output.write(data);
}

@Override
public InfinispanSessionData readFrom(ProtoStreamReader in) throws IOException
{
Expand Down Expand Up @@ -127,6 +90,9 @@ public InfinispanSessionData readFrom(ProtoStreamReader in) throws IOException
if (version == 0)
{
byte[] attributeArray = in.readBytes("attributes");
//only save the serialized bytes here, do NOT deserialize because
//infinispan has called this method with their own thread without
//the appropriate classloader being set
sd.setSerializedAttributes(attributeArray);
return sd;
}
Expand All @@ -152,7 +118,9 @@ public void writeTo(ProtoStreamWriter out, InfinispanSessionData sdata) throws I
out.writeLong("expiry", sdata.getExpiry());
out.writeLong("maxInactiveMs", sdata.getMaxInactiveMs());

sdata.serializeAttributes();
//the session data attributes MUST be previously serialized
//because this method is called from an infinispan thread that cannot
//have the appropriate classloader set on it
out.writeBytes("attributes", sdata.getSerializedAttributes());
}

Expand Down
1 change: 0 additions & 1 deletion jetty-infinispan/infinispan-embedded-query/pom.xml
Expand Up @@ -106,7 +106,6 @@
<dependency>
<groupId>org.infinispan</groupId>
<artifactId>infinispan-query</artifactId>
<version>${infinispan.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
Expand Down