Skip to content

Commit

Permalink
KYLIN-3317, replace UUID.randomUUID with new UUID(ThreadLocalRandom.c…
Browse files Browse the repository at this point in the history
…urrent().nextLong(), ThreadLocalRandom.current().nextLong()).
  • Loading branch information
Aaaaaaron authored and shaofengshi committed Aug 14, 2018
1 parent 0b5d255 commit 6483798
Show file tree
Hide file tree
Showing 36 changed files with 155 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;

import org.apache.kylin.common.exceptions.KylinTimeoutException;
import org.apache.kylin.common.util.RandomUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -67,7 +67,7 @@ public interface QueryStopListener {
}

QueryContext(long startMills) {
queryId = UUID.randomUUID().toString();
queryId = RandomUtil.randomUUID().toString();
queryStartMillis = startMills;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.NavigableSet;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

Expand All @@ -42,6 +41,7 @@
import org.apache.kylin.common.StorageURL;
import org.apache.kylin.common.util.ClassUtil;
import org.apache.kylin.common.util.OptionsHelper;
import org.apache.kylin.common.util.RandomUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -147,7 +147,7 @@ final public NavigableSet<String> listResourcesRecursively(String folderPath) th
abstract protected NavigableSet<String> listResourcesImpl(String folderPath, boolean recursive) throws IOException;

protected String createMetaStoreUUID() throws IOException {
return UUID.randomUUID().toString();
return RandomUtil.randomUUID().toString();
}

public String getMetaStoreUUID() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
import java.io.Serializable;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.UUID;

import org.apache.commons.lang.time.FastDateFormat;
import org.apache.kylin.common.KylinVersion;
import org.apache.kylin.common.util.RandomUtil;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
Expand Down Expand Up @@ -99,7 +99,7 @@ public void setLastModified(long lastModified) {
}

public void updateRandomUuid() {
setUuid(UUID.randomUUID().toString());
setUuid(RandomUtil.randomUUID().toString());
}

public boolean isCachedAndShared() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.common.util;

import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;

public class RandomUtil {
public static UUID randomUUID() {
return new UUID(ThreadLocalRandom.current().nextLong(), ThreadLocalRandom.current().nextLong());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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.common.util;

import java.util.UUID;

import org.junit.Assert;
import org.junit.Test;

public class RandomUtilTest {
@Test
public void testRandomUUID() {
Assert.assertEquals(RandomUtil.randomUUID().toString().length(), UUID.randomUUID().toString().length());
Assert.assertNotEquals(RandomUtil.randomUUID().toString(), RandomUtil.randomUUID().toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils;
import org.apache.kylin.common.KylinConfig;
import org.apache.kylin.common.persistence.JsonSerializer;
Expand All @@ -43,6 +41,7 @@
import org.apache.kylin.common.util.AutoReadWriteLock.AutoLock;
import org.apache.kylin.common.util.Dictionary;
import org.apache.kylin.common.util.Pair;
import org.apache.kylin.common.util.RandomUtil;
import org.apache.kylin.cube.cuboid.Cuboid;
import org.apache.kylin.cube.model.CubeDesc;
import org.apache.kylin.cube.model.SnapshotTableDesc;
Expand Down Expand Up @@ -82,6 +81,7 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;

/**
Expand Down Expand Up @@ -836,7 +836,7 @@ private CubeSegment newSegment(CubeInstance cube, TSRange tsRange, SegmentRange
DataModelDesc modelDesc = cube.getModel();

CubeSegment segment = new CubeSegment();
segment.setUuid(UUID.randomUUID().toString());
segment.setUuid(RandomUtil.randomUUID().toString());
segment.setName(CubeSegment.makeSegmentName(tsRange, segRange, modelDesc));
segment.setCreateTimeUTC(System.currentTimeMillis());
segment.setCubeInstance(cube);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.kylin.common.persistence.JsonSerializer;
import org.apache.kylin.common.util.RandomUtil;
import org.apache.kylin.cube.cuboid.TreeCuboidScheduler;
import org.apache.kylin.metadata.model.SegmentStatusEnum;
import org.junit.Assert;
Expand Down Expand Up @@ -66,8 +66,8 @@ public void copyCubeSegmentTest() {
CubeInstance newCubeInstance = CubeInstance.getCopyOf(cubeInstance);

CubeSegment mockSeg = new CubeSegment();
mockSeg.setUuid(UUID.randomUUID().toString());
mockSeg.setStorageLocationIdentifier(UUID.randomUUID().toString());
mockSeg.setUuid(RandomUtil.randomUUID().toString());
mockSeg.setStorageLocationIdentifier(RandomUtil.randomUUID().toString());
mockSeg.setStatus(SegmentStatusEnum.READY);
newCubeInstance.getSegments().add(mockSeg);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
package org.apache.kylin.dict.global;

import java.io.IOException;
import java.util.UUID;

import org.apache.kylin.common.KylinConfig;
import org.apache.kylin.common.util.Dictionary;
import org.apache.kylin.common.util.RandomUtil;
import org.apache.kylin.dict.DictionaryInfo;
import org.apache.kylin.dict.IDictionaryBuilder;

Expand Down Expand Up @@ -50,7 +50,7 @@ public void init(DictionaryInfo dictInfo, int baseId, String hdfsDir) throws IOE

//use UUID to make each segment dict in different HDFS dir and support concurrent build
//use timestamp to make the segment dict easily to delete
String baseDir = hdfsDir + "resources/SegmentDict" + dictInfo.getResourceDir() + "/" + UUID.randomUUID().toString() + "_" + System.currentTimeMillis()+ "/";
String baseDir = hdfsDir + "resources/SegmentDict" + dictInfo.getResourceDir() + "/" + RandomUtil.randomUUID().toString() + "_" + System.currentTimeMillis()+ "/";

this.builder = new AppendTrieDictionaryBuilder(baseDir, maxEntriesPerSlice, false);
this.baseId = baseId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@
import java.util.Map;
import java.util.Random;
import java.util.TreeMap;
import java.util.UUID;

import com.google.common.collect.Lists;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.kylin.common.KylinConfig;
import org.apache.kylin.common.util.HadoopUtil;
import org.apache.kylin.common.util.LocalFileMetadataTestCase;
import org.apache.kylin.common.util.RandomUtil;
import org.apache.kylin.dict.global.AppendDictSliceKey;
import org.apache.kylin.dict.global.AppendTrieDictionaryBuilder;
import org.apache.kylin.dict.global.GlobalDictHDFSStore;
Expand All @@ -60,8 +59,10 @@
import org.junit.Ignore;
import org.junit.Test;

import com.google.common.collect.Lists;

public class AppendTrieDictionaryTest extends LocalFileMetadataTestCase {
private static final String RESOURCE_DIR = "/dict/append_dict_test/" + UUID.randomUUID();
private static final String RESOURCE_DIR = "/dict/append_dict_test/" + RandomUtil.randomUUID();
private static String BASE_DIR;
private static String LOCAL_BASE_DIR;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@

package org.apache.kylin.dict;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

import org.apache.kylin.common.util.Dictionary;
import org.apache.kylin.common.util.RandomUtil;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
import java.util.UUID;

/**
* Created by xiefan on 16-12-28.
*/
Expand Down Expand Up @@ -166,7 +166,7 @@ private long runQueryIdByValueBytes(ArrayList<String> rawData, Dictionary<String
private ArrayList<String> genStringDataSet(int totalSize) {
ArrayList<String> data = new ArrayList<>();
for (int i = 0; i < totalSize; i++) {
data.add(UUID.randomUUID().toString());
data.add(RandomUtil.randomUUID().toString());
}
Collections.sort(data);
return data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
import java.io.IOException;
import java.util.Iterator;
import java.util.Random;
import java.util.UUID;

import org.apache.commons.io.FileUtils;
import org.apache.kylin.common.KylinConfig;
import org.apache.kylin.common.util.Array;
import org.apache.kylin.common.util.LocalFileMetadataTestCase;
import org.apache.kylin.common.util.RandomUtil;
import org.apache.kylin.dict.lookup.ExtTableSnapshotInfo;
import org.apache.kylin.dict.lookup.ExtTableSnapshotInfoManager;
import org.apache.kylin.dict.lookup.IExtLookupProvider;
Expand Down Expand Up @@ -81,7 +81,7 @@ public void tearDown() {

@Test
public void testBuildTableCache() throws Exception {
String snapshotID = UUID.randomUUID().toString();
String snapshotID = RandomUtil.randomUUID().toString();
ExtTableSnapshotInfo snapshotInfo = buildSnapshotCache(snapshotID, 100000);
assertEquals(CacheState.AVAILABLE, RocksDBLookupTableCache.getInstance(kylinConfig).getCacheState(snapshotInfo));
}
Expand All @@ -107,7 +107,7 @@ private ExtTableSnapshotInfo buildSnapshotCache(String snapshotID, int rowCnt) t

@Test
public void testRestoreCacheFromFiles() throws Exception {
String snapshotID = UUID.randomUUID().toString();
String snapshotID = RandomUtil.randomUUID().toString();
String snapshotCacheBasePath = RocksDBLookupTableCache.getCacheBasePath(kylinConfig) + File.separator
+ TABLE_COUNTRY + File.separator + snapshotID;
String dbPath = snapshotCacheBasePath + File.separator + "db";
Expand Down Expand Up @@ -137,14 +137,14 @@ public void testEvict() throws Exception {
int snapshotNum = 10;
int snapshotRowCnt = 100000;
for (int i = 0; i < snapshotNum; i++) {
buildSnapshotCache(UUID.randomUUID().toString(), snapshotRowCnt);
buildSnapshotCache(RandomUtil.randomUUID().toString(), snapshotRowCnt);
}
assertTrue(RocksDBLookupTableCache.getInstance(kylinConfig).getTotalCacheSize() < 0.006 * 1024 * 1024 * 1024);
}

@Test
public void testCheckCacheState() throws Exception {
ExtTableSnapshotInfo snapshotInfo = buildSnapshotCache(UUID.randomUUID().toString(), 1000);
ExtTableSnapshotInfo snapshotInfo = buildSnapshotCache(RandomUtil.randomUUID().toString(), 1000);
RocksDBLookupTableCache cache = RocksDBLookupTableCache.getInstance(kylinConfig);
ILookupTable cachedLookupTable = cache.getCachedLookupTable(tableDesc, snapshotInfo, false);
assertNotNull(cachedLookupTable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.regex.Matcher;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.kylin.common.KylinConfig;
import org.apache.kylin.common.util.MailService;
import org.apache.kylin.common.util.Pair;
import org.apache.kylin.common.util.RandomUtil;
import org.apache.kylin.common.util.StringUtil;
import org.apache.kylin.job.exception.ExecuteException;
import org.apache.kylin.job.exception.PersistentException;
Expand Down Expand Up @@ -65,7 +65,7 @@ public abstract class AbstractExecutable implements Executable, Idempotent {
private Map<String, String> params = Maps.newHashMap();

public AbstractExecutable() {
setId(UUID.randomUUID().toString());
setId(RandomUtil.randomUUID().toString());
}

protected void initConfig(KylinConfig config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import org.apache.kylin.common.KylinConfig;
import org.apache.kylin.common.persistence.JsonSerializer;
Expand All @@ -36,6 +35,7 @@
import org.apache.kylin.common.util.AutoReadWriteLock.AutoLock;
import org.apache.kylin.common.util.JsonUtil;
import org.apache.kylin.common.util.Pair;
import org.apache.kylin.common.util.RandomUtil;
import org.apache.kylin.metadata.cachesync.Broadcaster;
import org.apache.kylin.metadata.cachesync.Broadcaster.Event;
import org.apache.kylin.metadata.cachesync.CachedCrudAssist;
Expand Down Expand Up @@ -353,7 +353,7 @@ public TableExtDesc getTableExt(TableDesc t) {
if (null == result) {
result = new TableExtDesc();
result.setIdentity(t.getIdentity());
result.setUuid(UUID.randomUUID().toString());
result.setUuid(RandomUtil.randomUUID().toString());
result.setLastModified(0);
result.init(t.getProject());
srcExtMap.putLocal(mapKey(t.getIdentity(), t.getProject()), result);
Expand Down Expand Up @@ -426,7 +426,7 @@ private TableExtDesc convertOldTableExtToNewer(String resourceName) {
String tableIdentity = TableDesc.parseResourcePath(resourceName).getFirst();
TableExtDesc result = new TableExtDesc();
result.setIdentity(tableIdentity);
result.setUuid(UUID.randomUUID().toString());
result.setUuid(RandomUtil.randomUUID().toString());
result.setLastModified(0);
result.setCardinality(cardinality);
return result;
Expand Down
Loading

0 comments on commit 6483798

Please sign in to comment.