Skip to content

Commit

Permalink
format&clean 62 files in core
Browse files Browse the repository at this point in the history
  • Loading branch information
msgui committed Feb 19, 2024
1 parent cd7cc1e commit 3061943
Show file tree
Hide file tree
Showing 62 changed files with 274 additions and 272 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public synchronized void initServerInfo(GlobalMasterInfo nodeInfo) {
while (servers.hasNext()) {
existed = servers.next();
E.checkArgument(!existed.role().master() || !existed.alive(),
"Already existed master '%s' in current cluster",
"Already existed master '%s' in current cluster",
existed.id());
}
if (page != null) {
Expand Down Expand Up @@ -324,7 +324,7 @@ private int save(Collection<HugeServerInfo> serverInfos) {

private <V> V call(Callable<V> callable) {
assert !Thread.currentThread().getName().startsWith(
"server-info-db-worker") : "can't call by itself";
"server-info-db-worker") : "can't call by itself";
try {
// Pass context for db thread
callable = new TaskManager.ContextCallable<>(callable);
Expand Down Expand Up @@ -391,7 +391,7 @@ protected void updateServerInfos(Collection<HugeServerInfo> serverInfos) {
protected Collection<HugeServerInfo> allServerInfos() {
Iterator<HugeServerInfo> infos = this.serverInfos(NO_LIMIT, null);
try (ListIterator<HugeServerInfo> iter = new ListIterator<>(
MAX_SERVERS, infos)) {
MAX_SERVERS, infos)) {
return iter.list();
} catch (Exception e) {
throw new HugeException("Failed to close server info iterator", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public <V> void restoreTasks() {
do {
Iterator<HugeTask<V>> iter;
for (iter = this.findTask(status, PAGE_SIZE, page);
iter.hasNext();) {
iter.hasNext(); ) {
HugeTask<V> task = iter.next();
if (selfServer.equals(task.server())) {
taskList.add(task);
Expand All @@ -160,7 +160,7 @@ public <V> void restoreTasks() {
}
} while (page != null);
}
for (HugeTask<V> task : taskList){
for (HugeTask<V> task : taskList) {
LOG.info("restore task {}", task);
this.restore(task);
}
Expand Down Expand Up @@ -328,7 +328,7 @@ protected synchronized void scheduleTasksOnMaster() {
}

HugeServerInfo server = this.serverManager().pickWorkerNode(
serverInfos, task);
serverInfos, task);
if (server == null) {
LOG.info("The master can't find suitable servers to " +
"execute task '{}', wait for next schedule",
Expand Down Expand Up @@ -443,7 +443,7 @@ protected void remove(HugeTask<?> task) {
HugeTask<?> delTask = this.tasks.remove(task.id());
if (delTask != null && delTask != task) {
LOG.warn("Task '{}' may be inconsistent status {}(expect {})",
task.id(), task.status(), delTask.status());
task.id(), task.status(), delTask.status());

Check warning on line 446 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/StandardTaskScheduler.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/StandardTaskScheduler.java#L446

Added line #L446 was not covered by tests
}
assert delTask == null || delTask.completed() ||
delTask.cancelling() || delTask.isCancelled() : delTask;
Expand Down Expand Up @@ -528,7 +528,7 @@ public <V> Iterator<HugeTask<V>> tasks(TaskStatus status,
}

public <V> HugeTask<V> findTask(Id id) {
HugeTask<V> result = this.call(() -> {
HugeTask<V> result = this.call(() -> {
Iterator<Vertex> vertices = this.tx().queryVertices(id);
Vertex vertex = QueryResults.one(vertices);
if (vertex == null) {
Expand Down Expand Up @@ -595,13 +595,13 @@ public <V> HugeTask<V> delete(Id id) {

@Override
public <V> HugeTask<V> waitUntilTaskCompleted(Id id, long seconds)
throws TimeoutException {
throws TimeoutException {
return this.waitUntilTaskCompleted(id, seconds, QUERY_INTERVAL);
}

@Override
public <V> HugeTask<V> waitUntilTaskCompleted(Id id)
throws TimeoutException {
throws TimeoutException {
// This method is just used by tests
long timeout = this.graph.configuration()
.get(CoreOptions.TASK_WAIT_TIMEOUT);
Expand All @@ -610,10 +610,10 @@ public <V> HugeTask<V> waitUntilTaskCompleted(Id id)

private <V> HugeTask<V> waitUntilTaskCompleted(Id id, long seconds,
long intervalMs)
throws TimeoutException {
throws TimeoutException {
long passes = seconds * 1000 / intervalMs;
HugeTask<V> task = null;
for (long pass = 0;; pass++) {
for (long pass = 0; ; pass++) {
try {
task = this.task(id);
} catch (NotFoundException e) {
Expand All @@ -635,15 +635,15 @@ private <V> HugeTask<V> waitUntilTaskCompleted(Id id, long seconds,
sleep(intervalMs);
}
throw new TimeoutException(String.format(
"Task '%s' was not completed in %s seconds", id, seconds));
"Task '%s' was not completed in %s seconds", id, seconds));

Check warning on line 638 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/StandardTaskScheduler.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/StandardTaskScheduler.java#L638

Added line #L638 was not covered by tests
}

@Override
public void waitUntilAllTasksCompleted(long seconds)
throws TimeoutException {
throws TimeoutException {
long passes = seconds * 1000 / QUERY_INTERVAL;
int taskSize;
for (long pass = 0;; pass++) {
for (long pass = 0; ; pass++) {
taskSize = this.pendingTasks();
if (taskSize == 0) {
sleep(QUERY_INTERVAL);
Expand All @@ -655,8 +655,8 @@ public void waitUntilAllTasksCompleted(long seconds)
sleep(QUERY_INTERVAL);
}
throw new TimeoutException(String.format(
"There are still %s incomplete tasks after %s seconds",
taskSize, seconds));
"There are still %s incomplete tasks after %s seconds",
taskSize, seconds));

Check warning on line 659 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/StandardTaskScheduler.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/task/StandardTaskScheduler.java#L659

Added line #L659 was not covered by tests
}

@Override
Expand Down Expand Up @@ -711,7 +711,7 @@ private <V> V call(Runnable runnable) {

private <V> V call(Callable<V> callable) {
assert !Thread.currentThread().getName().startsWith(
"task-db-worker") : "can't call by itself";
"task-db-worker") : "can't call by itself";
try {
// Pass task context for db thread
callable = new ContextCallable<>(callable);
Expand Down Expand Up @@ -804,7 +804,7 @@ public void initSchema() {

private boolean existVertexLabel(String label) {
return this.params().schemaTransaction()
.getVertexLabel(label) != null;
.getVertexLabel(label) != null;
}

private String[] initProperties() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
import java.util.Set;
import java.util.concurrent.Callable;

import org.apache.tinkerpop.gremlin.structure.Transaction;
import org.slf4j.Logger;

import org.apache.hugegraph.HugeException;
import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.HugeGraphParams;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.Log;
import org.apache.tinkerpop.gremlin.structure.Transaction;
import org.slf4j.Logger;

import com.google.common.collect.ImmutableSet;

public abstract class TaskCallable<V> implements Callable<V> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public final class TaskManager {
public static final String TASK_WORKER = TASK_WORKER_PREFIX + "-%d";
public static final String TASK_DB_WORKER = "task-db-worker-%d";
public static final String SERVER_INFO_DB_WORKER =
"server-info-db-worker-%d";
"server-info-db-worker-%d";
public static final String TASK_SCHEDULER = "task-scheduler-%d";

protected static final long SCHEDULE_PERIOD = 1000L; // unit ms
Expand Down Expand Up @@ -73,12 +73,12 @@ private TaskManager(int pool) {
this.taskExecutor = ExecutorUtil.newFixedThreadPool(pool, TASK_WORKER);
// For save/query task state, just one thread is ok
this.taskDbExecutor = ExecutorUtil.newFixedThreadPool(
1, TASK_DB_WORKER);
1, TASK_DB_WORKER);
this.serverInfoDbExecutor = ExecutorUtil.newFixedThreadPool(
1, SERVER_INFO_DB_WORKER);
1, SERVER_INFO_DB_WORKER);
// For schedule task to run, just one thread is ok
this.schedulerExecutor = ExecutorUtil.newPausableScheduledThreadPool(
1, TASK_SCHEDULER);
1, TASK_SCHEDULER);
// Start after 10x period time waiting for HugeGraphServer startup
this.schedulerExecutor.scheduleWithFixedDelay(this::scheduleOrExecuteJob,
10 * SCHEDULE_PERIOD,
Expand All @@ -90,8 +90,8 @@ 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.taskExecutor, this.taskDbExecutor,
this.serverInfoDbExecutor);
this.schedulers.put(graph, scheduler);
}

Expand Down Expand Up @@ -171,7 +171,7 @@ public TaskScheduler getScheduler(HugeGraphParams graph) {

public ServerInfoManager getServerInfoManager(HugeGraphParams graph) {
StandardTaskScheduler scheduler = (StandardTaskScheduler)
this.getScheduler(graph);
this.getScheduler(graph);
if (scheduler == null) {
return null;
}
Expand Down Expand Up @@ -275,7 +275,7 @@ public void onAsRoleWorker() {

protected void notifyNewTask(HugeTask<?> task) {
Queue<Runnable> queue = ((ThreadPoolExecutor) this.schedulerExecutor)
.getQueue();
.getQueue();
if (queue.size() <= 1) {
/*
* Notify to schedule tasks initiatively when have new task
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import java.util.concurrent.Future;
import java.util.concurrent.TimeoutException;

import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.backend.id.Id;

public interface TaskScheduler {

Expand Down Expand Up @@ -53,13 +53,13 @@ <V> Iterator<HugeTask<V>> tasks(TaskStatus status,
boolean close();

<V> HugeTask<V> waitUntilTaskCompleted(Id id, long seconds)
throws TimeoutException;
throws TimeoutException;

<V> HugeTask<V> waitUntilTaskCompleted(Id id)
throws TimeoutException;
throws TimeoutException;

void waitUntilAllTasksCompleted(long seconds)
throws TimeoutException;
throws TimeoutException;

void checkRequirement(String op);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Set;

import org.apache.hugegraph.type.define.SerialEnum;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;

Expand All @@ -41,10 +42,10 @@ public enum TaskStatus implements SerialEnum {

// NOTE: order is important(RESTORING > RUNNING > QUEUED) when restoring
public static final List<TaskStatus> PENDING_STATUSES = ImmutableList.of(
TaskStatus.RESTORING, TaskStatus.RUNNING, TaskStatus.QUEUED);
TaskStatus.RESTORING, TaskStatus.RUNNING, TaskStatus.QUEUED);

public static final Set<TaskStatus> COMPLETED_STATUSES = ImmutableSet.of(
TaskStatus.SUCCESS, TaskStatus.CANCELLED, TaskStatus.FAILED);
TaskStatus.SUCCESS, TaskStatus.CANCELLED, TaskStatus.FAILED);

private byte status;
private String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@
import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.query.QueryResults;
import org.apache.hugegraph.traversal.algorithm.steps.EdgeStep;
import org.apache.tinkerpop.gremlin.structure.Edge;

import org.apache.hugegraph.iterator.FilterIterator;
import org.apache.hugegraph.iterator.FlatMapperIterator;
import org.apache.hugegraph.structure.HugeEdge;
import org.apache.hugegraph.traversal.algorithm.steps.EdgeStep;
import org.apache.hugegraph.util.E;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.util.CloseableIterator;

public class CountTraverser extends HugeTraverser {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,7 @@ public void append(Id current) {
}

public static class EdgeRecord {

private final Map<Long, Edge> edgeMap;
private final ObjectIntMapping<Id> idMapping;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,16 @@
import java.util.Map;
import java.util.Set;

import jakarta.ws.rs.core.MultivaluedMap;

import org.apache.hugegraph.HugeGraph;
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.structure.HugeEdge;
import org.apache.hugegraph.traversal.algorithm.steps.EdgeStep;
import org.apache.hugegraph.type.define.Directions;
import org.apache.tinkerpop.gremlin.structure.Edge;

import org.apache.hugegraph.structure.HugeEdge;
import org.apache.hugegraph.util.E;
import org.apache.hugegraph.util.OrderLimitMap;
import org.apache.tinkerpop.gremlin.structure.Edge;

import jakarta.ws.rs.core.MultivaluedMap;

public class NeighborRankTraverser extends HugeTraverser {

Expand Down Expand Up @@ -162,7 +161,7 @@ private boolean belongToPrevLayers(List<Ranks> ranks, Id target,
Ranks prevLayerRanks = ranks.get(i);
if (prevLayerRanks.containsKey(target)) {
Set<Id> nodes = prevLayerNodes.computeIfAbsent(
i, HugeTraverser::newSet);
i, HugeTraverser::newSet);

Check warning on line 164 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/NeighborRankTraverser.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/NeighborRankTraverser.java#L164

Added line #L164 was not covered by tests
nodes.add(target);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import com.google.common.base.Objects;

public abstract class OltpTraverser extends HugeTraverser
implements AutoCloseable {
implements AutoCloseable {

private static final String EXECUTOR_NAME = "oltp";
private static Consumers.ExecutorPool executors;
Expand Down Expand Up @@ -149,7 +149,7 @@ protected void traverseIdsByBfs(Iterator<Id> vertices,
long capacity,
Consumer<EdgeId> consumer) {
List<Id> labels = label == null ? Collections.emptyList() :
Collections.singletonList(label);
Collections.singletonList(label);
OneStepEdgeIterConsumer edgeIterConsumer = new OneStepEdgeIterConsumer(consumer, capacity);

EdgesIterator edgeIter = edgesOfVertices(vertices, dir, labels, degree);
Expand Down Expand Up @@ -248,7 +248,7 @@ protected boolean match(Element elem, String key, Object value) {
}

public static class ConcurrentMultiValuedMap<K, V>
extends ConcurrentHashMap<K, List<V>> {
extends ConcurrentHashMap<K, List<V>> {

private static final long serialVersionUID = -7249946839643493614L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@
import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.schema.EdgeLabel;
import org.apache.hugegraph.schema.VertexLabel;
import org.apache.hugegraph.type.define.Directions;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;

import org.apache.hugegraph.structure.HugeVertex;
import org.apache.hugegraph.type.define.Directions;
import org.apache.hugegraph.util.E;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;

public class PersonalRankTraverser extends HugeTraverser {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.hugegraph.traversal.algorithm.steps.EdgeStep;
import org.apache.hugegraph.type.define.Directions;
import org.apache.hugegraph.util.E;

import com.google.common.collect.ImmutableList;

public class PredictionTraverser extends OltpTraverser {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ public PathSet forward(boolean all) {
this.edgeResults.addEdge(source, target, edge);

PathSet paths = this.pathResults.findPath(target,
t -> !this.superNode(t, this.direction),
all, false);
t -> !this.superNode(t,
this.direction),
all, false);

if (paths.isEmpty()) {
continue;
Expand Down Expand Up @@ -244,8 +245,8 @@ public PathSet backward(boolean all) {
this.edgeResults.addEdge(source, target, edge);

PathSet paths = this.pathResults.findPath(target,
t -> !this.superNode(t, opposite),
all, false);
t -> !this.superNode(t, opposite),
all, false);

if (paths.isEmpty()) {
continue;
Expand Down
Loading

0 comments on commit 3061943

Please sign in to comment.