Search in sources :

Example 1 with KCVSConfigurationBuilder

use of org.janusgraph.diskstorage.configuration.backend.builder.KCVSConfigurationBuilder in project janusgraph by JanusGraph.

the class GraphDatabaseConfigurationBuilder method build.

public GraphDatabaseConfiguration build(ReadConfiguration localConfig) {
    Preconditions.checkNotNull(localConfig);
    BasicConfiguration localBasicConfiguration = new BasicConfiguration(ROOT_NS, localConfig, BasicConfiguration.Restriction.NONE);
    ModifiableConfiguration overwrite = new ModifiableConfiguration(ROOT_NS, new CommonsConfiguration(), BasicConfiguration.Restriction.NONE);
    final KeyColumnValueStoreManager storeManager = Backend.getStorageManager(localBasicConfiguration);
    final StoreFeatures storeFeatures = storeManager.getFeatures();
    final ReadConfiguration globalConfig = new ReadConfigurationBuilder().buildGlobalConfiguration(localConfig, localBasicConfiguration, overwrite, storeManager, new ModifiableConfigurationBuilder(), new KCVSConfigurationBuilder());
    // Copy over local config options
    ModifiableConfiguration localConfiguration = new ModifiableConfiguration(ROOT_NS, new CommonsConfiguration(), BasicConfiguration.Restriction.LOCAL);
    localConfiguration.setAll(getLocalSubset(localBasicConfiguration.getAll()));
    Configuration combinedConfig = new MixedConfiguration(ROOT_NS, globalConfig, localConfig);
    // Compute unique instance id
    String uniqueGraphId = UniqueInstanceIdRetriever.getInstance().getOrGenerateUniqueInstanceId(combinedConfig);
    overwrite.set(UNIQUE_INSTANCE_ID, uniqueGraphId);
    checkAndOverwriteTransactionLogConfiguration(combinedConfig, overwrite, storeFeatures);
    checkAndOverwriteSystemManagementLogConfiguration(combinedConfig, overwrite);
    MergedConfiguration configuration = new MergedConfiguration(overwrite, combinedConfig);
    return new GraphDatabaseConfiguration(localConfig, localConfiguration, uniqueGraphId, configuration);
}
Also used : StoreFeatures(org.janusgraph.diskstorage.keycolumnvalue.StoreFeatures) KCVSConfigurationBuilder(org.janusgraph.diskstorage.configuration.backend.builder.KCVSConfigurationBuilder) MergedConfiguration(org.janusgraph.diskstorage.configuration.MergedConfiguration) MergedConfiguration(org.janusgraph.diskstorage.configuration.MergedConfiguration) MixedConfiguration(org.janusgraph.diskstorage.configuration.MixedConfiguration) Configuration(org.janusgraph.diskstorage.configuration.Configuration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) BasicConfiguration(org.janusgraph.diskstorage.configuration.BasicConfiguration) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) ReadConfiguration(org.janusgraph.diskstorage.configuration.ReadConfiguration) MixedConfiguration(org.janusgraph.diskstorage.configuration.MixedConfiguration) CommonsConfiguration(org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration) ReadConfiguration(org.janusgraph.diskstorage.configuration.ReadConfiguration) ModifiableConfigurationBuilder(org.janusgraph.diskstorage.configuration.builder.ModifiableConfigurationBuilder) KeyColumnValueStoreManager(org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStoreManager) ReadConfigurationBuilder(org.janusgraph.diskstorage.configuration.builder.ReadConfigurationBuilder) BasicConfiguration(org.janusgraph.diskstorage.configuration.BasicConfiguration)

Example 2 with KCVSConfigurationBuilder

use of org.janusgraph.diskstorage.configuration.backend.builder.KCVSConfigurationBuilder in project janusgraph by JanusGraph.

the class Backend method initialize.

/**
 * Initializes this backend with the given configuration. Must be called before this Backend can be used
 *
 * @param config
 */
public void initialize(Configuration config) {
    try {
        // EdgeStore & VertexIndexStore
        KeyColumnValueStore idStore = storeManager.openDatabase(config.get(IDS_STORE_NAME));
        idAuthority = null;
        if (storeFeatures.isKeyConsistent()) {
            idAuthority = new ConsistentKeyIDAuthority(idStore, storeManager, config);
        } else {
            throw new IllegalStateException("Store needs to support consistent key or transactional operations for ID manager to guarantee proper id allocations");
        }
        KeyColumnValueStore edgeStoreRaw = storeManagerLocking.openDatabase(EDGESTORE_NAME);
        KeyColumnValueStore indexStoreRaw = storeManagerLocking.openDatabase(INDEXSTORE_NAME);
        // Configure caches
        if (cacheEnabled) {
            long expirationTime = configuration.get(DB_CACHE_TIME);
            Preconditions.checkArgument(expirationTime >= 0, "Invalid cache expiration time: %s", expirationTime);
            if (expirationTime == 0)
                expirationTime = ETERNAL_CACHE_EXPIRATION;
            long cacheSizeBytes;
            double cacheSize = configuration.get(DB_CACHE_SIZE);
            Preconditions.checkArgument(cacheSize > 0.0, "Invalid cache size specified: %s", cacheSize);
            if (cacheSize < 1.0) {
                // Its a percentage
                Runtime runtime = Runtime.getRuntime();
                cacheSizeBytes = (long) ((runtime.maxMemory() - (runtime.totalMemory() - runtime.freeMemory())) * cacheSize);
            } else {
                Preconditions.checkArgument(cacheSize > 1000, "Cache size is too small: %s", cacheSize);
                cacheSizeBytes = (long) cacheSize;
            }
            log.info("Configuring total store cache size: {}", cacheSizeBytes);
            long cleanWaitTime = configuration.get(DB_CACHE_CLEAN_WAIT);
            Preconditions.checkArgument(EDGESTORE_CACHE_PERCENT + INDEXSTORE_CACHE_PERCENT == 1.0, "Cache percentages don't add up!");
            long edgeStoreCacheSize = Math.round(cacheSizeBytes * EDGESTORE_CACHE_PERCENT);
            long indexStoreCacheSize = Math.round(cacheSizeBytes * INDEXSTORE_CACHE_PERCENT);
            edgeStore = new ExpirationKCVSCache(edgeStoreRaw, getMetricsCacheName(EDGESTORE_NAME), expirationTime, cleanWaitTime, edgeStoreCacheSize);
            indexStore = new ExpirationKCVSCache(indexStoreRaw, getMetricsCacheName(INDEXSTORE_NAME), expirationTime, cleanWaitTime, indexStoreCacheSize);
        } else {
            edgeStore = new NoKCVSCache(edgeStoreRaw);
            indexStore = new NoKCVSCache(indexStoreRaw);
        }
        // Just open them so that they are cached
        txLogManager.openLog(SYSTEM_TX_LOG_NAME);
        managementLogManager.openLog(SYSTEM_MGMT_LOG_NAME);
        txLogStore = new NoKCVSCache(storeManager.openDatabase(SYSTEM_TX_LOG_NAME));
        // Open global configuration
        KeyColumnValueStore systemConfigStore = storeManagerLocking.openDatabase(SYSTEM_PROPERTIES_STORE_NAME);
        KCVSConfigurationBuilder kcvsConfigurationBuilder = new KCVSConfigurationBuilder();
        systemConfig = kcvsConfigurationBuilder.buildGlobalConfiguration(new BackendOperation.TransactionalProvider() {

            @Override
            public StoreTransaction openTx() throws BackendException {
                return storeManagerLocking.beginTransaction(StandardBaseTransactionConfig.of(configuration.get(TIMESTAMP_PROVIDER), storeFeatures.getKeyConsistentTxConfig()));
            }

            @Override
            public void close() throws BackendException {
            // Do nothing, storeManager is closed explicitly by Backend
            }
        }, systemConfigStore, configuration);
        userConfig = kcvsConfigurationBuilder.buildConfiguration(new BackendOperation.TransactionalProvider() {

            @Override
            public StoreTransaction openTx() throws BackendException {
                return storeManagerLocking.beginTransaction(StandardBaseTransactionConfig.of(configuration.get(TIMESTAMP_PROVIDER)));
            }

            @Override
            public void close() throws BackendException {
            // Do nothing, storeManager is closed explicitly by Backend
            }
        }, systemConfigStore, USER_CONFIGURATION_IDENTIFIER, configuration);
    } catch (BackendException e) {
        throw new JanusGraphException("Could not initialize backend", e);
    }
}
Also used : ConsistentKeyIDAuthority(org.janusgraph.diskstorage.idmanagement.ConsistentKeyIDAuthority) KCVSConfigurationBuilder(org.janusgraph.diskstorage.configuration.backend.builder.KCVSConfigurationBuilder) KeyColumnValueStore(org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStore) NoKCVSCache(org.janusgraph.diskstorage.keycolumnvalue.cache.NoKCVSCache) ExpirationKCVSCache(org.janusgraph.diskstorage.keycolumnvalue.cache.ExpirationKCVSCache) JanusGraphException(org.janusgraph.core.JanusGraphException)

Aggregations

KCVSConfigurationBuilder (org.janusgraph.diskstorage.configuration.backend.builder.KCVSConfigurationBuilder)2 JanusGraphException (org.janusgraph.core.JanusGraphException)1 BasicConfiguration (org.janusgraph.diskstorage.configuration.BasicConfiguration)1 Configuration (org.janusgraph.diskstorage.configuration.Configuration)1 MergedConfiguration (org.janusgraph.diskstorage.configuration.MergedConfiguration)1 MixedConfiguration (org.janusgraph.diskstorage.configuration.MixedConfiguration)1 ModifiableConfiguration (org.janusgraph.diskstorage.configuration.ModifiableConfiguration)1 ReadConfiguration (org.janusgraph.diskstorage.configuration.ReadConfiguration)1 CommonsConfiguration (org.janusgraph.diskstorage.configuration.backend.CommonsConfiguration)1 ModifiableConfigurationBuilder (org.janusgraph.diskstorage.configuration.builder.ModifiableConfigurationBuilder)1 ReadConfigurationBuilder (org.janusgraph.diskstorage.configuration.builder.ReadConfigurationBuilder)1 ConsistentKeyIDAuthority (org.janusgraph.diskstorage.idmanagement.ConsistentKeyIDAuthority)1 KeyColumnValueStore (org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStore)1 KeyColumnValueStoreManager (org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStoreManager)1 StoreFeatures (org.janusgraph.diskstorage.keycolumnvalue.StoreFeatures)1 ExpirationKCVSCache (org.janusgraph.diskstorage.keycolumnvalue.cache.ExpirationKCVSCache)1 NoKCVSCache (org.janusgraph.diskstorage.keycolumnvalue.cache.NoKCVSCache)1 GraphDatabaseConfiguration (org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration)1