use of org.janusgraph.diskstorage.idmanagement.ConsistentKeyIDAuthority 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);
systemConfig = getGlobalConfiguration(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 = getConfiguration(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);
}
}
use of org.janusgraph.diskstorage.idmanagement.ConsistentKeyIDAuthority in project janusgraph by JanusGraph.
the class IDAuthorityTest method open.
public void open() throws BackendException {
manager = new KeyColumnValueStoreManager[CONCURRENCY];
idAuthorities = new IDAuthority[CONCURRENCY];
for (int i = 0; i < CONCURRENCY; i++) {
ModifiableConfiguration sc = StorageSetup.getConfig(baseStoreConfiguration.copy());
// sc.set(GraphDatabaseConfiguration.INSTANCE_RID_SHORT,(short)i);
sc.set(GraphDatabaseConfiguration.UNIQUE_INSTANCE_ID_SUFFIX, (short) i);
if (!sc.has(UNIQUE_INSTANCE_ID)) {
String uniqueGraphId = getOrGenerateUniqueInstanceId(sc);
log.debug("Setting unique instance id: {}", uniqueGraphId);
sc.set(UNIQUE_INSTANCE_ID, uniqueGraphId);
}
sc.set(GraphDatabaseConfiguration.CLUSTER_MAX_PARTITIONS, MAX_NUM_PARTITIONS);
manager[i] = openStorageManager();
StoreFeatures storeFeatures = manager[i].getFeatures();
KeyColumnValueStore idStore = manager[i].openDatabase("ids");
if (storeFeatures.isKeyConsistent())
idAuthorities[i] = new ConsistentKeyIDAuthority(idStore, manager[i], sc);
else
throw new IllegalArgumentException("Cannot open id store");
}
}
Aggregations