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

WIP: Add redis backed cache as alternative for infinispan #3534

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7007975
WIP: Refactor client-device-connection-infinispan module into 3 cache…
StFS Aug 24, 2023
a202675
Restructure modules as per PR comments
StFS Aug 26, 2023
f68e63d
WIP: experimenting with using the vertx-redis client library.
StFS Aug 29, 2023
2a20828
Add Lifecycle interface to RedisCache and simplify creation and closi…
StFS Aug 30, 2023
f7010c7
Merge remote-tracking branch 'origin/master' into implement_redis_bac…
StFS Sep 25, 2023
2f41346
Minor code formatting cleanup from PR comments.
StFS Sep 25, 2023
d51a705
Minor code formatting cleanup from PR comments.
StFS Sep 25, 2023
7e9242e
Clenup of dependencies and some requests for reviews on how that shou…
StFS Sep 27, 2023
e66006d
Integration tests with RedisCache actually working.
StFS Sep 27, 2023
b3a45c2
working on dependencies
StFS Sep 27, 2023
d94f28c
working on dependencies
StFS Sep 27, 2023
58d5fef
Merge remote-tracking branch 'origin/master' into implement_redis_bac…
StFS Sep 28, 2023
91549e6
working on dependencies
StFS Sep 28, 2023
0e6474c
working on dependencies
StFS Sep 28, 2023
00c20fb
First implementation of a Quarkus Redis Client cache.
StFS Oct 3, 2023
f4c31b6
Minor refactoring to unify the names of the Redis cache implementations.
StFS Oct 3, 2023
2669578
Merge remote-tracking branch 'origin/master' into implement_redis_bac…
StFS Oct 26, 2023
27a5715
Merge branch 'eclipse-hono:master' into implement_redis_backed_cache
StFS Nov 27, 2023
d474a01
Merge remote-tracking branch 'origin/master' into implement_redis_bac…
StFS Dec 7, 2023
9bf6855
Merge remote-tracking branch 'origin/master' into implement_redis_bac…
StFS Dec 19, 2023
372c9f4
Baby steps. Now using the quarkus vertx redis API that is injected by…
StFS Mar 2, 2024
c84ce95
Add config relocate interceptor that redirects requests for quarkus.r…
StFS Mar 2, 2024
0f40bf4
Add config relocate interceptor that redirects requests for quarkus.r…
StFS Mar 2, 2024
0043ce8
Merge remote-tracking branch 'origin/implement_redis_backed_cache' in…
StFS Mar 2, 2024
6583875
Merge remote-tracking branch 'origin' into implement_redis_backed_cache
StFS Mar 23, 2024
2b1fe30
Merge remote-tracking branch 'upstream/master' into implement_redis_b…
StFS Mar 23, 2024
b7320d7
Major refactoring, not using Quarkus Redis client anymore and instead…
StFS Mar 25, 2024
37c555b
Minor cleanup of PR
StFS Mar 25, 2024
0f60496
Minor cleanup of PR
StFS Mar 25, 2024
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
20 changes: 20 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,26 @@ quarkus.vertx.max-event-loop-execute-time=${max.event-loop.execute-time:20000}
<artifactId>hono-client-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.hono</groupId>
<artifactId>hono-cache-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.hono</groupId>
<artifactId>hono-cache-infinispan</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.hono</groupId>
<artifactId>hono-cache-redis</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.hono</groupId>
<artifactId>hono-client-device-connection</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.hono</groupId>
<artifactId>hono-client-common</artifactId>
Expand Down
112 changes: 112 additions & 0 deletions caches/cache-common/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2021, 2022 Contributors to the Eclipse Foundation

See the NOTICE file(s) distributed with this work for additional
information regarding copyright ownership.

This program and the accompanying materials are made available under the
terms of the Eclipse Public License 2.0 which is available at
http://www.eclipse.org/legal/epl-2.0

SPDX-License-Identifier: EPL-2.0
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.hono</groupId>
<artifactId>hono-caches-parent</artifactId>
<version>2.5.0-SNAPSHOT</version>
</parent>
<artifactId>hono-cache-common</artifactId>

<name>Hono Cache Common</name>
<description>Classes required for implementing Hono caches</description>

<dependencies>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.hono</groupId>
<artifactId>hono-client-common</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core</artifactId>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>org.jboss.logmanager</groupId>
<artifactId>jboss-logmanager-embedded</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-development-mode-spi</artifactId>
</exclusion>
<exclusion>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-bootstrap-runner</artifactId>
</exclusion>
<exclusion>
<groupId>org.jboss.slf4j</groupId>
<artifactId>slf4j-jboss-logmanager</artifactId>
</exclusion>
<exclusion>
<groupId>org.graalvm.sdk</groupId>
<artifactId>graal-sdk</artifactId>
</exclusion>
<exclusion>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-fs-util</artifactId>
</exclusion>
</exclusions>
</dependency>

