You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "azexcy (via GitHub)" <gi...@apache.org> on 2023/03/24 10:13:57 UTC
[GitHub] [shardingsphere] azexcy opened a new pull request, #24807: Add pipeline job listener
azexcy opened a new pull request, #24807:
URL: https://github.com/apache/shardingsphere/pull/24807
Now, pipeline job may not really stopped after executing the stop command, because the elastic job may not stop immediately, so need to wait elastic job task really stopped.
Changes proposed in this pull request:
- Add pipeline job listener for optimize pipeline job stopping process
---
Before committing this PR, I'm sure that I have checked the following options:
- [ ] My code follows the [code of conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) of this project.
- [ ] I have self-reviewed the commit code.
- [ ] I have (or in comment I request) added corresponding labels for the pull request.
- [ ] I have passed maven check locally : `./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e`.
- [ ] I have made corresponding changes to the documentation.
- [ ] I have added corresponding unit tests for my changes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] sandynz commented on a diff in pull request #24807: Add pipeline job listener
Posted by "sandynz (via GitHub)" <gi...@apache.org>.
sandynz commented on code in PR #24807:
URL: https://github.com/apache/shardingsphere/pull/24807#discussion_r1149080507
##########
kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/node/config/processor/impl/AbstractChangedJobConfigurationProcessor.java:
##########
@@ -66,8 +66,8 @@ public void process(final Type eventType, final JobConfiguration jobConfig) {
protected void onDisabled(final JobConfiguration jobConfig) {
String jobId = jobConfig.getJobName();
- for (Integer each : PipelineJobCenter.getShardingItems(jobId)) {
- PipelineDistributedBarrier.getInstance().persistEphemeralChildrenNode(PipelineMetaDataNode.getJobBarrierDisablePath(jobId), each);
+ for (int i = 0; i < jobConfig.getShardingTotalCount(); i++) {
+ PipelineDistributedBarrier.getInstance().persistEphemeralChildrenNode(PipelineMetaDataNode.getJobBarrierDisablePath(jobId), i);
Review Comment:
It's not equivalent
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] azexcy commented on a diff in pull request #24807: Add pipeline job listener
Posted by "azexcy (via GitHub)" <gi...@apache.org>.
azexcy commented on code in PR #24807:
URL: https://github.com/apache/shardingsphere/pull/24807#discussion_r1148373659
##########
kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/node/config/processor/impl/AbstractChangedJobConfigurationProcessor.java:
##########
@@ -38,16 +38,16 @@ public abstract class AbstractChangedJobConfigurationProcessor implements Change
@Override
public void process(final Type eventType, final JobConfiguration jobConfig) {
boolean disabled = jobConfig.isDisabled();
- if (disabled) {
- onDisabled(jobConfig);
- }
boolean deleted = Type.DELETED == eventType;
if (deleted) {
onDeleted(jobConfig);
}
String jobId = jobConfig.getJobName();
if (disabled || deleted) {
PipelineJobCenter.stop(jobId);
+ if (disabled) {
+ onDisabled(jobConfig);
+ }
Review Comment:
if `onDisabled` be called before job stopping, may have the problem that when execute start job command, the DistSQL return the result but the job is block at stopping.

https://github.com/apache/shardingsphere/actions/runs/4510078482/jobs/7941413185
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] azexcy commented on a diff in pull request #24807: Add pipeline job listener
Posted by "azexcy (via GitHub)" <gi...@apache.org>.
azexcy commented on code in PR #24807:
URL: https://github.com/apache/shardingsphere/pull/24807#discussion_r1148475722
##########
kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/node/config/processor/impl/AbstractChangedJobConfigurationProcessor.java:
##########
@@ -38,16 +38,16 @@ public abstract class AbstractChangedJobConfigurationProcessor implements Change
@Override
public void process(final Type eventType, final JobConfiguration jobConfig) {
boolean disabled = jobConfig.isDisabled();
- if (disabled) {
- onDisabled(jobConfig);
- }
boolean deleted = Type.DELETED == eventType;
if (deleted) {
onDeleted(jobConfig);
}
String jobId = jobConfig.getJobName();
if (disabled || deleted) {
PipelineJobCenter.stop(jobId);
+ if (disabled) {
+ onDisabled(jobConfig);
+ }
Review Comment:
Because this PR add the `org.apache.shardingsphere.data.pipeline.core.job.AbstractPipelineJob#awaitJobStopped`, it's maybe blocked unitil elastic job really stopped.
when PipelineDistributedBarrier persist all ephemeral node, DistSQL result will return, but the job info still at PipelineJobCenter.JOB_MAP
```
private void awaitJobStopped(final PipelineElasticJobListener jobListener, final String jobId, final long timeoutMillis) {
int time = 0;
int sleepTime = 50;
while (time < timeoutMillis) {
if (!jobListener.isJobRunning(jobId)) {
break;
}
try {
Thread.sleep(sleepTime);
} catch (final InterruptedException ignored) {
break;
}
time += sleepTime;
}
}
```
At first commit, `sleepTime` = 1000, if the user executes `start migration` DistSql within 1000 milliseconds immediately after the `stop migration` DistSQL returns, the problem will occur, so I adjusted sleepTime to 50
##########
kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/listener/PipelineJobListener.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.data.pipeline.core.listener;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.elasticjob.infra.listener.ElasticJobListener;
+import org.apache.shardingsphere.elasticjob.infra.listener.ShardingContexts;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Pipeline job listener.
+ */
+@Slf4j
+public final class PipelineJobListener implements ElasticJobListener {
Review Comment:
Ok
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] sandynz commented on a diff in pull request #24807: Add pipeline job listener
Posted by "sandynz (via GitHub)" <gi...@apache.org>.
sandynz commented on code in PR #24807:
URL: https://github.com/apache/shardingsphere/pull/24807#discussion_r1148466811
##########
kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/listener/PipelineJobListener.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.data.pipeline.core.listener;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.elasticjob.infra.listener.ElasticJobListener;
+import org.apache.shardingsphere.elasticjob.infra.listener.ShardingContexts;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Pipeline job listener.
+ */
+@Slf4j
+public final class PipelineJobListener implements ElasticJobListener {
Review Comment:
It's listener for ElasticJob, but not pipeline itself.
`PipelineElasticJobListener`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] sandynz commented on a diff in pull request #24807: Add pipeline job listener
Posted by "sandynz (via GitHub)" <gi...@apache.org>.
sandynz commented on code in PR #24807:
URL: https://github.com/apache/shardingsphere/pull/24807#discussion_r1148280244
##########
kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/listener/PipelineJobListener.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.data.pipeline.core.listener;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.elasticjob.infra.listener.ElasticJobListener;
+import org.apache.shardingsphere.elasticjob.infra.listener.ShardingContexts;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Pipeline job listener.
+ */
+@Slf4j
+public final class PipelineJobListener implements ElasticJobListener {
Review Comment:
`PipelineJobListener` class name could be improved
##########
kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/listener/PipelineJobListener.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.data.pipeline.core.listener;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.elasticjob.infra.listener.ElasticJobListener;
+import org.apache.shardingsphere.elasticjob.infra.listener.ShardingContexts;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Pipeline job listener.
+ */
+@Slf4j
+public final class PipelineJobListener implements ElasticJobListener {
+
+ // TODO ElasticJobServiceLoader.getCachedTypedServiceInstance return new class instance, it's the reason why static variables
+ private static final Map<String, Long> RUNNING_JOBS = new ConcurrentHashMap<>();
Review Comment:
From `ElasticJobServiceLoader.getCachedTypedServiceInstance` source code, looks it return cached service instance, could you verify it?
ElasticJobServiceLoader.java
```
public static <T extends TypedSPI> Optional<T> getCachedTypedServiceInstance(final Class<T> typedServiceInterface, final String type) {
return Optional.ofNullable(TYPED_SERVICES.get(typedServiceInterface)).map(services -> (T) services.get(type));
}
```
But `JobScheduler` create new service instance every time via `ElasticJobListenerFactory.createListener`:
```
private Collection<ElasticJobListener> getElasticJobListeners(final JobConfiguration jobConfig) {
return jobConfig.getJobListenerTypes().stream()
.map(type -> ElasticJobListenerFactory.createListener(type).orElseThrow(() -> new IllegalArgumentException(String.format("Can not find job listener type '%s'.", type))))
.collect(Collectors.toList());
}
```
##########
kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/node/config/processor/impl/AbstractChangedJobConfigurationProcessor.java:
##########
@@ -38,16 +38,16 @@ public abstract class AbstractChangedJobConfigurationProcessor implements Change
@Override
public void process(final Type eventType, final JobConfiguration jobConfig) {
boolean disabled = jobConfig.isDisabled();
- if (disabled) {
- onDisabled(jobConfig);
- }
boolean deleted = Type.DELETED == eventType;
if (deleted) {
onDeleted(jobConfig);
}
String jobId = jobConfig.getJobName();
if (disabled || deleted) {
PipelineJobCenter.stop(jobId);
+ if (disabled) {
+ onDisabled(jobConfig);
+ }
Review Comment:
Could `onDisabled` be called before job stopping?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] azexcy commented on a diff in pull request #24807: Add pipeline job listener
Posted by "azexcy (via GitHub)" <gi...@apache.org>.
azexcy commented on code in PR #24807:
URL: https://github.com/apache/shardingsphere/pull/24807#discussion_r1148373058
##########
kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/listener/PipelineJobListener.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.data.pipeline.core.listener;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.elasticjob.infra.listener.ElasticJobListener;
+import org.apache.shardingsphere.elasticjob.infra.listener.ShardingContexts;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Pipeline job listener.
+ */
+@Slf4j
+public final class PipelineJobListener implements ElasticJobListener {
Review Comment:
How about `PipelineJobRuntimeListener`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] sandynz commented on a diff in pull request #24807: Add pipeline job listener
Posted by "sandynz (via GitHub)" <gi...@apache.org>.
sandynz commented on code in PR #24807:
URL: https://github.com/apache/shardingsphere/pull/24807#discussion_r1148467290
##########
kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/node/config/processor/impl/AbstractChangedJobConfigurationProcessor.java:
##########
@@ -38,16 +38,16 @@ public abstract class AbstractChangedJobConfigurationProcessor implements Change
@Override
public void process(final Type eventType, final JobConfiguration jobConfig) {
boolean disabled = jobConfig.isDisabled();
- if (disabled) {
- onDisabled(jobConfig);
- }
boolean deleted = Type.DELETED == eventType;
if (deleted) {
onDeleted(jobConfig);
}
String jobId = jobConfig.getJobName();
if (disabled || deleted) {
PipelineJobCenter.stop(jobId);
+ if (disabled) {
+ onDisabled(jobConfig);
+ }
Review Comment:
How it occur?
`onDisabled` just persist ephemeral node by `PipelineDistributedBarrier`, and `added to executing jobs failed since it already exists` code block is after `onDisabled` invocation, no matter in original code and modified code of this PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] azexcy commented on a diff in pull request #24807: Add pipeline job listener
Posted by "azexcy (via GitHub)" <gi...@apache.org>.
azexcy commented on code in PR #24807:
URL: https://github.com/apache/shardingsphere/pull/24807#discussion_r1148372933
##########
kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/listener/PipelineJobListener.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.data.pipeline.core.listener;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.elasticjob.infra.listener.ElasticJobListener;
+import org.apache.shardingsphere.elasticjob.infra.listener.ShardingContexts;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Pipeline job listener.
+ */
+@Slf4j
+public final class PipelineJobListener implements ElasticJobListener {
+
+ // TODO ElasticJobServiceLoader.getCachedTypedServiceInstance return new class instance, it's the reason why static variables
+ private static final Map<String, Long> RUNNING_JOBS = new ConcurrentHashMap<>();
Review Comment:
Yes, my mistake
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] sandynz commented on a diff in pull request #24807: Add pipeline elastic job listener
Posted by "sandynz (via GitHub)" <gi...@apache.org>.
sandynz commented on code in PR #24807:
URL: https://github.com/apache/shardingsphere/pull/24807#discussion_r1149969066
##########
kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/metadata/node/config/processor/impl/AbstractChangedJobConfigurationProcessor.java:
##########
@@ -38,16 +38,16 @@ public abstract class AbstractChangedJobConfigurationProcessor implements Change
@Override
public void process(final Type eventType, final JobConfiguration jobConfig) {
boolean disabled = jobConfig.isDisabled();
- if (disabled) {
- onDisabled(jobConfig);
- }
boolean deleted = Type.DELETED == eventType;
if (deleted) {
onDeleted(jobConfig);
}
String jobId = jobConfig.getJobName();
if (disabled || deleted) {
PipelineJobCenter.stop(jobId);
+ if (disabled) {
+ onDisabled(jobConfig);
+ }
Review Comment:
OK
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] sandynz merged pull request #24807: Add pipeline elastic job listener
Posted by "sandynz (via GitHub)" <gi...@apache.org>.
sandynz merged PR #24807:
URL: https://github.com/apache/shardingsphere/pull/24807
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org