Package org.apache.derby.impl.store.raw.data

Examples of org.apache.derby.impl.store.raw.data.BasePage


     throws StandardException
  {
    if (pageNumber == ContainerHandle.INVALID_PAGE_NUMBER)
      return null;

    BasePage p = getUserPage(handle, pageNumber, overflowOK, wait);
    if (p != null)
    {
            // make sure the page is not too full
            if (!p.allowInsert())
            {
                p.unlatch();
                p = null;

                // it is too full, make sure we are tracking it so we won't
                // see it again.
                allocCache.trackUnfilledPage(pageNumber, false);
View Full Code Here


    BaseContainerHandle handle,
    int                 flag,
    long                pageno)
     throws StandardException
  {
    BasePage p = null;
    boolean getLastInserted =
            (flag & ContainerHandle.GET_PAGE_UNFILLED) == 0;

    if (getLastInserted)
    {
View Full Code Here

   */
  protected BasePage getPageForInsert(BaseContainerHandle handle,
                    int flag)
     throws StandardException
  {
    BasePage p = null;
    boolean getLastInserted = (flag & ContainerHandle.GET_PAGE_UNFILLED) == 0;

    if (getLastInserted)
    {
      // There is nothing protecting lastInsertePage from being changed
View Full Code Here

  protected BasePage getLatchedPage(BaseContainerHandle handle,
                                        long pageNumber)
    throws StandardException
  {
    PageKey pageKey = new PageKey(identity, pageNumber);
    BasePage page = (BasePage) pageCache.find(pageKey);
       
    if (SanityManager.DEBUG){
      SanityManager.ASSERT(page != null, "page is not found :" + pageKey);
    }
   
        // latch the page
        page = latchPage(handle, page, true);
   
    if (SanityManager.DEBUG){
      SanityManager.ASSERT(page.isLatched(), "page is not latched:" + pageKey);
    }

    return page;
  }
View Full Code Here

    throws StandardException {

    if (foundPage == null)
      return null;

    BasePage ret = super.latchPage(handle, foundPage, wait);
    if (ret == null) {
      // page is still cached
      pageCache.release((Cacheable) foundPage);
    }
    return ret;
View Full Code Here

    @exception StandardException Standard Cloudscape policy.
  */
  protected BasePage getPageForRedoRecovery(Transaction xact)
     throws StandardException
  {
    BasePage p = super.getPageForRedoRecovery(xact);
    if (p != null)
      return p;

    // create the page
    // RESOLVE: we need the page format to properly recreate an Alloc page
View Full Code Here

    StoredRecordHeader recordHeader = getHeaderAtSlot(slot);

    if (!recordHeader.hasOverflow())
      return super.fetchNumFieldsAtSlot(slot);

    BasePage overflowPage = getOverflowPage(recordHeader.getOverflowPage());
    int count = overflowPage.fetchNumFieldsAtSlot(getOverflowSlot(overflowPage, recordHeader));
    overflowPage.unlatch();
    return count;
  }
View Full Code Here

    FormatableBitSet                 validColumns,
    StoredRecordHeader      recordHeader)
    throws StandardException
  {

    BasePage overflowPage = getOverflowPage(recordHeader.getOverflowPage());

    try {

      int overflowSlot = getOverflowSlot(overflowPage, recordHeader);

      overflowPage.doUpdateAtSlot(t, overflowSlot, recordHeader.getOverflowId(), row, validColumns);
      overflowPage.unlatch();
      overflowPage = null;

      return;

    } finally {
      if (overflowPage != null) {
        overflowPage.unlatch();
        overflowPage = null;
      }
    }
  }
View Full Code Here

                    // 0 this will automatically handle any overflows in
          // this new portion

          // BasePage op = getNewOverflowPage();

                    BasePage op =
                        curPage.getOverflowPageForInsert(
                            slot,
                            newRow,
                            newColumnList,
                            nextColumn);

          // We have all the information from this page so unlatch it
          if (curPage != this)
                    {
            curPage.unlatch();
            curPage = null;
          }

          byte mode = Page.INSERT_OVERFLOW;
          if (nextPage != 0)
            mode |= Page.INSERT_FOR_SPLIT;

          RecordHandle nextPortionHandle =
            nextPage == 0 ? null :
            owner.makeRecordHandle(nextPage, id);

          // RESOLVED (sku):  even though we would like to roll back
                    // these inserts with PURGE rather than with delete,
                    // we have to delete because if we purge the last row
          // from an overflow page, the purge will queue a post
                    // commit to remove the page.
          // While this is OK with long columns, we cannot do this
                    // for long rows because long row overflow pages can be
                    // shared by more than one long rows, and thus it is unsafe
          // to remove the page without first latching the head page.
                    // However, the insert log record do not have the head
                    // row's page number so the rollback cannot put that
          // information into the post commit work.
          RecordHandle portionHandle =
            op.insertAllowOverflow(
                            0, newRow, newColumnList, nextColumn, mode, 100,
                            nextPortionHandle);

          // Update the previous record header to point to new portion
          if (curPage == this)
            updateOverflowDetails(this, handle, portionHandle);
          else
            updateOverflowDetails(handle, portionHandle);
          op.unlatch();
        }
                else
                {

          // See earlier comments on checking row reserved space.
View Full Code Here

    {
        boolean backupCompleted = false;
        File backupFile = null;
        RandomAccessFile backupRaf = null;
        boolean isStub = false;
        BasePage page = null;

        while(!backupCompleted) {
            try {

                synchronized (this) {
                    // wait if some one is removing the
                    // container because of a drop.
                    while (inRemove)
                    {
                        try  {
                            wait();
                        }
                        catch (InterruptedException ie)
                        {
                            throw StandardException.interrupt(ie);
                       
                    }

                    if (getCommittedDropState())
                        isStub = true;
                    inBackup = true;
                }
     
                // create container at the backup location.
                if (isStub) {
                    // get the stub ( it is a committted drop table container )
                    StorageFile file = privGetFileName((ContainerKey)getIdentity(),
                                                       true, false, true);
                    backupFile = new File(backupLocation, file.getName());

          // directly copy the stub to the backup
          if(!FileUtil.copyFile(dataFactory.getStorageFactory(),
                                          file, backupFile))
                    {
                        throw StandardException.newException(
                                              SQLState.RAWSTORE_ERROR_COPYING_FILE,
                                              file, backupFile);
                    }
                }else {
                    // regular container file
                    long lastPageNumber= getLastPageNumber(handle);
                    if (lastPageNumber == ContainerHandle.INVALID_PAGE_NUMBER) {
                        // last page number is invalid if there are no pages in
                        // the container yet. No need to backup this container,
                        // this container creation is yet to complete.The reason
                        // backup is getting called on such a container is
                        // because container handle appears in the cache after
                        // the file is created on the disk but before it's
                        // first page is allocated.
                        return;
                    }

                    StorageFile file =
                        privGetFileName(
                            (ContainerKey)getIdentity(), false, false, true);

                    backupFile = new File(backupLocation , file.getName());
                    backupRaf  = new RandomAccessFile(backupFile,  "rw");

                    byte[] encryptionBuf = null;
                    if (dataFactory.databaseEncrypted()) {
                        // Backup uses seperate encryption buffer to encrypt the
                        // page instead of encryption buffer used by the regular
                        // conatiner writes. Otherwise writes to the backup
                        // has to be synchronized with regualar database writes
                        // because backup can run in parallel to container
                        // writes.
                        encryptionBuf = new byte[pageSize];
                    }

                    // copy all the pages of the container from the database
                    // to the backup location by reading through the page cache.
                    for (long pageNumber = FIRST_ALLOC_PAGE_NUMBER;
                         pageNumber <= lastPageNumber; pageNumber++) {
                        page = getLatchedPage(handle, pageNumber);
                       
                        // update the page array before writing to the disk
                        // with container header and encrypt it if the database
                        // is encrypted.
                       
                        byte[] dataToWrite = updatePageArray(pageNumber,
                                                             page.getPageArray(),
                                                             encryptionBuf, false);
                        backupRaf.write(dataToWrite, 0, pageSize);

                        // unlatch releases page from cache, see
                        // StoredPage.releaseExclusive()
                        page.unlatch();
                        page = null;

                        // check if some one wants to commit drop the table while
                        // conatiner is being written to the backup. If so,
                        // abort  the backup and restart it once the drop
                        // is complete.

            synchronized (this)
            {
              if (inRemove) {
                break;
              }
            }
          }
        } 

                // sync and close the backup conatiner. Incase of a stub,
                // it is already synced and closed while doing the copy.
                if(!isStub) {
                    backupRaf.getFD().sync();
                    backupRaf.close();
                    backupRaf = null;
                }
               
                // backup of the conatiner is complete.
                backupCompleted = true;

            }catch (IOException ioe) {
                throw StandardException.newException(
                                                SQLState.BACKUP_FILE_IO_ERROR,
                                                ioe,
                                                backupFile);
            } finally {
                synchronized (this) {
                    inBackup = false;
                    notifyAll();
                }

                if (page != null) {
                    page.unlatch();
                    page = null;
                }

                // if backup of container is not complete, close the file
                // handles and  remove the container file from the backup
View Full Code Here

TOP

Related Classes of org.apache.derby.impl.store.raw.data.BasePage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.