kylin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gaoda...@apache.org
Subject kylin git commit: KYLIN-2105 remove QueryIdGenerator and QueryIdGeneratorTest, simply use UUID as QueryId
Date Thu, 27 Oct 2016 04:16:58 GMT
Repository: kylin
Updated Branches:
  refs/heads/master 4b3047a76 -> 5c1c24a9f


KYLIN-2105 remove QueryIdGenerator and QueryIdGeneratorTest, simply use UUID as QueryId


Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/5c1c24a9
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/5c1c24a9
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/5c1c24a9

Branch: refs/heads/master
Commit: 5c1c24a9f7cc5635e0fde5eb89be595f6a07ea25
Parents: 4b3047a
Author: gaodayue <gaodayue@meituan.com>
Authored: Thu Oct 27 12:14:49 2016 +0800
Committer: gaodayue <gaodayue@meituan.com>
Committed: Thu Oct 27 12:16:36 2016 +0800

----------------------------------------------------------------------
 .../apache/kylin/rest/service/QueryService.java |   8 +-
 .../kylin/rest/util/QueryIdGenerator.java       |  47 --------
 .../kylin/rest/util/QueryIdGeneratorTest.java   | 108 -------------------
 .../coprocessor/endpoint/CubeVisitService.java  |   2 +-
 4 files changed, 4 insertions(+), 161 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kylin/blob/5c1c24a9/server-base/src/main/java/org/apache/kylin/rest/service/QueryService.java
----------------------------------------------------------------------
diff --git a/server-base/src/main/java/org/apache/kylin/rest/service/QueryService.java b/server-base/src/main/java/org/apache/kylin/rest/service/QueryService.java
index 94f2dd5..81af044 100644
--- a/server-base/src/main/java/org/apache/kylin/rest/service/QueryService.java
+++ b/server-base/src/main/java/org/apache/kylin/rest/service/QueryService.java
@@ -39,6 +39,7 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.UUID;
 
 import javax.annotation.PostConstruct;
 import javax.sql.DataSource;
@@ -72,7 +73,6 @@ import org.apache.kylin.rest.model.TableMeta;
 import org.apache.kylin.rest.request.PrepareSqlRequest;
 import org.apache.kylin.rest.request.SQLRequest;
 import org.apache.kylin.rest.response.SQLResponse;
-import org.apache.kylin.rest.util.QueryIdGenerator;
 import org.apache.kylin.rest.util.QueryUtil;
 import org.apache.kylin.rest.util.Serializer;
 import org.apache.kylin.rest.util.TableauInterceptor;
