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

Refactor ProcessNodePath #34260

Merged
merged 1 commit into from
Jan 6, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,31 @@
import lombok.NoArgsConstructor;

/**
* Process node.
* Process node path.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class ProcessNode {
public final class ProcessNodePath {

private static final String EXECUTION_NODES = "execution_nodes";
private static final String ROOT_NODE = "execution_nodes";

/**
* Get process id path.
* Get process ID root path.
*
* @param processId process id
* @return execution path
* @param processId process ID
* @return process ID root path
*/
public static String getProcessIdPath(final String processId) {
return String.join("/", "", EXECUTION_NODES, processId);
public static String getRootPath(final String processId) {
return String.join("/", "", ROOT_NODE, processId);
}

/**
* Get process list instance path.
* Get instance process list.
*
* @param processId process id
* @param instancePath instance path
* @return execution path
* @param processId process ID
* @param instanceId instance ID
* @return instance process list
*/
public static String getProcessListInstancePath(final String processId, final String instancePath) {
return String.join("/", "", EXECUTION_NODES, processId, instancePath);
public static String getInstanceProcessList(final String processId, final String instanceId) {
return String.join("/", getRootPath(processId), instanceId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.apache.shardingsphere.metadata.persist.node;

import org.junit.jupiter.api.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

class ProcessNodePathTest {

@Test
void assertGetRootPath() {
assertThat(ProcessNodePath.getRootPath("foo_process_id"), is("/execution_nodes/foo_process_id"));
}

@Test
void assertGetInstanceProcessList() {
assertThat(ProcessNodePath.getInstanceProcessList("foo_process_id", "foo_instance_id"), is("/execution_nodes/foo_process_id/foo_instance_id"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ class ProcessNodeTest {

@Test
void assertGetProcessIdPath() {
assertThat(ProcessNode.getProcessIdPath("ae7d352a-ee1f-3cd6-8631-cd9e93b70a30"), is("/execution_nodes/ae7d352a-ee1f-3cd6-8631-cd9e93b70a30"));
assertThat(ProcessNodePath.getRootPath("ae7d352a-ee1f-3cd6-8631-cd9e93b70a30"), is("/execution_nodes/ae7d352a-ee1f-3cd6-8631-cd9e93b70a30"));
}

@Test
void assertGetProcessListInstancePath() {
assertThat(ProcessNode.getProcessListInstancePath("ae7d352a-ee1f-3cd6-8631-cd9e93b70a30", "proxy_127.0.0.1@983481"),
assertThat(ProcessNodePath.getInstanceProcessList("ae7d352a-ee1f-3cd6-8631-cd9e93b70a30", "proxy_127.0.0.1@983481"),
is("/execution_nodes/ae7d352a-ee1f-3cd6-8631-cd9e93b70a30/proxy_127.0.0.1@983481"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.apache.shardingsphere.infra.executor.sql.process.yaml.swapper.YamlProcessListSwapper;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.metadata.persist.node.ComputeNodePath;
import org.apache.shardingsphere.metadata.persist.node.ProcessNode;
import org.apache.shardingsphere.metadata.persist.node.ProcessNodePath;
import org.apache.shardingsphere.mode.persist.coordinator.ProcessPersistCoordinator;
import org.apache.shardingsphere.mode.spi.PersistRepository;

Expand All @@ -43,7 +43,7 @@ public final class ClusterProcessPersistCoordinator implements ProcessPersistCoo
public void reportLocalProcesses(final String instanceId, final String taskId) {
Collection<Process> processes = ProcessRegistry.getInstance().listAll();
if (!processes.isEmpty()) {
repository.persist(ProcessNode.getProcessListInstancePath(taskId, instanceId), YamlEngine.marshal(swapper.swapToYamlConfiguration(processes)));
repository.persist(ProcessNodePath.getInstanceProcessList(taskId, instanceId), YamlEngine.marshal(swapper.swapToYamlConfiguration(processes)));
}
repository.delete(ComputeNodePath.getShowProcessListTriggerPath(instanceId, taskId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.apache.shardingsphere.infra.instance.metadata.InstanceType;
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.metadata.persist.node.ComputeNodePath;
import org.apache.shardingsphere.metadata.persist.node.ProcessNode;
import org.apache.shardingsphere.metadata.persist.node.ProcessNodePath;
import org.apache.shardingsphere.mode.persist.service.divided.ProcessPersistService;
import org.apache.shardingsphere.mode.spi.PersistRepository;

Expand Down Expand Up @@ -53,7 +53,7 @@ public Collection<Process> getProcessList() {
isCompleted = ProcessOperationLockRegistry.getInstance().waitUntilReleaseReady(taskId, () -> isReady(triggerPaths));
return getShowProcessListData(taskId);
} finally {
repository.delete(ProcessNode.getProcessIdPath(taskId));
repository.delete(ProcessNodePath.getRootPath(taskId));
if (!isCompleted) {
triggerPaths.forEach(repository::delete);
}
Expand All @@ -62,8 +62,8 @@ public Collection<Process> getProcessList() {

private Collection<Process> getShowProcessListData(final String taskId) {
YamlProcessList yamlProcessList = new YamlProcessList();
for (String each : repository.getChildrenKeys(ProcessNode.getProcessIdPath(taskId)).stream()
.map(each -> repository.query(ProcessNode.getProcessListInstancePath(taskId, each))).collect(Collectors.toList())) {
for (String each : repository.getChildrenKeys(ProcessNodePath.getRootPath(taskId)).stream()
.map(each -> repository.query(ProcessNodePath.getInstanceProcessList(taskId, each))).collect(Collectors.toList())) {
yamlProcessList.getProcesses().addAll(YamlEngine.unmarshal(each, YamlProcessList.class).getProcesses());
}
return new YamlProcessListSwapper().swapToObject(yamlProcessList);
Expand Down
Loading