📄 environmentconfig.java
字号:
openFlags |= lockDown ? DbConstants.DB_LOCKDOWN : 0; openFlags |= isPrivate ? DbConstants.DB_PRIVATE : 0; openFlags |= register ? DbConstants.DB_REGISTER : 0; openFlags |= runRecovery ? DbConstants.DB_RECOVER : 0; openFlags |= runFatalRecovery ? DbConstants.DB_RECOVER_FATAL : 0; openFlags |= systemMemory ? DbConstants.DB_SYSTEM_MEM : 0; openFlags |= threaded ? DbConstants.DB_THREAD : 0; openFlags |= transactional ? DbConstants.DB_INIT_TXN : 0; openFlags |= useEnvironment ? DbConstants.DB_USE_ENVIRON : 0; openFlags |= useEnvironmentRoot ? DbConstants.DB_USE_ENVIRON_ROOT : 0; boolean succeeded = false; try { dbenv.open((home == null) ? null : home.toString(), openFlags, mode); succeeded = true; return dbenv; } finally { if (!succeeded) try { dbenv.close(0); } catch (Throwable t) { // Ignore it -- an exception is already in flight. } } } /* package */ DbEnv createEnvironment() throws DatabaseException { int createFlags = 0; if (rpcServer != null) createFlags |= DbConstants.DB_RPCCLIENT; final DbEnv dbenv = new DbEnv(createFlags); configureEnvironment(dbenv, DEFAULT); return dbenv; } /* package */ void configureEnvironment(final DbEnv dbenv, final EnvironmentConfig oldConfig) throws DatabaseException { if (errorHandler != oldConfig.errorHandler) dbenv.set_errcall(errorHandler); if (errorPrefix != oldConfig.errorPrefix && errorPrefix != null && !errorPrefix.equals(oldConfig.errorPrefix)) dbenv.set_errpfx(errorPrefix); if (errorStream != oldConfig.errorStream) dbenv.set_error_stream(errorStream); if (rpcServer != oldConfig.rpcServer || rpcClientTimeout != oldConfig.rpcClientTimeout || rpcServerTimeout != oldConfig.rpcServerTimeout) dbenv.set_rpc_server(rpcServer, rpcClientTimeout, rpcServerTimeout, 0); // We always set DB_TIME_NOTGRANTED in the Java API, because // LockNotGrantedException extends DeadlockException, so there's no // reason why an application would prefer one to the other. int onFlags = DbConstants.DB_TIME_NOTGRANTED; int offFlags = 0; if (cdbLockAllDatabases && !oldConfig.cdbLockAllDatabases) onFlags |= DbConstants.DB_CDB_ALLDB; if (!cdbLockAllDatabases && oldConfig.cdbLockAllDatabases) offFlags |= DbConstants.DB_CDB_ALLDB; if (directDatabaseIO && !oldConfig.directDatabaseIO) onFlags |= DbConstants.DB_DIRECT_DB; if (!directDatabaseIO && oldConfig.directDatabaseIO) offFlags |= DbConstants.DB_DIRECT_DB; if (directLogIO && !oldConfig.directLogIO) onFlags |= DbConstants.DB_DIRECT_LOG; if (!directLogIO && oldConfig.directLogIO) offFlags |= DbConstants.DB_DIRECT_LOG; if (dsyncDatabases && !oldConfig.dsyncDatabases) onFlags |= DbConstants.DB_DSYNC_DB; if (!dsyncDatabases && oldConfig.dsyncDatabases) offFlags |= DbConstants.DB_DSYNC_DB; if (dsyncLog && !oldConfig.dsyncLog) onFlags |= DbConstants.DB_DSYNC_LOG; if (!dsyncLog && oldConfig.dsyncLog) offFlags |= DbConstants.DB_DSYNC_LOG; if (initializeRegions && !oldConfig.initializeRegions) onFlags |= DbConstants.DB_REGION_INIT; if (!initializeRegions && oldConfig.initializeRegions) offFlags |= DbConstants.DB_REGION_INIT; if (logAutoRemove && !oldConfig.logAutoRemove) onFlags |= DbConstants.DB_LOG_AUTOREMOVE; if (!logAutoRemove && oldConfig.logAutoRemove) offFlags |= DbConstants.DB_LOG_AUTOREMOVE; if (logInMemory && !oldConfig.logInMemory) onFlags |= DbConstants.DB_LOG_INMEMORY; if (!logInMemory && oldConfig.logInMemory) offFlags |= DbConstants.DB_LOG_INMEMORY; if (multiversion && !oldConfig.multiversion) onFlags |= DbConstants.DB_MULTIVERSION; if (!multiversion && oldConfig.multiversion) offFlags |= DbConstants.DB_MULTIVERSION; if (noLocking && !oldConfig.noLocking) onFlags |= DbConstants.DB_NOLOCKING; if (!noLocking && oldConfig.noLocking) offFlags |= DbConstants.DB_NOLOCKING; if (noMMap && !oldConfig.noMMap) onFlags |= DbConstants.DB_NOMMAP; if (!noMMap && oldConfig.noMMap) offFlags |= DbConstants.DB_NOMMAP; if (noPanic && !oldConfig.noPanic) onFlags |= DbConstants.DB_NOPANIC; if (!noPanic && oldConfig.noPanic) offFlags |= DbConstants.DB_NOPANIC; if (overwrite && !oldConfig.overwrite) onFlags |= DbConstants.DB_OVERWRITE; if (!overwrite && oldConfig.overwrite) offFlags |= DbConstants.DB_OVERWRITE; if (txnNoSync && !oldConfig.txnNoSync) onFlags |= DbConstants.DB_TXN_NOSYNC; if (!txnNoSync && oldConfig.txnNoSync) offFlags |= DbConstants.DB_TXN_NOSYNC; if (txnNotDurable && !oldConfig.txnNotDurable) onFlags |= DbConstants.DB_TXN_NOT_DURABLE; if (!txnNotDurable && oldConfig.txnNotDurable) offFlags |= DbConstants.DB_TXN_NOT_DURABLE; if (txnSnapshot && !oldConfig.txnSnapshot) onFlags |= DbConstants.DB_TXN_SNAPSHOT; if (!txnSnapshot && oldConfig.txnSnapshot) offFlags |= DbConstants.DB_TXN_SNAPSHOT; if (txnWriteNoSync && !oldConfig.txnWriteNoSync) onFlags |= DbConstants.DB_TXN_WRITE_NOSYNC; if (!txnWriteNoSync && oldConfig.txnWriteNoSync) offFlags |= DbConstants.DB_TXN_WRITE_NOSYNC; if (yieldCPU && !oldConfig.yieldCPU) onFlags |= DbConstants.DB_YIELDCPU; if (!yieldCPU && oldConfig.yieldCPU) offFlags |= DbConstants.DB_YIELDCPU; if (onFlags != 0) dbenv.set_flags(onFlags, true); if (offFlags != 0) dbenv.set_flags(offFlags, false); /* Verbose flags */ if (verboseDeadlock && !oldConfig.verboseDeadlock) dbenv.set_verbose(DbConstants.DB_VERB_DEADLOCK, true); if (!verboseDeadlock && oldConfig.verboseDeadlock) dbenv.set_verbose(DbConstants.DB_VERB_DEADLOCK, false); if (verboseRecovery && !oldConfig.verboseRecovery) dbenv.set_verbose(DbConstants.DB_VERB_RECOVERY, true); if (!verboseRecovery && oldConfig.verboseRecovery) dbenv.set_verbose(DbConstants.DB_VERB_RECOVERY, false); if (verboseRegister && !oldConfig.verboseRegister) dbenv.set_verbose(DbConstants.DB_VERB_REGISTER, true); if (!verboseRegister && oldConfig.verboseRegister) dbenv.set_verbose(DbConstants.DB_VERB_REGISTER, false); if (verboseReplication && !oldConfig.verboseReplication) dbenv.set_verbose(DbConstants.DB_VERB_REPLICATION, true); if (!verboseReplication && oldConfig.verboseReplication) dbenv.set_verbose(DbConstants.DB_VERB_REPLICATION, false); if (verboseWaitsFor && !oldConfig.verboseWaitsFor) dbenv.set_verbose(DbConstants.DB_VERB_WAITSFOR, true); if (!verboseWaitsFor && oldConfig.verboseWaitsFor) dbenv.set_verbose(DbConstants.DB_VERB_WAITSFOR, false); /* Callbacks */ if (feedbackHandler != oldConfig.feedbackHandler) dbenv.set_feedback(feedbackHandler); if (logRecordHandler != oldConfig.logRecordHandler) dbenv.set_app_dispatch(logRecordHandler); if (eventHandler != oldConfig.eventHandler) dbenv.set_event_notify(eventHandler); if (messageHandler != oldConfig.messageHandler) dbenv.set_msgcall(messageHandler); if (panicHandler != oldConfig.panicHandler) dbenv.set_paniccall(panicHandler); if (replicationTransport != oldConfig.replicationTransport) dbenv.rep_set_transport(envid, replicationTransport); /* Other settings */ if (cacheSize != oldConfig.cacheSize || cacheCount != oldConfig.cacheCount) dbenv.set_cachesize(cacheSize, cacheCount); for (final java.util.Enumeration e = dataDirs.elements(); e.hasMoreElements();) { final java.io.File dir = (java.io.File)e.nextElement(); if (!oldConfig.dataDirs.contains(dir)) dbenv.set_data_dir(dir.toString()); } if (!lockConflictsEqual(lockConflicts, oldConfig.lockConflicts)) dbenv.set_lk_conflicts(lockConflicts); if (lockDetectMode != oldConfig.lockDetectMode) dbenv.set_lk_detect(lockDetectMode.getFlag()); if (maxLocks != oldConfig.maxLocks) dbenv.set_lk_max_locks(maxLocks); if (maxLockers != oldConfig.maxLockers) dbenv.set_lk_max_lockers(maxLockers); if (maxLockObjects != oldConfig.maxLockObjects) dbenv.set_lk_max_objects(maxLockObjects); if (maxLogFileSize != oldConfig.maxLogFileSize) dbenv.set_lg_max(maxLogFileSize); if (logBufferSize != oldConfig.logBufferSize) dbenv.set_lg_bsize(logBufferSize); if (logDirectory != oldConfig.logDirectory && logDirectory != null && !logDirectory.equals(oldConfig.logDirectory)) dbenv.set_lg_dir(logDirectory.toString()); if (logFileMode != oldConfig.logFileMode) dbenv.set_lg_filemode(logFileMode); if (logRegionSize != oldConfig.logRegionSize) dbenv.set_lg_regionmax(logRegionSize); if (maxOpenFiles != oldConfig.maxOpenFiles) dbenv.set_mp_max_openfd(maxOpenFiles); if (maxWrite != oldConfig.maxWrite || maxWriteSleep != oldConfig.maxWriteSleep) dbenv.set_mp_max_write(maxWrite, maxWriteSleep); if (messageStream != oldConfig.messageStream) dbenv.set_message_stream(messageStream); if (mmapSize != oldConfig.mmapSize) dbenv.set_mp_mmapsize(mmapSize); if (password != null) dbenv.set_encrypt(password, DbConstants.DB_ENCRYPT_AES); if (replicationLimit != oldConfig.replicationLimit) dbenv.rep_set_limit(replicationLimit); if (replicationRequestMin != oldConfig.replicationRequestMin || replicationRequestMax != oldConfig.replicationRequestMax) dbenv.set_rep_request(replicationRequestMin, replicationRequestMax); if (segmentId != oldConfig.segmentId) dbenv.set_shm_key(segmentId); if (mutexAlignment != oldConfig.mutexAlignment) dbenv.mutex_set_align(mutexAlignment); if (mutexIncrement != oldConfig.mutexIncrement) dbenv.mutex_set_increment(mutexIncrement); if (maxMutexes != oldConfig.maxMutexes) dbenv.mutex_set_max(maxMutexes); if (mutexTestAndSetSpins != oldConfig.mutexTestAndSetSpins) dbenv.mutex_set_tas_spins(mutexTestAndSetSpins); if (replicationNSites != oldConfig.replicationNSites) dbenv.rep_set_nsites(replicationNSites); if (replicationPriority != oldConfig.replicationPriority) dbenv.rep_set_priority(replicationPriority); if (lockTimeout != oldConfig.lockTimeout) dbenv.set_timeout(lockTimeout, DbConstants.DB_SET_LOCK_TIMEOUT); if (txnMaxActive != oldConfig.txnMaxActive) dbenv.set_tx_max(txnMaxActive); if (txnTimeout != oldConfig.txnTimeout) dbenv.set_timeout(txnTimeout, DbConstants.DB_SET_TXN_TIMEOUT); if (txnTimestamp != oldConfig.txnTimestamp && txnTimestamp != null && !txnTimestamp.equals(oldConfig.txnTimestamp)) dbenv.set_tx_timestamp(txnTimestamp); if (temporaryDirectory != oldConfig.temporaryDirectory && temporaryDirectory != null && !temporaryDirectory.equals(oldConfig.temporaryDirectory)) dbenv.set_tmp_dir(temporaryDirectory.toString()); if (repmgrAckPolicy != oldConfig.repmgrAckPolicy) dbenv.repmgr_set_ack_policy(repmgrAckPolicy.getId()); if (repmgrLocalSiteAddr != oldConfig.repmgrLocalSiteAddr) { dbenv.repmgr_set_local_site( repmgrLocalSiteAddr.host, repmgrLocalSiteAddr.port, 0); } for (java.util.Enumeration elems = repmgrRemoteSites.elements(); elems.hasMoreElements();) { ReplicationHostAddress nextAddr = (ReplicationHostAddress)elems.nextElement(); dbenv.repmgr_add_remote_site(nextAddr.host, nextAddr.port, nextAddr.isPeer ? DbConstants.DB_REPMGR_PEER : 0); } } /* package */ EnvironmentConfig(final DbEnv dbenv) throws DatabaseException { final int openFlags = dbenv.get_open_flags(); allowCreate = ((openFlags & DbConstants.DB_CREATE) != 0); initializeCache = ((openFlags & DbConstants.DB_INIT_MPOOL) != 0); initializeCDB = ((openFlags & DbConstants.DB_INIT_CDB) != 0); initializeLocking = ((openFlags & DbConstants.DB_INIT_LOCK) != 0); initializeLogging = ((openFlags & DbConstants.DB_INIT_LOG) != 0); initializeReplication = ((openFlags & DbConstants.DB_INIT_REP) != 0); joinEnvironment = ((openFlags & DbConstants.DB_JOINENV) != 0); lockDown = ((openFlags & DbConstants.DB_LOCKDOWN) != 0); isPrivate = ((openFlags & DbConstants.DB_PRIVATE) != 0); register = ((openFlags & DbConstants.DB_REGISTER) != 0); runRecovery = ((openFlags & DbConstants.DB_RECOVER) != 0); runFatalRecovery = ((openFlags & DbConstants.DB_RECOVER_FATAL) != 0); systemMemory = ((openFlags & DbConstants.DB_SYSTEM_MEM) != 0); threaded = ((openFlags & DbConstants.DB_THREAD) != 0); transactional = ((openFlags & DbConstants.DB_INIT_TXN) != 0); useEnvironment = ((openFlags & DbConstants.DB_USE_ENVIRON) != 0); useEnvironmentRoot = ((openFlags & DbConstants.DB_USE_ENVIRON_ROOT) != 0); final int envFlags = dbenv.get_flags(); cdbLockAllDatabases = ((envFlags & DbConstants.DB_CDB_ALLDB) != 0); directDatabaseIO = ((envFlags & DbConstants.DB_DIRECT_DB) != 0); directLogIO = ((envFlags & DbConstants.DB_DIRECT_LOG) != 0); dsyncDatabases = ((envFlags & DbConstants.DB_DSYNC_DB) != 0); dsyncLog = ((envFlags & DbConstants.DB_DSYNC_LOG) != 0); initializeRegions = ((envFlags & DbConstants.DB_REGION_INIT) != 0); logAutoRemove = ((envFlags & DbConstants.DB_LOG_AUTOREMOVE) != 0); logInMemory = ((envFlags & DbConstants.DB_LOG_INMEMORY) != 0); multiversion = ((envFlags & DbConstants.DB_MULTIVERSION) != 0); noLocking = ((envFlags & DbConstants.DB_NOLOCKING) != 0); noMMap = ((envFlags & DbConstants.DB_NOMMAP) != 0); noPanic = ((envFlags & DbConstants.DB_NOPANIC) != 0); overwrite = ((envFlags & DbConstants.DB_OVERWRITE) != 0); txnNoSync = ((envFlags & DbConstants.DB_TXN_NOSYNC) != 0); txnNotDurable = ((envFlags & DbConstants.DB_TXN_NOT_DURABLE) != 0); txnSnapshot = ((envFlags & DbConstants.DB_TXN_SNAPSHOT) != 0); txnWriteNoSync = ((envFlags & DbConstants.DB_TXN_WRITE_NOSYNC) != 0); yieldCPU = ((envFlags & DbConstants.DB_YIELDCPU) != 0); /* Verbose flags */ verboseDeadlock = dbenv.get_verbose(DbConstants.DB_VERB_DEADLOCK); verboseRecovery = dbenv.get_verbose(DbConstants.DB_VERB_RECOVERY); verboseRegister = dbenv.get_verbose(DbConstants.DB_VERB_REGISTER); verboseReplication = dbenv.get_verbose(DbConstants.DB_VERB_REPLICATION); verboseWaitsFor = dbenv.get_verbose(DbConstants.DB_VERB_WAITSFOR); /* Callbacks */ errorHandler = dbenv.get_errcall(); feedbackHandler = dbenv.get_feedback(); logRecordHandler = dbenv.get_app_dispatch(); eventHandler = dbenv.get_event_notify(); messageHandler = dbenv.get_msgcall(); panicHandler = dbenv.get_paniccall(); // XXX: replicationTransport and envid aren't available? /* Other settings */ if (initializeCache) { cacheSize = dbenv.get_cachesize(); cacheCount = dbenv.get_cachesize_ncache(); mmapSize = dbenv.get_mp_mmapsize(); maxOpenFiles = dbenv.get_mp_max_openfd(); maxWrite = dbenv.get_mp_max_write(); maxWriteSleep = dbenv.get_mp_max_write_sleep(); } String[] dataDirArray = dbenv.get_data_dirs(); if (dataDirArray == null) dataDirArray = new String[0]; dataDirs = new java.util.Vector(dataDirArray.length); dataDirs.setSize(dataDirArray.length); for (int i = 0; i < dataDirArray.length; i++) dataDirs.set(i, new java.io.File(dataDirArray[i])); errorPrefix = dbenv.get_errpfx(); errorStream = dbenv.get_error_stream(); if (initializeLocking) { lockConflicts = dbenv.get_lk_conflicts(); lockDetectMode = LockDetectMode.fromFlag(dbenv.get_lk_detect()); lockTimeout = dbenv.get_timeout(DbConstants.DB_SET_LOCK_TIMEOUT); maxLocks = dbenv.get_lk_max_locks(); maxLockers = dbenv.get_lk_max_lockers(); maxLockObjects = dbenv.get_lk_max_objects(); txnTimeout = dbenv.get_timeout(DbConstants.DB_SET_TXN_TIMEOUT); } else { lockConflicts = null; lockDetectMode = LockDetectMode.NONE; lockTimeout = 0L; maxLocks = 0; maxLockers = 0; maxLockObjects = 0; txnTimeout = 0L; } if (initializeLogging) { maxLogFileSize = dbenv.get_lg_max(); logBufferSize = dbenv.get_lg_bsize(); logDirectory = (dbenv.get_lg_dir() == null) ? null : new java.io.File(dbenv.get_lg_dir()); logFileMode = dbenv.get_lg_filemode(); logRegionSize = dbenv.get_lg_regionmax(); } else { maxLogFileSize = 0; logBufferSize = 0; logDirectory = null; logRegionSize = 0; } messageStream = dbenv.get_message_stream(); // XXX: intentional information loss? password = (dbenv.get_encrypt_flags() == 0) ? null : ""; if (initializeReplication) { replicationLimit = dbenv.rep_get_limit(); // XXX: no way to find out replicationRequest{Min,Max} } else { replicationLimit = 0L; replicationRequestMin = 0; replicationRequestMax = 0; } // XXX: no way to find RPC server? rpcServer = null; rpcClientTimeout = 0; rpcServerTimeout = 0; segmentId = dbenv.get_shm_key(); mutexAlignment = dbenv.mutex_get_align(); mutexIncrement = dbenv.mutex_get_increment(); maxMutexes = dbenv.mutex_get_max(); mutexTestAndSetSpins = dbenv.mutex_get_tas_spins(); replicationNSites = dbenv.rep_get_nsites(); replicationPriority = dbenv.rep_get_priority(); if (transactional) { txnMaxActive = dbenv.get_tx_max(); final long txnTimestampSeconds = dbenv.get_tx_timestamp(); if (txnTimestampSeconds != 0L) txnTimestamp = new java.util.Date(txnTimestampSeconds * 1000); else txnTimestamp = null; } else { txnMaxActive = 0; txnTimestamp = null; } temporaryDirectory = new java.io.File(dbenv.get_tmp_dir()); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -