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

[Feature][Admin]Mandatory use of Redis service for distributed locking and achieving distributed scheduling #3998

Draft
wants to merge 7 commits into
base: dev
Choose a base branch
from
Draft
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
19 changes: 19 additions & 0 deletions dinky-admin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,25 @@
<groupId>org.dinky</groupId>
<artifactId>dinky-alert-http</artifactId>
</dependency>
<dependency>
<groupId>org.signal</groupId>
<artifactId>embedded-redis</artifactId>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson-spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.dinky.configure;

import org.dinky.configure.properties.DinkyRedisProperties;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import redis.embedded.RedisServer;

@Configuration
@EnableConfigurationProperties(DinkyRedisProperties.class)
public class RedisConfiguration {
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(prefix = "spring.redis", name = "mode", havingValue = "embedded", matchIfMissing = true)
@Order(-1)
public RedisServer redisServer(RedisProperties redisProperties) {
RedisServer redisServer = new RedisServer(redisProperties.getPort());
redisServer.start();
return redisServer;
}

@Bean
@Order(1)
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<String, Object> template = new RedisTemplate<>();
// 设置Redis链接工厂对象
template.setConnectionFactory(redisConnectionFactory);

// 设置键的序列化方式为 String
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new StringRedisSerializer());

// 设置值的序列化方式为 JSON
template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
template.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());

return template;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

package org.dinky.configure.properties;

import org.springframework.boot.context.properties.ConfigurationProperties;

import lombok.Getter;
import lombok.Setter;

@ConfigurationProperties(prefix = "spring.redis")
@Getter
@Setter
public class DinkyRedisProperties {
private RedisRunMode mode;

public enum RedisRunMode {
Standalone,
Embedded
}

public boolean isEmbedded() {
return RedisRunMode.Embedded.equals(mode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import org.dinky.utils.JsonUtils;
import org.dinky.utils.TimeUtil;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -89,13 +89,8 @@ private static void fetchFlinkMetrics(String v, Map<String, String> m, String[]
}

String metricsName = String.join(",", m.keySet());
String urlParam = null;
try {
urlParam = String.format(
"/jobs/%s/vertices/%s/metrics?get=%s", jid, v, URLEncoder.encode(metricsName, "UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
String urlParam = String.format(
"/jobs/%s/vertices/%s/metrics?get=%s", jid, v, URLEncoder.encode(metricsName, StandardCharsets.UTF_8));

HttpUtils.request(new ArrayList<>(Arrays.asList(urlList)), urlParam, NetConstant.READ_TIME_OUT, x -> {
List<Dict> array = JsonUtils.toList(x.body(), Dict.class);
Expand Down
43 changes: 43 additions & 0 deletions dinky-admin/src/main/resources/application-redis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
spring:
redis:
host: 127.0.0.1
port: 6379
# redis operating mode,standalone\embedded
mode: embedded
database: 8
redisson:
# Single-node configuration
singleServerConfig:
# Connection idle timeout, in milliseconds
idleConnectionTimeout: 10000
# Connection timeout in milliseconds
connectTimeout: 10000
# Command wait timeout, in milliseconds
timeout: 3000
# Command Failed Retries (an error is thrown if the attempt reaches retryAttempts and the command still fails to send the command to a specified node).
# If the attempt to send within this limit is successful, timeout timing is enabled.
retryAttempts: 3
# The command retry send interval in milliseconds
retryInterval: 1500
# password
password: ${spring.redis.password}
# clientName
clientName: dinky-redis
# The maximum number of subscriptions for a single connection
subscriptionsPerConnection: 5
# Node address
address: redis://${spring.redis.host}:${spring.redis.port}
# The minimum number of idle connections for publish and subscribe connections
subscriptionConnectionMinimumIdleSize: 1
# Pub and sub connection pool size
subscriptionConnectionPoolSize: 50
# Minimum number of idle connections
connectionMinimumIdleSize: 5
# Connection pool size
connectionPoolSize: 10
# Database number
database: ${spring.redis.database}
# DNS monitoring interval, in milliseconds
dnsMonitoringInterval: 5000
# Transmission mode
transportMode: "NIO"
1 change: 1 addition & 0 deletions dinky-admin/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ spring:
include:
- jmx
- flyway
- redis
lifecycle:
timeout-per-shutdown-phase: 30s

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ static Optional<DaemonTask> get(DaemonTaskConfig config) {

static DaemonTask build(DaemonTaskConfig config) {
Optional<DaemonTask> optionalDaemonTask = DaemonTask.get(config);
if (!optionalDaemonTask.isPresent()) {
throw new DaemonTaskException(Status.DAEMON_TASK_NOT_SUPPORT.getMessage() + config.getType());
}
return optionalDaemonTask.get();
return optionalDaemonTask.orElseThrow(
() -> new DaemonTaskException(Status.DAEMON_TASK_NOT_SUPPORT.getMessage() + config.getType()));
}

DaemonTask setConfig(DaemonTaskConfig config);
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<protobuf-java.version>2.5.0</protobuf-java.version>
<redisson.version>3.39.0</redisson.version>
<reflections.version>0.10.2</reflections.version>
<revision>1.2.0-rc4</revision>
<sa-token.version>1.37.0</sa-token.version>
Expand Down Expand Up @@ -734,6 +735,11 @@
<artifactId>auto-service</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson-spring-boot-starter</artifactId>
<version>${redisson.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
Loading