Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

Commit 23de3bc

Browse files
authored
Apply modifications from test (#1709)
* fix hadoop version issue * make top hot files num configurable * fix class loader issue * avoid checkstorage error for directory
1 parent c4ddbf0 commit 23de3bc

File tree

6 files changed

+35
-2
lines changed

6 files changed

+35
-2
lines changed

conf/smart-default.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,14 @@
159159
</description>
160160
</property>
161161

162+
<property>
163+
<name>smart.top.hot.files.num</name>
164+
<value>200</value>
165+
<description>
166+
The number of top hot files displayed on web UI.
167+
</description>
168+
</property>
169+
162170
<property>
163171
<name>pd.client.port</name>
164172
<value>7060</value>

smart-common/src/main/java/org/smartdata/conf/SmartConfKeys.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ public class SmartConfKeys {
155155
"smart.storage.info.sampling.intervals";
156156
public static final String SMART_STORAGE_INFO_SAMPLING_INTERVALS_DEFAULT =
157157
"60s,60;1hour,60;1day";
158+
public static final String SMART_TOP_HOT_FILES_NUM_KEY = "smart.top.hot.files.num";
159+
public static final int SMART_TOP_HOT_FILES_NUM_DEFAULT = 200;
158160

159161
public static final String SMART_STATUS_REPORT_PERIOD_KEY = "smart.status.report.period";
160162
public static final int SMART_STATUS_REPORT_PERIOD_DEFAULT = 10;

smart-engine/src/main/java/org/smartdata/server/engine/StatesManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ public void reportFileAccessEvent(FileAccessEvent event) throws IOException {
162162
public List<FileAccessInfo> getHotFiles(List<AccessCountTable> tables,
163163
int topNum) throws IOException {
164164
try {
165+
if (topNum == 0) {
166+
topNum = serverContext.getConf().getInt(SmartConfKeys.SMART_TOP_HOT_FILES_NUM_KEY,
167+
SmartConfKeys.SMART_TOP_HOT_FILES_NUM_DEFAULT);
168+
return serverContext.getMetaStore().getHotFiles(tables, topNum);
169+
}
165170
return serverContext.getMetaStore().getHotFiles(tables, topNum);
166171
} catch (MetaStoreException e) {
167172
throw new IOException(e);

smart-hadoop-support/smart-hadoop/src/main/java/org/smartdata/hdfs/CompatibilityHelperLoader.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,23 @@
1818
package org.smartdata.hdfs;
1919

2020
import org.apache.hadoop.util.VersionInfo;
21+
import org.slf4j.Logger;
22+
import org.slf4j.LoggerFactory;
2123

2224
public class CompatibilityHelperLoader {
2325
private static CompatibilityHelper instance;
2426
private static final String HADOOP_26_HELPER_CLASS = "org.smartdata.hdfs.CompatibilityHelper26";
2527
private static final String HADOOP_27_HELPER_CLASS = "org.smartdata.hdfs.CompatibilityHelper27";
28+
public static final Logger LOG =
29+
LoggerFactory.getLogger(CompatibilityHelperLoader.class);
2630

2731
public static CompatibilityHelper getHelper() {
2832
if (instance == null) {
2933
String version = VersionInfo.getVersion();
34+
if (version == null || version.isEmpty() || version.equalsIgnoreCase("Unknown")) {
35+
LOG.error("Cannot get Hadoop version. Use default 2.6.3 version. ");
36+
version = "2.6.3";
37+
}
3038
String[] parts = version.split("\\.");
3139
if (parts.length < 2) {
3240
throw new RuntimeException("Illegal Hadoop Version: " + version + " (expected A.B.* format)");
@@ -47,7 +55,11 @@ public static CompatibilityHelper getHelper() {
4755

4856
private static CompatibilityHelper create(String classString) {
4957
try {
50-
Class clazz = Thread.currentThread().getContextClassLoader().loadClass(classString);
58+
ClassLoader loader = Thread.currentThread().getContextClassLoader();
59+
if (loader == null) {
60+
loader = ClassLoader.getSystemClassLoader();
61+
}
62+
Class clazz = loader.loadClass(classString);
5163
return (CompatibilityHelper) clazz.newInstance();
5264
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
5365
e.printStackTrace();

smart-hadoop-support/smart-hadoop/src/main/java/org/smartdata/hdfs/action/CheckStorageAction.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ protected void execute() throws Exception {
5353
if (fileStatus == null) {
5454
throw new ActionException("File does not exist.");
5555
}
56+
if (fileStatus.isDir()) {
57+
appendResult("This is a directory which has no storage result!");
58+
return;
59+
}
5660
long length = fileStatus.getLen();
5761
List<LocatedBlock> locatedBlocks =
5862
dfsClient.getLocatedBlocks(fileName, 0, length).getLocatedBlocks();

smart-zeppelin/zeppelin-server/src/main/java/org/smartdata/server/rest/ClusterRestApi.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,16 @@ public Response cachedFiles() {
7777
}
7878
}
7979

80+
//TODO(Philo): Make topNum settable on web UI.
81+
//Currently, topNum=0 means that SSM will use the value configured in smart-default.xml
8082
@GET
8183
@Path("/primary/hotfiles")
8284
public Response hotFiles() {
8385
try {
8486
List<AccessCountTable> tables =
8587
smartEngine.getStatesManager().getTablesInLast(Constants.ONE_HOUR_IN_MILLIS);
8688
return new JsonResponse<>(Response.Status.OK,
87-
smartEngine.getStatesManager().getHotFiles(tables, 20)).build();
89+
smartEngine.getStatesManager().getHotFiles(tables, 0)).build();
8890
} catch (Exception e) {
8991
logger.error("Exception in ClusterRestApi while listing hot files", e);
9092
return new JsonResponse<>(Response.Status.INTERNAL_SERVER_ERROR,

0 commit comments

Comments
 (0)