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

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


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

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

        open_conglom.getContainer().setEstimatedRowCount(
View Full Code Here



        // need to open the container and insert the row.  Since we are
        // creating it no need to bother with locking since no one can get
        // to it until after we have created it and returned it's id.
        ContainerHandle container = null;
        Page            page      = null;

        try
        {
            container =
                rawtran.openContainer(
                    id, (LockingPolicy) null,
                    ContainerHandle.MODE_FORUPDATE |
                        (isTemporary() ? ContainerHandle.MODE_TEMP_IS_KEPT : 0));

            // row in slot 0 of heap page 1 which is just a single column with
            // the heap entry.
            DataValueDescriptor[] control_row = new DataValueDescriptor[1];
            control_row[0] = this;

            page =
                container.getPage(ContainerHandle.FIRST_PAGE_NUMBER);

            page.insertAtSlot(
                Page.FIRST_SLOT_NUMBER,
                control_row,
                (FormatableBitSet) null,
                (LogicalUndo) null,
                Page.INSERT_OVERFLOW,
                AccessFactoryGlobals.HEAP_OVERFLOW_THRESHOLD);
            page.unlatch();
            page = null;

            // Don't include the control row in the estimated row count.
            container.setEstimatedRowCount(0, /* unused flag */ 0);
        }
        finally
        {
            if (container != null)
                container.close();
            if (page !=null)
                page.unlatch();
        }
  }
View Full Code Here

    Storable            template_column)
        throws StandardException
    {
        // need to open the container and update the row containing the
        // serialized format of the heap. 
        ContainerHandle container = null;
        Page            page      = null;
        Transaction     rawtran   = xact_manager.getRawStoreXact();

        try
        {
            container =
                rawtran.openContainer(
                    id,
                    rawtran.newLockingPolicy(
                        LockingPolicy.MODE_CONTAINER,
                        TransactionController.ISOLATION_SERIALIZABLE, true),
                    ContainerHandle.MODE_FORUPDATE |
                        (isTemporary() ? ContainerHandle.MODE_TEMP_IS_KEPT : 0));

            if (column_id != format_ids.length)
            {
                if (SanityManager.DEBUG)
                    SanityManager.THROWASSERT(
                        "column_id = " + column_id +
                        "format_ids.length = " + format_ids.length +
                        "format_ids = " + format_ids);

                throw(StandardException.newException(
                        SQLState.HEAP_TEMPLATE_MISMATCH,
                        new Long(column_id),
                        new Long(this.format_ids.length)));
            }

            // create a new array, and copy old values to it.
            int[] old_format_ids = format_ids;
            format_ids              = new int[old_format_ids.length + 1];
            System.arraycopy(
                old_format_ids, 0, format_ids, 0, old_format_ids.length);

            // add the new column
            format_ids[old_format_ids.length] =
                template_column.getTypeFormatId();

          
            // row in slot 0 of heap page 1 which is just a single column with
            // the heap entry.
            DataValueDescriptor[] control_row = new DataValueDescriptor[1];
            control_row[0] = this;

            page =
                container.getPage(ContainerHandle.FIRST_PAGE_NUMBER);

            page.updateAtSlot(
                Page.FIRST_SLOT_NUMBER,
                control_row,
                (FormatableBitSet) null);

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

        return;
View Full Code Here

    OpenConglomerate    open_conglom)
        throws StandardException
    {
        super.init(open_conglom);

        ContainerHandle container = open_conglom.getContainer();

        // look up costs from raw store.
        num_rows  = container.getEstimatedRowCount(/*unused flag*/ 0);

        // Don't use 0 rows (use 1 instead), as 0 rows often leads the
        // optimizer to produce plans which don't use indexes because of the 0
        // row edge case.
        //
        // Eventually the plan is recompiled when rows are added, but we
        // have seen multiple customer cases of deadlocks and timeouts
        // because of these 0 row based plans. 
        if (num_rows == 0)
            num_rows = 1;

        // eliminate the allocation page from the count.
        num_pages = container.getEstimatedPageCount(/* unused flag */ 0);

        Properties prop = new Properties();
        prop.put(Property.PAGE_SIZE_PARAMETER, "");
        container.getContainerProperties(prop);
        page_size =
            Integer.parseInt(prop.getProperty(Property.PAGE_SIZE_PARAMETER));

        row_size = (num_pages * page_size / num_rows);

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 = (B2I) 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

    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

    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

    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

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.