@@ -117,8 +117,6 @@ public class QueryService extends BasicService {
     private final String hbaseUrl;
     private final String userTableName;
 
-    private QueryIdGenerator queryIdGenerator = new QueryIdGenerator();
-
     @Autowired
     private CacheManager cacheManager;
 
@@ -325,7 +323,7 @@ public class QueryService extends BasicService {
             throw new InternalErrorException("Query is not allowed in " + serverMode + "
mode.");
         }
 
-        final String queryId = queryIdGenerator.nextId(sqlRequest.getProject());
+        final String queryId = UUID.randomUUID().toString();
 
         Map<String, String> toggles = new HashMap<>();
         toggles.put(BackdoorToggles.KEY_QUERY_ID, queryId);
@@ -334,7 +332,7 @@ public class QueryService extends BasicService {
         }
         BackdoorToggles.setToggles(toggles);
 
-        try (SetThreadName ignored = new SetThreadName("Query-%s", queryId)) {
+        try (SetThreadName ignored = new SetThreadName("Query %s", queryId)) {
             String sql = sqlRequest.getSql();
             String project = sqlRequest.getProject();
             logger.info("Using project: " + project);

http://git-wip-us.apache.org/repos/asf/kylin/blob/5c1c24a9/server-base/src/main/java/org/apache/kylin/rest/util/QueryIdGenerator.java
----------------------------------------------------------------------
diff --git a/server-base/src/main/java/org/apache/kylin/rest/util/QueryIdGenerator.java b/server-base/src/main/java/org/apache/kylin/rest/util/QueryIdGenerator.java
deleted file mode 100644
index 2dd19c2..0000000
--- a/server-base/src/main/java/org/apache/kylin/rest/util/QueryIdGenerator.java
+++ /dev/null
@@ -1,47 +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.kylin.rest.util;
-
-import org.apache.commons.lang3.time.FastDateFormat;
-
-import javax.annotation.Nonnull;
-import javax.annotation.concurrent.ThreadSafe;
-import java.util.concurrent.ThreadLocalRandom;
-
-@ThreadSafe
-public class QueryIdGenerator {
-    private static final char[] base26 = "abcdefghijklmnopqrstuvwxyz".toCharArray();
-    private static final FastDateFormat dateFormat = FastDateFormat.getInstance("yyyyMMdd_HHmmss");
-
-    /**
-     * @param project name of the project
-     * @return the next query id. We try to generate unique id as much as possible, but don't
guarantee it.
-     */
-    @Nonnull
-    public String nextId(final String project) {
-        char[] postfix = new char[6];
-        for (int i = 0; i < postfix.length; i++) {
-            postfix[i] = base26[ThreadLocalRandom.current().nextInt(base26.length)];
-        }
-
-        return new String(postfix);
-        //return String.format("%s_%s_%s", dateFormat.format(System.currentTimeMillis()),
project, new String(postfix));
-        //disabled testcase: org.apache.kylin.rest.util.QueryIdGeneratorTest.testIdFormat()
-    }
-}

http://git-wip-us.apache.org/repos/asf/kylin/blob/5c1c24a9/server-base/src/test/java/org/apache/kylin/rest/util/QueryIdGeneratorTest.java
----------------------------------------------------------------------
diff --git a/server-base/src/test/java/org/apache/kylin/rest/util/QueryIdGeneratorTest.java
b/server-base/src/test/java/org/apache/kylin/rest/util/QueryIdGeneratorTest.java
deleted file mode 100644
index dc82c17..0000000
--- a/server-base/src/test/java/org/apache/kylin/rest/util/QueryIdGeneratorTest.java
+++ /dev/null
@@ -1,108 +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.kylin.rest.util;
-
-import org.junit.Assert;
-import org.junit.Ignore;
-import org.junit.Test;
-
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-
-public class QueryIdGeneratorTest {
-
-    @Ignore
-    @Test
-    public void testIdFormat() {
-        QueryIdGenerator generator = new QueryIdGenerator();
-        for (int i = 0; i < 100; i++) {
-            String queryId = generator.nextId("project");
-            Assert.assertTrue(queryId.contains("project"));
-        }
-    }
-
-    @Test
-    public void testIdUniqueness() {
-        QueryIdGenerator generator = new QueryIdGenerator();
-        Set<String> idSet = new HashSet<>();
-
-        for (int i = 0; i < 1000; i++) {
-            idSet.add(generator.nextId("test"));
-        }
-
-        Assert.assertEquals(1000, idSet.size());
-    }
-
-    @Test
-    public void testSingleThreadThroughput() {
-        int N = 1_000_000;
-        long millis = new GenIdTask(new QueryIdGenerator(), N).call();
-
-        // ops / second
-        double throughput = (N * 1000.0) / millis;
-        System.out.format("QueryIdGenerator single thread throughput: %d ops/second\n", (int)
throughput);
-    }
-
-    @Test
-    public void testMultiThreadsThroughput() throws ExecutionException, InterruptedException
{
-        QueryIdGenerator generator = new QueryIdGenerator();
-        int N = 1_000_000;
-
-        final int numThreads = 4;
-        ExecutorService pool = Executors.newFixedThreadPool(numThreads);
-        Future[] futures = new Future[numThreads];
-
-        for (int i = 0; i < numThreads; i++) {
-            futures[i] = pool.submit(new GenIdTask(generator, N));
-        }
-
-        long sumMillis = 0;
-        for (int i = 0; i < numThreads; i++) {
-            sumMillis += (long) futures[i].get();
-        }
-        pool.shutdown();
-
-        double avgThroughputPerThread = (N * 1000.0) / (sumMillis / (double) numThreads);
-        System.out.format("QueryIdGenerator multi threads throughput: %d ops/second\n", (int)
avgThroughputPerThread);
-    }
-
-    private static class GenIdTask implements Callable<Long> {
-        private final QueryIdGenerator generator;
-        private final int N;
-
-        GenIdTask(QueryIdGenerator generator, int N) {
-            this.generator = generator;
-            this.N = N;
-        }
-
-        @Override
-        public Long call() {
-            long start = System.currentTimeMillis();
-            for (int i = 0; i < N; i++) {
-                generator.nextId("test");
-            }
-            return System.currentTimeMillis() - start;
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/kylin/blob/5c1c24a9/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/cube/v2/coprocessor/endpoint/CubeVisitService.java
----------------------------------------------------------------------
diff --git a/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/cube/v2/coprocessor/endpoint/CubeVisitService.java
b/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/cube/v2/coprocessor/endpoint/CubeVisitService.java
index 506778c..da9c932 100644
--- a/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/cube/v2/coprocessor/endpoint/CubeVisitService.java
+++ b/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/cube/v2/coprocessor/endpoint/CubeVisitService.java
@@ -176,7 +176,7 @@ public class CubeVisitService extends CubeVisitProtos.CubeVisitService
implement
         String debugGitTag = "";
 
         String queryId = request.hasQueryId() ? request.getQueryId() : "UnknownId";
-        try (SetThreadName ignored = new SetThreadName("Kylin Query-%s", queryId)) {
+        try (SetThreadName ignored = new SetThreadName("Query %s", queryId)) {
             this.serviceStartTime = System.currentTimeMillis();
 
             region = env.getRegion();


Mime
View raw message