提交 3a7e331a 编写于 作者: wu-sheng's avatar wu-sheng

Fix some resources leak. Format log. Set jdk level of common lib to 1.6 . Fix...

Fix some resources leak. Format log. Set jdk level of common lib to 1.6 . Fix some incorrect pom.xml .
上级 82edc01c
...@@ -8,13 +8,13 @@ ...@@ -8,13 +8,13 @@
<version>2.0-2016</version> <version>2.0-2016</version>
<modules> <modules>
<module>skywalking-commons</module>
<module>skywalking-alarm</module> <module>skywalking-alarm</module>
<module>skywalking-webui</module> <module>skywalking-webui</module>
<module>skywalking-sniffer</module> <module>skywalking-sniffer</module>
<module>skywalking-storage-center</module> <module>skywalking-storage-center</module>
<module>samples/skywalking-auth</module> <module>samples/skywalking-auth</module>
<module>samples/skywalking-example</module> <module>samples/skywalking-example</module>
<module>skywalking-commons</module>
</modules> </modules>
<packaging>pom</packaging> <packaging>pom</packaging>
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.version>2.0-2016</project.version>
</properties> </properties>
<dependencies> <dependencies>
......
...@@ -21,6 +21,18 @@ ...@@ -21,6 +21,18 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.version>2.0-2016</project.version>
</properties> </properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project> </project>
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<dependency> <dependency>
<groupId>com.a.eye</groupId> <groupId>com.a.eye</groupId>
<artifactId>skywalking-logging-api</artifactId> <artifactId>skywalking-logging-api</artifactId>
<version>2.0-2016</version> <version>${project.version}</version>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>
package com.a.eye.skywalking.health.report; package com.a.eye.skywalking.health.report;
import com.a.eye.skywalking.health.report.util.MachineUtil;
import com.a.eye.skywalking.logging.api.ILog; import com.a.eye.skywalking.logging.api.ILog;
import com.a.eye.skywalking.logging.api.LogManager; import com.a.eye.skywalking.logging.api.LogManager;
...@@ -10,15 +9,15 @@ import java.util.Map; ...@@ -10,15 +9,15 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
public class HealthCollector extends Thread { public class HealthCollector extends Thread {
private static ILog logger = private static ILog logger = LogManager.getLogger(HealthCollector.class);
LogManager.getLogger(HealthCollector.class); private static Map<String, HeathReading> heathReadings = new ConcurrentHashMap<String, HeathReading>();
private static Map<String, HeathReading> heathReadings =
new ConcurrentHashMap<String, HeathReading>();
private static final long DEFAULT_REPORT_INTERVAL = 60 * 1000; private static final long DEFAULT_REPORT_INTERVAL = 60 * 1000;
private final long reportInterval; private final long reportInterval;
private String reporterName;
private HealthCollector() { private HealthCollector(String reporterName) {
this(DEFAULT_REPORT_INTERVAL); this(DEFAULT_REPORT_INTERVAL);
this.reporterName = reporterName;
} }
private HealthCollector(long reportInterval) { private HealthCollector(long reportInterval) {
...@@ -27,8 +26,8 @@ public class HealthCollector extends Thread { ...@@ -27,8 +26,8 @@ public class HealthCollector extends Thread {
this.reportInterval = reportInterval; this.reportInterval = reportInterval;
} }
public static void init() { public static void init(String reporterName) {
new HealthCollector().start(); new HealthCollector(reporterName).start();
} }
public static HeathReading getCurrentHeathReading(String extraId) { public static HeathReading getCurrentHeathReading(String extraId) {
...@@ -37,8 +36,7 @@ public class HealthCollector extends Thread { ...@@ -37,8 +36,7 @@ public class HealthCollector extends Thread {
synchronized (heathReadings) { synchronized (heathReadings) {
if (!heathReadings.containsKey(id)) { if (!heathReadings.containsKey(id)) {
if (heathReadings.keySet().size() > 5000) { if (heathReadings.keySet().size() > 5000) {
throw new RuntimeException( throw new RuntimeException("use HealthCollector illegal. There is an overflow trend of Server Health Collector Report Data.");
"use HealthCollector illegal. There is an overflow trend of Server Health Collector Report Data.");
} }
heathReadings.put(id, new HeathReading(id)); heathReadings.put(id, new HeathReading(id));
} }
...@@ -48,8 +46,7 @@ public class HealthCollector extends Thread { ...@@ -48,8 +46,7 @@ public class HealthCollector extends Thread {
} }
private static String getId(String extraId) { private static String getId(String extraId) {
return "SkyWalking Health Report,P:" + MachineUtil.getProcessNo() + ",T:" + Thread.currentThread().getName() return "T:" + Thread.currentThread().getName() + "(" + Thread.currentThread().getId() + ")" + (extraId == null ? "" : ",extra:" + extraId);
+ "(" + Thread.currentThread().getId() + ")" + (extraId == null ? "" : ",extra:" + extraId);
} }
@Override @Override
...@@ -61,7 +58,7 @@ public class HealthCollector extends Thread { ...@@ -61,7 +58,7 @@ public class HealthCollector extends Thread {
String[] keyList = heathReadingsSnapshot.keySet().toArray(new String[0]); String[] keyList = heathReadingsSnapshot.keySet().toArray(new String[0]);
Arrays.sort(keyList); Arrays.sort(keyList);
StringBuilder log = new StringBuilder(); StringBuilder log = new StringBuilder();
log.append("\n---------Server Health Collector Report---------\n"); log.append("\n---------" + reporterName + " Health Report---------\n");
for (String key : keyList) { for (String key : keyList) {
log.append(heathReadingsSnapshot.get(key)).append("\n"); log.append(heathReadingsSnapshot.get(key)).append("\n");
} }
......
package com.a.eye.skywalking.health.report.util;
import java.lang.management.ManagementFactory;
/**
* Created by xin on 2016/11/14.
*/
public class MachineUtil {
private static String processNo;
static {
processNo = getProcessNo();
}
public static String getProcessNo() {
if (processNo == null) {
String name = ManagementFactory.getRuntimeMXBean().getName();
processNo = name.split("@")[0];
}
return processNo;
}
private MachineUtil() {
// Non
}
}
...@@ -18,20 +18,20 @@ ...@@ -18,20 +18,20 @@
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.8</version>
</dependency>
<dependency> <dependency>
<groupId>com.a.eye</groupId> <groupId>com.a.eye</groupId>
<artifactId>skywalking-logging-api</artifactId> <artifactId>skywalking-logging-api</artifactId>
<version>2.0-2016</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.a.eye</groupId> <groupId>com.a.eye</groupId>
<artifactId>skywalking-logging-impl-log4j2</artifactId> <artifactId>skywalking-logging-impl-log4j2</artifactId>
<version>2.0-2016</version> <version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.8</version>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>
...@@ -24,11 +24,15 @@ ...@@ -24,11 +24,15 @@
<artifactId>skywalking-logging</artifactId> <artifactId>skywalking-logging</artifactId>
<version>${parent.version}</version> <version>${parent.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.a.eye</groupId> <groupId>com.a.eye</groupId>
<artifactId>skywalking-network</artifactId> <artifactId>skywalking-network</artifactId>
<version>${parent.version}</version> <version>${parent.version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.a.eye</groupId>
<artifactId>data-carrier</artifactId>
<version>1.1</version>
</dependency>
</dependencies> </dependencies>
</project> </project>
...@@ -17,17 +17,17 @@ ...@@ -17,17 +17,17 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.a.eye</groupId> <groupId>com.a.eye</groupId>
<artifactId>skywalking-network</artifactId> <artifactId>skywalking-registry</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.a.eye</groupId> <groupId>com.a.eye</groupId>
<artifactId>skywalking-registry</artifactId> <artifactId>skywalking-logging-impl-log4j2</artifactId>
<version>2.0-2016</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.a.eye</groupId> <groupId>com.a.eye</groupId>
<artifactId>skywalking-logging-impl-log4j2</artifactId> <artifactId>skywalking-health-report</artifactId>
<version>${project.version}</version> <version>${project.version}</version>
</dependency> </dependency>
<dependency> <dependency>
...@@ -35,27 +35,12 @@ ...@@ -35,27 +35,12 @@
<artifactId>hsqldb</artifactId> <artifactId>hsqldb</artifactId>
<version>2.3.4</version> <version>2.3.4</version>
</dependency> </dependency>
<dependency>
<groupId>com.a.eye</groupId>
<artifactId>data-carrier</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.a.eye</groupId>
<artifactId>skywalking-registry</artifactId>
<version>${project.version}</version>
</dependency>
<dependency> <dependency>
<groupId>com.zaxxer</groupId> <groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId> <artifactId>HikariCP</artifactId>
<version>2.4.3</version> <version>2.4.3</version>
</dependency> </dependency>
<dependency>
<groupId>com.a.eye</groupId>
<artifactId>skywalking-health-report</artifactId>
<version>2.0-2016</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
......
...@@ -29,7 +29,8 @@ import static com.a.eye.skywalking.storage.config.Config.RegistryCenter.PATH_PRE ...@@ -29,7 +29,8 @@ import static com.a.eye.skywalking.storage.config.Config.RegistryCenter.PATH_PRE
*/ */
public class Main { public class Main {
private static ILog logger = LogManager.getLogger(Main.class); private static final ILog logger = LogManager.getLogger(Main.class);
private static final String SERVER_REPORTER_NAME = "Storage Server";
static { static {
LogManager.setLogResolver(new Log4j2Resolver()); LogManager.setLogResolver(new Log4j2Resolver());
...@@ -41,7 +42,7 @@ public class Main { ...@@ -41,7 +42,7 @@ public class Main {
try { try {
initializeParam(); initializeParam();
HealthCollector.init(); HealthCollector.init(SERVER_REPORTER_NAME);
DataFilesManager.init(); DataFilesManager.init();
...@@ -54,15 +55,15 @@ public class Main { ...@@ -54,15 +55,15 @@ public class Main {
provider.start(); provider.start();
if (logger.isDebugEnable()) { if (logger.isDebugEnable()) {
logger.debug("Service provider started successfully."); logger.debug("Service provider started.");
} }
registryNode(); registryNode();
logger.info("Storage service started successfully."); logger.info("SkyWalking storage server started.");
Thread.currentThread().join(); Thread.currentThread().join();
} catch (Throwable e) { } catch (Throwable e) {
logger.error("Failed to start service.", e); logger.error("SkyWalking storage server start failure.", e);
} finally { } finally {
provider.stop(); provider.stop();
IndexDataCapacityMonitor.stop(); IndexDataCapacityMonitor.stop();
...@@ -88,10 +89,10 @@ public class Main { ...@@ -88,10 +89,10 @@ public class Main {
printStorageConfig(properties); printStorageConfig(properties);
ConfigInitializer.initialize(properties, Config.class); ConfigInitializer.initialize(properties, Config.class);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
logger.error("Initialize the collect server configuration failed", e); logger.error("Initialize server configuration failure.", e);
throw e; throw e;
} catch (IOException e) { } catch (IOException e) {
logger.error("Initialize the collect server configuration failed", e); logger.error("Initialize server configuration failure.", e);
throw e; throw e;
} }
} }
......
...@@ -53,4 +53,10 @@ public class SpanDataConsumer implements IConsumer<SpanData> { ...@@ -53,4 +53,10 @@ public class SpanDataConsumer implements IConsumer<SpanData> {
HealthCollector.getCurrentHeathReading("SpanDataConsumer").updateData(HeathReading.ERROR, HealthCollector.getCurrentHeathReading("SpanDataConsumer").updateData(HeathReading.ERROR,
"Failed to consume span data. error message : " + throwable.getMessage()); "Failed to consume span data. error message : " + throwable.getMessage());
} }
@Override
public void onExit() {
cache.close();
fileWriter.close();
}
} }
...@@ -5,6 +5,7 @@ import com.a.eye.skywalking.logging.api.LogManager; ...@@ -5,6 +5,7 @@ import com.a.eye.skywalking.logging.api.LogManager;
import com.a.eye.skywalking.storage.block.index.BlockIndexEngine; import com.a.eye.skywalking.storage.block.index.BlockIndexEngine;
import com.a.eye.skywalking.storage.config.Config; import com.a.eye.skywalking.storage.config.Config;
import com.a.eye.skywalking.storage.config.Constants; import com.a.eye.skywalking.storage.config.Constants;
import com.a.eye.skywalking.storage.data.exception.ConnectionNotFoundException;
import com.a.eye.skywalking.storage.data.file.DataFileReader; import com.a.eye.skywalking.storage.data.file.DataFileReader;
import com.a.eye.skywalking.storage.data.index.*; import com.a.eye.skywalking.storage.data.index.*;
import com.a.eye.skywalking.storage.data.spandata.SpanData; import com.a.eye.skywalking.storage.data.spandata.SpanData;
...@@ -13,15 +14,16 @@ import com.zaxxer.hikari.HikariDataSource; ...@@ -13,15 +14,16 @@ import com.zaxxer.hikari.HikariDataSource;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.*; import java.util.*;
import java.util.concurrent.locks.ReentrantLock;
import static com.a.eye.skywalking.storage.config.Constants.SQL.DEFAULT_PASSWORD; import static com.a.eye.skywalking.storage.config.Constants.SQL.DEFAULT_PASSWORD;
import static com.a.eye.skywalking.storage.config.Constants.SQL.DEFAULT_USER; import static com.a.eye.skywalking.storage.config.Constants.SQL.DEFAULT_USER;
import static com.a.eye.skywalking.storage.util.PathResolver.getAbsolutePath; import static com.a.eye.skywalking.storage.util.PathResolver.getAbsolutePath;
public class SpanDataFinder { public class SpanDataFinder {
private static ILog logger = LogManager.getLogger(SpanDataFinder.class); private static ILog logger = LogManager.getLogger(SpanDataFinder.class);
private static IndexDataSourceCache datasourceCache = private static IndexDataSourceCache datasourceCache = new IndexDataSourceCache(Config.Finder.CACHED_SIZE);
new IndexDataSourceCache(Config.Finder.CACHED_SIZE); private static ReentrantLock createDatasourceLock = new ReentrantLock();
public static List<SpanData> find(String traceId) { public static List<SpanData> find(String traceId) {
long blockIndex = BlockIndexEngine.newFinder().find(fetchStartTimeFromTraceId(traceId)); long blockIndex = BlockIndexEngine.newFinder().find(fetchStartTimeFromTraceId(traceId));
...@@ -29,22 +31,40 @@ public class SpanDataFinder { ...@@ -29,22 +31,40 @@ public class SpanDataFinder {
return new ArrayList<SpanData>(); return new ArrayList<SpanData>();
} }
IndexDBConnector indexDBConnector = fetchIndexDBConnector(blockIndex); IndexDBConnector indexDBConnector = null;
IndexMetaCollection indexMetaCollection = indexDBConnector.queryByTraceId(traceId); IndexMetaCollection indexMetaCollection = null;
indexDBConnector.close(); try {
indexDBConnector = fetchIndexDBConnector(blockIndex);
indexMetaCollection = indexDBConnector.queryByTraceId(traceId);
} finally {
if (indexDBConnector != null) {
indexDBConnector.close();
}
}
Iterator<IndexMetaGroup<String>> iterator = if (indexMetaCollection == null) {
IndexMetaCollections.group(indexMetaCollection, new GroupKeyBuilder<String>() { return new ArrayList<SpanData>();
@Override }
public String buildKey(IndexMetaInfo metaInfo) {
return metaInfo.getFileName(); Iterator<IndexMetaGroup<String>> iterator = IndexMetaCollections.group(indexMetaCollection, new GroupKeyBuilder<String>() {
} @Override
}).iterator(); public String buildKey(IndexMetaInfo metaInfo) {
return metaInfo.getFileName();
}
}).iterator();
List<SpanData> result = new ArrayList<SpanData>(); List<SpanData> result = new ArrayList<SpanData>();
while (iterator.hasNext()) { while (iterator.hasNext()) {
IndexMetaGroup<String> group = iterator.next(); IndexMetaGroup<String> group = iterator.next();
result.addAll(new DataFileReader(group.getKey()).read(group.getMetaInfo())); DataFileReader reader = null;
try {
reader = new DataFileReader(group.getKey());
result.addAll(reader.read(group.getMetaInfo()));
} finally {
if (reader != null) {
reader.close();
}
}
} }
return result; return result;
...@@ -52,12 +72,11 @@ public class SpanDataFinder { ...@@ -52,12 +72,11 @@ public class SpanDataFinder {
private static IndexDBConnector fetchIndexDBConnector(long blockIndex) { private static IndexDBConnector fetchIndexDBConnector(long blockIndex) {
HikariDataSource datasource = getOrCreate(blockIndex); HikariDataSource datasource = getOrCreate(blockIndex);
IndexDBConnector indexDBConnector = null; IndexDBConnector indexDBConnector;
try { try {
indexDBConnector = new IndexDBConnector(datasource.getConnection()); indexDBConnector = new IndexDBConnector(datasource.getConnection());
} catch (SQLException e) { } catch (SQLException e) {
logger.warn("Failed to get connection from datasource,", e); throw new ConnectionNotFoundException("get connection failure.", e);
indexDBConnector = new IndexDBConnector(blockIndex);
} }
return indexDBConnector; return indexDBConnector;
} }
...@@ -65,17 +84,23 @@ public class SpanDataFinder { ...@@ -65,17 +84,23 @@ public class SpanDataFinder {
private static HikariDataSource getOrCreate(long blockIndex) { private static HikariDataSource getOrCreate(long blockIndex) {
HikariDataSource datasource = datasourceCache.get(blockIndex); HikariDataSource datasource = datasourceCache.get(blockIndex);
if (datasource == null) { if (datasource == null) {
HikariConfig dataSourceConfig = generateDatasourceConfig(blockIndex); createDatasourceLock.lock();
datasource = new HikariDataSource(dataSourceConfig); try {
datasourceCache.put(blockIndex, datasource); if (datasource == null) {
HikariConfig dataSourceConfig = generateDatasourceConfig(blockIndex);
datasource = new HikariDataSource(dataSourceConfig);
datasourceCache.put(blockIndex, datasource);
}
} finally {
createDatasourceLock.unlock();
}
} }
return datasource; return datasource;
} }
private static HikariConfig generateDatasourceConfig(long blockIndex) { private static HikariConfig generateDatasourceConfig(long blockIndex) {
HikariConfig config = new HikariConfig(); HikariConfig config = new HikariConfig();
config.setJdbcUrl(new ConnectURLGenerator(getAbsolutePath(Config.DataIndex.PATH), config.setJdbcUrl(new ConnectURLGenerator(getAbsolutePath(Config.DataIndex.PATH), Config.DataIndex.FILE_NAME).generate(blockIndex));
Config.DataIndex.FILE_NAME).generate(blockIndex));
config.setDriverClassName(Constants.DRIVER_CLASS_NAME); config.setDriverClassName(Constants.DRIVER_CLASS_NAME);
config.setUsername(DEFAULT_USER); config.setUsername(DEFAULT_USER);
config.setPassword(DEFAULT_PASSWORD); config.setPassword(DEFAULT_PASSWORD);
......
package com.a.eye.skywalking.storage.data.exception;
/**
* Created by xin on 2016/11/5.
*/
public class ConnectionNotFoundException extends RuntimeException {
public ConnectionNotFoundException(String message, Exception e) {
super(message, e);
}
}
package com.a.eye.skywalking.storage.data.exception; package com.a.eye.skywalking.storage.data.exception;
public class IndexMetaPersistenceFailedException extends RuntimeException { public class IndexMetaStoredFailedException extends RuntimeException {
public IndexMetaPersistenceFailedException(String message, Exception e){ public IndexMetaStoredFailedException(String message, Exception e){
super(message, e); super(message, e);
} }
} }
...@@ -3,7 +3,7 @@ package com.a.eye.skywalking.storage.data.exception; ...@@ -3,7 +3,7 @@ package com.a.eye.skywalking.storage.data.exception;
/** /**
* Created by xin on 2016/11/4. * Created by xin on 2016/11/4.
*/ */
public class SpanDataPersistenceFailedException extends RuntimeException { public class SpanDataStoredFailedException extends RuntimeException {
public SpanDataPersistenceFailedException(Exception e) { public SpanDataStoredFailedException(Exception e) {
} }
} }
...@@ -4,7 +4,7 @@ import com.a.eye.skywalking.logging.api.ILog; ...@@ -4,7 +4,7 @@ import com.a.eye.skywalking.logging.api.ILog;
import com.a.eye.skywalking.logging.api.LogManager; import com.a.eye.skywalking.logging.api.LogManager;
import com.a.eye.skywalking.storage.config.Config; import com.a.eye.skywalking.storage.config.Config;
import com.a.eye.skywalking.storage.data.exception.DataFileOperatorCreateFailedException; import com.a.eye.skywalking.storage.data.exception.DataFileOperatorCreateFailedException;
import com.a.eye.skywalking.storage.data.exception.SpanDataPersistenceFailedException; import com.a.eye.skywalking.storage.data.exception.SpanDataStoredFailedException;
import com.a.eye.skywalking.storage.data.exception.SpanDataReadFailedException; import com.a.eye.skywalking.storage.data.exception.SpanDataReadFailedException;
import com.a.eye.skywalking.storage.data.index.IndexMetaInfo; import com.a.eye.skywalking.storage.data.index.IndexMetaInfo;
import com.a.eye.skywalking.storage.data.spandata.SpanData; import com.a.eye.skywalking.storage.data.spandata.SpanData;
...@@ -84,7 +84,7 @@ public class DataFile { ...@@ -84,7 +84,7 @@ public class DataFile {
currentOffset += bytes.length; currentOffset += bytes.length;
return metaInfo; return metaInfo;
} catch (IOException e) { } catch (IOException e) {
throw new SpanDataPersistenceFailedException(e); throw new SpanDataStoredFailedException(e);
} }
} }
...@@ -92,10 +92,14 @@ public class DataFile { ...@@ -92,10 +92,14 @@ public class DataFile {
try { try {
operator.getWriter().flush(); operator.getWriter().flush();
} catch (IOException e) { } catch (IOException e) {
throw new SpanDataPersistenceFailedException(e); throw new SpanDataStoredFailedException(e);
} }
} }
public void close(){
operator.close();
}
public byte[] read(long offset, int length) { public byte[] read(long offset, int length) {
byte[] data = new byte[length]; byte[] data = new byte[length];
try { try {
...@@ -103,8 +107,7 @@ public class DataFile { ...@@ -103,8 +107,7 @@ public class DataFile {
operator.getReader().read(data, 0, length); operator.getReader().read(data, 0, length);
return data; return data;
} catch (IOException e) { } catch (IOException e) {
throw new SpanDataReadFailedException( throw new SpanDataReadFailedException("Failed to read dataFile[" + fileName + "], offset: " + offset + " " + "lenght: " + length, e);
"Failed to read dataFile[" + fileName + "], offset: " + offset + " " + "lenght: " + length, e);
} }
} }
...@@ -136,6 +139,23 @@ public class DataFile { ...@@ -136,6 +139,23 @@ public class DataFile {
return reader; return reader;
} }
public void close() {
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
}
}
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
}
}
}
} }
private File getDataFile() { private File getDataFile() {
......
...@@ -47,4 +47,8 @@ public class DataFileReader { ...@@ -47,4 +47,8 @@ public class DataFileReader {
return metaData; return metaData;
} }
public void close(){
dataFile.close();
}
} }
...@@ -15,6 +15,7 @@ public class DataFileWriter { ...@@ -15,6 +15,7 @@ public class DataFileWriter {
public IndexMetaCollection write(List<SpanData> spanData) { public IndexMetaCollection write(List<SpanData> spanData) {
if (dataFile.overLimitLength()) { if (dataFile.overLimitLength()) {
this.close();
dataFile = DataFilesManager.createNewDataFile(); dataFile = DataFilesManager.createNewDataFile();
} }
...@@ -26,4 +27,8 @@ public class DataFileWriter { ...@@ -26,4 +27,8 @@ public class DataFileWriter {
return collections; return collections;
} }
public void close(){
dataFile.close();
}
} }
...@@ -22,6 +22,10 @@ public class IndexDBConnectorCache { ...@@ -22,6 +22,10 @@ public class IndexDBConnectorCache {
return connector; return connector;
} }
public void close(){
cachedOperators.close();
}
private void updateCache(long timestamp, IndexDBConnector operator) { private void updateCache(long timestamp, IndexDBConnector operator) {
cachedOperators.put(timestamp, operator); cachedOperators.put(timestamp, operator);
} }
...@@ -43,5 +47,11 @@ public class IndexDBConnectorCache { ...@@ -43,5 +47,11 @@ public class IndexDBConnectorCache {
public LRUCache(int cacheSize) { public LRUCache(int cacheSize) {
super((int) Math.ceil(cacheSize / 0.75) + 1, 0.75f, true); super((int) Math.ceil(cacheSize / 0.75) + 1, 0.75f, true);
} }
public void close(){
for(Map.Entry<Long, IndexDBConnector> entry : this.entrySet()){
entry.getValue().close();
}
}
} }
} }
package com.a.eye.skywalking.storage.data.index; package com.a.eye.skywalking.storage.data.index;
import com.a.eye.skywalking.storage.data.IndexDataCapacityMonitor; import com.a.eye.skywalking.storage.data.IndexDataCapacityMonitor;
import com.a.eye.skywalking.storage.data.exception.IndexMetaPersistenceFailedException; import com.a.eye.skywalking.storage.data.exception.IndexMetaStoredFailedException;
import java.util.ArrayList;
import java.util.List;
public class IndexOperator { public class IndexOperator {
...@@ -21,7 +18,7 @@ public class IndexOperator { ...@@ -21,7 +18,7 @@ public class IndexOperator {
connector.batchUpdate(metaGroup); connector.batchUpdate(metaGroup);
IndexDataCapacityMonitor.addIndexData(timestamp, metaGroup.size()); IndexDataCapacityMonitor.addIndexData(timestamp, metaGroup.size());
} catch (Exception e) { } catch (Exception e) {
throw new IndexMetaPersistenceFailedException("Failed to batch save index meta", e); throw new IndexMetaStoredFailedException("Failed to batch save index meta", e);
} }
} }
......
...@@ -24,12 +24,12 @@ public class SearchListener implements TraceSearchListener { ...@@ -24,12 +24,12 @@ public class SearchListener implements TraceSearchListener {
SpanDataHelper helper = new SpanDataHelper(data); SpanDataHelper helper = new SpanDataHelper(data);
List<Span> span = helper.category().mergeData(); List<Span> span = helper.category().mergeData();
HealthCollector.getCurrentHeathReading("SearchListener") HealthCollector.getCurrentHeathReading("SearchListener")
.updateData(HeathReading.INFO, span.size() + " spans was founded by trace Id [" + traceId + "]."); .updateData(HeathReading.INFO, span.size() + " spans was found by trace Id [" + traceId + "].");
return span; return span;
} catch (Exception e) { } catch (Exception e) {
logger.error("Failed to search trace Id [{}]", traceId, e); logger.error("Search trace Id[{}] failure.", traceId, e);
HealthCollector.getCurrentHeathReading("SearchListener") HealthCollector.getCurrentHeathReading("SearchListener")
.updateData(HeathReading.ERROR, "Failed to search trace Id" + traceId + "."); .updateData(HeathReading.ERROR, "Search trace Id[" + traceId + "] failure.");
return new ArrayList<Span>(); return new ArrayList<Span>();
} }
} }
......
...@@ -28,13 +28,11 @@ public class StorageListener implements SpanStorageListener { ...@@ -28,13 +28,11 @@ public class StorageListener implements SpanStorageListener {
public boolean storage(RequestSpan requestSpan) { public boolean storage(RequestSpan requestSpan) {
try { try {
spanDataDataCarrier.produce(SpanDataBuilder.build(requestSpan)); spanDataDataCarrier.produce(SpanDataBuilder.build(requestSpan));
HealthCollector.getCurrentHeathReading("StorageListener").updateData(HeathReading.INFO,"Request span " HealthCollector.getCurrentHeathReading("StorageListener").updateData(HeathReading.INFO,"RequestSpan stored.");
+ "consume successfully");
return true; return true;
} catch (Exception e) { } catch (Exception e) {
logger.error("Failed to storage request span. Span Data:\n {}.", requestSpan.toByteString(), e); logger.error("RequestSpan trace-id[{}] store failure..", requestSpan.getTraceId(), e);
HealthCollector.getCurrentHeathReading("StorageListener").updateData(HeathReading.ERROR,"Request span " HealthCollector.getCurrentHeathReading("StorageListener").updateData(HeathReading.ERROR,"RequestSpan store failure.");
+ "consume failed");
return false; return false;
} }
} }
...@@ -43,9 +41,11 @@ public class StorageListener implements SpanStorageListener { ...@@ -43,9 +41,11 @@ public class StorageListener implements SpanStorageListener {
public boolean storage(AckSpan ackSpan) { public boolean storage(AckSpan ackSpan) {
try { try {
spanDataDataCarrier.produce(SpanDataBuilder.build(ackSpan)); spanDataDataCarrier.produce(SpanDataBuilder.build(ackSpan));
HealthCollector.getCurrentHeathReading("StorageListener").updateData(HeathReading.INFO,"AckSpan stored.");
return true; return true;
} catch (Exception e) { } catch (Exception e) {
logger.error("Failed to storage ack span. ack Data:\n {}.", ackSpan.toByteString(), e); logger.error("AckSpan trace-id[{}] store failure..", ackSpan.getTraceId(), e);
HealthCollector.getCurrentHeathReading("StorageListener").updateData(HeathReading.ERROR,"AckSpan store failure.");
return false; return false;
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册