private void createRepEnvInfo(String sleepTime) throws Throwable { /* * Set a large buffer size and disable the checkpointing, so the * data in the buffer can only be flushed by the LogFlushTask. */ EnvironmentConfig envConfig = RepTestUtils.createEnvConfig(Durability.COMMIT_NO_SYNC); envConfig.setConfigParam(EnvironmentParams.MAX_MEMORY.getName(), "20000000"); envConfig.setConfigParam(EnvironmentParams.LOG_MEM_SIZE.getName(), "120000000"); envConfig.setConfigParam(EnvironmentParams.NUM_LOG_BUFFERS.getName(), "4"); envConfig.setConfigParam(EnvironmentConfig.ENV_RUN_CHECKPOINTER, "false"); /* Configure the log flush task. */ ReplicationConfig repConfig = new ReplicationConfig(); repConfig.setConfigParam(ReplicationConfig.LOG_FLUSH_TASK_INTERVAL, sleepTime); repEnvInfo = RepTestUtils.setupEnvInfos(envRoot, 3, envConfig, repConfig); }
/** Initialize at construction time and when the cache is resized. */ private void reset(DbConfigManager configManager) throws DatabaseException { /* * Calculate the total memory allotted to JE. * 1. If je.maxMemory is specified, use that. Check that it's * not more than the jvm memory. * 2. Otherwise, take je.maxMemoryPercent * JVM max memory. */ long newMaxMemory = configManager.getLong(EnvironmentParams.MAX_MEMORY); long jvmMemory = getRuntimeMaxMemory(); if (newMaxMemory != 0) { /* Application specified a cache size number, validate it. */ if (jvmMemory < newMaxMemory) { throw new IllegalArgumentException( EnvironmentParams.MAX_MEMORY.getName() + " has a value of " + newMaxMemory + " but the JVM is only configured for " + jvmMemory + ". Consider using je.maxMemoryPercent."); } if (newMaxMemory < MIN_MAX_MEMORY_SIZE) { throw new IllegalArgumentException( EnvironmentParams.MAX_MEMORY.getName() + " is " + newMaxMemory + " which is less than the minimum: " + MIN_MAX_MEMORY_SIZE); } } else { /* * When no explicit cache size is specified and the JVM memory size * is unknown, assume a default sized (64 MB) heap. This produces * a reasonable cache size when no heap size is known. */ if (jvmMemory == Long.MAX_VALUE) { jvmMemory = N_64MB; } /* Use the configured percentage of the JVM memory size. */ int maxMemoryPercent = configManager.getInt(EnvironmentParams.MAX_MEMORY_PERCENT); newMaxMemory = (maxMemoryPercent * jvmMemory) / 100; } /* * Calculate the memory budget for log buffering. If the LOG_MEM_SIZE * parameter is not set, start by using 7% (1/16th) of the cache * size. If it is set, use that explicit setting. * * No point in having more log buffers than the maximum size. If * this starting point results in overly large log buffers, * reduce the log buffer budget again. */ long newLogBufferBudget = configManager.getLong(EnvironmentParams.LOG_MEM_SIZE); if (newLogBufferBudget == 0) { newLogBufferBudget = newMaxMemory >> 4; } else if (newLogBufferBudget > newMaxMemory / 2) { newLogBufferBudget = newMaxMemory / 2; } /* * We have a first pass at the log buffer budget. See what * size log buffers result. Don't let them be too big, it would * be a waste. */ int numBuffers = configManager.getInt(EnvironmentParams.NUM_LOG_BUFFERS); long startingBufferSize = newLogBufferBudget / numBuffers; int logBufferSize = configManager.getInt(EnvironmentParams.LOG_BUFFER_MAX_SIZE); if (startingBufferSize > logBufferSize) { startingBufferSize = logBufferSize; newLogBufferBudget = numBuffers * startingBufferSize; } else if (startingBufferSize < EnvironmentParams.MIN_LOG_BUFFER_SIZE) { startingBufferSize = EnvironmentParams.MIN_LOG_BUFFER_SIZE; newLogBufferBudget = numBuffers * startingBufferSize; } long newCriticalThreshold = (newMaxMemory * envImpl.getConfigManager().getInt(EnvironmentParams.EVICTOR_CRITICAL_PERCENTAGE)) / 100; long newTrackerBudget = (newMaxMemory * envImpl .getConfigManager() .getInt(EnvironmentParams.CLEANER_DETAIL_MAX_MEMORY_PERCENTAGE)) / 100; /* * If all has gone well, update the budget fields. Once the log buffer * budget is determined, the remainder of the memory is left for tree * nodes. */ maxMemory = newMaxMemory; criticalThreshold = newCriticalThreshold; logBufferBudget = newLogBufferBudget; trackerBudget = true ? newTrackerBudget : newMaxMemory; cacheBudget = newMaxMemory - newLogBufferBudget; nLockTables = configManager.getInt(EnvironmentParams.N_LOCK_TABLES); lockMemoryUsage = new long[nLockTables]; }