⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basedatafilefactory.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	 * @exception StandardExceptions Standard Cloudscape Error Policy	 */	private PageActions getLoggablePageActions() throws StandardException	{		if (loggablePageActions == null)			loggablePageActions = new LoggableActions();		return loggablePageActions;	}	/**	 * Get the loggable allocation action that is associated with this implementation	 *	 * @return the PageActions	 */	private AllocationActions getLoggableAllocationActions() 	{		if (loggableAllocActions == null)			loggableAllocActions = new LoggableAllocActions();		return loggableAllocActions;	}    synchronized StorageFile getTempDirectory()    {        actionCode = GET_TEMP_DIRECTORY_ACTION;        try        {            return (StorageFile) AccessController.doPrivileged( this);        }        catch( PrivilegedActionException pae){ return null;} // getTempDirectory does not actually throw an exception    }        private synchronized void removeTempDirectory()    {        if( storageFactory != null)        {            actionCode = REMOVE_TEMP_DIRECTORY_ACTION;            try            {                AccessController.doPrivileged( this);            }            catch( PrivilegedActionException pae){} // removeTempDirectory does not throw an exception        }    } // end of removeTempDirectory    /**     * Return the path to a container file.     * <p>     * Return the path to a container file that is relative to the root      * directory.     * <p>     * The format of the name of an existing container file is:     *     segNNN/cXXX.dat     * The format of the name of a stub describing a dropped container file is:     *     segNNN/dXXX.dat     *     * NNN = segment number, currently 0 is where normal db files are found.     * XXX = The hex representation of the container number     *     * The store will always create containers with this format name, but      * the store will also recognize the following two formats when attempting     * to open files - as some copy tools have uppercased our filesnames when     * moving across operating systems:     *     * The format of the name of an existing container file is:     *     segNNN/CXXX.DAT     * The format of the name of a stub describing a dropped container file is:     *     segNNN/DXXX.DAT     * <p>     *     *     * @param containerId The container being opened/created     * @param stub        True if the file name for the stub is requested,      *                      otherwise the file name for the data file     *	 * @return The StorageFile representing path to container relative to root.     *     **/	public StorageFile getContainerPath(    ContainerKey    containerId,     boolean         stub)     {        return getContainerPath( containerId, stub, GET_CONTAINER_PATH_ACTION);    }    private synchronized StorageFile getContainerPath(        ContainerKey containerId,         boolean stub,        int code)    {        actionCode = code;        try        {            this.containerId = containerId;            this.stub = stub;            try            {                return (StorageFile) AccessController.doPrivileged( this);            }            catch( PrivilegedActionException pae){ return null;} // getContainerPath does not throw an exception        }        finally { this.containerId = null; }	}	/**		Return an alternate path to a container file that is relative to the root directory.        The alternate path uses upper case 'C','D', and 'DAT' instead of         lower case - there have been cases of people copying the database and        somehow upper casing all the file names.        The intended use is as a bug fix for track 3444.		@param containerId The container being opened/created		@param stub True if the file name for the stub is requested, otherwise the file name for the data file	*/	public StorageFile getAlternateContainerPath(ContainerKey containerId, boolean stub)    {        return getContainerPath( containerId, stub, GET_ALTERNATE_CONTAINER_PATH_ACTION);	}	/**		Remove stubs in this database.  Stubs are committed deleted containers	*/	private synchronized void removeStubs()	{        actionCode = REMOVE_STUBS_ACTION;        try        {            AccessController.doPrivileged( this);        }        catch( PrivilegedActionException pae){} // removeStubs does not throw an exception	}	/**	 * keeps track of information about the stub files of the  committed deleted	 * containers. We use the info to delete them at checkpoints.	 * In addition to the file info , we also keep track of the identity of the	 * container; which helps to remove entry in the cache and the log instant	 * when the stub was created, which helps us to figure out whether we	 * require the stub file for the crash recovery.	 * We maintain the information in a hashtable:	 * key(LOG INSTANT) Values: File handle , and ContainerIdentity.	 **/	public void stubFileToRemoveAfterCheckPoint(StorageFile file, LogInstant												logInstant, Object identity) {		if(droppedTableStubInfo != null)		{			Object[] removeInfo = new Object[2];			removeInfo[0] = file;			removeInfo[1] = identity;			droppedTableStubInfo.put(logInstant, removeInfo);		}	}    	/**	 * Delete the stub files thare not required for recovery. A stub files	 * is not required to be around if the recovery is not going to see	 * any log record that belong to that container. Since the stub files	 * are create as a post commit operations, they are not necessary during	 * undo operation of the recovery.	 *	 * To remove a stub file we have to be sure that it was created before the	 * redoLWM in the check point record. We can be sure that the stub is not	 * require if the log instant when it was created is less than the redoLWM. 	 */	public void removeDroppedContainerFileStubs(LogInstant redoLWM) throws StandardException	{			if (droppedTableStubInfo != null) 		{			synchronized(droppedTableStubInfo)			{				for (Enumeration e = droppedTableStubInfo.keys(); e.hasMoreElements(); ) 				{					LogInstant logInstant  = (LogInstant) e.nextElement();					if(logInstant.lessThan(redoLWM))					{												Object[] removeInfo = (Object[]) droppedTableStubInfo.get(logInstant);						Object identity = removeInfo[1];						//delete the entry in the container cache.						Cacheable ccentry =	containerCache.findCached(identity);						if(ccentry!=null)							containerCache.remove(ccentry);						//delete the stub we don't require it during recovery                        synchronized( this)                        {                            actionFile = (StorageFile)removeInfo[0];                            actionCode = DELETE_IF_EXISTS_ACTION;                            try                            {                                if (AccessController.doPrivileged(this) != null)                                 {                                    //if we successfuly delete the file remove it                                     //from the hash table.                                    droppedTableStubInfo.remove(logInstant);                                }                            }                            catch( PrivilegedActionException pae) {} // DELETE_IF_EXISTS does not throw an exception                        }					}				}			}		}	}    /**     * Find the largest containerid is seg 0.     * <p>     * Do a file list of the files in seg0 and return the highest numbered     * file found.     * <p>     * Until I figure out some reliable place to store this information across     * a boot of the system, this is what is used following a boot to assign     * the next conglomerate id when a new conglomerate is created.  It is     * only called at most once, and then the value is cached by calling store     * code.     * <p>     *	 * @return The largest containerid in seg0.     **/	private synchronized long findMaxContainerId()	{        actionCode = FIND_MAX_CONTAINER_ID_ACTION;        try{            return ((Long) AccessController.doPrivileged( this)).longValue();        }        catch( PrivilegedActionException pae){ return 0;} // findMaxContainerId does not throw an exception	}	private void bootLogFactory(boolean create, Properties startParams) throws StandardException {		if (isReadOnly())			startParams.put(LogFactory.RUNTIME_ATTRIBUTES, LogFactory.RT_READONLY);		logFactory = (LogFactory)			Monitor.bootServiceModule(create, this, 									  rawStoreFactory.getLogFactoryModule(), 									  startParams);	}	/**		Does this factory support this service type.	*/	private boolean handleServiceType( Properties startParams, String type) {        try        {            PersistentService ps = Monitor.getMonitor().getServiceProvider( startParams, type);            return ps != null && ps.hasStorageFactory();        }        catch( StandardException se){ return false;}	}	/**		check to see if we are the only JBMS opened agains this database.		<BR>This method does nothing if this database is read only or we cannot		access files directly on the database directory.		<BR>We first see if a file named db.lck exists on the top database		directory (i.e., the directory where service.properties lives).  If it		doesn't exist, we create it and write to it our identity which is		generated per boot of the JBMS.		<BR>If the db.lck file already exists when we boot this database, we		try to delete it first, assuming that an opened RandomAccessFile can		act as a file lock against delete.  If that succeed, we may hold a		file lock against subsequent JBMS that tries to attach to this		database before we exit.		<BR>We test to see if we think an opened file will prevent it from		being deleted, if so, we will hold on to the open file descriptor and		use it as a filelock.  If not, and we started out deleting an existing		db.lck file, we issue a warning message to the info stream that we are		about to attached to a database which may already have another JBMS		attached to it. Then we overwrite that db.lck file with our identity.		<BR>Upon shutdown, we delete the db.lck file.  If the system crash		instead of shutdown cleanly, it will be cleaned up the next time the		system boots		@exception StandardException another JBMS is already attached to the		database at this directory	*/	private void getJBMSLockOnDB( UUID myUUID, UUIDFactory uuidFactory, String databaseDirectory)		 throws StandardException	{		if (fileLockOnDB != null) // I already got the lock!			return;		if (isReadOnly())			return;		if (SanityManager.DEBUG)		{			if (myUUID == null)				SanityManager.THROWASSERT("myUUID == null");		}        synchronized( this)        {            actionCode = GET_LOCK_ON_DB_ACTION;            this.myUUID = myUUID;            this.uuidFactory = uuidFactory;            this.databaseDirectory = databaseDirectory;                        try            {                AccessController.doPrivileged( this);            }            catch( PrivilegedActionException pae) { throw (StandardException) pae.getException(); }            finally            {                this.myUUID = null;                this.uuidFactory = null;                this.databaseDirectory = null;            }        }		// OK file lock is reliable, we think... keep the fileLockOnDB file		// descriptor open to prevent other JBMS from booting		// fileLockOnDB is not null in this case	}    // Called from within a privilege block    private void privGetJBMSLockOnDB() throws StandardException    {        boolean fileLockExisted = false;        String blownUUID = null;        StorageFile fileLock = storageFactory.newStorageFile( DB_LOCKFILE_NAME);        try        {            // assume we are not read only            // SECURITY PERMISSION MP1            if (fileLock.exists())            {                fileLockExisted = true;                // see what it says in case we cannot count on delete failing                // when someone else have an opened file descriptor.                // I may be blowing this JBMS's lock away                // SECURITY PERMISSION MP1                // SECURITY PERMISSION OP4                fileLockOnDB = fileLock.getRandomAccessFile( "rw");                try                {                    blownUUID = fileLockOnDB.readUTF();                }                catch (IOException ioe)                {                    // The previous owner of the lock may have died before                    // finish writing its UUID down.                    fileLockExisted = false;                }                fileLockOnDB.close();                fileLockOnDB = null;                // SECURITY PERMISSION OP5                if (!fileLock.delete())                {                    throw StandardException.newException(                        SQLState.DATA_MULTIPLE_JBMS_ON_DB,                        databaseDirectory);                }            }            // if file does not exists, we grab it immediately - there is a            // possibility that some other JBMS got to it sooner than we do,            // check the UUID after we write it to make sure            // SECURITY PERMISSION MP1            // SECURITY PERMISSION OP5            fileLockOnDB = fileLock.getRandomAccessFile( "rw");            fileLockOnDB.writeUTF(myUUID.toString()); // write it out for future reference            fileLockOnDB.sync( false);            fileLockOnDB.seek(0);            // check the UUID            UUID checkUUID = uuidFactory.recreateUUID(fileLockOnDB.readUTF());            if (!checkUUID.equals(myUUID))            {                throw StandardException.newException(                    SQLState.DATA_MULTIPLE_JBMS_ON_DB, databaseDirectory);            }        }        catch (IOException ioe)        {            // probably a read only db, don't do anything more            readOnly = true;            try            {                if (fileLockOnDB != null)                    fileLockOnDB.close();            }            catch (IOException ioe2)            { /* did the best I could */ }            fileLockOnDB = null;            return;        }        if (fileLock.delete())        {            // if I can delete it while I am holding a opened file descriptor,            // then the file lock is unreliable - send out a warning if I            // have blown off another JBMS's lock on the DB            Object[] args = new Object[3];            args[0] = myUUID;            args[1] = databaseDirectory;            args[2] = blownUUID;            //Try the exlcusive file lock method approach available in jdk1.4 or            //above jvms where delete machanism  does not reliably prevent double booting of             //cloudscape databases. If we don't get a reliable exclusive

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -