📄 rawstore.java
字号:
public void checkpoint() throws StandardException { logFactory.checkpoint(this, dataFactory, xactFactory, false); } public void freeze() throws StandardException { logFactory.checkpoint(this, dataFactory, xactFactory, true); dataFactory.freezePersistentStore(); logFactory.freezePersistentStore(); } public void unfreeze() throws StandardException { logFactory.unfreezePersistentStore(); dataFactory.unfreezePersistentStore(); } public void backup(String backupDir) throws StandardException { if (backupDir == null || backupDir.equals("")) { throw StandardException.newException( SQLState.RAWSTORE_CANNOT_CREATE_BACKUP_DIRECTORY, (File)null); } // in case this is an URL form String backupDirURL = null; try { URL url = new URL(backupDir); backupDirURL = url.getFile(); } catch (MalformedURLException ex) {} if (backupDirURL != null) backupDir = backupDirURL; backup(new File(backupDir)); } public synchronized void backup(File backupDir) throws StandardException { if (!privExists(backupDir)) { if (!privMkdirs(backupDir)) { throw StandardException.newException( SQLState.RAWSTORE_CANNOT_CREATE_BACKUP_DIRECTORY, (File) backupDir); } } else { if (!privIsDirectory(backupDir)) { throw StandardException.newException( SQLState.RAWSTORE_CANNOT_BACKUP_TO_NONDIRECTORY, (File) backupDir); } } boolean error = true; boolean renamed = false; boolean renameFailed = false; File oldbackup = null; File backupcopy = null; OutputStreamWriter historyFile = null; LogInstant backupInstant = logFactory.getFirstUnflushedInstant(); try { // first figure out our name StorageFile dbase = storageFactory.newStorageFile( null); // The database directory String canonicalDbName = storageFactory.getCanonicalName(); int lastSep = canonicalDbName.lastIndexOf( storageFactory.getSeparator()); String dbname = canonicalDbName.substring( lastSep + 1); // append to end of history file historyFile = privFileWriter( storageFactory.newStorageFile( BACKUP_HISTORY), true); logHistory(historyFile, MessageService.getTextMessage( MessageId.STORE_BACKUP_STARTED, canonicalDbName)); // if a backup copy of this database already exists, backupcopy = new File(backupDir, dbname); if (privExists(backupcopy)) { // first make a backup of the backup oldbackup = new File(backupDir, dbname+".OLD"); if (privExists(oldbackup)) { if (privIsDirectory(oldbackup)) privRemoveDirectory(oldbackup); else privDelete(oldbackup); } if (!privRenameTo(backupcopy,oldbackup)) { renameFailed = true; throw StandardException.newException( SQLState.RAWSTORE_ERROR_RENAMING_FILE, backupcopy, oldbackup, (Throwable)null); } else { logHistory( historyFile, MessageService.getTextMessage( MessageId.STORE_MOVED_BACKUP, backupcopy.getCanonicalPath(), oldbackup.getCanonicalPath())); renamed = true; } } // checkpoint the database and freeze it freeze(); // copy everything from the dataDirectory to the // backup directory (except temp files) if (!privCopyDirectory(dbase, backupcopy, (byte[])null, BACKUP_FILTER)) { throw StandardException.newException( SQLState.RAWSTORE_ERROR_COPYING_FILE, dbase, backupcopy, (Throwable)null); } logHistory(historyFile, MessageService.getTextMessage( MessageId.STORE_COPIED_DB_DIR, canonicalDbName, backupcopy.getCanonicalPath())); StorageFile logdir = logFactory.getLogDirectory(); // munge service.properties file if necessary StorageFile defaultLogDir = storageFactory.newStorageFile( LogFactory.LOG_DIRECTORY_NAME); if (!logdir.equals(defaultLogDir)) { // Read in property from service.properties file, remove // logDevice from it, then write it out again. try { String name = Monitor.getMonitor().getServiceName(this); PersistentService ps = Monitor.getMonitor().getServiceType(this); String fullName = ps.getCanonicalServiceName(name); Properties prop = ps.getServiceProperties(fullName, (Properties)null); prop.remove(Attribute.LOG_DEVICE); if (SanityManager.DEBUG) SanityManager.ASSERT(prop.getProperty(Attribute.LOG_DEVICE) == null, "cannot get rid of logDevice property"); ps.saveServiceProperties( backupcopy.getCanonicalPath(), prop, true); logHistory(historyFile, MessageService.getTextMessage( MessageId.STORE_EDITED_SERVICEPROPS)); } catch(StandardException se) { logHistory(historyFile, MessageService.getTextMessage( MessageId.STORE_ERROR_EDIT_SERVICEPROPS) + se); return; // skip the rest and let finally block clean up } } File logBackup = new File(backupcopy, LogFactory.LOG_DIRECTORY_NAME); // this is wierd, delete it if (privExists(logBackup)) { privRemoveDirectory(logBackup); } //Create the log directory if (!privMkdirs(logBackup)) { throw StandardException.newException( SQLState.RAWSTORE_CANNOT_CREATE_BACKUP_DIRECTORY, (File) logBackup); } // copy the log to the backup location if(!logFactory.copyActiveLogFiles(logBackup)) { throw StandardException.newException( SQLState.RAWSTORE_ERROR_COPYING_FILE, logdir, logBackup, (Throwable)null); } logHistory(historyFile, MessageService.getTextMessage( MessageId.STORE_COPIED_LOG, logdir.getCanonicalPath(), logBackup.getCanonicalPath())); error = false; } catch (IOException ioe) { throw StandardException.newException( SQLState.RAWSTORE_UNEXPECTED_EXCEPTION, ioe); } finally { // unfreeze db ASAP unfreeze(); try { if (error) { // remove the half backed up copy // unless the error occured during rename process; // inwhich case 'backupcopy' refers to the previous backup // not an half backed one. if(!renameFailed) privRemoveDirectory(backupcopy); if (renamed) // recover the old backup privRenameTo(oldbackup,backupcopy); logHistory(historyFile, MessageService.getTextMessage( MessageId.STORE_BACKUP_ABORTED)); } else { // success, remove the old backup copy if (renamed && privExists(oldbackup)) { // get rid of the old backup privRemoveDirectory(oldbackup); logHistory(historyFile, MessageService.getTextMessage( MessageId.STORE_REMOVED_BACKUP, oldbackup.getCanonicalPath())); } logHistory(historyFile, MessageService.getTextMessage( MessageId.STORE_BACKUP_COMPLETED, backupInstant)); } historyFile.close(); } catch (IOException ioe) { try { historyFile.close(); } catch (IOException ioe2){}; throw StandardException.newException( SQLState.RAWSTORE_UNEXPECTED_EXCEPTION, ioe); } } } public void backupAndEnableLogArchiveMode(String backupDir,boolean deleteOnlineArchivedLogFiles) throws StandardException { enableLogArchiveMode(); backup(backupDir); //After successful backup delete the archived log files //that are not necessary to do a roll-forward recovery //from this backup if requested. if(deleteOnlineArchivedLogFiles) { logFactory.deleteOnlineArchivedLogFiles(); } } public void backupAndEnableLogArchiveMode(File backupDir,boolean deleteOnlineArchivedLogFiles) throws StandardException { enableLogArchiveMode(); backup(backupDir); //After successful backup delete the archived log files //that are not necessary to do a roll-forward recovery //from this backup if requested. if(deleteOnlineArchivedLogFiles) { logFactory.deleteOnlineArchivedLogFiles(); } } private void enableLogArchiveMode() throws StandardException { logFactory.enableLogArchiveMode(); } public void disableLogArchiveMode(boolean deleteOnlineArchivedLogFiles) throws StandardException { logFactory.disableLogArchiveMode(); if(deleteOnlineArchivedLogFiles) { logFactory.deleteOnlineArchivedLogFiles(); } } //copies the files from the backup that does not need //any special handling like jars. private void restoreRemainingFromBackup(String backupPath) throws StandardException { /** *copy the files from the backup except the ones that we already *copied in the boot methods(like log directory and data segments) *AND Service.properties file which we create last to *indicate the end of copy from backup. */ File backuploc = new File(backupPath); String[] fromList = privList(backuploc); for(int i =0 ; i < fromList.length ; i++) { StorageFile toFile = storageFactory.newStorageFile( fromList[i]); if(privExists(toFile) || fromList[i].equals(PersistentService.PROPERTIES_NAME)){ continue; } File fromFile = new File(backuploc, fromList[i]); if(privIsDirectory(fromFile)) { if (!privCopyDirectory(fromFile, toFile)){ throw StandardException.newException( SQLState.UNABLE_TO_COPY_FILE_FROM_BACKUP, fromFile, toFile); } }else{ if (!privCopyFile(fromFile, toFile)){ throw StandardException.newException( SQLState.UNABLE_TO_COPY_FILE_FROM_BACKUP, fromFile, toFile); } } } } public void idle() throws StandardException { dataFactory.idle(); } public TransactionInfo[] getTransactionInfo() { return xactFactory.getTransactionInfo(); } public ScanHandle openFlushedScan(DatabaseInstant start, int groupsIWant) throws StandardException { return logFactory.openFlushedScan(start,groupsIWant); } public DaemonService getDaemon() { return rawStoreDaemon; } public void createFinished() throws StandardException { xactFactory.createFinished(); dataFactory.createFinished(); } /** * Get JBMS properties relavent to raw store * @exception StandardException Standard Cloudscape Error Policy */ public void getRawStoreProperties(PersistentSet set) throws StandardException { logFactory.getLogFactoryProperties(set); } /* ** backup restore */ /** Freeze persistent store. Reads can still happen, only cannot write. @exception StandardException Standard Cloudscape Error Policy */ public void freezePersistentStore() throws StandardException { // do a checkpoint to get the persistent store up to date. logFactory.checkpoint(this, dataFactory, xactFactory,true); logFactory.freezePersistentStore(); } /** Freeze persistent store. Reads can still happen, only cannot write. @exception StandardException Standard Cloudscape Error Policy */ public void unfreezePersistentStore() throws StandardException { logFactory.unfreezePersistentStore(); } /* ** data encryption/decryption support */ /** Encrypt cleartext into ciphertext. @see CipherProvider#encrypt @exception StandardException Standard Cloudscape Error Policy */ public int encrypt(byte[] cleartext, int offset, int length, byte[] ciphertext, int outputOffset) throws StandardException
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -