Package org.apache.derby.iapi.store.raw

Examples of org.apache.derby.iapi.store.raw.Page


      // Reclaiming a page - called by undo of insert which purged the
      // last row off an overflow page. It is safe to reclaim the page
      // without first locking the head row because unlike post commit
      // work, this is post abort work.  Abort is guarenteed to happen
      // and to happen only once, if at all.
      Page p = containerHdl.getPageNoWait(work.getPageId().getPageNumber());
      if (p != null)
        containerHdl.removePage(p);

      tran.commit();
      return Serviceable.DONE;
View Full Code Here


            // There's no point in attempting to reposition too early, as we're
            // likely to hit the same WaitError again (and again). So instead
            // let's sleep here until the left sibling page has been released,
            // and then return to let the caller reposition and retry.
            Page leftPage = container.getPage(left);
            if (leftPage != null) {
                // Got the latch. Anything may have happened while we didn't
                // hold any latches, so we don't know if we're still supposed
                // to go to that page. Just release the latch and let the
                // caller reposition to the right spot in the B-tree.
                leftPage.unlatch();
                leftPage = null;
            }

            return false;
        }
View Full Code Here

                leaf.page.recordCount() - 1 - leaf.page.nonDeletedRecordCount();

            if (num_possible_commit_delete > 0)
            {

                Page page   = leaf.page;


                // RowLocation column is in last column of template.
                FetchDescriptor lock_fetch_desc =
                    RowUtil.getFetchDescriptorConstant(
                        scratch_template.length - 1);

                // loop backward so that purges which affect the slot table
                // don't affect the loop (ie. they only move records we
                // have already looked at).
                for (int slot_no = page.recordCount() - 1;
                     slot_no > 0;
                     slot_no--)
                {
                    if (page.isDeletedAtSlot(slot_no))
                    {
                        // try to get an exclusive lock on the row, if we can
                        // then the row is a committed deleted row and it is
                        // safe to purge it.
                        if (btree_locking_policy.lockScanCommittedDeletedRow(
                                open_btree, leaf, scratch_template,
                                lock_fetch_desc, slot_no))
                        {
                            // the row is a committed deleted row, purge it.
                            page.purgeAtSlot(slot_no, 1, true);

                            purged_at_least_one_row = true;
                        }
                    }
                }
View Full Code Here

            lastInsertedPage = new long[4];
            lastInsertedPage[0] = last;

            for (int i = 3; i > 0; i--)
            {
                Page page = addPage(handle, false);
                lastInsertedPage[i] = page.getPageNumber();
                page.unlatch();
            }
        }
    }
View Full Code Here

        prop.put(Page.DIAG_ROWSIZE,          "");
        prop.put(Page.DIAG_MINROWSIZE,       "");
        prop.put(Page.DIAG_MAXROWSIZE,       "");

        // scan all pages in the heap gathering summary stats in stat
        Page page = container.getFirstPage();

        while (page != null)
        {
            D_HeapController.diag_page(page, prop, stat);
            pageid = page.getPageNumber();
            page.unlatch();
            page = container.getNextPage(pageid);
        }

        return(D_HeapController.diag_tabulate(prop, stat));
    }
