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

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


    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)
            {
                // this should do nothing, since we requested isolation 3
                // but we can't assume that, so call the policy correctly.

        cl.unlockContainer(t, ch)
      }
    }

    return containerId;
  }
View Full Code Here


     throws StandardException
  {
    boolean tmpContainer =
            (ckey.getSegmentId() == ContainerHandle.TEMPORARY_SEGMENT);

    LockingPolicy cl = null;

    if (!tmpContainer)
        {
      if (isReadOnly())
            {
View Full Code Here

   
    if (files != null) {
      // No user visible locks are acquired to backup the database. A stable backup
      // is made by latching the pages and internal synchronization
      // mechanisms.
      LockingPolicy lockPolicy =   rt.newLockingPolicy(LockingPolicy.MODE_NONE,
                              TransactionController.ISOLATION_NOLOCK,
                              false);
      long segmentId = 0;

      // loop through all the files in seg0 and backup all valid containers.
View Full Code Here

  private StorageFile encryptContainer(RawTransaction  t,
                                         ContainerKey    ckey)
        throws StandardException
  {

        LockingPolicy cl =
            t.newLockingPolicy(
                               LockingPolicy.MODE_CONTAINER,
                               TransactionController.ISOLATION_SERIALIZABLE,
                               true);
   
View Full Code Here

    {

    if (mode == LockingPolicy.MODE_NONE)
      isolation = TransactionController.ISOLATION_NOLOCK;

    LockingPolicy policy = lockingPolicies[mode][isolation];

    if ((policy != null) || (!stricterOk))
      return policy;

    for (mode++; mode <= LockingPolicy.MODE_CONTAINER; mode++)
View Full Code Here

    // Else, not reclaiming container. Get a no-wait shared lock on the
    // container regardless of how the user transaction had the
    // container opened.

    LockingPolicy container_rlock =
      tran.newLockingPolicy(LockingPolicy.MODE_RECORD,
                  TransactionController.ISOLATION_SERIALIZABLE,
                  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
        return Serviceable.REQUEUE;
      else
        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)
View Full Code Here

     throws StandardException
  {
    // when we want to reclaim the whole container, gets an exclusive
    // XLock on the container, wait for the lock.

    LockingPolicy container_xlock =
      tran.newLockingPolicy(LockingPolicy.MODE_CONTAINER,
                  TransactionController.ISOLATION_SERIALIZABLE,
                  true /* stricter OK */ );

    if (SanityManager.DEBUG)
View Full Code Here

        locking policy would be set to do no locking.
        Moreover, if the container is an index, the locking policy would
        always be set to do no locking.
        */

        LockingPolicy lp =
            owner.getTransaction().newLockingPolicy(
                LockingPolicy.MODE_RECORD,
                TransactionController.ISOLATION_REPEATABLE_READ, true);

        // reopen the container
View Full Code Here

     **/
    private LockingPolicy determine_locking_policy(
    int requested_lock_level,
    int isolation_level)
    {
        LockingPolicy ret_locking_policy;

        if ((accessmanager.getSystemLockLevel() ==
                TransactionController.MODE_TABLE) ||
            (requested_lock_level == TransactionController.MODE_TABLE))
        {
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)
            {
                // this should do nothing, since we requested isolation 3
                // but we can't assume that, so call the policy correctly.

        cl.unlockContainer(t, ch)
      }
    }

    return containerId;
  }
View Full Code Here

TOP

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

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.