📄 env.java
字号:
transactionManager = null; storeManager.shutdown(); storeManager = null; userManager.shutdown(); userManager = null; classManager.shutdown(); classManager = null; keyGenerator.shutdown(); keyGenerator = null; garbageCollector.shutdown(); garbageCollector = null; storeSetup(); components = null; logWriter.newEntry(this, "Halted.", LogWriter.INFO); theEnv = null; } catch (Exception e) { fatalError(null, "Env.shutdown(): " + e.toString(), e); } } public void startExternalEventProcessing() throws Exception { try { invokeServer = new InvokeServer(this, portNum()); invokeServer.startup(); invokeServer.accept(); logWriter.newEntry(this, "external event processing started", LogWriter.INFO); } catch (Exception e) { logWriter.newEntry(this, "Client port (" + portNum() + ") or admin port (" + adminPortNum() + ") are already in use.", e, LogWriter.ERROR); throw e; } } public void startDeadlockRecognition() { logWriter.newEntry(this, "deadlock recognition started", LogWriter.INFO); deadlockThread = new DeadlockThread(3000, transactionManager); deadlockThread.setPriority(DEADLOCK_THREAD_PRIORITY); deadlockThread.setDaemon(true); deadlockThread.start(); } /** * Initialize the setup (state and config) of this server environment. When * searching specific property look in setup file first, then in the * properties file, then use defaults, then use System properties. */ protected void initSetup() throws Exception { Setup defaults = new Setup(this); defaults.fillWithOzoneDefaults(); FileInputStream configIn = new FileInputStream(new File(databaseDir, CONFIG_FILE)); FileInputStream stateIn = new FileInputStream(new File(databaseDir, STATE_FILE)); try { config = new Setup(this, defaults); config.load(configIn); config.addProperties(System.getProperties(), "ozoneDB."); config.addProperties(System.getProperties(), "org.ozoneDB."); //config.print( System.out, "ozoneDB.", " " ); // config.addObserver( this ); state = new Setup(this); state.load(stateIn); // state.addObserver( this ); } finally { configIn.close(); stateIn.close(); } } public boolean isComponentStateChanged() { boolean hasChanged = false; DxIterator it = components.iterator(); while (it.next() != null) { ServerComponent component = (ServerComponent) it.object(); if (component.hasChanged()) { hasChanged = true; } } return hasChanged; } /** * Save the setup (state and config) of the current server environment. */ protected synchronized void storeSetup() { logWriter.newEntry(this, "storeSetup()... ", LogWriter.DEBUG); try { // having all components updating their properties DxIterator it = components.iterator(); while (it.next() != null) { ServerComponent component = (ServerComponent) it.object(); if (component.hasChanged()) { logWriter.newEntry(this, " changed component: " + component, LogWriter.DEBUG); component.save(); component.clearChanged(); } } // actually save properties to disk OutputStream stateOut = new BufferedOutputStream(new FileOutputStream(new File(databaseDir, STATE_FILE))); OutputStream configOut = new BufferedOutputStream(new FileOutputStream(new File(databaseDir, CONFIG_FILE))); try { // save state state.store(stateOut, "Ozone Server State File.\n#Do not edit!"); // save config StringBuffer head = new StringBuffer(1024); head.append("Ozone Server Config File.\n"); head.append("#\n"); head.append("# Do not use comments. This file will be overwritten,\n"); head.append("# if the config changes. See the ozone documentation\n"); head.append("# for details about the properties and their values.\n"); head.append("#\n"); head.append("\n"); head.append("# The below are not set to a default value so they are shown here as exmples \n"); head.append("# of what can be set, see the configuration docs for details \n"); head.append("# "+ Setup.TOTAL_MEMORY + "=16777216" +"\n"); head.append("# "+ Setup.MIN_FREE_MEMORY + "=4194304" +"\n"); config.store(configOut, head.toString()); } finally { stateOut.close(); configOut.close(); } } catch (Exception e) { fatalError(this, "Unable to store server state.", e); } } /** * Initialize server logging. There are two LogTargets: stdout and file. * Which log messages are written to which target is specified in the * config file. If the server runs in debug mode, debug * messages are written to each target. * If debugLevelName is set to null the setting from the config.properties file is used */ protected void initLogs(String debugLevelName) throws Exception { if (debugLevelName == null) { String defaultLevel = OzoneDebugLevel.INFO_STR; debugLevelName = config.getProperty(Setup.LOG_LEVEL, defaultLevel); } System.out.println("logging level set to " + debugLevelName); logWriter = new LogWriterLog4JImpl(databaseDir, OzoneDebugLevel.toLevel(debugLevelName)); } /** * Fires an error message and exits the VM */ public void fatalError(Object sender, String msg, Exception e) { logWriter.newEntry(sender, msg, e, LogWriter.ERROR); // FIXME: shutdown??? if (theEnv != null) { theEnv.shutdown(); } System.exit(1); } public String getDatabaseDir() { return databaseDir.getAbsolutePath() + File.separator; } public int dbID() { return config.intProperty(Setup.DB_ID, -1); } public int portNum() { return config.intProperty(Setup.PORT, -1); } public int adminPortNum() { return config.intProperty(Setup.ADMIN_PORT, -1); } /** * Factory method to create or re-use a DR object. */ public DeadlockRecognition deadlockRecognition() { if (dr == null) { dr = new EdgeChasing(this); } return dr; } /** * Initialize the internal memory counter so that freeMemory() returns * correct results. */ protected void calcMemory() { Runtime rt = Runtime.getRuntime(); // suggested by Leo, might get cluster caching to work again totalMemory = config.longProperty(Setup.TOTAL_MEMORY, -1); //long totalMemory = config.longProperty(Setup.TOTAL_MEMORY, -1); /* Computing totalMemory this way is bad. The reason is, that the reserved VM memory is increased to maximum. This is not bad itself (despite the long startup time induced due to swapout required to get to maximum possible memory). It is bad, that after reaching maximum memory, the JavaVM thinks that all that memory once reached is memory to be used. But because this is only virtual memory, the JavaVM thus creates massive swapping on using all the available memory, scattering all memory accesses across the reserved memory area. If the reserved memory area is smaller (as this is usually the case after startup of a Java application), less real RAM is required, less swapping will occur, with the same application running. Because the behaviour is bad, we only revert to it if we do not get any value set by the user for total memory. */ if (totalMemory < 0) { logWriter.newEntry(this, "checking memory... ", LogWriter.INFO); try { DxBag bag = new DxArrayBag(); for (; ;) { bag.add(new byte[100000]); } } catch (OutOfMemoryError e) { totalMemory = rt.totalMemory(); } } long absoluteMinimumFreeMemoryRequest = config.longProperty(Setup.MIN_FREE_MEMORY, -1); if (absoluteMinimumFreeMemoryRequest < 0) { keepMemory = Math.min(4000000L, totalMemory / 10); } else { keepMemory = absoluteMinimumFreeMemoryRequest; } rt.gc(); logWriter.newEntry(this, " total: " + totalMemory, LogWriter.INFO); logWriter.newEntry(this, " free : " + rt.freeMemory(), LogWriter.INFO); logWriter.newEntry(this, " keep : " + keepMemory, LogWriter.INFO); } /** * Return the amount of *total* free memory in the system. The results * returned by Runtime.freeMemory() may change overtime and so its * useless for ozone. */ public long freeMemory() { Runtime rt = Runtime.getRuntime(); long hiddenMemory = totalMemory - rt.totalMemory(); // keep xMB free at least return Math.max(rt.freeMemory() + hiddenMemory - keepMemory, 0); } public LogWriter getLogWriter() { return logWriter; } public TransactionManager getTransactionManager() { return transactionManager; } public Setup getState() { return state; } public InvokeServer getInvokeServer() { return invokeServer; } public StoreManager getStoreManager() { return storeManager; } public UserManager getUserManager() { return userManager; } public GarbageCollector getGarbageCollector() { return garbageCollector; } public LocalClientTracker getLocalClientTracker() { return localClientTracker; } public OzoneInterface getDatabase() { return database; }}// :indentSize=4:tabSize=4:noTabs=true:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -