Examples of StoredRecordHeader


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

  private void storeRecordForUpdate(int slot, ObjectInput in)
    throws StandardException, IOException
  {
    // set up to read the in-memory record header back from the record
    StoredRecordHeader recordHeader = getHeaderAtSlot(slot);
    StoredRecordHeader newRecorderHeader = new StoredRecordHeader();

    // recordHeader represents the new version of the record header.
    newRecorderHeader.read(in);

    int oldFieldCount = recordHeader.getNumberFields();
    int newFieldCount = newRecorderHeader.getNumberFields();

    int startField = recordHeader.getFirstField();
    if (SanityManager.DEBUG) {
      if (startField != newRecorderHeader.getFirstField())
        SanityManager.THROWASSERT("First field changed from " + startField + " to " + newRecorderHeader.getFirstField());
    }

    // See if the number of fields shrunk, if so clear out the old data
    // we do this first to stop shuffling about the fields that are going to
    // be deleted during the update of the earlier fields. This case occurs
    // on an update that changes the row to be overflowed.
    if (newFieldCount < oldFieldCount) {

      int oldDataStartingOffset = getFieldOffset(slot, startField + newFieldCount);

      // calculate the length of the to be deleted fields
      int deleteLength = getRecordOffset(slot) + getRecordPortionLength(slot) - oldDataStartingOffset;

      // we are updateing to zero bytes!
      updateRecordPortionLength(slot, -(deleteLength), deleteLength);
    }

    // write each field out to the page

    int startingOffset = getRecordOffset(slot);
    int newOffset = startingOffset;
    int oldOffset = startingOffset;

    // see which field we get to use the reserve space
    int reservedSpaceFieldId = newFieldCount < oldFieldCount ?
      newFieldCount - 1 : oldFieldCount - 1;
    reservedSpaceFieldId += startField;


    // the new data the needs to be written at newOffset but can't until
    // unsedSpace >= newDataToWrite.length (allowing for the header)
    DynamicByteArrayOutputStream newDataToWrite = null;

    rawDataOut.setPosition(newOffset);

    // write the record header, which may change in size
    int oldLength = recordHeader.size();
    int newLength = newRecorderHeader.size();

    int unusedSpace = oldLength; // the unused space at newOffset

    // no fields, so we can eat into the reserve space
    if (reservedSpaceFieldId < startField) // no fields
      unusedSpace += getReservedCount(slot);

    if (unusedSpace >= newLength) {
      newRecorderHeader.write(rawDataOut);
      newOffset += newLength;
      unusedSpace -= newLength;
     
    } else {     

      newDataToWrite = new DynamicByteArrayOutputStream(getPageSize());
      newRecorderHeader.write(newDataToWrite);
    }
    oldOffset += oldLength;
    int recordDelta = (newLength - oldLength);

    int oldFieldStatus = 0;
View Full Code Here

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

  }

  public void skipRecord(ObjectInput in) throws IOException
  {

    StoredRecordHeader recordHeader = new StoredRecordHeader();
    recordHeader.read(in);

    for (int i = recordHeader.getNumberFields(); i > 0; i--) {
      skipField(in);   
    }
  }
View Full Code Here

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

    deletedRowCount += super.setDeleteStatus(slot, delete);
    headerOutOfDate = true;

    int offset = getRecordOffset(slot);
    StoredRecordHeader recordHeader = getHeaderAtSlot(slot);

    rawDataOut.setPosition(offset);
    recordHeader.write(logicalDataOut);
  }
View Full Code Here

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

  private int getFieldOffset(int slot, int fieldNumber) throws IOException
  {
    // RESOLVE - overflow, needs to be changed
    int offset = getRecordOffset(slot);

    StoredRecordHeader recordHeader = getHeaderAtSlot(slot);

    // get the number of fields
    int startField = recordHeader.getFirstField();

    if (SanityManager.DEBUG) {
      int numberFields = recordHeader.getNumberFields();

      if ((fieldNumber < startField) || (fieldNumber >= (startField + numberFields)))
        SanityManager.THROWASSERT(
          "fieldNumber: " + fieldNumber +
          " start field: " + startField +
          " number of fields " + numberFields);
    }

    ArrayInputStream lrdi = rawDataIn;

    // skip the record header
    lrdi.setPosition(offset + recordHeader.size());

    // skip any earlier fields ...
    for (int i = startField; i < fieldNumber; i++) {
      skipField(lrdi);
    }
View Full Code Here

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

    if (SanityManager.DEBUG)
    {
      String str = new String();
      try
      {
        StoredRecordHeader recordHeader = getHeaderAtSlot(slot);
        int offset = getRecordOffset(slot);
        int numberFields = recordHeader.getNumberFields();
        str = "\nslot " + slot + " offset " + offset + " " +
                         " recordlen " + getTotalSpace(slot) +
                         " (" + getRecordPortionLength(slot) +
                         "," + getReservedCount(slot) + ")"+
                         recordHeader.toString();

        rawDataIn.setPosition(offset + recordHeader.size());

        for (int i = 0; i < numberFields; i++)
        {
          int fieldStatus = StoredFieldHeader.readStatus(rawDataIn);
          int fieldDataLength = StoredFieldHeader.readFieldDataLength(rawDataIn, fieldStatus, slotFieldSize);
View Full Code Here

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

    long   currentOverflowPageNumber = 0;

slotScan:
    for (int slot = 0; (slot < slotsInUse) && (pageCount < pageList.length); slot++) {

      StoredRecordHeader recordHeader = getHeaderAtSlot(slot);
      if (!recordHeader.hasOverflow())
        continue;

      long overflowPageNumber = recordHeader.getOverflowPage();

      if (slot == currentSlot) {
        currentOverflowPageNumber = overflowPageNumber;
        continue;
      }
View Full Code Here

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

    boolean rowHasReservedSpace = false;

    StoredPage curPage = this;
    for (;;)
        {
      StoredRecordHeader rh = curPage.getHeaderAtSlot(slot);

      int startField          = rh.getFirstField();
      int endFieldExclusive   = startField + rh.getNumberFields();

      // curPage contains column[startField] to column[endFieldExclusive-1]

      // Need to cope with an update that is increasing the number of
            // columns.  If this occurs we want to make sure that we perform a
            // single update to the last portion of a record, and not an update
            // of the current columns and then an update to append a column.

      long nextPage        = -1;
      int  realStartColumn = -1;
      int  realSpaceOnPage = -1;

      if (!rh.hasOverflow() ||
                ((startColumn >= startField) &&
                 (startColumn <  endFieldExclusive)))
      {
        boolean                 hitLongColumn;
        int                     nextColumn      = -1;
        Object[]   savedFields     = null;
        DynamicByteArrayOutputStream  logBuffer       = null;

        do
                {
          try
                    {
            // Update this portion of the record.
            // Pass in headRowHandle in case we are to update any
            // long column and they need to be cleaned up by post
            // commit processing.  We don't want to purge the
            // columns right now because in order to reclaim the
            // page, we need to remove them.  But it would be bad
            // to remove them now because the transaction may not
            // commit for a long time.  We can do both purging of
            // the long column and page removal together in the
            // post commit.
            nextColumn =
                            owner.getActionSet().actionUpdate(
                                t, curPage, slot, id, row, validColumns,
                  realStartColumn, logBuffer,
                                realSpaceOnPage, headRowHandle);

            hitLongColumn = false;

          }
                    catch (LongColumnException lce)
                    {
 
            if (lce.getRealSpaceOnPage() == -1)
                        {
              // an update that has caused the row to increase
                            // in size *and* push some fields off the page
                            // that need to be inserted in an overflow page

              // no need to make a copy as we are going to use
                            // this buffer right away
              logBuffer = lce.getLogBuffer();

              savedFields     =
                                (Object[]) lce.getColumn();
                           
              realStartColumn = lce.getNextColumn();
              realSpaceOnPage = -1;

              hitLongColumn   = true;

              continue;
            }

           
            // we caught a real long column exception
            // three things should happen here:
            // 1. insert the long column into overflow pages.
            // 2. append the overflow field header in the main chain.
            // 3. continue the update in the main data chain.
            logBuffer =
                            new DynamicByteArrayOutputStream(lce.getLogBuffer());

            // step 1: insert the long column ... if this update
                        // operation rolls back, purge the after image column
                        // chain and reclaim the overflow page because the
                        // whole chain will be orphaned anyway.
            RecordHandle longColumnHandle =
              insertLongColumn(
                                curPage, lce, Page.INSERT_UNDO_WITH_PURGE);

            // step 2: append overflow field header to log buffer
            int overflowFieldLen = 0;
            try
                        {
              overflowFieldLen +=
                appendOverflowFieldHeader(
                                    logBuffer, longColumnHandle);

            }
                        catch (IOException ioe)
                        {
              throw StandardException.newException(
                                SQLState.DATA_UNEXPECTED_EXCEPTION, ioe);
            }

            // step 3: continue the insert in the main data chain
            // need to pass the log buffer, and start column to the
                        // next insert.
            realStartColumn = lce.getNextColumn() + 1;
            realSpaceOnPage = lce.getRealSpaceOnPage() - overflowFieldLen;
            hitLongColumn = true;

          }

        } while (hitLongColumn);


        // See if we completed all the columns that are on this page.
        int validColumnsSize =
                    (validColumns == null) ? 0 : validColumns.getLength();

        if (nextColumn != -1)
                {

          if (SanityManager.DEBUG)
                    {
            // note nextColumn might be less than the the first
                        // column we started updating. This is because the
                        // update might force the record header to grow and
                        // push fields before the one we are updating off the
                        // page and into this insert.

            if ((nextColumn < startField) ||
                            (rh.hasOverflow() && (nextColumn >= endFieldExclusive)))
                        {
              SanityManager.THROWASSERT(
                                "nextColumn out of range = " + nextColumn +
                " expected between " +
                                startField + " and " + endFieldExclusive);
                        }
          }

          // Need to insert rows from nextColumn to endFieldExclusive
                    // onto a new overflow page.
          // If the column is not being updated we
          // pick it up from the current page. If it is being updated
          // we take it from the new value.
          int possibleLastFieldExclusive = endFieldExclusive;
                   
          if (!rh.hasOverflow())
                    {
            // we might be adding a field here
            if (validColumns == null)
                        {
              if (row.length > possibleLastFieldExclusive)
                possibleLastFieldExclusive = row.length;
            }
                        else
                        {
              if (validColumnsSize > possibleLastFieldExclusive)
                possibleLastFieldExclusive = validColumnsSize;
            }
          }


                    // use a sparse row
          Object[] newRow =
                        new Object[possibleLastFieldExclusive];

          FormatableBitSet  newColumnList =
                        new FormatableBitSet(possibleLastFieldExclusive);

          ByteArrayOutputStream fieldStream = null;

          for (int i = nextColumn; i < possibleLastFieldExclusive; i++)
                    {
            if ((validColumns == null) ||
                            (validColumnsSize > i && validColumns.isSet(i)))
                        {
              newColumnList.set(i);
              // use the new value
              newRow[i] = RowUtil.getColumn(row, validColumns, i);

            }
                        else if (i < endFieldExclusive)
                        {
              newColumnList.set(i);

              // use the old value
              newRow[i] = savedFields[i - nextColumn];
            }
          }

          RecordHandle handle = curPage.getRecordHandleAtSlot(slot);

          // If the portion we just updated is the last portion then
                    // there cannot be any updates to do.
          if (rh.hasOverflow())
                    {
            // We have to carry across the overflow information
            // from the current record, if any.
            nextPage = rh.getOverflowPage();
            id = rh.getOverflowId();

            // find the next starting column before unlatching page
            startColumn =
                            RowUtil.nextColumn(
                                row, validColumns, endFieldExclusive);
          }
                    else
                    {
            startColumn = -1;
            nextPage = 0;
          }


          // After the update is done, see if this row piece has
          // shrunk in curPage if no other row pieces have shrunk so
          // far.  In head page, need to respect minimumRecordSize.
          // In overflow page, only need to respect
          // RawStoreFactory.MINIMUM_RECORD_SIZE_DEFAULT
          // Don't bother with temp container.
          if (!rowHasReservedSpace && headRowHandle != null &&
            curPage != null && !owner.isTemporaryContainer())
          {
            rowHasReservedSpace =
                            curPage.checkRowReservedSpace(slot);
          }


          // insert the record portion on a new overflow page at slot
                    // 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.
          if (!rowHasReservedSpace    &&
                        headRowHandle != null   &&
            curPage != null         &&
                        !owner.isTemporaryContainer())
                    {
            rowHasReservedSpace =
                            curPage.checkRowReservedSpace(slot);
          }


          // find the next starting column before we unlatch the page
          startColumn =
                        rh.hasOverflow() ?
                            RowUtil.nextColumn(
                                row, validColumns, endFieldExclusive) : -1;
        }

        // have we completed this update?
        if (startColumn == -1) {

          if ((curPage != this) && (curPage != null))
            curPage.unlatch();
          break;    // break out of the for loop
        }
      }

      if (nextPage == -1)
            {
        if (SanityManager.DEBUG)
                {
          SanityManager.ASSERT(
                        curPage != null,
                        "Current page is null be no overflow information has been obtained");
        }

        // Get the next page info while we still have the page
        // latched.
        nextPage = rh.getOverflowPage();
        id = rh.getOverflowId();
      }
     
      if ((curPage != this) && (curPage != null))
        curPage.unlatch();

View Full Code Here

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

  {
    // If this is a head row piece, first take care of the entire overflow
    // row chain.  Don't need to worry about long column because they are
    // not in place updatable.
    if (isOverflowPage() == false) {
      StoredRecordHeader recordHeader = getHeaderAtSlot(slot);

      while (recordHeader.hasOverflow()) {
        StoredPage nextPageInRowChain =
          getOverflowPage(recordHeader.getOverflowPage());

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

        try {
          int nextId = recordHeader.getOverflowId();
          int nextSlot = getOverflowSlot(nextPageInRowChain, recordHeader);

          nextPageInRowChain.compactRecord(t, nextSlot, nextId);

          // Follow the next long row pointer.
View Full Code Here

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

    throws StandardException
    {
        return(
            overflowRecordHeader != null ?
                overflowRecordHeader :
                (overflowRecordHeader = new StoredRecordHeader()));
    }
View Full Code Here

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

        int slot =
            findRecordById(
                parent_recordHeader.getOverflowId(), Page.FIRST_SLOT_NUMBER);

        StoredRecordHeader recordHeader = getHeaderAtSlot(slot);

        try
        {
            int offset_to_row_data =
                getRecordOffset(slot) + recordHeader.size();

            if (SanityManager.DEBUG)
            {
                if (getRecordOffset(slot) <
                        (PAGE_HEADER_OFFSET + PAGE_HEADER_SIZE))
                {
                    SanityManager.THROWASSERT(
                        "Incorrect offset.  offset = " +
                            getRecordOffset(slot) +
                        ", offset should be < " +
                        "(PAGE_HEADER_OFFSET + PAGE_HEADER_SIZE) = " +
                            (PAGE_HEADER_OFFSET + PAGE_HEADER_SIZE) +
                        ", current slot = " + slot +
                        ", total slotsInUse = " + slotsInUse);
                }
            }

            // position the array reading stream at beginning of row data
            // just past the record header.
            ArrayInputStream lrdi = rawDataIn;
            lrdi.setPosition(offset_to_row_data);

            if (fetchDesc != null)
            {
                if (fetchDesc.getQualifierList() != null)
                {
                    fetchDesc.reset();
                }

                readRecordFromArray(
                    row,
                    (fetchDesc.getValidColumns() == null) ?
                        row.length - 1 : fetchDesc.getMaxFetchColumnId(),
                    fetchDesc.getValidColumnsArray(),
                    fetchDesc.getMaterializedColumns(),
                    lrdi,
                    recordHeader,
                    (ErrorObjectInput) null /* always null */,
                    recordToLock);
            }
            else
            {
                readRecordFromArray(
                    row,
                    row.length - 1,
                    (int[]) null,
                    (int[]) null,
                    lrdi,
                    recordHeader,
                    (ErrorObjectInput) null /* always null */,
                    recordToLock);
            }

            return(recordHeader.hasOverflow() ? recordHeader : null);
        }
        catch (IOException ioe)
        {
            if (SanityManager.DEBUG)
            {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.