Update hole data

@param iUpdateFromMemory

@throws IOException
323814
public synchronized void updateHole(final ODataHoleInfo iHole, final long iNewDataOffset, final int iNewRecordSize)
      throws IOException {
    final long timer = OProfiler.getInstance().startChrono();

    final boolean offsetChanged = iNewDataOffset != iHole.dataOffset;
    final boolean sizeChanged = iNewRecordSize != iHole.size;

    if (maxHoleSize < iNewRecordSize)
      maxHoleSize = iNewRecordSize;

    // IN MEMORY
    if (offsetChanged)
      availableHolesByPosition.remove(iHole);
    if (sizeChanged)
      availableHolesBySize.remove(iHole);

    if (offsetChanged)
      iHole.dataOffset = iNewDataOffset;
    if (sizeChanged)
      iHole.size = iNewRecordSize;

    if (offsetChanged)
      availableHolesByPosition.put(iHole, iHole);
    if (sizeChanged)
      availableHolesBySize.put(iHole, iHole);

    // TO FILE
    final long holePosition = iHole.holeOffset * RECORD_SIZE;
    if (offsetChanged)
      file.writeLong(holePosition, iNewDataOffset);
    if (sizeChanged)
      file.writeInt(holePosition + OBinaryProtocol.SIZE_LONG, iNewRecordSize);

    OProfiler.getInstance().stopChrono(PROFILER_DATA_HOLE_UPDATE, timer);
  }
102060
public void addPhysicalPosition(final OPhysicalPosition iPPosition) throws IOException {
    final long[] pos;
    final boolean recycled;
    long offset;

    acquireExclusiveLock();
    try {

      offset = holeSegment.popLastEntryPosition();
      if (offset > -1) {
        // REUSE THE HOLE
        pos = fileSegment.getRelativePosition(offset);
        recycled = true;
      } else {
        // NO HOLES FOUND: ALLOCATE MORE SPACE
        pos = allocateRecord();
        offset = fileSegment.getAbsolutePosition(pos);
        recycled = false;
      }

      final OFile file = fileSegment.files[(int) pos[0]];
      long p = pos[1];

      file.writeShort(p, (short) iPPosition.dataSegmentId);
      file.writeLong(p += OBinaryProtocol.SIZE_SHORT, iPPosition.dataSegmentPos);
      file.writeByte(p += OBinaryProtocol.SIZE_LONG, iPPosition.recordType);

      if (recycled)
        // GET LAST VERSION
        iPPosition.recordVersion = file.readInt(p + OBinaryProtocol.SIZE_BYTE) * -1;
      else
        iPPosition.recordVersion = 0;

      file.writeInt(p + OBinaryProtocol.SIZE_BYTE, iPPosition.recordVersion);

      iPPosition.clusterPosition = offset / RECORD_SIZE;

      updateBoundsAfterInsertion(iPPosition.clusterPosition);

    } finally {
      releaseExclusiveLock();
    }
  }
1036850
public UpdateResponse update(UpdateRequest request) throws IOException {
        return new UpdateResponse(client.doPost(request.toUrl(), request.getBody()));
    }
154155
public void update(Record record, boolean isText) throws MPXJException
   {
      int length = record.getLength();

      for (int i = 0; i < length; i++)
      {
         if (isText == true)
         {
            add(getTaskCode(record.getString(i)));
         }
         else
         {
            add(record.getInteger(i).intValue());
         }
      }
   }
75845
public void updateFromEntry(UpdateInodeFileEntry entry) {
    if (entry.hasPersistJobId()) {
      setPersistJobId(entry.getPersistJobId());
    }
    if (entry.hasReplicationMax()) {
      setReplicationMax(entry.getReplicationMax());
    }
    if (entry.hasReplicationMin()) {
      setReplicationMin(entry.getReplicationMin());
    }
    if (entry.hasTempUfsPath()) {
      setTempUfsPath(entry.getTempUfsPath());
    }
    if (entry.hasBlockSizeBytes()) {
      setBlockSizeBytes(entry.getBlockSizeBytes());
    }
    if (entry.hasCacheable()) {
      setCacheable(entry.getCacheable());
    }
    if (entry.hasCompleted()) {
      setCompleted(entry.getCompleted());
    }
    if (entry.hasLength()) {
      setLength(entry.getLength());
    }
    if (entry.getSetBlocksCount() > 0) {
      setBlockIds(entry.getSetBlocksList());
    }
  }
1042568
private void processAssignmentData() throws IOException
   {
      DirectoryEntry assnDir = (DirectoryEntry) m_projectDir.getEntry("TBkndAssn");
      FixFix assnFixedData = new FixFix(204, new DocumentInputStream(((DocumentEntry) assnDir.getEntry("FixFix   0"))));
      if (assnFixedData.getDiff() != 0 || (assnFixedData.getSize() % 238 == 0 && testAssignmentTasks(assnFixedData) == false))
      {
         assnFixedData = new FixFix(238, new DocumentInputStream(((DocumentEntry) assnDir.getEntry("FixFix   0"))));
      }

      int count = assnFixedData.getItemCount();
      FixDeferFix assnVarData = null;

      for (int loop = 0; loop < count; loop++)
      {
         if (assnVarData == null)
         {
            assnVarData = new FixDeferFix(new DocumentInputStream(((DocumentEntry) assnDir.getEntry("FixDeferFix   0"))));
         }

         byte[] data = assnFixedData.getByteArrayValue(loop);

         //
         // Check that the deleted flag isn't set
         //
         if (MPPUtility.getByte(data, 168) != 0x02)
         {
            Task task = m_file.getTaskByUniqueID(Integer.valueOf(MPPUtility.getInt(data, 16)));
            Resource resource = m_file.getResourceByUniqueID(Integer.valueOf(MPPUtility.getInt(data, 20)));

            if (task != null && resource != null)
            {
               ResourceAssignment assignment = task.addResourceAssignment(resource);
               assignment.setActualCost(NumberHelper.getDouble(((double) MPPUtility.getLong6(data, 138)) / 100));
               assignment.setActualWork(MPPUtility.getDuration(((double) MPPUtility.getLong6(data, 96)) / 100, TimeUnit.HOURS));
               assignment.setCost(NumberHelper.getDouble(((double) MPPUtility.getLong6(data, 132)) / 100));
               //assignment.setDelay(); // Not sure what this field maps on to in MSP
               assignment.setFinish(MPPUtility.getTimestamp(data, 28));
               assignment.setOvertimeWork(MPPUtility.getDuration(((double) MPPUtility.getLong6(data, 90)) / 100, TimeUnit.HOURS));
               //assignment.setPlannedCost(); // Not sure what this field maps on to in MSP
               //assignment.setPlannedWork(); // Not sure what this field maps on to in MSP
               assignment.setRemainingWork(MPPUtility.getDuration(((double) MPPUtility.getLong6(data, 114)) / 100, TimeUnit.HOURS));
               assignment.setStart(MPPUtility.getTimestamp(data, 24));
               assignment.setUniqueID(Integer.valueOf(MPPUtility.getInt(data, 0)));
               assignment.setUnits(Double.valueOf(((double) MPPUtility.getShort(data, 80)) / 100));
               assignment.setWork(MPPUtility.getDuration(((double) MPPUtility.getLong6(data, 84)) / 100, TimeUnit.HOURS));

               m_eventManager.fireAssignmentReadEvent(assignment);
            }
         }
      }
   }
1330407
public synchronized void createHole(final long iRecordOffset, final int iRecordSize) throws IOException {
    final long timer = OProfiler.getInstance().startChrono();

    // IN MEMORY
    final int recycledPosition;
    final ODataHoleInfo hole;
    if (!freeHoles.isEmpty()) {
      // RECYCLE THE FIRST FREE HOLE
      recycledPosition = freeHoles.remove(0);
      hole = availableHolesList.get(recycledPosition);
      hole.dataOffset = iRecordOffset;
      hole.size = iRecordSize;
    } else {
      // APPEND A NEW ONE
      recycledPosition = getHoles();
      hole = new ODataHoleInfo(iRecordSize, iRecordOffset, recycledPosition);
      availableHolesList.add(hole);
      file.allocateSpace(RECORD_SIZE);
    }

    availableHolesBySize.put(hole, hole);
    availableHolesByPosition.put(hole, hole);

    if (maxHoleSize < iRecordSize)
      maxHoleSize = iRecordSize;

    // TO FILE
    final long p = recycledPosition * RECORD_SIZE;
    file.writeLong(p, iRecordOffset);
    file.writeInt(p + OBinaryProtocol.SIZE_LONG, iRecordSize);

    OProfiler.getInstance().stopChrono(PROFILER_DATA_HOLE_CREATE, timer);
  }
