📄 basedatafilefactory.java
字号:
throws StandardException { boolean tmpContainer = (segmentId == ContainerHandle.TEMPORARY_SEGMENT); StreamContainerHandle containerHdl = null; try { ContainerKey ckey = new ContainerKey(segmentId, containerId); // close all open containers and 'onCommit' objects of this container t.notifyObservers(ckey); containerHdl = t.openStreamContainer(segmentId, containerId, false); if (tmpContainer && (containerHdl != null)) { containerHdl.removeContainer(); return; } } finally { if (containerHdl != null) containerHdl.close(); } } /** re-Create a container during recovery load tran. called ONLY during recovery load tran. @exception StandardException Standard Cloudscape Error policy */ public void reCreateContainerForLoadTran(RawTransaction t, long segmentId, long containerId, ByteArray containerInfo) throws StandardException { if (SanityManager.DEBUG) SanityManager.ASSERT(segmentId != ContainerHandle.TEMPORARY_SEGMENT, "Cannot recreate temp container during load tran"); ContainerKey identity = new ContainerKey(segmentId, containerId); // no need to lock container during load tran // no need to create any page for the container, they will be created // as their log records are encountered later in load tran FileContainer container = (FileContainer)containerCache.create(identity, containerInfo); containerCache.release(container); } /** Drop a container. <P><B>Synchronisation</B> <P> This call will mark the container as dropped and then obtain an CX lock on the container. Once a container has been marked as dropped it cannot be retrieved by an openContainer() call unless explicitly with droppedOK. <P> Once the exclusive lock has been obtained the container is removed and all its pages deallocated. The container will be fully removed at the commit time of the transaction. @exception StandardException Standard Cloudscape error policy */ public void dropContainer(RawTransaction t, ContainerKey ckey) throws StandardException { boolean tmpContainer = (ckey.getSegmentId() == ContainerHandle.TEMPORARY_SEGMENT); LockingPolicy cl = null; if (!tmpContainer) { if (isReadOnly()) { throw StandardException.newException( SQLState.DATA_CONTAINER_READ_ONLY); } cl = t.newLockingPolicy( LockingPolicy.MODE_CONTAINER, TransactionController.ISOLATION_SERIALIZABLE, true); if (SanityManager.DEBUG) SanityManager.ASSERT(cl != null); } // close all open containers and 'onCommit' objects of this container t.notifyObservers(ckey); RawContainerHandle containerHdl = (RawContainerHandle) t.openContainer(ckey, cl, ContainerHandle.MODE_FORUPDATE); // If container is already dropped or is no longer there, throw // containerVanished exception unless container is temporary, in that // case just return. Upper layer is supposed to prevent such from // happening thru some means other than the lock we are getting here. try { if (containerHdl == null || containerHdl.getContainerStatus() != RawContainerHandle.NORMAL) { // If we are a temp container, don't worry about it. if (tmpContainer) { if (containerHdl != null) containerHdl.removeContainer((LogInstant)null); return; } else { throw StandardException.newException( SQLState.DATA_CONTAINER_VANISHED, ckey); } } // Container exist, is updatable and we got the lock. if (tmpContainer) { containerHdl.dropContainer((LogInstant)null, true); containerHdl.removeContainer((LogInstant)null); } else { ContainerOperation lop = new ContainerOperation(containerHdl, ContainerOperation.DROP); // mark the container as pre-dirtied so that if a checkpoint // happens after the log record is sent to the log stream, the // cache cleaning will wait for this change. containerHdl.preDirty(true); try { t.logAndDo(lop); } finally { // in case logAndDo fail, make sure the container is not // stuck in preDirty state. containerHdl.preDirty(false); } // remember this as a post commit work item Serviceable p = new ReclaimSpace(ReclaimSpace.CONTAINER, ckey, this, true /* service ASAP */); if (SanityManager.DEBUG) { if (SanityManager.DEBUG_ON(DaemonService.DaemonTrace)) { SanityManager.DEBUG( DaemonService.DaemonTrace, "Add post commit work " + p); } } t.addPostCommitWork(p); } } finally { if (containerHdl != null) containerHdl.close(); } } public void checkpoint() throws StandardException { pageCache.cleanAll(); containerCache.cleanAll(); } public void idle() throws StandardException { pageCache.ageOut(); containerCache.ageOut(); } public void setRawStoreFactory(RawStoreFactory rsf, boolean create, Properties startParams) throws StandardException { rawStoreFactory = rsf; /* * boot the log factory here because different implementation of the * data factory wants different types of log factory */ bootLogFactory(create, startParams); } /** Return my unique identifier @see DataFactory#getIdentifier */ public UUID getIdentifier() { return identifier; } /* ** Called by post commit daemon, calling ReclaimSpace.performWork() */ public int reclaimSpace(Serviceable work, ContextManager contextMgr) throws StandardException { if (work == null) return Serviceable.DONE; Transaction tran = rawStoreFactory.findUserTransaction( contextMgr, AccessFactoryGlobals.SYS_TRANS_NAME); if (SanityManager.DEBUG) { SanityManager.ASSERT(tran != null, "null transaction"); if (SanityManager.DEBUG_ON(DaemonService.DaemonTrace)) SanityManager.DEBUG(DaemonService.DaemonTrace, "Performing post commit work " + work); } return ReclaimSpaceHelper.reclaimSpace(this, (RawTransaction)tran, (ReclaimSpace)work); } /** Really this is just a convience routine for callers that might not have access to a log factory. */ public StandardException markCorrupt(StandardException originalError) { boolean firsttime = !isCorrupt; isCorrupt = true; if (getLogFactory() != null) getLogFactory().markCorrupt(originalError); // if firsttime markCorrupt is called, release the JBMS lock so user // can move the database if so desired. if (firsttime) { // get rid of everything from the cache without first cleaning them if (pageCache != null) pageCache.discard(null); if (containerCache != null) containerCache.discard(null); // don't read in any more pages pageCache = null; containerCache = null; releaseJBMSLockOnDB(); } return originalError; } public FileResource getFileHandler() { return fileHandler; } public void removeStubsOK() { removeStubsOK = true; } /* ** Implementation specific methods */ public int getIntParameter(String parameterName, Properties properties, int defaultValue, int minimumValue, int maximumValue) { int newValue; String parameter = null; if (properties != null) parameter = properties.getProperty(parameterName); if (parameter == null) parameter = PropertyUtil.getSystemProperty(parameterName); if (parameter != null) { try { newValue = Integer.parseInt(parameter); if ((newValue >= minimumValue) && (newValue <= maximumValue)) return newValue; } catch (NumberFormatException nfe) { // just leave the size at the default. } } return defaultValue; } CacheManager getContainerCache() { return containerCache; } CacheManager getPageCache() { return pageCache; } public long[] getCacheStats(String cacheName) { if (cacheName == null) { // cache name is not specified, return the default. return getPageCache().getCacheStats(); } if (cacheName.equals("pageCache")) { return getPageCache().getCacheStats(); } else // return default set of cache. return getPageCache().getCacheStats(); } public void resetCacheStats(String cacheName) { if (cacheName == null) { // cache name is not specified, return the default. getPageCache().resetCacheStats(); return; } if (cacheName.equals("pageCache")) { getPageCache().resetCacheStats(); } else // default getPageCache().resetCacheStats(); } /** Ask the log factory to flush up to this log instant. @exception StandardException cannot sync log file */ void flush(LogInstant instant) throws StandardException { getLogFactory().flush(instant); } /** Ask the log factory to flush the side log up to this bip location Not implemented in this class - subclass who deals with side log must override this. @exception StandardException Cloudscape Standard Error Policy */ private void syncSideLog(long bipLocation) throws StandardException { return; } LogFactory getLogFactory() { return logFactory; } RawStoreFactory getRawStoreFactory() { return rawStoreFactory; } /** Get the root directory of the data storage area. Is always guaranteed to be an absolute path. */ public String getRootDirectory() { return dataDirectory; } /** * Return the Class of the Containers to be produced by this factory. * <p> * Concrete implementations of a DataFactory must implement this routine * to indicate what kind of containers are produced. For instance * the DataFileFactory produce RAFContainer's. * <p> * It is expected that this class is called only once, and thus does * not worry about the overhead of repeated Class.forName() lookups. * * @return The Class object for the Container class. * **/ Cacheable newContainerObject() { if( supportsRandomAccess) return new RAFContainer(this); else return new InputStreamContainer( this); } /** * This page is going from clean to dirty, this is a chance for the * sub class to do something if so desired * * @exception StandardException Standard Cloudscape Error Policy */ private void pageToDirty(RawTransaction t, StoredPage page) throws StandardException { return; // this implementation does nothing } /* * Get the loggable page action that is associated with this implementation * * @return the PageActions
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -