You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hugegraph.apache.org by "VGalaxies (via GitHub)" <gi...@apache.org> on 2023/09/25 03:32:07 UTC
[GitHub] [incubator-hugegraph] VGalaxies opened a new pull request, #2319: feat: preliminary support for distributed task scheduler
VGalaxies opened a new pull request, #2319:
URL: https://github.com/apache/incubator-hugegraph/pull/2319
<!--
Thank you very much for contributing to Apache HugeGraph, we are happy that you want to help us improve it!
Here are some tips for you:
1. If this is your first time, please read the [contributing guidelines](https://github.com/apache/hugegraph/blob/master/CONTRIBUTING.md)
2. If a PR fix/close an issue, type the message "close xxx" (xxx is the link of related
issue) in the content, GitHub will auto link it (Required)
3. Name the PR title in "Google Commit Format", start with "feat | fix | perf | refactor | doc | chore",
such like: "feat(core): support the PageRank algorithm" or "fix: wrong break in the compute loop" (module is optional)
skip it if you are unsure about which is the best component.
4. One PR address one issue, better not to mix up multiple issues.
5. Put an `x` in the `[ ]` to mark the item as CHECKED. `[x]` (or click it directly after
published)
-->
## Purpose of the PR
subtask of https://github.com/apache/incubator-hugegraph/issues/2265
add `DistributedTaskScheduler` and its corresponding `TaskAndResultTransaction`:
- The scheduler type can be configured via `hugegraph.properties` configuration file (default to local).
- Add a `force` parameter to the `TaskAPI.delete`.
<!--
Please explain more context in this section, clarify why the changes are needed.
e.g:
- If you propose a new API, clarify the use case for a new API.
- If you fix a bug, you can clarify why it is a bug, and should be associated with an issue.
-->
## Main Changes
<!-- Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. These change logs are helpful for better ant faster reviews.)
For example:
- If you introduce a new feature, please show detailed design here or add the link of design documentation.
- If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
- If there is a discussion in the mailing list, please add the link. -->
For detailed adaptation documentation, refer to https://hugegraph.feishu.cn/wiki/HLIPwe8zei3mTvkWjoJchB0dn3g.
**TODO:** Currently, there exists duplicated codes in both the `DistributedTaskScheduler` and `StandardTaskScheduler`. We need to explore options for reuse without compromising existing functionality.
## Verifying these changes
<!-- Please pick the proper options below -->
- [ ] Trivial rework / code cleanup without any test coverage. (No Need)
- [ ] Already covered by existing tests, such as *(please modify tests here)*.
- [x] Need tests and can be verified as follows:
- validate that the functionality of **local** task scheduler remains unaffected
- verify the basic functionality of **distributed** task scheduler
| backend | task scheduler | test | status |
| :-----: | :-------------------------------------: | :----: | :----: |
| hstore | local | basic graph import | √ |
| hstore | local | ldbc validation (without query 4 and 5) | √ |
| hstore | distributed | basic graph import | √ |
| hstore | distributed | ldbc validation (without query 4 and 5) | √ |
## Does this PR potentially affect the following parts?
<!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
- [ ] Nope
- [ ] Dependencies (add/update license info) <!-- Don't forget to add/update the info in "LICENSE" & "NOTICE" files (both in root & dist module) -->
- [ ] Modify configurations
- [ ] The public API
- [x] Other affects (maybe breaking changes)
## Documentation Status
<!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
- [x] `Doc - TODO` <!-- Your PR changes impact docs and you will update later -->
- [ ] `Doc - Done` <!-- Related docs have been already added or updated -->
- [ ] `Doc - No Need` <!-- Your PR changes don't impact/need docs -->
--
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: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feat: preliminary support for distributed task scheduler [incubator-hugegraph]
Posted by "zyxxoo (via GitHub)" <gi...@apache.org>.
zyxxoo commented on code in PR #2319:
URL: https://github.com/apache/incubator-hugegraph/pull/2319#discussion_r1351655856
##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/DistributedTaskScheduler.java:
##########
@@ -0,0 +1,666 @@
+/*
+ * 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.hugegraph.task;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.locks.Lock;
+
+import org.apache.hugegraph.HugeException;
+import org.apache.hugegraph.HugeGraph;
+import org.apache.hugegraph.HugeGraphParams;
+import org.apache.hugegraph.backend.id.Id;
+import org.apache.hugegraph.backend.page.PageInfo;
+import org.apache.hugegraph.backend.query.QueryResults;
+import org.apache.hugegraph.concurrent.LockGroup;
+import org.apache.hugegraph.concurrent.LockManager;
+import org.apache.hugegraph.config.CoreOptions;
+import org.apache.hugegraph.exception.ConnectionException;
+import org.apache.hugegraph.exception.NotFoundException;
+import org.apache.hugegraph.meta.MetaManager;
+import org.apache.hugegraph.meta.lock.LockResult;
+import org.apache.hugegraph.structure.HugeVertex;
+import org.apache.hugegraph.util.E;
+import org.apache.hugegraph.util.LockUtil;
+import org.apache.hugegraph.util.Log;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.slf4j.Logger;
+
+public class DistributedTaskScheduler extends TaskAndResultScheduler {
+ protected static final int SCHEDULE_PERIOD = 10;
+ private static final Logger LOG = Log.logger(DistributedTaskScheduler.class);
+ private final ExecutorService taskDbExecutor;
+ private final ExecutorService schemaTaskExecutor;
+ private final ExecutorService olapTaskExecutor;
+ private final ExecutorService ephemeralTaskExecutor;
+ private final ExecutorService gremlinTaskExecutor;
+ private final ScheduledThreadPoolExecutor schedulerExecutor;
+ private final ScheduledFuture<?> cronFuture;
+
+ private final String lockGroupName;
+
+ /**
+ * the status of scheduler
+ */
+ private final AtomicBoolean closed = new AtomicBoolean(true);
+
+ private final ConcurrentHashMap<Id, HugeTask<?>> runningTasks = new ConcurrentHashMap<>();
+
+ public DistributedTaskScheduler(HugeGraphParams graph,
+ ScheduledThreadPoolExecutor schedulerExecutor,
+ ExecutorService taskDbExecutor,
+ ExecutorService schemaTaskExecutor,
+ ExecutorService olapTaskExecutor,
+ ExecutorService gremlinTaskExecutor,
+ ExecutorService ephemeralTaskExecutor,
+ ExecutorService serverInfoDbExecutor) {
+ super(graph, serverInfoDbExecutor);
+
+ this.taskDbExecutor = taskDbExecutor;
+ this.schemaTaskExecutor = schemaTaskExecutor;
+ this.olapTaskExecutor = olapTaskExecutor;
+ this.gremlinTaskExecutor = gremlinTaskExecutor;
+ this.ephemeralTaskExecutor = ephemeralTaskExecutor;
+
+ this.schedulerExecutor = schedulerExecutor;
+
+ lockGroupName = String.format("%s_%s_distributed", graphSpace, graph);
+ LockManager.instance().create(lockGroupName);
+
+ this.closed.set(false);
+
+ this.cronFuture = this.schedulerExecutor.scheduleWithFixedDelay(
+ () -> {
+ // TODO: uncomment later - graph space
+ // LockUtil.lock(this.graph().spaceGraphName(), LockUtil.GRAPH_LOCK);
+ LockUtil.lock("", LockUtil.GRAPH_LOCK);
+ try {
+ // TODO: 使用超级管理员权限,查询任务
+ // TaskManager.useAdmin();
+ this.cronSchedule();
+ } catch (Throwable t) {
+ LOG.info("cronScheduler exception ", t);
+ } finally {
+ // TODO: uncomment later - graph space
+ LockUtil.unlock("", LockUtil.GRAPH_LOCK);
+ // LockUtil.unlock(this.graph().spaceGraphName(), LockUtil.GRAPH_LOCK);
+ }
+ },
+ 10L, SCHEDULE_PERIOD,
+ TimeUnit.SECONDS);
+ }
+
+ private static boolean sleep(long ms) {
+ try {
+ Thread.sleep(ms);
+ return true;
+ } catch (InterruptedException ignored) {
+ // Ignore InterruptedException
+ return false;
+ }
+ }
+
+ public void cronSchedule() {
Review Comment:
另外,看文档时说有根据负载来执行任务的,但是这里貌似没看到,是在其他地方还是暂时没实现哈=。=?原来的调度策略是 master 根据各个节点的负载来指定任务的
##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/DistributedTaskScheduler.java:
##########
@@ -0,0 +1,666 @@
+/*
+ * 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.hugegraph.task;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.locks.Lock;
+
+import org.apache.hugegraph.HugeException;
+import org.apache.hugegraph.HugeGraph;
+import org.apache.hugegraph.HugeGraphParams;
+import org.apache.hugegraph.backend.id.Id;
+import org.apache.hugegraph.backend.page.PageInfo;
+import org.apache.hugegraph.backend.query.QueryResults;
+import org.apache.hugegraph.concurrent.LockGroup;
+import org.apache.hugegraph.concurrent.LockManager;
+import org.apache.hugegraph.config.CoreOptions;
+import org.apache.hugegraph.exception.ConnectionException;
+import org.apache.hugegraph.exception.NotFoundException;
+import org.apache.hugegraph.meta.MetaManager;
+import org.apache.hugegraph.meta.lock.LockResult;
+import org.apache.hugegraph.structure.HugeVertex;
+import org.apache.hugegraph.util.E;
+import org.apache.hugegraph.util.LockUtil;
+import org.apache.hugegraph.util.Log;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.slf4j.Logger;
+
+public class DistributedTaskScheduler extends TaskAndResultScheduler {
+ protected static final int SCHEDULE_PERIOD = 10;
+ private static final Logger LOG = Log.logger(DistributedTaskScheduler.class);
+ private final ExecutorService taskDbExecutor;
+ private final ExecutorService schemaTaskExecutor;
+ private final ExecutorService olapTaskExecutor;
+ private final ExecutorService ephemeralTaskExecutor;
+ private final ExecutorService gremlinTaskExecutor;
+ private final ScheduledThreadPoolExecutor schedulerExecutor;
+ private final ScheduledFuture<?> cronFuture;
+
+ private final String lockGroupName;
+
+ /**
+ * the status of scheduler
+ */
+ private final AtomicBoolean closed = new AtomicBoolean(true);
+
+ private final ConcurrentHashMap<Id, HugeTask<?>> runningTasks = new ConcurrentHashMap<>();
+
+ public DistributedTaskScheduler(HugeGraphParams graph,
+ ScheduledThreadPoolExecutor schedulerExecutor,
+ ExecutorService taskDbExecutor,
+ ExecutorService schemaTaskExecutor,
+ ExecutorService olapTaskExecutor,
+ ExecutorService gremlinTaskExecutor,
+ ExecutorService ephemeralTaskExecutor,
+ ExecutorService serverInfoDbExecutor) {
+ super(graph, serverInfoDbExecutor);
+
+ this.taskDbExecutor = taskDbExecutor;
+ this.schemaTaskExecutor = schemaTaskExecutor;
+ this.olapTaskExecutor = olapTaskExecutor;
+ this.gremlinTaskExecutor = gremlinTaskExecutor;
+ this.ephemeralTaskExecutor = ephemeralTaskExecutor;
+
+ this.schedulerExecutor = schedulerExecutor;
+
+ lockGroupName = String.format("%s_%s_distributed", graphSpace, graph);
+ LockManager.instance().create(lockGroupName);
+
+ this.closed.set(false);
+
+ this.cronFuture = this.schedulerExecutor.scheduleWithFixedDelay(
+ () -> {
+ // TODO: uncomment later - graph space
+ // LockUtil.lock(this.graph().spaceGraphName(), LockUtil.GRAPH_LOCK);
+ LockUtil.lock("", LockUtil.GRAPH_LOCK);
+ try {
+ // TODO: 使用超级管理员权限,查询任务
+ // TaskManager.useAdmin();
+ this.cronSchedule();
+ } catch (Throwable t) {
+ LOG.info("cronScheduler exception ", t);
+ } finally {
+ // TODO: uncomment later - graph space
+ LockUtil.unlock("", LockUtil.GRAPH_LOCK);
+ // LockUtil.unlock(this.graph().spaceGraphName(), LockUtil.GRAPH_LOCK);
+ }
+ },
+ 10L, SCHEDULE_PERIOD,
+ TimeUnit.SECONDS);
+ }
+
+ private static boolean sleep(long ms) {
+ try {
+ Thread.sleep(ms);
+ return true;
+ } catch (InterruptedException ignored) {
+ // Ignore InterruptedException
+ return false;
+ }
+ }
+
+ public void cronSchedule() {
Review Comment:
另外,看文档时说有根据负载来执行任务的,但是这里貌似没看到,是在其他地方还是暂时没实现哈=。=?原来的调度策略是 master 根据各个节点的负载来指定任务的
--
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: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feat: preliminary support for distributed task scheduler [incubator-hugegraph]
Posted by "VGalaxies (via GitHub)" <gi...@apache.org>.
VGalaxies commented on code in PR #2319:
URL: https://github.com/apache/incubator-hugegraph/pull/2319#discussion_r1359862016
##########
hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/job/TaskAPI.java:
##########
@@ -136,11 +136,12 @@ public Map<String, Object> get(@Context GraphManager manager,
@RedirectFilter.RedirectMasterRole
Review Comment:
在 `org.apache.hugegraph.api.filter.RedirectFilter#filter` 处进行了修改,当匹配到 TaskAPI 调用且对应 graph 的 scheduler 类型为 `DistributedTaskScheduler` 时不进行重定向
##########
hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/job/TaskAPI.java:
##########
@@ -136,11 +136,12 @@ public Map<String, Object> get(@Context GraphManager manager,
@RedirectFilter.RedirectMasterRole
Review Comment:
在 `org.apache.hugegraph.api.filter.RedirectFilter#filter` 处进行了修改,当匹配到 TaskAPI 调用且对应 graph 的 scheduler 类型为 `DistributedTaskScheduler` 时不进行重定向
--
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: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feat: preliminary support for distributed task scheduler [incubator-hugegraph]
Posted by "VGalaxies (via GitHub)" <gi...@apache.org>.
VGalaxies commented on code in PR #2319:
URL: https://github.com/apache/incubator-hugegraph/pull/2319#discussion_r1359868973
##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/DistributedTaskScheduler.java:
##########
@@ -0,0 +1,666 @@
+/*
+ * 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.hugegraph.task;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.locks.Lock;
+
+import org.apache.hugegraph.HugeException;
+import org.apache.hugegraph.HugeGraph;
+import org.apache.hugegraph.HugeGraphParams;
+import org.apache.hugegraph.backend.id.Id;
+import org.apache.hugegraph.backend.page.PageInfo;
+import org.apache.hugegraph.backend.query.QueryResults;
+import org.apache.hugegraph.concurrent.LockGroup;
+import org.apache.hugegraph.concurrent.LockManager;
+import org.apache.hugegraph.config.CoreOptions;
+import org.apache.hugegraph.exception.ConnectionException;
+import org.apache.hugegraph.exception.NotFoundException;
+import org.apache.hugegraph.meta.MetaManager;
+import org.apache.hugegraph.meta.lock.LockResult;
+import org.apache.hugegraph.structure.HugeVertex;
+import org.apache.hugegraph.util.E;
+import org.apache.hugegraph.util.LockUtil;
+import org.apache.hugegraph.util.Log;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.slf4j.Logger;
+
+public class DistributedTaskScheduler extends TaskAndResultScheduler {
+ protected static final int SCHEDULE_PERIOD = 10;
+ private static final Logger LOG = Log.logger(DistributedTaskScheduler.class);
+ private final ExecutorService taskDbExecutor;
+ private final ExecutorService schemaTaskExecutor;
+ private final ExecutorService olapTaskExecutor;
+ private final ExecutorService ephemeralTaskExecutor;
+ private final ExecutorService gremlinTaskExecutor;
+ private final ScheduledThreadPoolExecutor schedulerExecutor;
+ private final ScheduledFuture<?> cronFuture;
+
+ private final String lockGroupName;
+
+ /**
+ * the status of scheduler
+ */
+ private final AtomicBoolean closed = new AtomicBoolean(true);
+
+ private final ConcurrentHashMap<Id, HugeTask<?>> runningTasks = new ConcurrentHashMap<>();
+
+ public DistributedTaskScheduler(HugeGraphParams graph,
+ ScheduledThreadPoolExecutor schedulerExecutor,
+ ExecutorService taskDbExecutor,
+ ExecutorService schemaTaskExecutor,
+ ExecutorService olapTaskExecutor,
+ ExecutorService gremlinTaskExecutor,
+ ExecutorService ephemeralTaskExecutor,
+ ExecutorService serverInfoDbExecutor) {
+ super(graph, serverInfoDbExecutor);
+
+ this.taskDbExecutor = taskDbExecutor;
+ this.schemaTaskExecutor = schemaTaskExecutor;
+ this.olapTaskExecutor = olapTaskExecutor;
+ this.gremlinTaskExecutor = gremlinTaskExecutor;
+ this.ephemeralTaskExecutor = ephemeralTaskExecutor;
+
+ this.schedulerExecutor = schedulerExecutor;
+
+ lockGroupName = String.format("%s_%s_distributed", graphSpace, graph);
+ LockManager.instance().create(lockGroupName);
+
+ this.closed.set(false);
+
+ this.cronFuture = this.schedulerExecutor.scheduleWithFixedDelay(
+ () -> {
+ // TODO: uncomment later - graph space
+ // LockUtil.lock(this.graph().spaceGraphName(), LockUtil.GRAPH_LOCK);
+ LockUtil.lock("", LockUtil.GRAPH_LOCK);
+ try {
+ // TODO: 使用超级管理员权限,查询任务
+ // TaskManager.useAdmin();
+ this.cronSchedule();
+ } catch (Throwable t) {
+ LOG.info("cronScheduler exception ", t);
+ } finally {
+ // TODO: uncomment later - graph space
+ LockUtil.unlock("", LockUtil.GRAPH_LOCK);
+ // LockUtil.unlock(this.graph().spaceGraphName(), LockUtil.GRAPH_LOCK);
+ }
+ },
+ 10L, SCHEDULE_PERIOD,
+ TimeUnit.SECONDS);
+ }
+
+ private static boolean sleep(long ms) {
+ try {
+ Thread.sleep(ms);
+ return true;
+ } catch (InterruptedException ignored) {
+ // Ignore InterruptedException
+ return false;
+ }
+ }
+
+ public void cronSchedule() {
Review Comment:
> 这里个人有个想法可以讨论下哈:这段代码看着应该是每隔一段时间,查询所有的任务,然后过滤出没有被锁的任务,最后驱动这些没有被锁的任务的状态,我理解没错的话,那么其实所有节点都会查询一次所有的任务,再上层会做filter,这里看着似乎可以将这个逻辑下层到store,store 层每次返回给server的节点的批量数据都需要先锁定,然后在返回给server, 如果已经被锁定了,就在store 层过滤掉
我的理解是,这里过滤出没有被锁 (无节点在执行) 的任务主要出于三个目的
1. 将处于 RUNNING 状态且无节点在执行的任务状态转移到 FAILED
2. 将处于 CANCELLING 状态且无节点在执行的任务状态转移到 CANCELLED
3. 将处于 DELETING 状态且无节点在执行的任务删除
如果在 store 层过滤掉已经被锁定的任务,server 层就无法对这些任务进行相应的处理了 (例如对处于 RUNNING 状态的任务初始化环境变量,此时这些任务应当是被锁定的)
##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/DistributedTaskScheduler.java:
##########
@@ -0,0 +1,666 @@
+/*
+ * 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.hugegraph.task;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.locks.Lock;
+
+import org.apache.hugegraph.HugeException;
+import org.apache.hugegraph.HugeGraph;
+import org.apache.hugegraph.HugeGraphParams;
+import org.apache.hugegraph.backend.id.Id;
+import org.apache.hugegraph.backend.page.PageInfo;
+import org.apache.hugegraph.backend.query.QueryResults;
+import org.apache.hugegraph.concurrent.LockGroup;
+import org.apache.hugegraph.concurrent.LockManager;
+import org.apache.hugegraph.config.CoreOptions;
+import org.apache.hugegraph.exception.ConnectionException;
+import org.apache.hugegraph.exception.NotFoundException;
+import org.apache.hugegraph.meta.MetaManager;
+import org.apache.hugegraph.meta.lock.LockResult;
+import org.apache.hugegraph.structure.HugeVertex;
+import org.apache.hugegraph.util.E;
+import org.apache.hugegraph.util.LockUtil;
+import org.apache.hugegraph.util.Log;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.slf4j.Logger;
+
+public class DistributedTaskScheduler extends TaskAndResultScheduler {
+ protected static final int SCHEDULE_PERIOD = 10;
+ private static final Logger LOG = Log.logger(DistributedTaskScheduler.class);
+ private final ExecutorService taskDbExecutor;
+ private final ExecutorService schemaTaskExecutor;
+ private final ExecutorService olapTaskExecutor;
+ private final ExecutorService ephemeralTaskExecutor;
+ private final ExecutorService gremlinTaskExecutor;
+ private final ScheduledThreadPoolExecutor schedulerExecutor;
+ private final ScheduledFuture<?> cronFuture;
+
+ private final String lockGroupName;
+
+ /**
+ * the status of scheduler
+ */
+ private final AtomicBoolean closed = new AtomicBoolean(true);
+
+ private final ConcurrentHashMap<Id, HugeTask<?>> runningTasks = new ConcurrentHashMap<>();
+
+ public DistributedTaskScheduler(HugeGraphParams graph,
+ ScheduledThreadPoolExecutor schedulerExecutor,
+ ExecutorService taskDbExecutor,
+ ExecutorService schemaTaskExecutor,
+ ExecutorService olapTaskExecutor,
+ ExecutorService gremlinTaskExecutor,
+ ExecutorService ephemeralTaskExecutor,
+ ExecutorService serverInfoDbExecutor) {
+ super(graph, serverInfoDbExecutor);
+
+ this.taskDbExecutor = taskDbExecutor;
+ this.schemaTaskExecutor = schemaTaskExecutor;
+ this.olapTaskExecutor = olapTaskExecutor;
+ this.gremlinTaskExecutor = gremlinTaskExecutor;
+ this.ephemeralTaskExecutor = ephemeralTaskExecutor;
+
+ this.schedulerExecutor = schedulerExecutor;
+
+ lockGroupName = String.format("%s_%s_distributed", graphSpace, graph);
+ LockManager.instance().create(lockGroupName);
+
+ this.closed.set(false);
+
+ this.cronFuture = this.schedulerExecutor.scheduleWithFixedDelay(
+ () -> {
+ // TODO: uncomment later - graph space
+ // LockUtil.lock(this.graph().spaceGraphName(), LockUtil.GRAPH_LOCK);
+ LockUtil.lock("", LockUtil.GRAPH_LOCK);
+ try {
+ // TODO: 使用超级管理员权限,查询任务
+ // TaskManager.useAdmin();
+ this.cronSchedule();
+ } catch (Throwable t) {
+ LOG.info("cronScheduler exception ", t);
+ } finally {
+ // TODO: uncomment later - graph space
+ LockUtil.unlock("", LockUtil.GRAPH_LOCK);
+ // LockUtil.unlock(this.graph().spaceGraphName(), LockUtil.GRAPH_LOCK);
+ }
+ },
+ 10L, SCHEDULE_PERIOD,
+ TimeUnit.SECONDS);
+ }
+
+ private static boolean sleep(long ms) {
+ try {
+ Thread.sleep(ms);
+ return true;
+ } catch (InterruptedException ignored) {
+ // Ignore InterruptedException
+ return false;
+ }
+ }
+
+ public void cronSchedule() {
Review Comment:
> 这里个人有个想法可以讨论下哈:这段代码看着应该是每隔一段时间,查询所有的任务,然后过滤出没有被锁的任务,最后驱动这些没有被锁的任务的状态,我理解没错的话,那么其实所有节点都会查询一次所有的任务,再上层会做filter,这里看着似乎可以将这个逻辑下层到store,store 层每次返回给server的节点的批量数据都需要先锁定,然后在返回给server, 如果已经被锁定了,就在store 层过滤掉
我的理解是,这里过滤出没有被锁 (无节点在执行) 的任务主要出于三个目的
1. 将处于 RUNNING 状态且无节点在执行的任务状态转移到 FAILED
2. 将处于 CANCELLING 状态且无节点在执行的任务状态转移到 CANCELLED
3. 将处于 DELETING 状态且无节点在执行的任务删除
如果在 store 层过滤掉已经被锁定的任务,server 层就无法对这些任务进行相应的处理了 (例如对处于 RUNNING 状态的任务初始化环境变量,此时这些任务应当是被锁定的)
--
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: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feat: preliminary support for distributed task scheduler [incubator-hugegraph]
Posted by "VGalaxies (via GitHub)" <gi...@apache.org>.
VGalaxies commented on code in PR #2319:
URL: https://github.com/apache/incubator-hugegraph/pull/2319#discussion_r1359834929
##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/DistributedTaskScheduler.java:
##########
@@ -0,0 +1,666 @@
+/*
+ * 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.hugegraph.task;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.locks.Lock;
+
+import org.apache.hugegraph.HugeException;
+import org.apache.hugegraph.HugeGraph;
+import org.apache.hugegraph.HugeGraphParams;
+import org.apache.hugegraph.backend.id.Id;
+import org.apache.hugegraph.backend.page.PageInfo;
+import org.apache.hugegraph.backend.query.QueryResults;
+import org.apache.hugegraph.concurrent.LockGroup;
+import org.apache.hugegraph.concurrent.LockManager;
+import org.apache.hugegraph.config.CoreOptions;
+import org.apache.hugegraph.exception.ConnectionException;
+import org.apache.hugegraph.exception.NotFoundException;
+import org.apache.hugegraph.meta.MetaManager;
+import org.apache.hugegraph.meta.lock.LockResult;
+import org.apache.hugegraph.structure.HugeVertex;
+import org.apache.hugegraph.util.E;
+import org.apache.hugegraph.util.LockUtil;
+import org.apache.hugegraph.util.Log;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.slf4j.Logger;
+
+public class DistributedTaskScheduler extends TaskAndResultScheduler {
+ protected static final int SCHEDULE_PERIOD = 10;
+ private static final Logger LOG = Log.logger(DistributedTaskScheduler.class);
+ private final ExecutorService taskDbExecutor;
+ private final ExecutorService schemaTaskExecutor;
+ private final ExecutorService olapTaskExecutor;
+ private final ExecutorService ephemeralTaskExecutor;
+ private final ExecutorService gremlinTaskExecutor;
+ private final ScheduledThreadPoolExecutor schedulerExecutor;
+ private final ScheduledFuture<?> cronFuture;
+
+ private final String lockGroupName;
+
+ /**
+ * the status of scheduler
+ */
+ private final AtomicBoolean closed = new AtomicBoolean(true);
+
+ private final ConcurrentHashMap<Id, HugeTask<?>> runningTasks = new ConcurrentHashMap<>();
+
+ public DistributedTaskScheduler(HugeGraphParams graph,
+ ScheduledThreadPoolExecutor schedulerExecutor,
+ ExecutorService taskDbExecutor,
+ ExecutorService schemaTaskExecutor,
+ ExecutorService olapTaskExecutor,
+ ExecutorService gremlinTaskExecutor,
+ ExecutorService ephemeralTaskExecutor,
+ ExecutorService serverInfoDbExecutor) {
+ super(graph, serverInfoDbExecutor);
+
+ this.taskDbExecutor = taskDbExecutor;
+ this.schemaTaskExecutor = schemaTaskExecutor;
+ this.olapTaskExecutor = olapTaskExecutor;
+ this.gremlinTaskExecutor = gremlinTaskExecutor;
+ this.ephemeralTaskExecutor = ephemeralTaskExecutor;
+
+ this.schedulerExecutor = schedulerExecutor;
+
+ lockGroupName = String.format("%s_%s_distributed", graphSpace, graph);
+ LockManager.instance().create(lockGroupName);
+
+ this.closed.set(false);
+
+ this.cronFuture = this.schedulerExecutor.scheduleWithFixedDelay(
+ () -> {
+ // TODO: uncomment later - graph space
+ // LockUtil.lock(this.graph().spaceGraphName(), LockUtil.GRAPH_LOCK);
+ LockUtil.lock("", LockUtil.GRAPH_LOCK);
+ try {
+ // TODO: 使用超级管理员权限,查询任务
+ // TaskManager.useAdmin();
+ this.cronSchedule();
+ } catch (Throwable t) {
+ LOG.info("cronScheduler exception ", t);
+ } finally {
+ // TODO: uncomment later - graph space
+ LockUtil.unlock("", LockUtil.GRAPH_LOCK);
+ // LockUtil.unlock(this.graph().spaceGraphName(), LockUtil.GRAPH_LOCK);
+ }
+ },
+ 10L, SCHEDULE_PERIOD,
+ TimeUnit.SECONDS);
+ }
+
+ private static boolean sleep(long ms) {
+ try {
+ Thread.sleep(ms);
+ return true;
+ } catch (InterruptedException ignored) {
+ // Ignore InterruptedException
+ return false;
+ }
+ }
+
+ public void cronSchedule() {
+ // 执行周期调度任务
+
+ if (!this.graph.started() || this.graph.closed()) {
+ return;
+ }
+
+ if (!this.closed.get()) {
Review Comment:
已对应修改
##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/DistributedTaskScheduler.java:
##########
@@ -0,0 +1,666 @@
+/*
+ * 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.hugegraph.task;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.locks.Lock;
+
+import org.apache.hugegraph.HugeException;
+import org.apache.hugegraph.HugeGraph;
+import org.apache.hugegraph.HugeGraphParams;
+import org.apache.hugegraph.backend.id.Id;
+import org.apache.hugegraph.backend.page.PageInfo;
+import org.apache.hugegraph.backend.query.QueryResults;
+import org.apache.hugegraph.concurrent.LockGroup;
+import org.apache.hugegraph.concurrent.LockManager;
+import org.apache.hugegraph.config.CoreOptions;
+import org.apache.hugegraph.exception.ConnectionException;
+import org.apache.hugegraph.exception.NotFoundException;
+import org.apache.hugegraph.meta.MetaManager;
+import org.apache.hugegraph.meta.lock.LockResult;
+import org.apache.hugegraph.structure.HugeVertex;
+import org.apache.hugegraph.util.E;
+import org.apache.hugegraph.util.LockUtil;
+import org.apache.hugegraph.util.Log;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.slf4j.Logger;
+
+public class DistributedTaskScheduler extends TaskAndResultScheduler {
+ protected static final int SCHEDULE_PERIOD = 10;
+ private static final Logger LOG = Log.logger(DistributedTaskScheduler.class);
+ private final ExecutorService taskDbExecutor;
+ private final ExecutorService schemaTaskExecutor;
+ private final ExecutorService olapTaskExecutor;
+ private final ExecutorService ephemeralTaskExecutor;
+ private final ExecutorService gremlinTaskExecutor;
+ private final ScheduledThreadPoolExecutor schedulerExecutor;
+ private final ScheduledFuture<?> cronFuture;
+
+ private final String lockGroupName;
+
+ /**
+ * the status of scheduler
+ */
+ private final AtomicBoolean closed = new AtomicBoolean(true);
+
+ private final ConcurrentHashMap<Id, HugeTask<?>> runningTasks = new ConcurrentHashMap<>();
+
+ public DistributedTaskScheduler(HugeGraphParams graph,
+ ScheduledThreadPoolExecutor schedulerExecutor,
+ ExecutorService taskDbExecutor,
+ ExecutorService schemaTaskExecutor,
+ ExecutorService olapTaskExecutor,
+ ExecutorService gremlinTaskExecutor,
+ ExecutorService ephemeralTaskExecutor,
+ ExecutorService serverInfoDbExecutor) {
+ super(graph, serverInfoDbExecutor);
+
+ this.taskDbExecutor = taskDbExecutor;
+ this.schemaTaskExecutor = schemaTaskExecutor;
+ this.olapTaskExecutor = olapTaskExecutor;
+ this.gremlinTaskExecutor = gremlinTaskExecutor;
+ this.ephemeralTaskExecutor = ephemeralTaskExecutor;
+
+ this.schedulerExecutor = schedulerExecutor;
+
+ lockGroupName = String.format("%s_%s_distributed", graphSpace, graph);
+ LockManager.instance().create(lockGroupName);
+
+ this.closed.set(false);
+
+ this.cronFuture = this.schedulerExecutor.scheduleWithFixedDelay(
+ () -> {
+ // TODO: uncomment later - graph space
+ // LockUtil.lock(this.graph().spaceGraphName(), LockUtil.GRAPH_LOCK);
+ LockUtil.lock("", LockUtil.GRAPH_LOCK);
+ try {
+ // TODO: 使用超级管理员权限,查询任务
+ // TaskManager.useAdmin();
+ this.cronSchedule();
+ } catch (Throwable t) {
+ LOG.info("cronScheduler exception ", t);
+ } finally {
+ // TODO: uncomment later - graph space
+ LockUtil.unlock("", LockUtil.GRAPH_LOCK);
+ // LockUtil.unlock(this.graph().spaceGraphName(), LockUtil.GRAPH_LOCK);
+ }
+ },
+ 10L, SCHEDULE_PERIOD,
+ TimeUnit.SECONDS);
+ }
+
+ private static boolean sleep(long ms) {
+ try {
+ Thread.sleep(ms);
+ return true;
+ } catch (InterruptedException ignored) {
+ // Ignore InterruptedException
+ return false;
+ }
+ }
+
+ public void cronSchedule() {
+ // 执行周期调度任务
+
+ if (!this.graph.started() || this.graph.closed()) {
+ return;
+ }
+
+ if (!this.closed.get()) {
Review Comment:
已对应修改
--
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: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feat: preliminary support for distributed task scheduler [incubator-hugegraph]
Posted by "zyxxoo (via GitHub)" <gi...@apache.org>.
zyxxoo commented on code in PR #2319:
URL: https://github.com/apache/incubator-hugegraph/pull/2319#discussion_r1360039510
##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/TaskManager.java:
##########
@@ -87,11 +108,36 @@ private TaskManager(int pool) {
public void addScheduler(HugeGraphParams graph) {
E.checkArgumentNotNull(graph, "The graph can't be null");
-
- TaskScheduler scheduler = new StandardTaskScheduler(graph,
- this.taskExecutor, this.taskDbExecutor,
- this.serverInfoDbExecutor);
- this.schedulers.put(graph, scheduler);
+ LOG.info("Use {} as the scheduler of graph ({})",
+ graph.schedulerType(), graph.name());
Review Comment:
可以先这样吧,没个图实例单独设置不同的调度类型,意义不大,基本都是一样的
##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/TaskManager.java:
##########
@@ -87,11 +108,36 @@ private TaskManager(int pool) {
public void addScheduler(HugeGraphParams graph) {
E.checkArgumentNotNull(graph, "The graph can't be null");
-
- TaskScheduler scheduler = new StandardTaskScheduler(graph,
- this.taskExecutor, this.taskDbExecutor,
- this.serverInfoDbExecutor);
- this.schedulers.put(graph, scheduler);
+ LOG.info("Use {} as the scheduler of graph ({})",
+ graph.schedulerType(), graph.name());
Review Comment:
可以先这样吧,没个图实例单独设置不同的调度类型,意义不大,基本都是一样的
--
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: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feat: preliminary support for distributed task scheduler [incubator-hugegraph]
Posted by "zyxxoo (via GitHub)" <gi...@apache.org>.
zyxxoo commented on code in PR #2319:
URL: https://github.com/apache/incubator-hugegraph/pull/2319#discussion_r1351292741
##########
hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/job/TaskAPI.java:
##########
@@ -136,11 +136,12 @@ public Map<String, Object> get(@Context GraphManager manager,
@RedirectFilter.RedirectMasterRole
Review Comment:
看 DistributedTaskScheduler 实现,我理解就是所有的节点都会处理任务,通过分布式锁来保证任务只被一个节点处理,原来的方式任务只能被 master 提交,由 master 分配给其他节点处理,所以现在这个逻辑应该不需要了,对吧,硬刺这里RedirectFilter这里的拦截器实现可以加下开关,使用 DistributedTaskScheduler 的时候不生效
##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/DistributedTaskScheduler.java:
##########
@@ -0,0 +1,666 @@
+/*
+ * 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.hugegraph.task;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.locks.Lock;
+
+import org.apache.hugegraph.HugeException;
+import org.apache.hugegraph.HugeGraph;
+import org.apache.hugegraph.HugeGraphParams;
+import org.apache.hugegraph.backend.id.Id;
+import org.apache.hugegraph.backend.page.PageInfo;
+import org.apache.hugegraph.backend.query.QueryResults;
+import org.apache.hugegraph.concurrent.LockGroup;
+import org.apache.hugegraph.concurrent.LockManager;
+import org.apache.hugegraph.config.CoreOptions;
+import org.apache.hugegraph.exception.ConnectionException;
+import org.apache.hugegraph.exception.NotFoundException;
+import org.apache.hugegraph.meta.MetaManager;
+import org.apache.hugegraph.meta.lock.LockResult;
+import org.apache.hugegraph.structure.HugeVertex;
+import org.apache.hugegraph.util.E;
+import org.apache.hugegraph.util.LockUtil;
+import org.apache.hugegraph.util.Log;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.slf4j.Logger;
+
+public class DistributedTaskScheduler extends TaskAndResultScheduler {
+ protected static final int SCHEDULE_PERIOD = 10;
+ private static final Logger LOG = Log.logger(DistributedTaskScheduler.class);
+ private final ExecutorService taskDbExecutor;
+ private final ExecutorService schemaTaskExecutor;
+ private final ExecutorService olapTaskExecutor;
+ private final ExecutorService ephemeralTaskExecutor;
+ private final ExecutorService gremlinTaskExecutor;
+ private final ScheduledThreadPoolExecutor schedulerExecutor;
+ private final ScheduledFuture<?> cronFuture;
+
+ private final String lockGroupName;
+
+ /**
+ * the status of scheduler
+ */
+ private final AtomicBoolean closed = new AtomicBoolean(true);
+
+ private final ConcurrentHashMap<Id, HugeTask<?>> runningTasks = new ConcurrentHashMap<>();
+
+ public DistributedTaskScheduler(HugeGraphParams graph,
+ ScheduledThreadPoolExecutor schedulerExecutor,
+ ExecutorService taskDbExecutor,
+ ExecutorService schemaTaskExecutor,
+ ExecutorService olapTaskExecutor,
+ ExecutorService gremlinTaskExecutor,
+ ExecutorService ephemeralTaskExecutor,
+ ExecutorService serverInfoDbExecutor) {
+ super(graph, serverInfoDbExecutor);
+
+ this.taskDbExecutor = taskDbExecutor;
+ this.schemaTaskExecutor = schemaTaskExecutor;
+ this.olapTaskExecutor = olapTaskExecutor;
+ this.gremlinTaskExecutor = gremlinTaskExecutor;
+ this.ephemeralTaskExecutor = ephemeralTaskExecutor;
+
+ this.schedulerExecutor = schedulerExecutor;
+
+ lockGroupName = String.format("%s_%s_distributed", graphSpace, graph);
+ LockManager.instance().create(lockGroupName);
+
+ this.closed.set(false);
+
+ this.cronFuture = this.schedulerExecutor.scheduleWithFixedDelay(
+ () -> {
+ // TODO: uncomment later - graph space
+ // LockUtil.lock(this.graph().spaceGraphName(), LockUtil.GRAPH_LOCK);
+ LockUtil.lock("", LockUtil.GRAPH_LOCK);
+ try {
+ // TODO: 使用超级管理员权限,查询任务
+ // TaskManager.useAdmin();
+ this.cronSchedule();
+ } catch (Throwable t) {
+ LOG.info("cronScheduler exception ", t);
+ } finally {
+ // TODO: uncomment later - graph space
+ LockUtil.unlock("", LockUtil.GRAPH_LOCK);
+ // LockUtil.unlock(this.graph().spaceGraphName(), LockUtil.GRAPH_LOCK);
+ }
+ },
+ 10L, SCHEDULE_PERIOD,
+ TimeUnit.SECONDS);
+ }
+
+ private static boolean sleep(long ms) {
+ try {
+ Thread.sleep(ms);
+ return true;
+ } catch (InterruptedException ignored) {
+ // Ignore InterruptedException
+ return false;
+ }
+ }
+
+ public void cronSchedule() {
+ // 执行周期调度任务
+
+ if (!this.graph.started() || this.graph.closed()) {
+ return;
+ }
+
+ if (!this.closed.get()) {
Review Comment:
这个方法是不是在每次查询或者while执行前都判断一次比较好?
##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/DistributedTaskScheduler.java:
##########
@@ -0,0 +1,666 @@
+/*
+ * 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.hugegraph.task;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.locks.Lock;
+
+import org.apache.hugegraph.HugeException;
+import org.apache.hugegraph.HugeGraph;
+import org.apache.hugegraph.HugeGraphParams;
+import org.apache.hugegraph.backend.id.Id;
+import org.apache.hugegraph.backend.page.PageInfo;
+import org.apache.hugegraph.backend.query.QueryResults;
+import org.apache.hugegraph.concurrent.LockGroup;
+import org.apache.hugegraph.concurrent.LockManager;
+import org.apache.hugegraph.config.CoreOptions;
+import org.apache.hugegraph.exception.ConnectionException;
+import org.apache.hugegraph.exception.NotFoundException;
+import org.apache.hugegraph.meta.MetaManager;
+import org.apache.hugegraph.meta.lock.LockResult;
+import org.apache.hugegraph.structure.HugeVertex;
+import org.apache.hugegraph.util.E;
+import org.apache.hugegraph.util.LockUtil;
+import org.apache.hugegraph.util.Log;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.slf4j.Logger;
+
+public class DistributedTaskScheduler extends TaskAndResultScheduler {
+ protected static final int SCHEDULE_PERIOD = 10;
+ private static final Logger LOG = Log.logger(DistributedTaskScheduler.class);
+ private final ExecutorService taskDbExecutor;
+ private final ExecutorService schemaTaskExecutor;
+ private final ExecutorService olapTaskExecutor;
+ private final ExecutorService ephemeralTaskExecutor;
+ private final ExecutorService gremlinTaskExecutor;
+ private final ScheduledThreadPoolExecutor schedulerExecutor;
+ private final ScheduledFuture<?> cronFuture;
+
+ private final String lockGroupName;
+
+ /**
+ * the status of scheduler
+ */
+ private final AtomicBoolean closed = new AtomicBoolean(true);
+
+ private final ConcurrentHashMap<Id, HugeTask<?>> runningTasks = new ConcurrentHashMap<>();
+
+ public DistributedTaskScheduler(HugeGraphParams graph,
+ ScheduledThreadPoolExecutor schedulerExecutor,
+ ExecutorService taskDbExecutor,
+ ExecutorService schemaTaskExecutor,
+ ExecutorService olapTaskExecutor,
+ ExecutorService gremlinTaskExecutor,
+ ExecutorService ephemeralTaskExecutor,
+ ExecutorService serverInfoDbExecutor) {
+ super(graph, serverInfoDbExecutor);
+
+ this.taskDbExecutor = taskDbExecutor;
+ this.schemaTaskExecutor = schemaTaskExecutor;
+ this.olapTaskExecutor = olapTaskExecutor;
+ this.gremlinTaskExecutor = gremlinTaskExecutor;
+ this.ephemeralTaskExecutor = ephemeralTaskExecutor;
+
+ this.schedulerExecutor = schedulerExecutor;
+
+ lockGroupName = String.format("%s_%s_distributed", graphSpace, graph);
+ LockManager.instance().create(lockGroupName);
+
+ this.closed.set(false);
+
+ this.cronFuture = this.schedulerExecutor.scheduleWithFixedDelay(
+ () -> {
+ // TODO: uncomment later - graph space
+ // LockUtil.lock(this.graph().spaceGraphName(), LockUtil.GRAPH_LOCK);
+ LockUtil.lock("", LockUtil.GRAPH_LOCK);
+ try {
+ // TODO: 使用超级管理员权限,查询任务
+ // TaskManager.useAdmin();
+ this.cronSchedule();
+ } catch (Throwable t) {
+ LOG.info("cronScheduler exception ", t);
+ } finally {
+ // TODO: uncomment later - graph space
+ LockUtil.unlock("", LockUtil.GRAPH_LOCK);
+ // LockUtil.unlock(this.graph().spaceGraphName(), LockUtil.GRAPH_LOCK);
+ }
+ },
+ 10L, SCHEDULE_PERIOD,
+ TimeUnit.SECONDS);
+ }
+
+ private static boolean sleep(long ms) {
+ try {
+ Thread.sleep(ms);
+ return true;
+ } catch (InterruptedException ignored) {
+ // Ignore InterruptedException
+ return false;
+ }
+ }
+
+ public void cronSchedule() {
+ // 执行周期调度任务
+
+ if (!this.graph.started() || this.graph.closed()) {
+ return;
+ }
+
+ if (!this.closed.get()) {
Review Comment:
这个方法是不是在每次查询或者while执行前都判断一次比较好?
##########
hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/job/TaskAPI.java:
##########
@@ -136,11 +136,12 @@ public Map<String, Object> get(@Context GraphManager manager,
@RedirectFilter.RedirectMasterRole
Review Comment:
看 DistributedTaskScheduler 实现,我理解就是所有的节点都会处理任务,通过分布式锁来保证任务只被一个节点处理,原来的方式任务只能被 master 提交,由 master 分配给其他节点处理,所以现在这个逻辑应该不需要了,对吧,硬刺这里RedirectFilter这里的拦截器实现可以加下开关,使用 DistributedTaskScheduler 的时候不生效
##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/DistributedTaskScheduler.java:
##########
@@ -0,0 +1,666 @@
+/*
+ * 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.hugegraph.task;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.locks.Lock;
+
+import org.apache.hugegraph.HugeException;
+import org.apache.hugegraph.HugeGraph;
+import org.apache.hugegraph.HugeGraphParams;
+import org.apache.hugegraph.backend.id.Id;
+import org.apache.hugegraph.backend.page.PageInfo;
+import org.apache.hugegraph.backend.query.QueryResults;
+import org.apache.hugegraph.concurrent.LockGroup;
+import org.apache.hugegraph.concurrent.LockManager;
+import org.apache.hugegraph.config.CoreOptions;
+import org.apache.hugegraph.exception.ConnectionException;
+import org.apache.hugegraph.exception.NotFoundException;
+import org.apache.hugegraph.meta.MetaManager;
+import org.apache.hugegraph.meta.lock.LockResult;
+import org.apache.hugegraph.structure.HugeVertex;
+import org.apache.hugegraph.util.E;
+import org.apache.hugegraph.util.LockUtil;
+import org.apache.hugegraph.util.Log;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.slf4j.Logger;
+
+public class DistributedTaskScheduler extends TaskAndResultScheduler {
+ protected static final int SCHEDULE_PERIOD = 10;
+ private static final Logger LOG = Log.logger(DistributedTaskScheduler.class);
+ private final ExecutorService taskDbExecutor;
+ private final ExecutorService schemaTaskExecutor;
+ private final ExecutorService olapTaskExecutor;
+ private final ExecutorService ephemeralTaskExecutor;
+ private final ExecutorService gremlinTaskExecutor;
+ private final ScheduledThreadPoolExecutor schedulerExecutor;
+ private final ScheduledFuture<?> cronFuture;
+
+ private final String lockGroupName;
+
+ /**
+ * the status of scheduler
+ */
+ private final AtomicBoolean closed = new AtomicBoolean(true);
+
+ private final ConcurrentHashMap<Id, HugeTask<?>> runningTasks = new ConcurrentHashMap<>();
+
+ public DistributedTaskScheduler(HugeGraphParams graph,
+ ScheduledThreadPoolExecutor schedulerExecutor,
+ ExecutorService taskDbExecutor,
+ ExecutorService schemaTaskExecutor,
+ ExecutorService olapTaskExecutor,
+ ExecutorService gremlinTaskExecutor,
+ ExecutorService ephemeralTaskExecutor,
+ ExecutorService serverInfoDbExecutor) {
+ super(graph, serverInfoDbExecutor);
+
+ this.taskDbExecutor = taskDbExecutor;
+ this.schemaTaskExecutor = schemaTaskExecutor;
+ this.olapTaskExecutor = olapTaskExecutor;
+ this.gremlinTaskExecutor = gremlinTaskExecutor;
+ this.ephemeralTaskExecutor = ephemeralTaskExecutor;
+
+ this.schedulerExecutor = schedulerExecutor;
+
+ lockGroupName = String.format("%s_%s_distributed", graphSpace, graph);
+ LockManager.instance().create(lockGroupName);
+
+ this.closed.set(false);
+
+ this.cronFuture = this.schedulerExecutor.scheduleWithFixedDelay(
+ () -> {
+ // TODO: uncomment later - graph space
+ // LockUtil.lock(this.graph().spaceGraphName(), LockUtil.GRAPH_LOCK);
+ LockUtil.lock("", LockUtil.GRAPH_LOCK);
+ try {
+ // TODO: 使用超级管理员权限,查询任务
+ // TaskManager.useAdmin();
+ this.cronSchedule();
+ } catch (Throwable t) {
+ LOG.info("cronScheduler exception ", t);
+ } finally {
+ // TODO: uncomment later - graph space
+ LockUtil.unlock("", LockUtil.GRAPH_LOCK);
+ // LockUtil.unlock(this.graph().spaceGraphName(), LockUtil.GRAPH_LOCK);
+ }
+ },
+ 10L, SCHEDULE_PERIOD,
+ TimeUnit.SECONDS);
+ }
+
+ private static boolean sleep(long ms) {
+ try {
+ Thread.sleep(ms);
+ return true;
+ } catch (InterruptedException ignored) {
+ // Ignore InterruptedException
+ return false;
+ }
+ }
+
+ public void cronSchedule() {
Review Comment:
这里个人有个想法可以讨论下哈:这段代码看着应该是每隔一段时间,查询所有的任务,然后过滤出没有被锁的任务,最后驱动这些没有被锁的任务的状态,我理解没错的话,那么其实所有节点都会查询一次所有的任务,再上层会做filter,这里看着似乎可以将这个逻辑下层到store,store 层每次返回给server的节点的批量数据都需要先锁定,然后在返回给server, 如果已经被锁定了,就在store 层过滤掉
##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/DistributedTaskScheduler.java:
##########
@@ -0,0 +1,666 @@
+/*
+ * 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.hugegraph.task;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.locks.Lock;
+
+import org.apache.hugegraph.HugeException;
+import org.apache.hugegraph.HugeGraph;
+import org.apache.hugegraph.HugeGraphParams;
+import org.apache.hugegraph.backend.id.Id;
+import org.apache.hugegraph.backend.page.PageInfo;
+import org.apache.hugegraph.backend.query.QueryResults;
+import org.apache.hugegraph.concurrent.LockGroup;
+import org.apache.hugegraph.concurrent.LockManager;
+import org.apache.hugegraph.config.CoreOptions;
+import org.apache.hugegraph.exception.ConnectionException;
+import org.apache.hugegraph.exception.NotFoundException;
+import org.apache.hugegraph.meta.MetaManager;
+import org.apache.hugegraph.meta.lock.LockResult;
+import org.apache.hugegraph.structure.HugeVertex;
+import org.apache.hugegraph.util.E;
+import org.apache.hugegraph.util.LockUtil;
+import org.apache.hugegraph.util.Log;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.slf4j.Logger;
+
+public class DistributedTaskScheduler extends TaskAndResultScheduler {
+ protected static final int SCHEDULE_PERIOD = 10;
+ private static final Logger LOG = Log.logger(DistributedTaskScheduler.class);
+ private final ExecutorService taskDbExecutor;
+ private final ExecutorService schemaTaskExecutor;
+ private final ExecutorService olapTaskExecutor;
+ private final ExecutorService ephemeralTaskExecutor;
+ private final ExecutorService gremlinTaskExecutor;
+ private final ScheduledThreadPoolExecutor schedulerExecutor;
+ private final ScheduledFuture<?> cronFuture;
+
+ private final String lockGroupName;
+
+ /**
+ * the status of scheduler
+ */
+ private final AtomicBoolean closed = new AtomicBoolean(true);
+
+ private final ConcurrentHashMap<Id, HugeTask<?>> runningTasks = new ConcurrentHashMap<>();
+
+ public DistributedTaskScheduler(HugeGraphParams graph,
+ ScheduledThreadPoolExecutor schedulerExecutor,
+ ExecutorService taskDbExecutor,
+ ExecutorService schemaTaskExecutor,
+ ExecutorService olapTaskExecutor,
+ ExecutorService gremlinTaskExecutor,
+ ExecutorService ephemeralTaskExecutor,
+ ExecutorService serverInfoDbExecutor) {
+ super(graph, serverInfoDbExecutor);
+
+ this.taskDbExecutor = taskDbExecutor;
+ this.schemaTaskExecutor = schemaTaskExecutor;
+ this.olapTaskExecutor = olapTaskExecutor;
+ this.gremlinTaskExecutor = gremlinTaskExecutor;
+ this.ephemeralTaskExecutor = ephemeralTaskExecutor;
+
+ this.schedulerExecutor = schedulerExecutor;
+
+ lockGroupName = String.format("%s_%s_distributed", graphSpace, graph);
+ LockManager.instance().create(lockGroupName);
+
+ this.closed.set(false);
+
+ this.cronFuture = this.schedulerExecutor.scheduleWithFixedDelay(
+ () -> {
+ // TODO: uncomment later - graph space
+ // LockUtil.lock(this.graph().spaceGraphName(), LockUtil.GRAPH_LOCK);
+ LockUtil.lock("", LockUtil.GRAPH_LOCK);
+ try {
+ // TODO: 使用超级管理员权限,查询任务
+ // TaskManager.useAdmin();
+ this.cronSchedule();
+ } catch (Throwable t) {
+ LOG.info("cronScheduler exception ", t);
+ } finally {
+ // TODO: uncomment later - graph space
+ LockUtil.unlock("", LockUtil.GRAPH_LOCK);
+ // LockUtil.unlock(this.graph().spaceGraphName(), LockUtil.GRAPH_LOCK);
+ }
+ },
+ 10L, SCHEDULE_PERIOD,
+ TimeUnit.SECONDS);
+ }
+
+ private static boolean sleep(long ms) {
+ try {
+ Thread.sleep(ms);
+ return true;
+ } catch (InterruptedException ignored) {
+ // Ignore InterruptedException
+ return false;
+ }
+ }
+
+ public void cronSchedule() {
Review Comment:
这里个人有个想法可以讨论下哈:这段代码看着应该是每隔一段时间,查询所有的任务,然后过滤出没有被锁的任务,最后驱动这些没有被锁的任务的状态,我理解没错的话,那么其实所有节点都会查询一次所有的任务,再上层会做filter,这里看着似乎可以将这个逻辑下层到store,store 层每次返回给server的节点的批量数据都需要先锁定,然后在返回给server, 如果已经被锁定了,就在store 层过滤掉
--
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: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feat: preliminary support for distributed task scheduler [incubator-hugegraph]
Posted by "VGalaxies (via GitHub)" <gi...@apache.org>.
VGalaxies commented on code in PR #2319:
URL: https://github.com/apache/incubator-hugegraph/pull/2319#discussion_r1359866234
##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/TaskManager.java:
##########
@@ -87,11 +108,36 @@ private TaskManager(int pool) {
public void addScheduler(HugeGraphParams graph) {
E.checkArgumentNotNull(graph, "The graph can't be null");
-
- TaskScheduler scheduler = new StandardTaskScheduler(graph,
- this.taskExecutor, this.taskDbExecutor,
- this.serverInfoDbExecutor);
- this.schedulers.put(graph, scheduler);
+ LOG.info("Use {} as the scheduler of graph ({})",
+ graph.schedulerType(), graph.name());
Review Comment:
@zyxxoo 意思是将 `task.scheduler_type` 这个选项从 `CoreOptions` 移动到 `ServerOptions` 中吗?我理解的是每个图实例都可以单独设定调度类型
##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/TaskManager.java:
##########
@@ -87,11 +108,36 @@ private TaskManager(int pool) {
public void addScheduler(HugeGraphParams graph) {
E.checkArgumentNotNull(graph, "The graph can't be null");
-
- TaskScheduler scheduler = new StandardTaskScheduler(graph,
- this.taskExecutor, this.taskDbExecutor,
- this.serverInfoDbExecutor);
- this.schedulers.put(graph, scheduler);
+ LOG.info("Use {} as the scheduler of graph ({})",
+ graph.schedulerType(), graph.name());
Review Comment:
@zyxxoo 意思是将 `task.scheduler_type` 这个选项从 `CoreOptions` 移动到 `ServerOptions` 中吗?我理解的是每个图实例都可以单独设定调度类型
--
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: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feat: preliminary support for distributed task scheduler [incubator-hugegraph]
Posted by "VGalaxies (via GitHub)" <gi...@apache.org>.
VGalaxies commented on code in PR #2319:
URL: https://github.com/apache/incubator-hugegraph/pull/2319#discussion_r1359869892
##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/TaskManager.java:
##########
@@ -156,6 +206,21 @@ private void closeSchedulerTx(HugeGraphParams graph) {
}
}
+ private void closeDistributedSchedulerTx(HugeGraphParams graph) {
+ final Callable<Void> closeTx = () -> {
+ // Do close-tx for current thread
+ graph.closeTx();
+ // Let other threads run
+ Thread.yield();
Review Comment:
> 这里为啥会有这段代码哈? 为什么要让其他线程run呢
参考的是 close `schedulerExecutor` 的逻辑 `org.apache.hugegraph.task.TaskManager#closeSchedulerTx`
##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/TaskManager.java:
##########
@@ -156,6 +206,21 @@ private void closeSchedulerTx(HugeGraphParams graph) {
}
}
+ private void closeDistributedSchedulerTx(HugeGraphParams graph) {
+ final Callable<Void> closeTx = () -> {
+ // Do close-tx for current thread
+ graph.closeTx();
+ // Let other threads run
+ Thread.yield();
Review Comment:
> 这里为啥会有这段代码哈? 为什么要让其他线程run呢
参考的是 close `schedulerExecutor` 的逻辑 `org.apache.hugegraph.task.TaskManager#closeSchedulerTx`
--
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: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feat: preliminary support for distributed task scheduler [incubator-hugegraph]
Posted by "zyxxoo (via GitHub)" <gi...@apache.org>.
zyxxoo commented on code in PR #2319:
URL: https://github.com/apache/incubator-hugegraph/pull/2319#discussion_r1351604299
##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/TaskManager.java:
##########
@@ -87,11 +108,36 @@ private TaskManager(int pool) {
public void addScheduler(HugeGraphParams graph) {
E.checkArgumentNotNull(graph, "The graph can't be null");
-
- TaskScheduler scheduler = new StandardTaskScheduler(graph,
- this.taskExecutor, this.taskDbExecutor,
- this.serverInfoDbExecutor);
- this.schedulers.put(graph, scheduler);
+ LOG.info("Use {} as the scheduler of graph ({})",
+ graph.schedulerType(), graph.name());
Review Comment:
调度类型似乎全局的更合适,因为如果使用了自研的分布式存储,那其实就不会用原来的调度了,而是使用新的
##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/TaskManager.java:
##########
@@ -156,6 +206,21 @@ private void closeSchedulerTx(HugeGraphParams graph) {
}
}
+ private void closeDistributedSchedulerTx(HugeGraphParams graph) {
+ final Callable<Void> closeTx = () -> {
+ // Do close-tx for current thread
+ graph.closeTx();
+ // Let other threads run
+ Thread.yield();
Review Comment:
这里为啥会有这段代码哈?
为什么要让其他线程run呢
##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/TaskManager.java:
##########
@@ -87,11 +108,36 @@ private TaskManager(int pool) {
public void addScheduler(HugeGraphParams graph) {
E.checkArgumentNotNull(graph, "The graph can't be null");
-
- TaskScheduler scheduler = new StandardTaskScheduler(graph,
- this.taskExecutor, this.taskDbExecutor,
- this.serverInfoDbExecutor);
- this.schedulers.put(graph, scheduler);
+ LOG.info("Use {} as the scheduler of graph ({})",
+ graph.schedulerType(), graph.name());
Review Comment:
调度类型似乎全局的更合适,因为如果使用了自研的分布式存储,那其实就不会用原来的调度了,而是使用新的
##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/TaskManager.java:
##########
@@ -156,6 +206,21 @@ private void closeSchedulerTx(HugeGraphParams graph) {
}
}
+ private void closeDistributedSchedulerTx(HugeGraphParams graph) {
+ final Callable<Void> closeTx = () -> {
+ // Do close-tx for current thread
+ graph.closeTx();
+ // Let other threads run
+ Thread.yield();
Review Comment:
这里为啥会有这段代码哈?
为什么要让其他线程run呢
--
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: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feat: preliminary support for distributed task scheduler [incubator-hugegraph]
Posted by "VGalaxies (via GitHub)" <gi...@apache.org>.
VGalaxies commented on code in PR #2319:
URL: https://github.com/apache/incubator-hugegraph/pull/2319#discussion_r1359865027
##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/DistributedTaskScheduler.java:
##########
@@ -0,0 +1,666 @@
+/*
+ * 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.hugegraph.task;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.locks.Lock;
+
+import org.apache.hugegraph.HugeException;
+import org.apache.hugegraph.HugeGraph;
+import org.apache.hugegraph.HugeGraphParams;
+import org.apache.hugegraph.backend.id.Id;
+import org.apache.hugegraph.backend.page.PageInfo;
+import org.apache.hugegraph.backend.query.QueryResults;
+import org.apache.hugegraph.concurrent.LockGroup;
+import org.apache.hugegraph.concurrent.LockManager;
+import org.apache.hugegraph.config.CoreOptions;
+import org.apache.hugegraph.exception.ConnectionException;
+import org.apache.hugegraph.exception.NotFoundException;
+import org.apache.hugegraph.meta.MetaManager;
+import org.apache.hugegraph.meta.lock.LockResult;
+import org.apache.hugegraph.structure.HugeVertex;
+import org.apache.hugegraph.util.E;
+import org.apache.hugegraph.util.LockUtil;
+import org.apache.hugegraph.util.Log;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.slf4j.Logger;
+
+public class DistributedTaskScheduler extends TaskAndResultScheduler {
+ protected static final int SCHEDULE_PERIOD = 10;
+ private static final Logger LOG = Log.logger(DistributedTaskScheduler.class);
+ private final ExecutorService taskDbExecutor;
+ private final ExecutorService schemaTaskExecutor;
+ private final ExecutorService olapTaskExecutor;
+ private final ExecutorService ephemeralTaskExecutor;
+ private final ExecutorService gremlinTaskExecutor;
+ private final ScheduledThreadPoolExecutor schedulerExecutor;
+ private final ScheduledFuture<?> cronFuture;
+
+ private final String lockGroupName;
+
+ /**
+ * the status of scheduler
+ */
+ private final AtomicBoolean closed = new AtomicBoolean(true);
+
+ private final ConcurrentHashMap<Id, HugeTask<?>> runningTasks = new ConcurrentHashMap<>();
+
+ public DistributedTaskScheduler(HugeGraphParams graph,
+ ScheduledThreadPoolExecutor schedulerExecutor,
+ ExecutorService taskDbExecutor,
+ ExecutorService schemaTaskExecutor,
+ ExecutorService olapTaskExecutor,
+ ExecutorService gremlinTaskExecutor,
+ ExecutorService ephemeralTaskExecutor,
+ ExecutorService serverInfoDbExecutor) {
+ super(graph, serverInfoDbExecutor);
+
+ this.taskDbExecutor = taskDbExecutor;
+ this.schemaTaskExecutor = schemaTaskExecutor;
+ this.olapTaskExecutor = olapTaskExecutor;
+ this.gremlinTaskExecutor = gremlinTaskExecutor;
+ this.ephemeralTaskExecutor = ephemeralTaskExecutor;
+
+ this.schedulerExecutor = schedulerExecutor;
+
+ lockGroupName = String.format("%s_%s_distributed", graphSpace, graph);
+ LockManager.instance().create(lockGroupName);
+
+ this.closed.set(false);
+
+ this.cronFuture = this.schedulerExecutor.scheduleWithFixedDelay(
+ () -> {
+ // TODO: uncomment later - graph space
+ // LockUtil.lock(this.graph().spaceGraphName(), LockUtil.GRAPH_LOCK);
+ LockUtil.lock("", LockUtil.GRAPH_LOCK);
+ try {
+ // TODO: 使用超级管理员权限,查询任务
+ // TaskManager.useAdmin();
+ this.cronSchedule();
+ } catch (Throwable t) {
+ LOG.info("cronScheduler exception ", t);
+ } finally {
+ // TODO: uncomment later - graph space
+ LockUtil.unlock("", LockUtil.GRAPH_LOCK);
+ // LockUtil.unlock(this.graph().spaceGraphName(), LockUtil.GRAPH_LOCK);
+ }
+ },
+ 10L, SCHEDULE_PERIOD,
+ TimeUnit.SECONDS);
+ }
+
+ private static boolean sleep(long ms) {
+ try {
+ Thread.sleep(ms);
+ return true;
+ } catch (InterruptedException ignored) {
+ // Ignore InterruptedException
+ return false;
+ }
+ }
+
+ public void cronSchedule() {
Review Comment:
> 另外,看文档时说有根据负载来执行任务的,但是这里貌似没看到,是在其他地方还是暂时没实现哈=。=?原来的调度策略是 master 根据各个节点的负载来指定任务的
check 了下内部版代码,应该是暂时未实现 😵💫
##########
hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/DistributedTaskScheduler.java:
##########
@@ -0,0 +1,666 @@
+/*
+ * 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.hugegraph.task;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.locks.Lock;
+
+import org.apache.hugegraph.HugeException;
+import org.apache.hugegraph.HugeGraph;
+import org.apache.hugegraph.HugeGraphParams;
+import org.apache.hugegraph.backend.id.Id;
+import org.apache.hugegraph.backend.page.PageInfo;
+import org.apache.hugegraph.backend.query.QueryResults;
+import org.apache.hugegraph.concurrent.LockGroup;
+import org.apache.hugegraph.concurrent.LockManager;
+import org.apache.hugegraph.config.CoreOptions;
+import org.apache.hugegraph.exception.ConnectionException;
+import org.apache.hugegraph.exception.NotFoundException;
+import org.apache.hugegraph.meta.MetaManager;
+import org.apache.hugegraph.meta.lock.LockResult;
+import org.apache.hugegraph.structure.HugeVertex;
+import org.apache.hugegraph.util.E;
+import org.apache.hugegraph.util.LockUtil;
+import org.apache.hugegraph.util.Log;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.slf4j.Logger;
+
+public class DistributedTaskScheduler extends TaskAndResultScheduler {
+ protected static final int SCHEDULE_PERIOD = 10;
+ private static final Logger LOG = Log.logger(DistributedTaskScheduler.class);
+ private final ExecutorService taskDbExecutor;
+ private final ExecutorService schemaTaskExecutor;
+ private final ExecutorService olapTaskExecutor;
+ private final ExecutorService ephemeralTaskExecutor;
+ private final ExecutorService gremlinTaskExecutor;
+ private final ScheduledThreadPoolExecutor schedulerExecutor;
+ private final ScheduledFuture<?> cronFuture;
+
+ private final String lockGroupName;
+
+ /**
+ * the status of scheduler
+ */
+ private final AtomicBoolean closed = new AtomicBoolean(true);
+
+ private final ConcurrentHashMap<Id, HugeTask<?>> runningTasks = new ConcurrentHashMap<>();
+
+ public DistributedTaskScheduler(HugeGraphParams graph,
+ ScheduledThreadPoolExecutor schedulerExecutor,
+ ExecutorService taskDbExecutor,
+ ExecutorService schemaTaskExecutor,
+ ExecutorService olapTaskExecutor,
+ ExecutorService gremlinTaskExecutor,
+ ExecutorService ephemeralTaskExecutor,
+ ExecutorService serverInfoDbExecutor) {
+ super(graph, serverInfoDbExecutor);
+
+ this.taskDbExecutor = taskDbExecutor;
+ this.schemaTaskExecutor = schemaTaskExecutor;
+ this.olapTaskExecutor = olapTaskExecutor;
+ this.gremlinTaskExecutor = gremlinTaskExecutor;
+ this.ephemeralTaskExecutor = ephemeralTaskExecutor;
+
+ this.schedulerExecutor = schedulerExecutor;
+
+ lockGroupName = String.format("%s_%s_distributed", graphSpace, graph);
+ LockManager.instance().create(lockGroupName);
+
+ this.closed.set(false);
+
+ this.cronFuture = this.schedulerExecutor.scheduleWithFixedDelay(
+ () -> {
+ // TODO: uncomment later - graph space
+ // LockUtil.lock(this.graph().spaceGraphName(), LockUtil.GRAPH_LOCK);
+ LockUtil.lock("", LockUtil.GRAPH_LOCK);
+ try {
+ // TODO: 使用超级管理员权限,查询任务
+ // TaskManager.useAdmin();
+ this.cronSchedule();
+ } catch (Throwable t) {
+ LOG.info("cronScheduler exception ", t);
+ } finally {
+ // TODO: uncomment later - graph space
+ LockUtil.unlock("", LockUtil.GRAPH_LOCK);
+ // LockUtil.unlock(this.graph().spaceGraphName(), LockUtil.GRAPH_LOCK);
+ }
+ },
+ 10L, SCHEDULE_PERIOD,
+ TimeUnit.SECONDS);
+ }
+
+ private static boolean sleep(long ms) {
+ try {
+ Thread.sleep(ms);
+ return true;
+ } catch (InterruptedException ignored) {
+ // Ignore InterruptedException
+ return false;
+ }
+ }
+
+ public void cronSchedule() {
Review Comment:
> 另外,看文档时说有根据负载来执行任务的,但是这里貌似没看到,是在其他地方还是暂时没实现哈=。=?原来的调度策略是 master 根据各个节点的负载来指定任务的
check 了下内部版代码,应该是暂时未实现 😵💫
--
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: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org
Re: [PR] feat: preliminary support for distributed task scheduler [incubator-hugegraph]
Posted by "zyxxoo (via GitHub)" <gi...@apache.org>.
zyxxoo merged PR #2319:
URL: https://github.com/apache/incubator-hugegraph/pull/2319
--
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: issues-unsubscribe@hugegraph.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org