Search in sources :

Example 1 with DBVendor

use of org.aion.db.impl.DBVendor in project aion by aionnetwork.

the class EditCliTest method paramsForTestConverter.

public Object paramsForTestConverter() {
    List<Object> params = new ArrayList<>();
    EditCli.EnabledConverter enabledConverter = new EditCli.EnabledConverter();
    EditCli.DBVendorConverter dbVendorConverter = new EditCli.DBVendorConverter();
    EditCli.DBPruneOptionConverter dbPruneOptionConverter = new EditCli.DBPruneOptionConverter();
    EditCli.PortNumberConverter portNumberConverter = new EditCli.PortNumberConverter();
    EditCli.LogConverter logConverter = new EditCli.LogConverter();
    params.add(new Object[] { "on", enabledConverter, true });
    params.add(new Object[] { "off", enabledConverter, false });
    for (DBVendor vendor : DBVendor.values()) {
        if (!vendor.equals(DBVendor.UNKNOWN)) {
            params.add(new Object[] { vendor.toString().toUpperCase(), dbVendorConverter, vendor });
            params.add(new Object[] { vendor.toString().toLowerCase(), dbVendorConverter, vendor });
        }
    }
    for (CfgDb.PruneOption pruneOption : CfgDb.PruneOption.values()) {
        params.add(new Object[] { pruneOption.toString().toUpperCase(), dbPruneOptionConverter, pruneOption });
        params.add(new Object[] { pruneOption.toString().toLowerCase(), dbPruneOptionConverter, pruneOption });
    }
    for (LogEnum logEnum : LogEnum.values()) {
        for (LogLevel logLevel : LogLevel.values()) {
            params.add(new Object[] { logEnum.toString() + "=" + logLevel.toString(), logConverter, new Object[] { logEnum, logLevel } });
        }
    }
    int[] ports = { 0x1, 0xF, 0xFF, 0xFFF, 0xFFFF };
    for (Integer port : ports) {
        params.add(new Object[] { port.toString(), portNumberConverter, port });
    }
    return params;
}
Also used : PruneOption(org.aion.zero.impl.config.CfgDb.PruneOption) CfgDb(org.aion.zero.impl.config.CfgDb) ArrayList(java.util.ArrayList) DBVendor(org.aion.db.impl.DBVendor) LogLevel(org.aion.log.LogLevel) LogEnum(org.aion.log.LogEnum)

Example 2 with DBVendor

use of org.aion.db.impl.DBVendor in project aion by aionnetwork.

the class AionRepositoryImpl method initializeDatabasesAndCaches.

/**
 * Initializes all necessary databases and caches.
 *
 * @throws IllegalStateException when called with a persistent database vendor for which the
 *     data store cannot be created or opened.
 * @implNote This function is not locked. Locking must be done from calling function.
 */
private void initializeDatabasesAndCaches(RepositoryConfig cfg) throws IOException {
    // Given that this function is only called on startup, enforce conditions here for safety.
    Objects.requireNonNull(cfg);
    DBVendor vendor = DBVendor.fromString(cfg.getDatabaseConfig(DEFAULT).getProperty(Props.DB_TYPE));
    LOGGEN.info("The DB vendor is: {}", vendor);
    String dbPath = cfg.getDbPath();
    boolean isPersistent = vendor.isFileBased();
    if (isPersistent) {
        // verify user-provided path
        File f = new File(dbPath);
        verifyAndBuildPath(f);
        if (vendor.equals(DBVendor.LEVELDB) || vendor.equals(DBVendor.ROCKSDB)) {
            verifyDBfileType(f, vendor.toValue());
        }
    }
    Properties sharedProps;
    databaseGroup = new ArrayList<>();
    // getting state specific properties
    sharedProps = getDatabaseConfig(cfg, STATE, dbPath);
    this.stateDatabase = connectAndOpen(sharedProps, LOG);
    if (stateDatabase == null || stateDatabase.isClosed()) {
        throw newException(STATE, sharedProps);
    }
    databaseGroup.add(stateDatabase);
    // getting transaction specific properties
    sharedProps = getDatabaseConfig(cfg, TRANSACTION, dbPath);
    this.transactionDatabase = connectAndOpen(sharedProps, LOG);
    if (transactionDatabase == null || transactionDatabase.isClosed()) {
        throw newException(TRANSACTION, sharedProps);
    }
    databaseGroup.add(transactionDatabase);
    // getting contract index specific properties
    // this db will be used only for fast sync
    sharedProps = getDatabaseConfig(cfg, CONTRACT_INDEX, dbPath);
    this.contractIndexDatabase = connectAndOpen(sharedProps, LOG);
    if (contractIndexDatabase == null || contractIndexDatabase.isClosed()) {
        throw newException(CONTRACT_INDEX, sharedProps);
    }
    databaseGroup.add(contractIndexDatabase);
    // getting contract perform code specific properties
    sharedProps = getDatabaseConfig(cfg, CONTRACT_PERFORM_CODE, dbPath);
    this.contractPerformCodeDatabase = connectAndOpen(sharedProps, LOG);
    if (contractPerformCodeDatabase == null || contractPerformCodeDatabase.isClosed()) {
        throw newException(CONTRACT_PERFORM_CODE, sharedProps);
    }
    databaseGroup.add(contractPerformCodeDatabase);
    // getting details specific properties
    sharedProps = getDatabaseConfig(cfg, DETAILS, dbPath);
    this.detailsDatabase = connectAndOpen(sharedProps, LOG);
    if (detailsDatabase == null || detailsDatabase.isClosed()) {
        throw newException(DETAILS, sharedProps);
    }
    databaseGroup.add(detailsDatabase);
    // getting storage specific properties
    sharedProps = getDatabaseConfig(cfg, STORAGE, dbPath);
    this.storageDatabase = connectAndOpen(sharedProps, LOG);
    if (storageDatabase == null || storageDatabase.isClosed()) {
        throw newException(STORAGE, sharedProps);
    }
    databaseGroup.add(storageDatabase);
    // getting graph specific properties
    sharedProps = getDatabaseConfig(cfg, GRAPH, dbPath);
    this.graphDatabase = connectAndOpen(sharedProps, LOG);
    if (graphDatabase == null || graphDatabase.isClosed()) {
        throw newException(GRAPH, sharedProps);
    }
    databaseGroup.add(graphDatabase);
    // getting index specific properties
    sharedProps = getDatabaseConfig(cfg, INDEX, dbPath);
    this.indexDatabase = connectAndOpen(sharedProps, LOG);
    if (indexDatabase == null || indexDatabase.isClosed()) {
        throw newException(INDEX, sharedProps);
    }
    databaseGroup.add(indexDatabase);
    // getting block specific properties
    sharedProps = getDatabaseConfig(cfg, BLOCK, dbPath);
    this.blockDatabase = connectAndOpen(sharedProps, LOG);
    if (blockDatabase == null || blockDatabase.isClosed()) {
        throw newException(BLOCK, sharedProps);
    }
    databaseGroup.add(blockDatabase);
    // getting pending tx pool specific properties
    sharedProps = getDatabaseConfig(cfg, TX_POOL, dbPath);
    this.txPoolDatabase = connectAndOpen(sharedProps, LOG);
    if (txPoolDatabase == null || txPoolDatabase.isClosed()) {
        throw newException(TX_POOL, sharedProps);
    }
    databaseGroup.add(txPoolDatabase);
    // getting pending tx cache specific properties
    sharedProps = getDatabaseConfig(cfg, TX_CACHE, dbPath);
    this.pendingTxCacheDatabase = connectAndOpen(sharedProps, LOG);
    if (pendingTxCacheDatabase == null || pendingTxCacheDatabase.isClosed()) {
        throw newException(TX_CACHE, sharedProps);
    }
    databaseGroup.add(pendingTxCacheDatabase);
}
Also used : DBVendor(org.aion.db.impl.DBVendor) Hex.toHexString(org.aion.util.conversions.Hex.toHexString) Properties(java.util.Properties) File(java.io.File)

