|
27 | 27 | import lombok.extern.slf4j.Slf4j; |
28 | 28 | import org.apache.commons.collections4.CollectionUtils; |
29 | 29 | import org.apache.commons.lang3.StringUtils; |
| 30 | +import org.iq80.leveldb.Options; |
30 | 31 | import org.spongycastle.util.encoders.Hex; |
31 | 32 | import org.springframework.stereotype.Component; |
32 | 33 | import org.tron.common.crypto.ECKey; |
@@ -65,8 +66,11 @@ public class Args { |
65 | 66 | @Parameter(names = {"-p", "--private-key"}, description = "private-key") |
66 | 67 | private String privateKey = ""; |
67 | 68 |
|
68 | | - @Parameter(names = {"--storage-directory"}, description = "Storage directory") |
69 | | - private String storageDirectory = ""; |
| 69 | + @Parameter(names = {"--storage-db-directory"}, description = "Storage db directory") |
| 70 | + private String storageDbDirectory = ""; |
| 71 | + |
| 72 | + @Parameter(names = {"--storage-index-directory"}, description = "Storage index directory") |
| 73 | + private String storageIndexDirectory = ""; |
70 | 74 |
|
71 | 75 | @Getter |
72 | 76 | private Storage storage; |
@@ -218,8 +222,16 @@ public static void clearParam() { |
218 | 222 | INSTANCE.witness = false; |
219 | 223 | INSTANCE.seedNodes = new ArrayList<>(); |
220 | 224 | INSTANCE.privateKey = ""; |
221 | | - INSTANCE.storageDirectory = ""; |
222 | | - INSTANCE.storage = null; |
| 225 | + INSTANCE.storageDbDirectory = ""; |
| 226 | + INSTANCE.storageIndexDirectory = ""; |
| 227 | + |
| 228 | + // FIXME: INSTANCE.storage maybe null ? |
| 229 | + if (INSTANCE.storage != null) { |
| 230 | + // WARNING: WILL DELETE DB STORAGE PATHS |
| 231 | + INSTANCE.storage.deleteAllStoragePaths(); |
| 232 | + INSTANCE.storage = null; |
| 233 | + } |
| 234 | + |
223 | 235 | INSTANCE.overlay = null; |
224 | 236 | INSTANCE.seedNode = null; |
225 | 237 | INSTANCE.genesisBlock = null; |
@@ -253,6 +265,7 @@ public static void clearParam() { |
253 | 265 | INSTANCE.getTransactionsToThisCountFeature = false; |
254 | 266 | INSTANCE.getTransactionsByTimestampFeature = false; |
255 | 267 | INSTANCE.getTransactionsByTimestampCountFeature = false; |
| 268 | + |
256 | 269 | } |
257 | 270 |
|
258 | 271 | /** |
@@ -281,9 +294,16 @@ public static void setParam(final String[] args, final String confFileName) { |
281 | 294 | } |
282 | 295 |
|
283 | 296 | INSTANCE.storage = new Storage(); |
284 | | - INSTANCE.storage.setDirectory(Optional.ofNullable(INSTANCE.storageDirectory) |
| 297 | + INSTANCE.storage.setDbDirectory(Optional.ofNullable(INSTANCE.storageDbDirectory) |
285 | 298 | .filter(StringUtils::isNotEmpty) |
286 | | - .orElse(config.getString("storage.directory"))); |
| 299 | + .orElse(config.getString("storage.db.directory"))); |
| 300 | + |
| 301 | + INSTANCE.storage.setIndexDirectory(Optional.ofNullable(INSTANCE.storageIndexDirectory) |
| 302 | + .filter(StringUtils::isNotEmpty) |
| 303 | + .orElse(config.getString("storage.index.directory"))); |
| 304 | + |
| 305 | + INSTANCE.storage.setPropertyMapFromConfig(config); |
| 306 | + |
287 | 307 | INSTANCE.seedNode = new SeedNode(); |
288 | 308 | INSTANCE.seedNode.setIpList(Optional.ofNullable(INSTANCE.seedNodes) |
289 | 309 | .filter(seedNode -> 0 != seedNode.size()) |
@@ -436,6 +456,20 @@ public static Args getInstance() { |
436 | 456 | return INSTANCE; |
437 | 457 | } |
438 | 458 |
|
| 459 | + /** |
| 460 | + * Get storage path by name of database |
| 461 | + * |
| 462 | + * @param dbName name of database |
| 463 | + * @return path of that database |
| 464 | + */ |
| 465 | + public String getOutputDirectoryByDbName(String dbName) { |
| 466 | + String path = storage.getPathByDbName(dbName); |
| 467 | + if (!StringUtils.isBlank(path)) { |
| 468 | + return path; |
| 469 | + } |
| 470 | + return getOutputDirectory(); |
| 471 | + } |
| 472 | + |
439 | 473 | /** |
440 | 474 | * get output directory. |
441 | 475 | */ |
@@ -475,7 +509,7 @@ private static String getGeneratedNodePrivateKey() { |
475 | 509 | String nodeId; |
476 | 510 | try { |
477 | 511 | File file = new File( |
478 | | - INSTANCE.outputDirectory + File.separator + INSTANCE.storage.getDirectory(), |
| 512 | + INSTANCE.outputDirectory + File.separator + INSTANCE.storage.getDbDirectory(), |
479 | 513 | "nodeId.properties"); |
480 | 514 | Properties props = new Properties(); |
481 | 515 | if (file.canRead()) { |
|
0 commit comments