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

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


        ControlRow            root                      = null;
        ControlRow            control_row               = null;
        DataValueDescriptor[] logged_index_row_template = null;
        DataValueDescriptor[] template                  = null;
        Page                  ret_page                  = null;
        ContainerHandle       container                 = pageOp.getContainer();
        RecordHandle          rechandle                 = pageOp.getRecordHandle();
        boolean               ok_exit                   = false;
        int                   compare_result            = 1;
        B2I                   btree                     = null;
View Full Code Here


        {
            SanityManager.DEBUG_PRINT("", "reclaimPrepareLocks().");
            SanityManager.ASSERT(getRecordHandle() != null);
        }

        ContainerHandle ch = t.openContainer(
            getPageId().getContainerId(), locking_policy,
            (ContainerHandle.MODE_FORUPDATE          |
             ContainerHandle.MODE_OPEN_FOR_LOCK_ONLY |
             ContainerHandle.MODE_LOCK_NOWAIT));

        if (SanityManager.DEBUG)
        {
            SanityManager.ASSERT(ch != null);
        }

        if (ch != null)
            ch.close();

        /*
        // get the intent lock on the container.
        boolean lock_granted =
            locking_policy.lockContainer(
View Full Code Here

    ContainerKey identity = new ContainerKey(segmentId, containerId);

    boolean tmpContainer = (segmentId == ContainerHandle.TEMPORARY_SEGMENT);

    ContainerHandle ch = null;
    LockingPolicy   cl = null;

    if (!tmpContainer)
        {
      // lock the container before we create it.

      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);

      ch = t.openContainer(identity, cl,
                   (ContainerHandle.MODE_FORUPDATE |
                    ContainerHandle.MODE_OPEN_FOR_LOCK_ONLY));
    }

    FileContainer container =
      (FileContainer) containerCache.create(identity, tableProperties);

    // 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);

      if (containerHdl != null)
            {
        containerHdl.close();
        containerHdl = null;
      }

      if (!tmpContainer)
            {
View Full Code Here

         for restore to work correctly. That is
         *  why we are using a open call that let us
         *  open dropped containers.
         */

        ContainerHandle containerHdl = openDroppedContainer((RawTransaction)rt,
                                  identity, lockPolicy,
                                  ContainerHandle.MODE_READONLY);
        /*
         * Note 1:
         * If a container creation is  in progress , open call will wait
         * until it is complete; It will never return a handle to a
         * container that is partially created. (see cache manager code
         * for more details)
         *
         * Note 2:
         * if a container creation failed in the middle after the list
         * of the names are read from seg0, it will not exist in
         * the database any more, so nothing to backup.  Attempt
         * to open such container will return null.
         *
         */

        if( containerHdl !=  null) {
          containerHdl.backupContainer(backupDir.getPath());
          containerHdl.close();
        }
      }
    } else
    {
      if (SanityManager.DEBUG)
View Full Code Here

        if (!open_conglom.getHold())
        {
            return(false);
        }
       
        ContainerHandle container = open_conglom.reopen();
        switch (scan_state) {
        case SCAN_INPROGRESS:
        case SCAN_HOLD_INPROGRESS:
        case SCAN_DONE:
            if (container.getReusableRecordIdSequenceNumber() !=
                reusableRecordIdSequenceNumber)
            {
                rowLocationsInvalidated = true;
            }
            break;
        case SCAN_INIT:
        case SCAN_HOLD_INIT:
            reusableRecordIdSequenceNumber =
                container.getReusableRecordIdSequenceNumber();
            break;
        default:
            break;
        }
        return(true);
View Full Code Here

   * @exception  StandardException  Standard exception policy.
     **/
    public void setEstimatedRowCount(long count)
    throws StandardException
    {
        ContainerHandle container = open_conglom.getContainer();

        if (container == null)
            open_conglom.reopen();

        // the container could still be null if a DROP TABLE or TRUNCATE TABLE
        // has removed the old conglomerate

        container = open_conglom.getContainer();

        if ( container != null )
        {
            container.setEstimatedRowCount(
                count, /* unused flag */ 0);
        }
    }
View Full Code Here

                  true /* stricter OK */ );

    if (SanityManager.DEBUG)
      SanityManager.ASSERT(container_rlock != null);

    ContainerHandle containerHdl =
      openContainerNW(tran, container_rlock, work.getContainerId());

    if (containerHdl == null)
    {
      tran.abort();

      if (SanityManager.DEBUG)
            {
                if (SanityManager.DEBUG_ON(DaemonService.DaemonTrace))
                {
                    SanityManager.DEBUG(
                        DaemonService.DaemonTrace, " aborted " + work +
                        " because container is locked or dropped");
                }
            }

      if (work.incrAttempts() < 3) // retry this for serveral times
        // it is however, unlikely that three tries will be
        // enough because there is no delay between retries.
        // See DERBY-4059 and DERBY-4055 for details.
            {
        return Serviceable.REQUEUE;
            }
      else
            {
                // If code gets here, the space will be lost forever, and
                // can only be reclaimed by a full offline compress of the
                // table/index.

                if (SanityManager.DEBUG)
                {
                    if (SanityManager.DEBUG_ON(DaemonService.DaemonTrace))
                    {
                        SanityManager.DEBUG(
                            DaemonService.DaemonTrace,
                            "  gave up after 3 tries to get container lock " +
                            work);
                    }
                }

        return Serviceable.DONE;
            }
    } 

    // At this point, container is opened with IX lock.

    if (work.reclaimWhat() == ReclaimSpace.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;
    }

    // We are reclaiming row space or long column. 
    // First get an xlock on the head row piece.
    RecordHandle headRecord = work.getHeadRowHandle();

    if (!container_rlock.lockRecordForWrite(
                tran, headRecord, false /* not insert */, false /* nowait */))
    {
      // cannot get the row lock, retry
      tran.abort();
      if (work.incrAttempts() < 3)
            {
        return Serviceable.REQUEUE;
            }
      else
            {
                // If code gets here, the space will be lost forever, and
                // can only be reclaimed by a full offline compress of the
                // table/index.

                if (SanityManager.DEBUG)
                {
                    if (SanityManager.DEBUG_ON(DaemonService.DaemonTrace))
                    {
                        SanityManager.DEBUG(
                            DaemonService.DaemonTrace,
                            "  gave up after 3 tries to get row lock " +
                            work);
                    }
                }
        return Serviceable.DONE;
            }
    }

    // The exclusive lock on the head row has been gotten.

    if (work.reclaimWhat() == ReclaimSpace.ROW_RESERVE)
    {
      // This row may benefit from compaction.
      containerHdl.compactRecord(headRecord);

            // This work is being done - post commit, there is no user
            // transaction that depends on the commit being sync'd.  It is safe
            // to commitNoSync() This do as one of 2 things will happen:
            //
            //     1) if any data page associated with this transaction is
            //        moved from cache to disk, then the transaction log
            //        must be sync'd to the log record for that change and
            //        all log records including the commit of this xact must
            //        be sync'd before returning.
            //
            //     2) if the data page is never written then the log record
            //        for the commit may never be written, and the xact will
            //        never make to disk.  This is ok as no subsequent action
            //        depends on this operation being committed.
            //
      tran.commitNoSync(Transaction.RELEASE_LOCKS);

      return Serviceable.DONE;
    }
    else
    {
      if (SanityManager.DEBUG)
        SanityManager.ASSERT(work.reclaimWhat() == ReclaimSpace.COLUMN_CHAIN);

      // Reclaiming a long column chain due to update.  The long column
      // chain being reclaimed is the before image of the update
      // operation. 
      //
      long headPageId = ((PageKey)headRecord.getPageId()).getPageNumber();
      //DERBY-4050 - we wait for the page so we don't have to retry.
      // prior to the 4050 fix, we called getPageNoWait and just
      // retried 3 times.  This left unreclaimed space if we were
      // not successful after three tries.
      StoredPage headRowPage =
        (StoredPage)containerHdl.getPage(headPageId);
      if (headRowPage == null)
      {
        // It is not clear why headRowPage would be null,
        // but logging the failure in case it happens.
        // If code gets here, the space will be lost forever, and
View Full Code Here

   */
  private static ContainerHandle openContainerNW(Transaction tran,
    LockingPolicy rlock, ContainerKey containerId)
    throws StandardException
  {
    ContainerHandle containerHdl = null;
    try {
        containerHdl = tran.openContainer
        (containerId, rlock,
            ContainerHandle.MODE_FORUPDATE |
            ContainerHandle.MODE_LOCK_NOWAIT);
View Full Code Here

    TransactionManager  xact_manager,
    ContainerKey        container_key)
    throws StandardException
    {
        Conglomerate    btree      = null;
        ContainerHandle container  = null;
        ControlRow      root       = null;

        try
        {
            // open readonly, with no locks.  Dirty read is ok as it is the
            // responsibility of client code to make sure this data is not
            // changing while being read.  The only changes that currently
            // happen to this data is creation and deletion - no updates
            // ever happen to btree conglomerates.
            container =
                (xact_manager.getRawStoreXact()).openContainer(
                    container_key,
                    (LockingPolicy) null,
                    ContainerHandle.MODE_READONLY);

            if (container == null)
            {
                // thrown a "known" error if the conglomerate does not exist
                // which is checked for explicitly by callers of the store
                // interface.

                throw StandardException.newException(
                    SQLState.STORE_CONGLOMERATE_DOES_NOT_EXIST,
                    new Long(container_key.getContainerId()));
            }

            // The conglomerate is located in the control row on the root page.
            root = ControlRow.get(container, BTree.ROOTPAGEID);

            if (SanityManager.DEBUG)
                SanityManager.ASSERT(root.getPage().isLatched());

            // read the Conglomerate from it's entry in the control row.
            btree = (Conglomerate) root.getConglom(B2I.FORMAT_NUMBER);

            if (SanityManager.DEBUG)
                SanityManager.ASSERT(btree instanceof B2I);
        }
        finally
        {

            if (root != null)
                root.release();

            if (container != null)
                container.close();
        }

        // if any error, just return null - meaning can't access the container.

        return(btree);
View Full Code Here

     **/
    public String diag()
        throws StandardException
    {
        long pageid;
        ContainerHandle container =
            ((HeapController) this.diag_object).getOpenConglom().getContainer();

        TableStats stat = new TableStats();

        // ask page to provide diag info:
        Properties prop = new Properties();
        prop.put(Page.DIAG_PAGE_SIZE,        "");
        prop.put(Page.DIAG_BYTES_FREE,       "");
        prop.put(Page.DIAG_BYTES_RESERVED,   "");
        prop.put(Page.DIAG_RESERVED_SPACE,   "");
        prop.put(Page.DIAG_MINIMUM_REC_SIZE, "");
        prop.put(Page.DIAG_NUMOVERFLOWED,    "");
        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

TOP

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

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.