You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2020/06/20 05:42:39 UTC

[shardingsphere] branch master updated: Scaling improve (#6144)

This is an automated email from the ASF dual-hosted git repository.

zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new db5f7d1  Scaling improve (#6144)
db5f7d1 is described below

commit db5f7d14d2caff4aa9863dc4b7ecafacb7c97355
Author: 孙念君 Sun Nianjun <ka...@outlook.com>
AuthorDate: Sat Jun 20 13:42:26 2020 +0800

    Scaling improve (#6144)
    
    * Refactor: try to remove the Util which is not necessary
    
    * Refactor: replace offer with put for the blocking queue, add error log
    
    * Drop: remove the util which is not necessary
---
 .../apache/shardingsphere/scaling/Bootstrap.java   |  8 ++---
 .../shardingsphere/scaling/utils/RuntimeUtil.java  | 39 ----------------------
 .../execute/executor/channel/MemoryChannel.java    |  5 +--
 .../incremental/IncrementalDataScalingTask.java    |  1 +
 .../task/inventory/InventoryDataScalingTask.java   |  1 +
 5 files changed, 7 insertions(+), 47 deletions(-)

diff --git a/shardingsphere-scaling/shardingsphere-scaling-bootstrap/src/main/java/org/apache/shardingsphere/scaling/Bootstrap.java b/shardingsphere-scaling/shardingsphere-scaling-bootstrap/src/main/java/org/apache/shardingsphere/scaling/Bootstrap.java
index ec301ee..291eeb8 100755
--- a/shardingsphere-scaling/shardingsphere-scaling-bootstrap/src/main/java/org/apache/shardingsphere/scaling/Bootstrap.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-bootstrap/src/main/java/org/apache/shardingsphere/scaling/Bootstrap.java
@@ -18,6 +18,7 @@
 package org.apache.shardingsphere.scaling;
 
 import com.google.common.base.Preconditions;
+import com.google.common.io.Resources;
 import io.netty.bootstrap.ServerBootstrap;
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelOption;
@@ -27,11 +28,10 @@ import io.netty.channel.socket.nio.NioServerSocketChannel;
 import io.netty.handler.logging.LogLevel;
 import io.netty.handler.logging.LoggingHandler;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
 import org.apache.shardingsphere.scaling.core.config.ScalingContext;
 import org.apache.shardingsphere.scaling.core.config.ServerConfiguration;
-import org.apache.shardingsphere.scaling.utils.RuntimeUtil;
 import org.apache.shardingsphere.scaling.web.HttpServerInitializer;
-import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
 
 import java.io.File;
 import java.io.IOException;
@@ -42,7 +42,7 @@ import java.io.IOException;
 @Slf4j
 public final class Bootstrap {
     
-    private static final String DEFAULT_CONFIG_PATH = "/conf/";
+    private static final String DEFAULT_CONFIG_PATH = "conf/";
     
     private static final String DEFAULT_CONFIG_FILE_NAME = "server.yaml";
     
@@ -77,7 +77,7 @@ public final class Bootstrap {
     }
     
     private static void initServerConfig() throws IOException {
-        File yamlFile = new File(RuntimeUtil.getResourcePath(DEFAULT_CONFIG_PATH + DEFAULT_CONFIG_FILE_NAME));
+        File yamlFile = new File(Resources.getResource(DEFAULT_CONFIG_PATH + DEFAULT_CONFIG_FILE_NAME).getPath());
         ServerConfiguration serverConfiguration = YamlEngine.unmarshal(yamlFile, ServerConfiguration.class);
         Preconditions.checkNotNull(serverConfiguration, "Server configuration file `%s` is invalid.", yamlFile.getName());
         ScalingContext.getInstance().init(serverConfiguration);
diff --git a/shardingsphere-scaling/shardingsphere-scaling-bootstrap/src/main/java/org/apache/shardingsphere/scaling/utils/RuntimeUtil.java b/shardingsphere-scaling/shardingsphere-scaling-bootstrap/src/main/java/org/apache/shardingsphere/scaling/utils/RuntimeUtil.java
deleted file mode 100644
index 090455a..0000000
--- a/shardingsphere-scaling/shardingsphere-scaling-bootstrap/src/main/java/org/apache/shardingsphere/scaling/utils/RuntimeUtil.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.scaling.utils;
-
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.scaling.Bootstrap;
-
-/**
- * Runtime util.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class RuntimeUtil {
-    
-    /**
-     * Get runtime classpath.
-     *
-     * @param relativePath relative resource path
-     * @return classpath
-     */
-    public static String getResourcePath(final String relativePath) {
-        return Bootstrap.class.getResource(relativePath).getFile();
-    }
-}
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/execute/executor/channel/MemoryChannel.java b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/execute/executor/channel/MemoryChannel.java
index 865e4d2..0a2fe02 100755
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/execute/executor/channel/MemoryChannel.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/execute/executor/channel/MemoryChannel.java
@@ -25,7 +25,6 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.concurrent.ArrayBlockingQueue;
 import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.TimeUnit;
 
 /**
  * Memory channel.
@@ -46,9 +45,7 @@ public final class MemoryChannel implements Channel {
     
     @Override
     public void pushRecord(final Record dataRecord) throws InterruptedException {
-        if (!queue.offer(dataRecord, PUSH_TIMEOUT, TimeUnit.MILLISECONDS)) {
-            throw new RuntimeException();
-        }
+        queue.put(dataRecord);
     }
     
     @Override
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/job/task/incremental/IncrementalDataScalingTask.java b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/job/task/incremental/IncrementalDataScalingTask.java
index 946107b..5edd960 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/job/task/incremental/IncrementalDataScalingTask.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/job/task/incremental/IncrementalDataScalingTask.java
@@ -81,6 +81,7 @@ public final class IncrementalDataScalingTask extends AbstractShardingScalingExe
         
             @Override
             public void onFailure(final Throwable throwable) {
+                log.error("get an error when migrating the increment data", throwable);
                 dumper.stop();
             }
         });
diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/job/task/inventory/InventoryDataScalingTask.java b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/job/task/inventory/InventoryDataScalingTask.java
index 22e6224..872f55b 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/job/task/inventory/InventoryDataScalingTask.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-core/src/main/java/org/apache/shardingsphere/scaling/core/job/task/inventory/InventoryDataScalingTask.java
@@ -92,6 +92,7 @@ public final class InventoryDataScalingTask implements ScalingTask {
     
             @Override
             public void onFailure(final Throwable throwable) {
+                log.error("get an error when migrating the inventory data", throwable);
                 dumper.stop();
             }
         });