1295522
public void updateEntryPointsCache() {
        if (kBase.getAddedEntryNodeCache() != null) {
            for (EntryPointNode addedNode : kBase.getAddedEntryNodeCache()) {
                EntryPointId id = addedNode.getEntryPoint();
                if (EntryPointId.DEFAULT.equals(id)) continue;
                WorkingMemoryEntryPoint wmEntryPoint = new NamedEntryPoint(id, addedNode, this);
                entryPoints.put(id.getEntryPointId(), wmEntryPoint);
            }
        }

        if (kBase.getRemovedEntryNodeCache() != null) {
            for (EntryPointNode removedNode : kBase.getRemovedEntryNodeCache()) {
                entryPoints.remove(removedNode.getEntryPoint().getEntryPointId());
            }
        }
    }
417429
@Override
    public Map<Integer, Long> createUpdatedMap() {
        if (storageFile == null) {
            //In-Memory Stats Storage
            db = DBMaker.memoryDB().make();
        } else {
            db = DBMaker.fileDB(storageFile).closeOnJvmShutdown().transactionEnable() //Default to Write Ahead Log - lower performance, but has crash protection
                            .make();
        }

        updated = db.hashMap("updated").keySerializer(Serializer.INTEGER).valueSerializer(Serializer.LONG)
                        .createOrOpen();
        return updated;
    }
898488
def update(self, update_finished_cb):
        """"""
        if not self._update_finished_cb:
            self._update_finished_cb = update_finished_cb
            self.valid = False
            logger.debug('Updating content of memory {}'.format(self.id))
            # Start reading the header
            self.mem_handler.read(self, 0, 11)
10934
@Override
    public void update(Object pData) throws APPErrorException {
        valid(pData);
        mDao.updateByPrimaryKey(pData);
    }
145425
public void updateIfNewRow(int iRowIndex)
        throws DBException
    {
        if ((m_iCurrentLockedRowIndex != -1) && (m_iCurrentLockedRowIndex != iRowIndex))
            if (m_buffCurrentLockedData != null)
        {
            {
                FieldList fieldList = this.makeRowCurrent(m_iCurrentLockedRowIndex, false);     // Read this row if it isn't current
                if (this.isRecordChanged())
                {   // Only update if there are changes.
                    synchronized (this)
                    {   // This time do the physical read (last time I asked for the cache)
                        DBException ex = null;
                        fieldList = this.makeRowCurrent(m_iCurrentLockedRowIndex, true);        // Read this row if it isn't current
                        if ((this.isAppending())
                            && ((m_iCurrentLockedRowIndex == m_iLastRecord + 1) && (m_iLastRecord != RECORD_UNKNOWN)))
                        {
                            m_table.add(fieldList);   // New record = add
                            this.setCurrentRow(-1);     // Make sure I don't try to use this unknown record without re-reading it.
                            if (m_iLastRecord != RECORD_UNKNOWN)    // Could have been set in 'add'
                                m_iLastRecord++;
                        }
                        else
                        {
                            if ((fieldList.getEditMode() == Constants.EDIT_CURRENT) || (fieldList.getEditMode() == Constants.EDIT_IN_PROGRESS))
                            {
                                try {
                                    m_table.set(fieldList);   // Current record = set
                                } catch (DBException e) {
                                    ex = e;
                                }
                            }
                            this.setCurrentRow(-1);    // Can't use current record anymore
                        }
                        m_iCurrentLockedRowIndex = -1;
                        m_buffCurrentLockedData = null;
                        if (ex != null)
                            throw ex;
                    }
                }
            }
        }
    }
26029
@Override
  public void update(final long value) {
    count.incrementAndGet();
    int index = (int) (value / binWidth);
    if (index >= numBins) {
      index = numBins - 1;
    }
    values.incrementAndGet(index);
  }
478446
private void updateEntry(HashtableEntry entry)
                    throws IOException, EOFException, FileManagerException, ClassNotFoundException {
        //
        // We'll write the header, key, and data into a byte arry first,
        // then allocate, seek, and write with a single write operation.
        // It is necessary to buffer the data first like this because we cannot
        // determine the size of storage to allocate without first examining the
        // size of the serialize object.
        //

        //
        // Serialize key and data.  If the data is already a byte[] array, we can
        // bypass serialization.
        //
        byte[] serializedKey = entry.serializedKey;
        int keySize = 0;
        byte[] serializedValue = null;
        int valueSize = -1;
        int bytes = 0;
        byte[] serializedCacheValue = entry.serializedCacheValue;
        int cacheValueSize = -1;
        int dataSize = HTENTRY_OVERHEAD_SIZE;

        if (serializedKey == null) {
            if (keyout == null) {
                keyout = new ByteArrayPlusOutputStream(500);
            } else {
                keyout.reset();
            }
            serializeTimer.reset();
            ObjectOutputStream out = new ObjectOutputStream(keyout);
            out.writeObject(entry.key);
            out.close();
            serializedKey = keyout.getTheBuffer();
            keySize = keyout.size();
            bytes_serialized += keySize;
        } else {
            keySize = entry.serializedKey.length;
        }
        dataSize += keySize;

        if (entry.value != null) {
            if (isByteArray(entry.value)) {
                bytes = 1;
                serializedValue = (byte[]) entry.value;
                if (entry.valuelen != -1) {
                    valueSize = entry.valuelen;
                } else {
                    valueSize = serializedValue.length;
                }
            } else {
                if (dataout == null) {
                    dataout = new ByteArrayPlusOutputStream(500);
                } else {
                    dataout.reset();
                }
                ObjectOutputStream out = new ObjectOutputStream(dataout);
                out.writeObject(entry.value);
                out.close();
                serializedValue = dataout.getTheBuffer();
                valueSize = dataout.size();
                bytes_serialized += valueSize;
                //
                // If an unusally large object is written it bloats the buffer, which can
                // hog resources.  If this happens dump the static buffer and start a new 
                // one on the next write.
                //
                if (valueSize > 100000) {
                    dataout = null;
                }
            }
        }

        serialize_time += serializeTimer.elapsed();

        int allocateSize = DWORDSIZE + // room for "next"
                           SWORDSIZE + // room for fastpath hash key
                           DWORDSIZE + // room for old format: last-modified
                                       //          new format: validator expiration time(VET)
                           DWORDSIZE + // room for old format: last-referenced;   // LI4337-17
                                       //          new format: H-Word = unused 
                                       //                      L-word = cache value hashcode 
                           DWORDSIZE + // room for first_created
                           DWORDSIZE + // room for expiration (RET)
                           DWORDSIZE + // room for flag + object size
                           SWORDSIZE + // room for size of the key
                           keySize + // room for serialized key
                           SWORDSIZE + // room for bytes flag
                           SWORDSIZE; // room for size of the value

        if (valueSize != -1) {
            allocateSize += valueSize; // room for serialized value
            dataSize += valueSize; // add value size to data size 
        }

        if (this.bHasCacheValue && !entry.bAliasId) {
            allocateSize += SWORDSIZE; // room for size of cacheValue
            if (serializedCacheValue != null) { // any cacheValue?
                cacheValueSize = serializedCacheValue.length; // size of the cacheValue
                allocateSize += cacheValueSize; // room for serialized cacheValue
                dataSize += cacheValueSize; // add cacheValue size to data size
            }
        }
        if (dataSize % 512 != 0) { // size adjustment for 512 blocks
            dataSize = (dataSize / 512 + 1) * 512;
        }
        //System.out.println("**** HashtableOnDisk: id=" + entry.key + " size=" + dataSize + " allocateSize=" + allocateSize);
        long tempData = 0;
        if (entry.bAliasId) {
            tempData = HTENTRY_MAGIC + HTENTRY_VERSION + HTENTRY_ALIAS_ID + dataSize;
        } else {
            tempData = HTENTRY_MAGIC + HTENTRY_VERSION + dataSize;
        }

        // end write key and value
        //
        // physical allocation
        //

        // For testing for cache id 
        //String testId = (String)entry.key;
        //if (testId.indexOf("928") > 0 || testId.indexOf("1028") > 0) {
        //    throw new IOException(com.ibm.ws.cache.HTODDynacache.DISK_CACHE_IN_GB_OVER_LIMIT_MSG);
        //}
        // For testing for depid/template
        //if (!this.bHasCacheValue) {
        //    String testId = (String)entry.key;
        //    if (testId.indexOf("926") > 0) {
        //        throw new IOException(com.ibm.ws.cache.HTODDynacache.DISK_CACHE_IN_GB_OVER_LIMIT_MSG);
        //    }
        //}
        entry.location = filemgr.allocate(allocateSize);

        initWriteBuffer();
        headerout.writeLong(entry.next);
        headerout.writeInt(entry.hash);
        //headerout.writeLong(System.currentTimeMillis());  // old format: last update
        headerout.writeLong(entry.validatorExpiration); // new format: VET
        //headerout.writeLong(System.currentTimeMillis());  // old format: last reference
        headerout.writeInt(0); // new format: unused    // LI4337-17
        headerout.writeInt(entry.cacheValueHashcode); //             cache value hashcode
        headerout.writeLong(entry.first_created); // when object is first created
        headerout.writeLong(entry.expiration); // expiration (RET) 
        headerout.writeLong(tempData); // write magic, version, flag & data size 
        headerout.writeInt(keySize);
        headerout.flush();

        //
        // Physical write the record like this:
        filemgr.seek(entry.location);
        filemgr.write(headeroutbuf);
        //
        // int keysize;            length of key
        // byte[] serialized key;  The key
        // int valueSize           length of value
        // int value_is_byte_array 0 if value is serialized obj 1 if a byte array
        // byte[] value            serialized value
        //
        filemgr.write(serializedKey, 0, keySize);
        filemgr.writeInt(bytes);
        filemgr.writeInt(valueSize);
        if (valueSize != -1) {
            filemgr.write(serializedValue, 0, valueSize);
        }

        //
        // if there is any cacheValue
        // int cacheValueSize      size of cacheValue - -1 if cacheValue is empty
        // byte[] cacheValue   serialized cacheValue
        //
        if (this.bHasCacheValue) {
            filemgr.writeInt(cacheValueSize);
            if (cacheValueSize != -1) {
                filemgr.write(serializedCacheValue, 0, cacheValueSize);
            }
        }

        //if (serializedCacheValue != null) {
        //   traceDebug("updateEntry()", "cacheName=" + this.htoddc.cacheName + " key=" + entry.key + " allocateSize=" + allocateSize + " dataSize=" + dataSize + " valueSize=" + valueSize + " cacheValueSize=" + cacheValueSize);
        //} else {
        //    traceDebug("updateEntry()", "cacheName=" + this.htoddc.cacheName + " key=" + entry.key + " allocateSize=" + allocateSize + " valueSize=" + valueSize);
        //}
    }
639268
public void updateMemoryInfo() {

		MemoryMXBean meminfo = ManagementFactory.getMemoryMXBean();

		MemoryUsage usage = meminfo.getHeapMemoryUsage();
		long _heapUsed = usage.getUsed();
		updateMaximum(heapUsed, _heapUsed);
		updateMaximum(heapTotal, usage.getMax());

		usage = meminfo.getNonHeapMemoryUsage();
		updateMaximum(nonHeapUsed, usage.getUsed());
		updateMaximum(nonHeapTotal, usage.getMax());

		// Log the memory usage if requested. Check the log level before logging
		// to minimize object creation overheads during preparation of the call
		// parameters.
		if (memoryLogger.isLoggable(Level.INFO)) {
			memoryLogger.log(Level.INFO, "MEM", new Object[] { _heapUsed });
		}
	}
64377
public void upsert(AbstractKVStorable[] toAdd) throws IOException {
        try {
            /* Another thread can have access to this file in parallel. So we must wait to get exclusive access. */
            dataFile = new HeaderIndexFile<Data>(
                    dataFilename,
                    AccessMode.READ_WRITE,
                    Integer.MAX_VALUE,
                    gp
                    );
            header = dataFile.getIndex(); // Pointer to the Index
        } catch (FileLockException e) {
            log.error("Errror occurred while opening database file.", e);
        }
        try {
            toAdd = AbstractKVStorable.merge(toAdd);

            readOffset = 0;
            filledUpToWhenStarted = dataFile.getFilledUpFromContentStart(); // need to remember how a many "old" bytes
                                                                            // were written in the file (will be
                                                                            // overwritten)
            writeOffset = 0; // at this position we want to start writing

            // readFirstChunkFromFile(toAdd[0]); // We read the chunk, where the first element has to be inserted or
            // updated from the disk
            readNextChunkFromFile();

            // We take one AbstractKVStorable from the chunk. The chunk will be automatically incremented
            byte[] dateFromDisk = getFromDisk();

            int indexOfToAdd = 0;
            int keyLength = prototype.getKey().length;

            // handle all AbstractKVStorable (update or insert)
            int compare;
            for (indexOfToAdd = 0; indexOfToAdd < toAdd.length && dateFromDisk != null;) {
                AbstractKVStorable dateFromBucket = toAdd[indexOfToAdd];
                compare = KeyUtils.compareKey(dateFromBucket.getKey(), dateFromDisk, keyLength);

                /* insert element from bucket */
                if (compare < 0) {
                    write(dateFromBucket.toByteBuffer().array(), false); // write date
                    indexOfToAdd++;// next dateFromBucket

                    // Incrementing the number of inserted entries.
                    numberOfInsertedEntries++;
                    continue;
                }

                /* merges element from bucket and element from disk */
                if (compare == 0) {
                    prototype.initFromByteBuffer(ByteBuffer.wrap(dateFromDisk));
                    AbstractKVStorable newDate = prototype.merge(dateFromBucket);

                    // TODO: think about update
                    write(newDate.toByteBuffer().array(), true); // write date
                    indexOfToAdd++; // next dateFromBucket
                    dateFromDisk = getFromDisk(); // get next date from disk

                    // Incrementing the number of updated entries.
                    numberOfUpdateEntries++;
                    continue;
                }

                /* insert element from disk (pendingElements) */
                if (compare > 0) {
                    prototype.initFromByteBuffer(ByteBuffer.wrap(dateFromDisk));
                    // if the dateFromDisk was marked as deleted
                    if (!prototype.isMarkedAsDeleted()) {
                        write(dateFromDisk, true); // write date
                        dateFromDisk = getFromDisk(); // get next date from disk
                        numberOfOldEntries++;
                    }
                    continue;
                }
            }

            // end of the already stored elements, but there are still elements from bucket to insert
            if (dateFromDisk == null) {
                for (; indexOfToAdd < toAdd.length; indexOfToAdd++) {
                    if (write(toAdd[indexOfToAdd].toByteBuffer().array(), false)) {
                        numberOfInsertedEntries++; // Incrementing the number of inserted entries.
                    }
                }
            }

            // all entries from bucket were added, but there are still pending elements .
            while (dateFromDisk != null) {
                write(dateFromDisk, true);
                dateFromDisk = getFromDisk();
            }

            // write the remaining elements from the bufferedWriter to the disk
            this.writeBuffer(); // TODO: check if the data fits into one chunk

            int lastChunkId = dataFile.getChunkIndex(writeOffset + bufferedWriter.position());
            this.header.setLargestKey(lastChunkId, largestKeyInChunk);
        } finally {
            // close the file
            dataFile.close();
        }
    }
781457
private void syncInternal() throws IOException {
        syncCompactor();
        fireBeforePersist();
        
        /* CALLS ORDERED: Need force _segment first and then persist
         * _addressArray. During recovery, the _addressArray can always
         * point to addresses which are valid though may not reflect the
         * most recent address update.
         */
        _segment.force();
        _addressArray.sync();
        _segmentManager.updateMeta();
        
        fireAfterPersist();
    }