private static void checkPageSizeAndRelatedParametersInGlobalConfiguration() { final int pageSize = OGlobalConfiguration.DISK_CACHE_PAGE_SIZE.getValueAsInteger() * 1024; final int freeListBoundary = OGlobalConfiguration.PAGINATED_STORAGE_LOWEST_FREELIST_BOUNDARY.getValueAsInteger() * 1024; final int maxKeySize = OGlobalConfiguration.SBTREE_MAX_KEY_SIZE.getValueAsInteger(); if (freeListBoundary > pageSize / 2) { throw new OStorageException("Value of parameter " + OGlobalConfiguration.DISK_CACHE_PAGE_SIZE.getKey() + " should be at least 2 times bigger than value of parameter " + OGlobalConfiguration.PAGINATED_STORAGE_LOWEST_FREELIST_BOUNDARY.getKey() + " but real values are :" + OGlobalConfiguration.DISK_CACHE_PAGE_SIZE.getKey() + " = " + pageSize + " , " + OGlobalConfiguration.PAGINATED_STORAGE_LOWEST_FREELIST_BOUNDARY.getKey() + " = " + freeListBoundary); } if (maxKeySize > pageSize / 4) { throw new OStorageException("Value of parameter " + OGlobalConfiguration.DISK_CACHE_PAGE_SIZE.getKey() + " should be at least 4 times bigger than value of parameter " + OGlobalConfiguration.SBTREE_MAX_KEY_SIZE.getKey() + " but real values are :" + OGlobalConfiguration.DISK_CACHE_PAGE_SIZE.getKey() + " = " + pageSize + " , " + OGlobalConfiguration.SBTREE_MAX_KEY_SIZE.getKey() + " = " + maxKeySize); } }
/** * Find the OGlobalConfiguration instance by the key. Key is case insensitive. * * @param iKey Key to find. It's case insensitive. * * @return OGlobalConfiguration instance if found, otherwise null */ public static OGlobalConfiguration findByKey(final String iKey) { for (OGlobalConfiguration v : values()) { if (v.getKey().equalsIgnoreCase(iKey)) return v; } return null; }
public String getConnectionStrategy() { Object val = getProperty(OGlobalConfiguration.CLIENT_CONNECTION_STRATEGY.getKey()); return val == null ? null : val.toString(); }
/** * @param config Global configuration parameter. * * @return Value of configuration parameter stored in this context as enumeration if such one exists, otherwise value stored in * passed in {@link OGlobalConfiguration} instance. * * @throws ClassCastException if stored value can not be casted and parsed from string to passed in enumeration class. * @throws IllegalArgumentException if value associated with configuration parameter is a string bug can not be converted to * instance of passed in enumeration class. */ public <T extends Enum<T>> T getValueAsEnum(final OGlobalConfiguration config, Class<T> enumType) { final Object value; if (this.config != null && this.config.containsKey(config.getKey())) { value = this.config.get(config.getKey()); } else { value = config.getValue(); } if (value == null) return null; if (enumType.isAssignableFrom(value.getClass())) { return enumType.cast(value); } else if (value instanceof String) { final String presentation = value.toString(); return Enum.valueOf(enumType, presentation); } else { throw new ClassCastException("Value " + value + " can not be cast to enumeration " + enumType.getSimpleName()); } }
private void bindPropertiesToContext(OContextConfiguration configuration, final Map<String, Object> iProperties) { final String connectionStrategy = iProperties != null ? (String) iProperties.get("connectionStrategy") : null; if (connectionStrategy != null) configuration.setValue(OGlobalConfiguration.CLIENT_CONNECTION_STRATEGY, connectionStrategy); final String compressionMethod = iProperties != null ? (String) iProperties.get(OGlobalConfiguration.STORAGE_COMPRESSION_METHOD.getKey().toLowerCase(Locale.ENGLISH)) : null; if (compressionMethod != null) // SAVE COMPRESSION METHOD IN CONFIGURATION configuration.setValue(OGlobalConfiguration.STORAGE_COMPRESSION_METHOD, compressionMethod); final String encryptionMethod = iProperties != null ? (String) iProperties.get(OGlobalConfiguration.STORAGE_ENCRYPTION_METHOD.getKey().toLowerCase(Locale.ENGLISH)) : null; if (encryptionMethod != null) // SAVE ENCRYPTION METHOD IN CONFIGURATION configuration.setValue(OGlobalConfiguration.STORAGE_ENCRYPTION_METHOD, encryptionMethod); final String encryptionKey = iProperties != null ? (String) iProperties.get(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey().toLowerCase(Locale.ENGLISH)) : null; if (encryptionKey != null) // SAVE ENCRYPTION KEY IN CONFIGURATION configuration.setValue(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY, encryptionKey); }
private SecretKey createKey(String base64EncodedKey) { if (base64EncodedKey == null) { throw new OSecurityException(format(MISSING_KEY_ERROR, OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey())); } try { final byte[] keyBytes = Base64.getDecoder().decode(base64EncodedKey.getBytes()); validateKeySize(keyBytes.length); return new SecretKeySpec(keyBytes, ALGORITHM_NAME); } catch (IllegalArgumentException e) { throw OException.wrapException(new OInvalidStorageEncryptionKeyException(INVALID_KEY_ERROR), e); } }
public void setConnectionStrategy(final String connectionStrategy) { this.setProperty(OGlobalConfiguration.CLIENT_CONNECTION_STRATEGY.getKey(),connectionStrategy); this.settings.setConnectionStrategy(connectionStrategy); }
/** * Changes the configuration values in one shot by passing a Map of values. Keys can be the Java ENUM names or the string * representation of configuration values */ public static void setConfiguration(final Map<String, Object> iConfig) { for (Entry<String, Object> config : iConfig.entrySet()) { for (OGlobalConfiguration v : values()) { if (v.getKey().equals(config.getKey())) { v.setValue(config.getValue()); break; } else if (v.name().equals(config.getKey())) { v.setValue(config.getValue()); break; } } } }
public OEncryption configure(final String iOptions) { initialized = false; if (iOptions == null) throw new OSecurityException( "AES encryption has been selected, but no key was found. Please configure it by passing the key as property at database create/open. The property key is: '" + OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey() + "'"); try { final byte[] key = Base64.getDecoder().decode(iOptions); theKey = new SecretKeySpec(key, ALGORITHM_NAME); // AES } catch (Exception e) { throw OException.wrapException(new OInvalidStorageEncryptionKeyException( "Cannot initialize AES encryption with current key. Assure the key is a BASE64 - 128 oe 256 bits long"), e); } this.initialized = true; return this; }
public OEncryption configure(final String iOptions) { initialized = false; if (iOptions == null) throw new OSecurityException( "DES encryption has been selected, but no key was found. Please configure it by passing the key as property at database create/open. The property key is: '" + OGlobalConfiguration.STORAGE_ENCRYPTION_KEY.getKey() + "'"); try { final byte[] key = Base64.getDecoder().decode(iOptions); final DESKeySpec desKeySpec = new DESKeySpec(key); final SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(ALGORITHM_NAME); theKey = keyFactory.generateSecret(desKeySpec); cipher = Cipher.getInstance(TRANSFORMATION); } catch (Exception e) { throw OException.wrapException(new OInvalidStorageEncryptionKeyException( "Cannot initialize DES encryption with current key. Assure the key is a BASE64 - 64 bits long"), e); } this.initialized = true; return this; }
private void checkPageSizeAndRelatedParameters() { final int pageSize = OGlobalConfiguration.DISK_CACHE_PAGE_SIZE.getValueAsInteger() * 1024; final int freeListBoundary = OGlobalConfiguration.PAGINATED_STORAGE_LOWEST_FREELIST_BOUNDARY.getValueAsInteger() * 1024; final int maxKeySize = OGlobalConfiguration.SBTREE_MAX_KEY_SIZE.getValueAsInteger(); if (configuration.getPageSize() != -1 && configuration.getPageSize() != pageSize) { throw new OStorageException( "Storage is created with value of " + OGlobalConfiguration.DISK_CACHE_PAGE_SIZE.getKey() + " parameter equal to " + configuration.getPageSize() + " but current value is " + pageSize); } if (configuration.getFreeListBoundary() != -1 && configuration.getFreeListBoundary() != freeListBoundary) { throw new OStorageException( "Storage is created with value of " + OGlobalConfiguration.PAGINATED_STORAGE_LOWEST_FREELIST_BOUNDARY.getKey() + " parameter equal to " + configuration.getFreeListBoundary() + " but current value is " + freeListBoundary); } if (configuration.getMaxKeySize() != -1 && configuration.getMaxKeySize() != maxKeySize) { throw new OStorageException( "Storage is created with value of " + OGlobalConfiguration.SBTREE_MAX_KEY_SIZE.getKey() + " parameter equal to " + configuration.getMaxKeySize() + " but current value is " + maxKeySize); } }
public static void unsubscribe(Integer id, ODatabaseInternal db) { if (Boolean.FALSE.equals(db.getConfiguration().getValue(QUERY_LIVE_SUPPORT))) { OLogManager.instance().warn(db, "Live query support is disabled impossible to unsubscribe a listener, set '%s' to true for enable the live query support", QUERY_LIVE_SUPPORT.getKey()); return; } try { OLiveQueryOps ops = getOpsReference(db); synchronized (ops.threadLock) { ops.unsubscribe(id); } } catch (Exception e) { OLogManager.instance().warn(OLiveQueryHookV2.class, "Error on unsubscribing client", e); } }
public static void unsubscribe(Integer id, ODatabaseInternal db) { if (Boolean.FALSE.equals(db.getConfiguration().getValue(QUERY_LIVE_SUPPORT))) { OLogManager.instance().warn(db, "Live query support is disabled impossible to unsubscribe a listener, set '%s' to true for enable the live query support", QUERY_LIVE_SUPPORT.getKey()); return; } try { OLiveQueryOps ops = getOpsReference(db); synchronized (ops.threadLock) { ops.queueThread.unsubscribe(id); } } catch (Exception e) { OLogManager.instance().warn(OLiveQueryHook.class, "Error on unsubscribing client", e); } }
OLogManager.instance().warn(this, "Maximum amount of pinned pages is reached, given page " + cacheEntry + " will not be marked as pinned which may lead to performance degradation. You may consider to increase the percent of pinned pages " + "by changing the property '" + OGlobalConfiguration.DISK_CACHE_PINNED_PAGES.getKey() + "'");
public static Integer subscribe(Integer token, OLiveQueryListenerV2 iListener, ODatabaseInternal db) { if (Boolean.FALSE.equals(db.getConfiguration().getValue(QUERY_LIVE_SUPPORT))) { OLogManager.instance().warn(db, "Live query support is disabled impossible to subscribe a listener, set '%s' to true for enable the live query support", QUERY_LIVE_SUPPORT.getKey()); return -1; } OLiveQueryOps ops = getOpsReference(db); synchronized (ops.threadLock) { if (!ops.queueThread.isAlive()) { ops.queueThread = ops.queueThread.clone(); ops.queueThread.start(); } } return ops.subscribe(token, iListener); }
public static Integer subscribe(Integer token, OLiveQueryListener iListener, ODatabaseInternal db) { if (Boolean.FALSE.equals(db.getConfiguration().getValue(QUERY_LIVE_SUPPORT))) { OLogManager.instance().warn(db, "Live query support is disabled impossible to subscribe a listener, set '%s' to true for enable the live query support", QUERY_LIVE_SUPPORT.getKey()); return -1; } OLiveQueryOps ops = getOpsReference(db); synchronized (ops.threadLock) { if (!ops.queueThread.isAlive()) { ops.queueThread = ops.queueThread.clone(); ops.queueThread.start(); } } return ops.queueThread.subscribe(token, iListener); }
@ConsoleCommand(description = "Return all the configuration values") public void config() throws IOException { if (orientDB != null && !OrientDBInternal.extract(orientDB).isEmbedded()) { final Map<String, String> values = ((OrientDBRemote) OrientDBInternal.extract(orientDB)) .getGlobalConfigurations(currentDatabaseUserName, currentDatabaseUserPassword); message("\nREMOTE SERVER CONFIGURATION"); final List<ODocument> resultSet = new ArrayList<ODocument>(); for (Entry<String, String> p : values.entrySet()) { final ODocument row = new ODocument(); resultSet.add(row); row.field("NAME", p.getKey()); row.field("VALUE", p.getValue()); } final OTableFormatter formatter = new OTableFormatter(this); formatter.writeRecords(resultSet, -1); } else { // LOCAL STORAGE message("\nLOCAL SERVER CONFIGURATION"); final List<ODocument> resultSet = new ArrayList<ODocument>(); for (OGlobalConfiguration cfg : OGlobalConfiguration.values()) { final ODocument row = new ODocument(); resultSet.add(row); row.field("NAME", cfg.getKey()); row.field("VALUE", (Object) cfg.getValue()); } final OTableFormatter formatter = new OTableFormatter(this); formatter.writeRecords(resultSet, -1); } message("\n"); }
private void evict() { final long start = Orient.instance().getProfiler().startChrono(); final int initialSize = lruList.size(); int closedFiles = 0; while (lruList.size() > openLimit) { //we may only close items in open state so we "peek" them first Iterator<OClosableEntry<K, V>> iterator = lruList.iterator(); boolean entryClosed = false; while (iterator.hasNext()) { OClosableEntry<K, V> entry = iterator.next(); if (entry.makeClosed()) { closedFiles++; iterator.remove(); entryClosed = true; countClosedFiles(); break; } } //there are no items in open state stop eviction if (!entryClosed) break; } if (closedFiles > 0) { OLogManager.instance().debug(this, "Reached maximum of opened files %d (max=%d), closed %d files. Consider to raise this limit by increasing the global setting '%s' and the OS limit on opened files per processor", initialSize, openLimit, closedFiles, OGlobalConfiguration.OPEN_FILES_LIMIT.getKey()); } Orient.instance().getProfiler() .stopChrono("disk.closeFiles", "Close the opened files because reached the configured limit", start); }