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

Add WorkerIDNodePath and ProcessNodePath #34715

Merged
merged 2 commits into from
Feb 19, 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 @@ -15,23 +15,19 @@
* limitations under the License.
*/

package org.apache.shardingsphere.mode.node.path.state;
package org.apache.shardingsphere.mode.node.path.execution;

import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.mode.node.path.NodePath;

/**
* Process node path generator.
* Execution node path.
*/
@RequiredArgsConstructor
public final class ProcessNodePath implements NodePath {
public final class ExecutionNodePath implements NodePath {

private static final String ROOT_NODE = "/execution_nodes";

private final String processId;

@Override
public String getRootPath() {
return String.join("/", ROOT_NODE, processId);
return ROOT_NODE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.mode.node.path.execution.process;

import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.mode.node.path.NodePath;
import org.apache.shardingsphere.mode.node.path.NodePathGenerator;
import org.apache.shardingsphere.mode.node.path.execution.ExecutionNodePath;

/**
* Process node path.
*/
@RequiredArgsConstructor
public final class ProcessNodePath implements NodePath {

private final String processId;

private final NodePathGenerator nodePathGenerator = new NodePathGenerator(new ExecutionNodePath());

@Override
public String getRootPath() {
return String.join("/", nodePathGenerator.getPath(processId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
public final class ReservationNodePath implements NodePath {

private static final String ROOT_NODE = "/reservation/worker_id";
private static final String ROOT_NODE = "/reservation";

@Override
public String getRootPath() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.mode.node.path.reservation.workerid;

import org.apache.shardingsphere.mode.node.path.NodePath;
import org.apache.shardingsphere.mode.node.path.NodePathGenerator;
import org.apache.shardingsphere.mode.node.path.reservation.ReservationNodePath;

/**
* Worker ID node path.
*/
public final class WorkerIDNodePath implements NodePath {

private static final String ROOT_NODE = "worker_id";

private final NodePathGenerator nodePathGenerator = new NodePathGenerator(new ReservationNodePath());

@Override
public String getRootPath() {
return String.join("/", nodePathGenerator.getPath(ROOT_NODE));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.mode.node.path.execution;

import org.junit.jupiter.api.Test;

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

class ExecutionNodePathTest {

@Test
void assertGetRootPath() {
assertThat(new ExecutionNodePath().getRootPath(), is("/execution_nodes"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.shardingsphere.mode.node.path.state;
package org.apache.shardingsphere.mode.node.path.execution.process;

import org.junit.jupiter.api.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
class ReservationNodePathTest {

@Test
void assertGetWorkerIdReservationPath() {
assertThat(new ReservationNodePath().getRootPath(), is("/reservation/worker_id"));
void assertGetRootPath() {
assertThat(new ReservationNodePath().getRootPath(), is("/reservation"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.mode.node.path.reservation.workerid;

import org.junit.jupiter.api.Test;

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

class WorkerIDNodePathTest {

@Test
void assertGetRootPath() {
assertThat(new WorkerIDNodePath().getRootPath(), is("/reservation/worker_id"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.mode.node.path.NodePathGenerator;
import org.apache.shardingsphere.mode.node.path.node.ComputeNodePathGenerator;
import org.apache.shardingsphere.mode.node.path.state.ProcessNodePath;
import org.apache.shardingsphere.mode.node.path.execution.process.ProcessNodePath;
import org.apache.shardingsphere.mode.spi.repository.PersistRepository;

import java.util.Collection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.apache.shardingsphere.infra.util.yaml.YamlEngine;
import org.apache.shardingsphere.mode.node.path.NodePathGenerator;
import org.apache.shardingsphere.mode.node.path.node.ComputeNodePathGenerator;
import org.apache.shardingsphere.mode.node.path.state.ProcessNodePath;
import org.apache.shardingsphere.mode.node.path.execution.process.ProcessNodePath;
import org.apache.shardingsphere.mode.persist.service.ProcessPersistService;
import org.apache.shardingsphere.mode.spi.repository.PersistRepository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.mode.node.path.NodePathGenerator;
import org.apache.shardingsphere.mode.node.path.reservation.ReservationNodePath;
import org.apache.shardingsphere.mode.node.path.reservation.workerid.WorkerIDNodePath;
import org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
import org.apache.shardingsphere.mode.repository.cluster.exception.ClusterRepositoryPersistException;

Expand All @@ -43,7 +43,7 @@ public final class ReservationPersistService {
public Optional<Integer> reserveWorkerId(final Integer preselectedWorkerId, final String instanceId) {
try {
return repository.persistExclusiveEphemeral(
new NodePathGenerator(new ReservationNodePath()).getPath(preselectedWorkerId), instanceId) ? Optional.of(preselectedWorkerId) : Optional.empty();
new NodePathGenerator(new WorkerIDNodePath()).getPath(preselectedWorkerId), instanceId) ? Optional.of(preselectedWorkerId) : Optional.empty();
} catch (final ClusterRepositoryPersistException ignore) {
return Optional.empty();
}
Expand Down
Loading