Skip to content

Commit

Permalink
Fix some clustering bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
robinshine committed Apr 28, 2023
1 parent 51b5317 commit 5ce97ef
Show file tree
Hide file tree
Showing 95 changed files with 449 additions and 4,222 deletions.
13 changes: 6 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<version>1.2.0</version>
</parent>
<artifactId>server</artifactId>
<version>8.1.3</version>
<version>8.1.4</version>
<packaging>pom</packaging>
<build>
<finalName>${project.groupId}.${project.artifactId}-${project.version}</finalName>
Expand Down Expand Up @@ -95,7 +95,6 @@
<modules>
<module>server-core</module>
<module>server-plugin</module>
<module>server-ee</module>
<module>server-product</module>
</modules>
<dependencyManagement>
Expand Down Expand Up @@ -256,11 +255,6 @@
<artifactId>hibernate-hikaricp</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-hibernate53</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>com.nimbusds</groupId>
<artifactId>oauth2-oidc-sdk</artifactId>
Expand Down Expand Up @@ -596,6 +590,11 @@
<artifactId>hazelcast</artifactId>
<version>5.1.4</version>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-hibernate53</artifactId>
<version>2.2.1</version>
</dependency>
</dependencies>
</dependencyManagement>
<repositories>
Expand Down
10 changes: 5 additions & 5 deletions server-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.onedev</groupId>
<artifactId>server</artifactId>
<version>8.1.3</version>
<version>8.1.4</version>
</parent>
<build>
<plugins>
Expand Down Expand Up @@ -296,10 +296,6 @@
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jcache</artifactId>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-hibernate53</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
Expand Down Expand Up @@ -340,6 +336,10 @@
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-hibernate53</artifactId>
</dependency>
</dependencies>
<properties>
<moduleClass>io.onedev.server.CoreModule</moduleClass>
Expand Down
3 changes: 3 additions & 0 deletions server-core/src/main/java/io/onedev/server/CoreModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import io.onedev.server.git.signature.SignatureVerificationKeyLoader;
import io.onedev.server.infomanager.*;
import io.onedev.server.jetty.DefaultJettyLauncher;
import io.onedev.server.jetty.DefaultSessionDataStoreFactory;
import io.onedev.server.jetty.JettyLauncher;
import io.onedev.server.job.DefaultJobManager;
import io.onedev.server.job.DefaultResourceAllocator;
Expand Down Expand Up @@ -141,6 +142,7 @@
import org.apache.wicket.Application;
import org.apache.wicket.protocol.http.WicketFilter;
import org.apache.wicket.protocol.http.WicketServlet;
import org.eclipse.jetty.server.session.SessionDataStoreFactory;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.servlet.ServletContainer;
Expand Down Expand Up @@ -451,6 +453,7 @@ private void configureWeb() {
bind(WicketFilter.class).to(DefaultWicketFilter.class);
bind(EditSupportRegistry.class).to(DefaultEditSupportRegistry.class);
bind(WebSocketManager.class).to(DefaultWebSocketManager.class);
bind(SessionDataStoreFactory.class).to(DefaultSessionDataStoreFactory.class);

contributeFromPackage(EditSupport.class, EditSupport.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.hazelcast.cluster.MembershipEvent;
import com.hazelcast.cluster.MembershipListener;
import com.hazelcast.config.Config;
import com.hazelcast.config.SerializerConfig;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IExecutorService;
Expand All @@ -20,6 +21,7 @@
import io.onedev.server.persistence.HibernateConfig;
import io.onedev.server.persistence.PersistenceManager;
import io.onedev.server.replica.ProjectReplica;
import org.eclipse.jetty.server.session.SessionData;

import javax.inject.Inject;
import javax.inject.Singleton;
Expand Down Expand Up @@ -140,6 +142,10 @@ public Collection<String> call() {
config.getMapConfig("default").setStatisticsEnabled(false);
config.getNetworkConfig().setPort(serverConfig.getClusterPort()).setPortAutoIncrement(false);
config.getNetworkConfig().getJoin().getTcpIpConfig().setEnabled(true);
SerializerConfig sc = new SerializerConfig()
.setImplementation(new SessionDataSerializer())
.setTypeClass(SessionData.class);
config.getSerializationConfig().addSerializerConfig(sc);

var hasLocalhost = false;
var hasNonLocalhost = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//
// ========================================================================
// Copyright (c) 1995-2022 Mort Bay Consulting Pty Ltd and others.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//

package io.onedev.server.cluster;

import com.hazelcast.nio.ObjectDataInput;
import com.hazelcast.nio.ObjectDataOutput;
import com.hazelcast.nio.serialization.StreamSerializer;
import org.eclipse.jetty.server.session.SessionData;
import org.eclipse.jetty.util.ClassLoadingObjectInputStream;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

/**
* SessionDataSerializer
*
* Handles serialization on behalf of the SessionData object, and
* ensures that we use jetty's classloading knowledge.
*/
public class SessionDataSerializer implements StreamSerializer<SessionData>
{
public static final int __TYPEID = 99;

@Override
public int getTypeId()
{
return __TYPEID;
}

@Override
public void destroy()
{
}

@Override
public void write(ObjectDataOutput out, SessionData data) throws IOException
{
out.writeUTF(data.getId());
out.writeUTF(data.getContextPath());
out.writeUTF(data.getVhost());

out.writeLong(data.getAccessed());
out.writeLong(data.getLastAccessed());
out.writeLong(data.getCreated());
out.writeLong(data.getCookieSet());
out.writeUTF(data.getLastNode());

out.writeLong(data.getExpiry());
out.writeLong(data.getMaxInactiveMs());

try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos))
{
SessionData.serializeAttributes(data, oos);
out.writeByteArray(baos.toByteArray());
}
}

@Override
public SessionData read(ObjectDataInput in) throws IOException
{
String id = in.readUTF();
String contextPath = in.readUTF();
String vhost = in.readUTF();

long accessed = in.readLong();
long lastAccessed = in.readLong();
long created = in.readLong();
long cookieSet = in.readLong();
String lastNode = in.readUTF();
long expiry = in.readLong();
long maxInactiveMs = in.readLong();

SessionData sd = new SessionData(id, contextPath, vhost, created, accessed, lastAccessed, maxInactiveMs);

ByteArrayInputStream bais = new ByteArrayInputStream(in.readByteArray());
try (ClassLoadingObjectInputStream ois = new ClassLoadingObjectInputStream(bais))
{
SessionData.deserializeAttributes(sd, ois);
}
catch (ClassNotFoundException e)
{
throw new IOException(e);
}
sd.setCookieSet(cookieSet);
sd.setLastNode(lastNode);
sd.setExpiry(expiry);
return sd;
}
}
Loading

0 comments on commit 5ce97ef

Please sign in to comment.