Skip to content

Commit

Permalink
TIP128: fix sonar check, redirect log output
Browse files Browse the repository at this point in the history
  • Loading branch information
tomatoishealthy committed Apr 7, 2020
1 parent bd2e4d8 commit 428ea21
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 126 deletions.
10 changes: 4 additions & 6 deletions chainbase/src/main/java/org/tron/core/db2/common/TxCacheDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ public class TxCacheDB implements DB<byte[], byte[]>, Flusher {
private Multimap<Long, Key> blockNumMap = ArrayListMultimap.create();
private String name;

// add a persistent storage, just for now the store name is: trans-cache
// when fullnode startup, transactionCache will read transations from this store
// instead of blockStore
// add a persistent storage, the store name is: trans-cache
// when fullnode startup, transactionCache initializes transactions from this store
private DB<byte[], byte[]> persistentStore;

public TxCacheDB(String name) {
Expand Down Expand Up @@ -67,8 +66,7 @@ public TxCacheDB(String name) {
}

/**
* this method only used for init, put all data from tran-cache into the two map,
* does not check the map.size()
* this method only used for init, put all data in tran-cache into the two maps.
*/
private void init() {
DBIterator iterator = (DBIterator) persistentStore.iterator();
Expand Down Expand Up @@ -102,7 +100,7 @@ public void put(byte[] key, byte[] value) {
Long v = Longs.fromByteArray(value);
blockNumMap.put(v, k);
db.put(k, v);
// also put the data into persistent storage
// put the data into persistent storage
persistentStore.put(key, value);
removeEldest();
}
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/java/org/tron/core/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class Constant {
public static final String DATABASE_DIR = "storage.directory";

// locate in storageDbDirectory, store the db infos,
// now only has the snapshot block number
// now only has the split block number
public static final String INFO_FILE_NAME = "info.properties";
// the block number that split between the snapshot and history
public static final String SPLIT_BLOCK_NUM = "split_block_num";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,11 @@ public static Set<String> getFilterMethods() {
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call,
Metadata headers, ServerCallHandler<ReqT, RespT> next) {
String methodName = call.getMethodDescriptor().getFullMethodName();
boolean shouldBeFiltered = false;
if (CommonParameter.getInstance().isLiteFullNode
&& !CommonParameter.getInstance().openHistoryQueryWhenLiteFN) {
if (filterMethods.contains(methodName)) {
shouldBeFiltered = true;
}
&& !CommonParameter.getInstance().openHistoryQueryWhenLiteFN
&& filterMethods.contains(call.getMethodDescriptor().getFullMethodName())) {
shouldBeFiltered = true;
}
if (shouldBeFiltered) {
call.close(Status.UNAVAILABLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public static Set<String> getFilterPaths() {

@Override
public void init(FilterConfig filterConfig) throws ServletException {
// do nothing
}

@Override
Expand All @@ -67,10 +68,9 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo
String requestPath = ((HttpServletRequest) servletRequest).getRequestURI();
boolean shouldBeFiltered = false;
if (CommonParameter.getInstance().isLiteFullNode
&& !CommonParameter.getInstance().openHistoryQueryWhenLiteFN) {
if (filterPaths.contains(requestPath)) {
shouldBeFiltered = true;
}
&& !CommonParameter.getInstance().openHistoryQueryWhenLiteFN
&& filterPaths.contains(requestPath)) {
shouldBeFiltered = true;
}
if (shouldBeFiltered) {
servletResponse.getWriter().write("this API is closed because this node is a lite fullnode");
Expand All @@ -81,5 +81,6 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo

@Override
public void destroy() {
// do nothing
}
}
13 changes: 7 additions & 6 deletions framework/src/main/java/org/tron/tool/litefullnode/DbTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ public class DbTool {

private static final String KEY_ENGINE = "ENGINE";
private static final String ENGINE_FILE = "engine.properties";
private static final String FILE_SEPARATOR = File.separator;
private static final String ROCKSDB = "ROCKSDB";

private static Map<String, DBInterface> dbMap = Maps.newHashMap();
private static DbType type;

enum DbType {
LevelDB,
Expand All @@ -55,7 +56,7 @@ public static DBInterface getDB(String sourceDir, String dbName)
if (dbMap.containsKey(path.toString())) {
return dbMap.get(path.toString());
}
type = getDbType(sourceDir, dbName);
DbType type = getDbType(sourceDir, dbName);
DBInterface db;
switch (type) {
case LevelDB:
Expand Down Expand Up @@ -103,20 +104,20 @@ public static void close() {
try {
next.getValue().close();
} catch (IOException e) {
e.printStackTrace();
logger.error("close db failed, db: {}", next.getKey(), e);
}
iterator.remove();
}
}

private static DbType getDbType(String sourceDir, String dbName) {
String engineFile = String.format("%s%s%s%s%s", sourceDir, File.separator,
dbName, File.separator, ENGINE_FILE);
String engineFile = String.format("%s%s%s%s%s", sourceDir, FILE_SEPARATOR,
dbName, FILE_SEPARATOR, ENGINE_FILE);
if (!new File(engineFile).exists()) {
return DbType.LevelDB;
}
String engine = PropUtil.readProperty(engineFile, KEY_ENGINE);
if (engine.equalsIgnoreCase("ROCKSDB")) {
if (engine.equalsIgnoreCase(ROCKSDB)) {
return DbType.RocksDB;
} else {
return DbType.LevelDB;
Expand Down
Loading

0 comments on commit 428ea21

Please sign in to comment.