View Full Code Here

   * @exception  StandardException  Standard exception policy.
     **/
  private RecordHandle doInsert(DataValueDescriptor[] row)
    throws StandardException
  {
    Page page = null;
        byte  insert_mode;
   
        RecordHandle rh;

        if (SanityManager.DEBUG)
        {
            Heap heap = (Heap) open_conglom.getConglomerate();
            // Make sure valid columns are in the list.  The RowUtil
            // call is too expensive to make in a released system for
            // every insert.

            int invalidColumn =
                RowUtil.columnOutOfRange(
                    row, null, heap.format_ids.length);

            if (invalidColumn >= 0)
            {
                throw(StandardException.newException(
                        SQLState.HEAP_TEMPLATE_MISMATCH,
                        new Long(invalidColumn),
                        new Long(heap.format_ids.length)));
            }
        }

        // Get the last page that was returned for insert or the last page
        // that was allocated.
        page = open_conglom.getContainer().getPageForInsert(0);

        if (page != null) {

            // if there are 0 rows on the page allow the insert to overflow.
            insert_mode =
                (page.recordCount() == 0) ?
                    Page.INSERT_OVERFLOW : Page.INSERT_DEFAULT;

            // Check to see if there is enough space on the page
            // for the row.
            rh = page.insert(row, null, insert_mode,
        AccessFactoryGlobals.HEAP_OVERFLOW_THRESHOLD);
            page.unlatch();
            page = null;

            // If we have found a page with enough space for the row,
            // insert it and release exclusive access to the page.
            if (rh != null)
            {
                return rh;

            }
        }

        // If the last inserted page is now full, or RawStore have
        // forgotten what it was, or the row cannot fit on the last
        // inserted page, try to have rawStore get a relatively unfilled
        // page.

        page =
            open_conglom.getContainer().getPageForInsert(
                ContainerHandle.GET_PAGE_UNFILLED);

        if (page != null)
        {
            // Do the insert all over again hoping that it will fit into
            // this page, and if not, allocate a new page.

            // if there are 0 rows on the page allow the insert to overflow.
            insert_mode =
                (page.recordCount() == 0) ?
                    Page.INSERT_OVERFLOW : Page.INSERT_DEFAULT;
           
            rh = page.insert(row, null, insert_mode,
        AccessFactoryGlobals.HEAP_OVERFLOW_THRESHOLD);

            page.unlatch();
            page = null;

            // If we have found a page with enough space for the row,
            // insert it and release exclusive access to the page.
            if (rh != null)
            {
                return rh;
            }
        }

        page = open_conglom.getContainer().addPage();

        // At this point with long rows the raw store will guarantee
        // that any size row will fit on an empty page.

        rh = page.insert(row, null, Page.INSERT_OVERFLOW,
      AccessFactoryGlobals.HEAP_OVERFLOW_THRESHOLD);
        page.unlatch();
        page = null;

        if (SanityManager.DEBUG)
        {
            // a null will only be returned if this page is not empty
View Full Code Here

    // out these rows if the transaction rolls back.  We are counting on
    // the allocation page rollback to obliterate these rows if the
    // transaction fails, or, in the CREAT_UNLOGGED case, the whole
    // container to be removed.

    Page page = open_conglom.getContainer().addPage();

    boolean callbackWithRowLocation = rowSource.needsRowLocation();
    RecordHandle rh;
    HeapRowLocation rowlocation;

        if (callbackWithRowLocation ||
            rowSource.needsRowLocationForDeferredCheckConstraints())
      rowlocation = new HeapRowLocation();
    else
      rowlocation = null;

        FormatableBitSet validColumns = rowSource.getValidColumns();

    try
    {
       // get the next row and its valid columns from the rowSource
      DataValueDescriptor[] row;
            while ((row = rowSource.getNextRowFromRowSource()) != null)
            {
                num_rows_loaded++;

                if (SanityManager.DEBUG)
                {
                    // Make sure valid columns are in the list.  The RowUtil
                    // call is too expensive to make in a released system for
                    // every insert.
                    int invalidColumn =
                        RowUtil.columnOutOfRange(
                            row, validColumns, heap.format_ids.length);

                    if (invalidColumn >= 0)
                    {
                        throw(StandardException.newException(
                                SQLState.HEAP_TEMPLATE_MISMATCH,
                                new Long(invalidColumn),
                                new Long(heap.format_ids.length)));
                    }
                }


        // Insert it onto this page as long as it can fit more rows.
        if ((rh = page.insert(
                        row, validColumns, Page.INSERT_DEFAULT,
            AccessFactoryGlobals.HEAP_OVERFLOW_THRESHOLD))
                                == null)
        {
          // Insert faied, row did not fit.  Get a new page. 

          page.unlatch();
          page = null;

          page = open_conglom.getContainer().addPage();

          // RESOLVE (mikem) - no long rows yet so the following code
          // will get an exception from the raw store for a row that
          // does not fit on a page.
          //
          // Multi-thread considerations aside, the raw store will
                    // guarantee that any size row will fit on an empty page.
          rh = page.insert(
                            row, validColumns, Page.INSERT_OVERFLOW,
              AccessFactoryGlobals.HEAP_OVERFLOW_THRESHOLD);

        }

        // Else, the row fit.  If we are expected to call back with the
        // row location, do so.  All the while keep the page latched
        // and go for the next row.
        if (callbackWithRowLocation)
        {
          rowlocation.setFrom(rh);
          rowSource.rowLocation(rowlocation);
        }

                if (rowSource.needsRowLocationForDeferredCheckConstraints()) {
                    rowlocation.setFrom(rh);
                    rowSource.offendingRowLocation(rowlocation,
                                                   heap.getContainerid());
                }
      }
      page.unlatch();
      page = null;

      // Done with the container, now we need to flush it to disk since
      // it is unlogged.
            if (!heap.isTemporary())
View Full Code Here

            lastInsertedPage = new long[4];
            lastInsertedPage[0] = last;

            for (int i = 3; i > 0; i--)
            {
                Page page = addPage(handle, false);
                lastInsertedPage[i] = page.getPageNumber();
                page.unlatch();
            }
        }
    }
View Full Code Here

  public void restoreLoggedRow(
    Object[]   row,
    LimitObjectInput        in)
    throws StandardException, IOException
  {
    Page p = null;

    try {
      // the optional data is written by the page in the same format it
      // stores record on the page,
      // only a page knows how to restore a logged row back to a storable row
      // first get the page where the insert went even though the row may no
      // longer be there
      p = getContainer().getPage(getPageId().getPageNumber());


      ((BasePage)p).restoreRecordFromStream(in, row);

    } finally {

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

    // create the first alloc page and the first user page,
    // if this fails for any reason the transaction
    // will roll back and the container will be dropped (removed)
    ContainerHandle containerHdl = null;
    Page            firstPage    = null;

    try
        {
      // if opening a temporary container with IS_KEPT flag set,
      // make sure to open it with IS_KEPT too.
      if (tmpContainer &&
        ((temporaryFlag & TransactionController.IS_KEPT) ==
                     TransactionController.IS_KEPT))
            {

        mode |= ContainerHandle.MODE_TEMP_IS_KEPT;
      }

      // open no-locking as we already have the container locked
      containerHdl =
                t.openContainer(
                    identity, null, (ContainerHandle.MODE_FORUPDATE | mode));

      // we just added it, containerHdl should not be null
            if (SanityManager.DEBUG)
                SanityManager.ASSERT(containerHdl != null);

      if (!tmpContainer)
            {
        // make it persistent (in concept if not in reality)
        RawContainerHandle rch = (RawContainerHandle)containerHdl;

        ContainerOperation lop =
          new ContainerOperation(rch, ContainerOperation.CREATE);

        // 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.
        rch.preDirty(true);
        try
        {
          t.logAndDo(lop);

          // flush the log to reduce the window between where
          // the container is created & synced and the log record
          // for it makes it to disk. If we fail in this
          // window we will leave a stranded container file.
          flush(t.getLastLogInstant());
        }
        finally
        {
          // in case logAndDo fail, make sure the container is not
          // stuck in preDirty state.
          rch.preDirty(false);
        }
      }

      firstPage = containerHdl.addPage();

    }
        finally
        {

      if (firstPage != null)
            {
        firstPage.unlatch();
        firstPage = null;
      }
     
      containerCache.release(container);
View Full Code Here

TOP

Related Classes of org.apache.derby.iapi.store.raw.Page

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.