Example 3 with DBVendor

use of org.aion.db.impl.DBVendor in project aion by aionnetwork.

the class EditCliTest method paramsForTestConverterValidation.

public Object paramsForTestConverterValidation() {
    List<Object[]> params = new ArrayList<>();
    EditCli.EnabledConverter enabledConverter = new EditCli.EnabledConverter();
    EditCli.DBVendorConverter dbVendorConverter = new EditCli.DBVendorConverter();
    EditCli.DBPruneOptionConverter dbPruneOptionConverter = new EditCli.DBPruneOptionConverter();
    EditCli.PortNumberConverter portNumberConverter = new EditCli.PortNumberConverter();
    EditCli.LogConverter logConverter = new EditCli.LogConverter();
    params.add(new Object[] { "onn", enabledConverter });
    params.add(new Object[] { "offf", enabledConverter });
    params.add(new Object[] { "on".toUpperCase(), enabledConverter });
    params.add(new Object[] { "off".toUpperCase(), enabledConverter });
    params.add(new Object[] { "".toUpperCase(), enabledConverter });
    for (DBVendor vendor : DBVendor.values()) {
        params.add(new Object[] { vendor + "1", dbVendorConverter });
    }
    params.add(new Object[] { "", dbVendorConverter });
    for (CfgDb.PruneOption pruneOption : CfgDb.PruneOption.values()) {
        params.add(new Object[] { pruneOption.toString().toUpperCase() + "1", dbPruneOptionConverter });
        params.add(new Object[] { pruneOption.toString().toLowerCase() + "1", dbPruneOptionConverter });
    }
    params.add(new Object[] { "", dbPruneOptionConverter });
    for (LogEnum logEnum : LogEnum.values()) {
        for (LogLevel logLevel : LogLevel.values()) {
            params.add(new Object[] { logEnum.toString() + "-" + logLevel.toString(), logConverter });
            params.add(new Object[] { logEnum.toString() + "=" + logLevel.toString() + "1", logConverter });
            params.add(new Object[] { logEnum.toString() + "1" + "=" + logLevel.toString() + "1", logConverter });
            params.add(new Object[] { logEnum.toString() + "1" + "=" + logLevel.toString(), logConverter });
        }
    }
    params.add(new Object[] { "", logConverter });
    int[] ports = { 0x0, 0xFFFF + 1 };
    for (Integer port : ports) {
        params.add(new Object[] { port.toString(), portNumberConverter });
    }
    params.add(new Object[] { "", portNumberConverter });
    return params;
}
Also used : PruneOption(org.aion.zero.impl.config.CfgDb.PruneOption) CfgDb(org.aion.zero.impl.config.CfgDb) ArrayList(java.util.ArrayList) DBVendor(org.aion.db.impl.DBVendor) LogLevel(org.aion.log.LogLevel) LogEnum(org.aion.log.LogEnum)

Aggregations

DBVendor (org.aion.db.impl.DBVendor)3 ArrayList (java.util.ArrayList)2 LogEnum (org.aion.log.LogEnum)2 LogLevel (org.aion.log.LogLevel)2 CfgDb (org.aion.zero.impl.config.CfgDb)2 PruneOption (org.aion.zero.impl.config.CfgDb.PruneOption)2 File (java.io.File)1 Properties (java.util.Properties)1 Hex.toHexString (org.aion.util.conversions.Hex.toHexString)1