<!--
<dependency>
<groupId>org.eclipse.hono</groupId>
<artifactId>hono-core</artifactId>
<exclusions>
<exclusion>
<groupId>io.opentracing</groupId>
<artifactId>opentracing-noop</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-health-check</artifactId>
<exclusions>
<exclusion>
<groupId>io.vertx</groupId>
<artifactId>vertx-auth-common</artifactId>
</exclusion>
</exclusions>
</dependency>
-->
<!-- testing -->
<!--
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
-->
</dependencies>
</project>
119 changes: 119 additions & 0 deletions caches/cache-common/src/main/java/org/eclipse/hono/cache/Cache.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
/**
* Copyright (c) 2020, 2021 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/

package org.eclipse.hono.cache;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import io.vertx.core.Future;
import io.vertx.core.json.JsonObject;

/**
* A simple {@code Map} like interface to a data grid cache.
*
* @param <K> The type of keys used for looking up data.
* @param <V> The type of values stored in grid.
*/
public interface Cache<K, V> {

/**
* Checks if the cache is connected to the data grid.
* <p>
* If a cache is found to be not connected here, this method may trigger a connection (re)establishment.
*
* @return A future that is completed with information about a successful check's result.
* Otherwise, the future will be failed with a
* {@link org.eclipse.hono.client.ServerErrorException}.
*/
Future<JsonObject> checkForCacheAvailability();

/**
* Puts a value to the cache.
*
* @param key The key.
* @param value The value.
* @return A succeeded future if the value has been stored successfully.
* A failed future if the value could not be stored in the cache.
* @throws NullPointerException if any of the parameters is {@code null}.
*/
Future<Void> put(K key, V value);

/**
* Puts a value to the cache.
*
* @param key The key.
* @param value The value.
* @param lifespan The lifespan of the entry. A negative value is interpreted as an unlimited lifespan.
* @param lifespanUnit The time unit for the lifespan.
* @return A succeeded future if the value has been stored successfully.
* A failed future if the value could not be stored in the cache.
* @throws NullPointerException if any of the parameters is {@code null}.
*/
Future<Void> put(K key, V value, long lifespan, TimeUnit lifespanUnit);

/**
* Puts all values of the given map to the cache.
*
* @param data The map with the entries to add.
* @return A succeeded future if the operation succeeded.
* A failed future if there was an error storing the entries in the cache.
* @throws NullPointerException if data is {@code null}.
*/
Future<Void> putAll(Map<? extends K, ? extends V> data);

/**
* Puts all values of the given map to the cache.
*
* @param data The map with the entries to add.
* @param lifespan The lifespan of the entries. A negative value is interpreted as an unlimited lifespan.
* @param lifespanUnit The time unit for the lifespan.
* @return A succeeded future if the operation succeeded.
* A failed future if there was an error storing the entries in the cache.
* @throws NullPointerException if any of the parameters is {@code null}.
*/
Future<Void> putAll(Map<? extends K, ? extends V> data, long lifespan, TimeUnit lifespanUnit);

/**
* Gets a value from the cache.
*
* @param key The key.
* @return A succeeded future containing the value or {@code null} if the
* cache didn't contain the key yet.
* A failed future if the value could not be read from the cache.
* @throws NullPointerException if key is {@code null}.
*/
Future<V> get(K key);

/**
* Removes a key/value mapping from the cache.
*
* @param key The key.
* @param value The value.
* @return A succeeded future containing {@code true} if the key was
* mapped to the value, {@code false} otherwise.
* A failed future if the value could not be removed from the cache.
* @throws NullPointerException if any of the parameters is {@code null}.
*/
Future<Boolean> remove(K key, V value);

/**
* Gets the values for the specified keys from the cache.
*
* @param keys The keys.
* @return A succeeded future containing a map with key/value pairs.
* @throws NullPointerException if keys is {@code null}.
*/
Future<Map<K, V>> getAll(Set<? extends K> keys);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*******************************************************************************
* Copyright (c) 2020, 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/

package org.eclipse.hono.cache;

import com.google.common.base.MoreObjects;

/**
* Common cache configuration options.
*/
public class CommonCacheConfig {

/**
* The default name of the (remote) cache in the data grid that is used for
* storing device connection information.
*/
public static final String DEFAULT_CACHE_NAME = "device-connection";

private String cacheName = DEFAULT_CACHE_NAME;

private String checkKey = "KEY_CONNECTION_CHECK";
private String checkValue = "VALUE_CONNECTION_CHECK";

/**
* Creates properties for default values.
*/
public CommonCacheConfig() {
super();
}

/**
* Creates properties for existing options.
*
* @param options The options to copy.
*/
public CommonCacheConfig(final CommonCacheOptions options) {
super();
this.cacheName = options.cacheName();
this.checkKey = options.checkKey();
this.checkValue = options.checkValue();
}

public void setCacheName(final String cacheName) {
this.cacheName = cacheName;
}

public String getCacheName() {
return cacheName;
}

public void setCheckKey(final String checkKey) {
this.checkKey = checkKey;
}

public String getCheckKey() {
return checkKey;
}

public void setCheckValue(final String checkValue) {
this.checkValue = checkValue;
}

public String getCheckValue() {
return checkValue;
}

@Override
public String toString() {
return MoreObjects
.toStringHelper(this)
.add("cacheName", this.cacheName)
.add("checkKey", this.checkKey)
.add("checkValue", this.checkValue)
.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/

package org.eclipse.hono.cache;

import org.eclipse.hono.util.CommandRouterConstants;

import io.smallrye.config.ConfigMapping;
import io.smallrye.config.ConfigMapping.NamingStrategy;
import io.smallrye.config.WithDefault;

/**
* Common options for configuring a cache.
*
*/
@ConfigMapping(prefix = "hono.cache.common", namingStrategy = NamingStrategy.VERBATIM)
public interface CommonCacheOptions {

/**
* Gets the name of the cache.
*
* @return The name.
*/
@WithDefault(CommandRouterConstants.DEFAULT_CACHE_NAME)
String cacheName();

/**
* Gets the key to use for checking the cache's availability.
*
* @return The key.
*/
@WithDefault("KEY_CONNECTION_CHECK")
String checkKey();

/**
* The value to use for checking the cache's availability.
*
* @return The value.
*/
@WithDefault("VALUE_CONNECTION_CHECK")
String checkValue();
}
Loading