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

📄 rafcontainer.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
			{				long len = pageOffset - currentEOF;				if (len > pageSize)					len = pageSize;				file.write(zero, 0, (int) len);			}			finally			{				dataFactory.writeFinished();			}			currentEOF += pageSize;		}		return true;	}	/**		@exception StandardException Standard Cloudscape error policy	*/	public void clean(boolean forRemove) throws StandardException	{		boolean waited = false;		synchronized (this) {			// committed and dropped, do nothing.  			// This file container has already been stubbified			if (getCommittedDropState()) {				clearDirty();				return;			}			// The container is about to change, need to wait till it is really			// changed.  We are in the predirty state only for the duration			// where the log record that changed the container has been sent to			// the log and before the change actually happened.			while(preDirty == true)			{				waited = true;				try				{					wait();				}				catch (InterruptedException ie)				{					throw StandardException.interrupt(ie);				}			}			if (waited)			{				// someone else may have stubbified this while we waited 				if (getCommittedDropState())				{					clearDirty();					return;				}			}			if (forRemove) {				//				removeFile()				//				clearDirty();			} else if (isDirty()) { 				try {					// Cannot get the alloc page and write it out					// because in order to do so, the alloc page will need to 					// find this container object.  But this container object					// is in the middle of being cleaned and may not be 					// 'found' and we will hang.					//					// Instead, just clobber the container info, which is 					// checksum'ed seperately from the alloc page					//					writeRAFHeader(fileData,								   false,  // don't create, container exists 								   true);  // syncfile					clearDirty();				} catch (IOException ioe) {					throw dataFactory.markCorrupt(                        StandardException.newException(                            SQLState.FILE_CONTAINER_EXCEPTION, ioe, this));				}			}		}	}	private void clearDirty() {		isDirty = false;		needsSync = false;	}	/**		Preallocate some pages if need be	*/	protected int preAllocate(long lastPreallocPagenum, 							  int preAllocSize)	{  			/* we had a condition here , that looks at the file size before		 * preallocation to handle the optimization cases like , we 		 * preallocated the space and then crashed, as we don;t log the 		 * preallocated length, we don't have updated value until AlocExtent		 * page get flushed to the disk. only way to find out that the pages		 * we want already exist  is to look at the file length.		 * Althought it was nice thing to do, we had bug no: 3813 from		 * customer , who for some unexplainable reasons he gets lots of		 * junk at the end of the file. As junk is not initialized with		 * format-ID , we get into recovery problem.		 * To avoid such unforseen conditions, removed the file size check 		 * condition , as it is better not to fail in recovery than 		 * losing some special case performance improvement.		 */  		int n = doPreAllocatePages(lastPreallocPagenum, preAllocSize); 		if (n > 0)				// sync the file		{			synchronized(this)			{				boolean inwrite = false;				try				{					dataFactory.writeInProgress();					inwrite = true;                    if (!dataFactory.dataNotSyncedAtAllocation)                        fileData.sync(false);  				}				catch (IOException ioe)				{					// The disk may have run out of space. 					// Don't error out in pre-allocation since the user may not					// actually need this page.					n = 0;				}				catch (StandardException se)				{					// some problem calling writeInProgress					n = 0;				}				finally				{					if (inwrite)						dataFactory.writeFinished();				}			}		}		return n;	}    /**     * Truncate pages of a container.     * <p>     * Truncate all pages from lastValidPagenum+1 through the end of the file.     * <p>     *     * @param lastValidPagenum  The page number of the last valid page of the     *                          file.  All pages after this one are truncated.     *	 * @exception  StandardException  Standard exception policy.     **/	protected void truncatePages(    long lastValidPagenum)        throws StandardException	{          synchronized(this)        {            boolean inwrite = false;            try            {                dataFactory.writeInProgress();                inwrite = true;                fileData.setLength((lastValidPagenum + 1) * pageSize);            }            catch (IOException ioe)            {                // The disk may have run out of space.                 // Don't error out in un-allocation since application can                // still function even if allocation fails.            }            catch (StandardException se)            {                // some problem calling writeInProgress            }            finally            {                if (inwrite)                    dataFactory.writeFinished();            }        }		return;	}	/*		Write the header of a random access file and sync it		@param create if true, the container is being created				if false, the container already exist		@param syncFile if true, sync the file	*/	private void writeRAFHeader(StorageRandomAccessFile file, boolean create, 								boolean syncFile) 		 throws IOException, StandardException	{		byte[] epage;		if (create)		{			// the file doesn't exist yet, get an embryonic page buffer			epage = getEmbryonicPage((DataInput)null); 		}		else		{			file.seek(FIRST_ALLOC_PAGE_OFFSET);			epage = getEmbryonicPage(file);		}		// need to check for frozen state		file.seek(FIRST_ALLOC_PAGE_OFFSET);		writeHeader(file, create, epage);		// leave the end of the file at a page boundry. This		// is to work around bugs in the EPOC jvm where a seek		// beyond the end of a file does not throw an exception		// but just moves the offset to the end of the file. This only		// occurs when the second page is written after the header has		// been written, ending up with the page at the incorrect offset.		if (create) {			padFile(file, pageSize);		}		if (syncFile)		{			dataFactory.writeInProgress();			try			{                if (!dataFactory.dataNotSyncedAtCheckpoint)                   file.sync(false);			}			finally			{				dataFactory.writeFinished();			}		}		epage = null;	}	/**		flush the cache to ensure all of my pages are written to disk		@exception StandardException Standard Cloudscape error policy	*/	protected void flushAll() throws StandardException {		pageCache.clean(identity);		// now clean myself which will sync all my pages.		clean(false);	}	 synchronized StorageFile getFileName(ContainerKey identity, boolean stub,											 boolean errorOK, boolean tryAlternatePath)		 throws StandardException	 {         // RESOLVE - READ ONLY         actionCode = GET_FILE_NAME_ACTION;         actionIdentity = identity;         actionStub = stub;         actionErrorOK = errorOK;         actionTryAlternatePath = tryAlternatePath;         try         {             return (StorageFile) AccessController.doPrivileged( this);         }         catch( PrivilegedActionException pae){ throw (StandardException) pae.getException();}         finally{ actionIdentity = null; }	 }    protected StorageFile privGetFileName(ContainerKey identity, boolean stub,                                    boolean errorOK, boolean tryAlternatePath)        throws StandardException    {        StorageFile container = dataFactory.getContainerPath( identity, stub);        // retry with small case 'c' and 'd'        // bug fix for track 3444        if (!container.exists() && tryAlternatePath)        {            container = dataFactory.getAlternateContainerPath( identity, stub);        }        if (!container.exists()) {            StorageFile directory = container.getParentDir();            if (!directory.exists())            {                // make sure only 1 thread can create a segment at one time                synchronized(dataFactory)                {                    if (!directory.exists())                    {                        if (!directory.mkdirs())                        {                            if (errorOK)                            {                                return null;                            }                            else                            {                                throw StandardException.newException(                                    SQLState.FILE_CANNOT_CREATE_SEGMENT,                                    directory);                            }                        }                    }                }            }        }        return container;    } // end of privGetFileName	synchronized void createContainer(ContainerKey newIdentity)        throws StandardException    {		if (SanityManager.DEBUG) {			if ((spareSpace < 0) || (spareSpace > 100))				SanityManager.THROWASSERT("invalid spare space " + spareSpace);		}        actionCode = CREATE_CONTAINER_ACTION;        actionIdentity = newIdentity;        try        {            AccessController.doPrivileged( this);        }        catch( PrivilegedActionException pae){ throw (StandardException) pae.getException();}        finally{ actionIdentity = null; }    } // end of createContainer	synchronized boolean removeFile(StorageFile file)        throws SecurityException, StandardException    {        actionCode = REMOVE_FILE_ACTION;        actionFile = file;        try        {            return AccessController.doPrivileged( this) != null;        }        catch( PrivilegedActionException pae){ throw (StandardException) pae.getException();}        finally{ actionFile = null; }    } // end of removeFile

⌨️ 快捷键说明

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