Space accounting.

@see com.ibm.ws.objectManager.ObjectStore#reserve(int,boolean)
484743
public final void reserve(int deltaSize, boolean paced)
                    throws ObjectManagerException
    {
        final String methodName = "reserve";
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this,
                        cclass,
                        methodName,
                        new Object[] { new Integer(deltaSize), new Boolean(paced) });

        long newReservedSize = reservedSize.addAndGet(deltaSize);

        if (newReservedSize > reservationCheckpointThreshold) {
            numberOfReservationCheckpointsTriggered++;
            objectManagerState.requestCheckpoint(persistent);

            // Pacing: slow paced requests.
            // ----------------------------   
            if (paced) {
                synchronized (reservationPacingLock) {

                    // TODO not during restart!
                    // TODO Need to release all waiters at shutdown.
                    while (newReservedSize > reservationCheckpointThreshold
                           && reservationPacing
                           && paced) {
                        if (Tracing.isAnyTracingEnabled() && trace.isDebugEnabled())
                            trace.debug(this, cclass, methodName, new Object[] { "wait:728",
                                                                                new Long(newReservedSize),
                                                                                new Long(reservationCheckpointThreshold),
                                                                                new Long(reservationThreshold),
                                                                                new Boolean(reservationPacing) });
                        try {
                            newReservedSize = reservedSize.addAndGet(-deltaSize);
                            reservationPacingLock.wait();

                        } catch (InterruptedException exception) {
                            // No FFDC Code Needed.
                            ObjectManager.ffdc.processException(this, cclass, methodName, exception, "1:739:1.57");
                            if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
                                trace.exit(this, cclass, methodName, exception);
                            throw new UnexpectedExceptionException(this, exception);

                        } finally {
                            newReservedSize = reservedSize.addAndGet(deltaSize);
                        } // try...
                    } // while (newReservedSize > reservationCheckpointThreshold...

                    // If we have a big enough backlog of reserved space in the store, 
                    // make subsequent paced requests also wait, 
                    // except during restart or shutdown.
                    if (newReservedSize > reservationCheckpointThreshold
                        && (objectManagerState.state == ObjectManagerState.stateColdStarted
                        || objectManagerState.state == ObjectManagerState.stateWarmStarted)) {
                        reservationPacing = true;
                    } else {
                        // Allow at least one more waiter to proceed.
                        reservationPacing = false;
                        reservationPacingLock.notify();
                    } // if (newReservedSize...
                } // synchronized (reservationPacingLock).

            } // if (paced)..

            // Expand the file size if necessary.
            // ----------------------------------

            if (newReservedSize > reservationThreshold) {
                synchronized (this) {
                    // Try extending the file.
                    // TODO setAllocationAllowed() will release another paced reservation.
                    setAllocationAllowed();

                    if (newReservedSize > (storeFileSizeAllocated - storeFileSizeUsed - directoryReservedSize)) {
                        // Suppress storeFull exceptions during recovery.
                        // Also suppress the exception if we are releasing space by using a negative delta size.
                        // During commit surplus space is released into the store. If the directory depth has
                        // increased meanwhile this may mean that there is still insufficient space in the store to allow
                        // further reservation requests, but we still allow negative requests.
                        if (objectManagerState.getObjectManagerStateState() == ObjectManagerState.stateReplayingLog
                            || deltaSize <= 0) {
                            if (Tracing.isAnyTracingEnabled() && trace.isDebugEnabled())
                                trace.debug(this, cclass, methodName, new Object[] { "Objectstorefull exception supressed:783",
                                                                                    new Long(newReservedSize) });
                        } else {
                            // We can't make the reservation so take it back.
                            reservedSize.addAndGet(-deltaSize);

                            if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
                                trace.exit(this, cclass, methodName, new Object[] { new Long(newReservedSize) });
                            throw new ObjectStoreFullException(this, null); // TODO objectToStore
                        } // if (objectManagerState...
                    } // if (reservedSize > (storeFileSizeAllocated - storeFileSizeUsed)).
                } // synchronized (this).

            } // if (newReservedSize > reservationThreshold).

        } else if (reservationPacing) {
            // We are below the limit so release any paced reservations.
            synchronized (reservationPacingLock) {
                pacedReservationsReleased++;
                reservationPacing = false;
                reservationPacingLock.notify();
            } // synchronized (reservationPacingLock).

        } // if (newReservedSize > reservationCheckpointThreshold).

        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this, cclass, methodName);
    }
787470
private long getSpaceCount(ContentStore store, String spaceId)
        throws ContentStoreException {
        SpaceStatsDTOList stats =
            store.getSpaceStats(spaceId, new Date(System.currentTimeMillis() - (24 * 60 * 60 * 1000)), new Date());

        long count = 0;

        if (stats != null && stats.size() > 0) {
            count = stats.getLast().getObjectCount();
        }

        return count;
    }
283429
public void setReservationStatus(com.google.api.ads.admanager.axis.v201811.ReservationStatus reservationStatus) {
        this.reservationStatus = reservationStatus;
    }
371353
@Override
    @SuppressWarnings("unchecked")
    protected void ensureCapacity(int capacity) {
        checkCapacity(capacity);
        ArrayHandle[] newArray = (ArrayHandle[]) Array.newInstance(ArrayHandle.class, capacity + 1);
        System.arraycopy(array, 1, newArray, 1, size);
        array = newArray;
    }
75963
public void setReservedDBInstancesOfferings(java.util.Collection<ReservedDBInstancesOffering> reservedDBInstancesOfferings) {
        if (reservedDBInstancesOfferings == null) {
            this.reservedDBInstancesOfferings = null;
            return;
        }

        this.reservedDBInstancesOfferings = new com.amazonaws.internal.SdkInternalList<ReservedDBInstancesOffering>(reservedDBInstancesOfferings);
    }
550625
protected void countSpaces(String host,
                               DuplicationInfo info,
                               ContentStore store,
                               List<String> spaces,
                               boolean primary) {
        String storeId = store.getStoreId();
        String storeType = store.getStorageProviderType();
        for (String spaceId : spaces) {
            boolean doCount = false;
            // Handle spaces which include space ID, formatted like: spaceId:storeId
            if (spaceId.indexOf(":") > -1) {
                String[] spaceAndStoreId = spaceId.split(":");
                spaceId = spaceAndStoreId[0];
                if (primary || storeId.equals(spaceAndStoreId[1])) {
                    doCount = true;
                }
            } else {
                doCount = true;
            }

            if (doCount) {
                countSpace(host, spaceId, storeId, storeType, info, store);
            }
        }
    }
1126468
public void setStorageSize(java.util.Collection<Range> storageSize) {
        if (storageSize == null) {
            this.storageSize = null;
            return;
        }

        this.storageSize = new java.util.ArrayList<Range>(storageSize);
    }
1184291
private boolean makeSpace() {
        clearCaches();
        int offset = savedScannerPosition == -1 ?
            position : savedScannerPosition;
        buf.position(offset);
        // Gain space by compacting buffer
        if (offset > 0) {
            buf.compact();
            translateSavedIndexes(offset);
            position -= offset;
            buf.flip();
            return true;
        }
        // Gain space by growing buffer
        int newSize = buf.capacity() * 2;
        CharBuffer newBuf = CharBuffer.allocate(newSize);
        newBuf.put(buf);
        newBuf.flip();
        translateSavedIndexes(offset);
        position -= offset;
        buf = newBuf;
        matcher.reset(buf);
        return true;
    }
101536
private void ensureSize(int minsize) {
    if(minsize <= store.length) {
      return;
    }
    int asize = store.length;
    while(asize < minsize) {
      asize = (asize >>> 1) + asize;
    }
    final int[] prev = store;
    store = new int[asize];
    System.arraycopy(prev, 0, store, 0, size);
  }
1141821
public void setCapacity(int capacity) {
        if (capacity <= 0) {
            throw new IllegalArgumentException("capacity must be greater than 0");
        }

        synchronized (queue) {
            // If the capacity was reduced, we remove oldest elements until the
            // queue fits inside the specified capacity
            if (capacity < this.capacity) {
                while (queue.size() > capacity) {
                    queue.removeFirst();
                }
            }
        }

        this.capacity = capacity;
    }
575661
public void shrink(int count) {
        char[] keepAllocated;

        if (count == 0) {
            throw new IllegalArgumentException();
        }
        if (count > lastNo) {
            throw new IllegalArgumentException(count + " vs " + lastNo);
        }
        lastNo -= count;
        keepAllocated = pages[0];
        System.arraycopy(pages, count, pages, 0, lastNo + 1);
        pages[lastNo + 1] = keepAllocated;
        for (int i = lastNo + 2; i < pages.length; i++) {
            pages[i] = null;
        }
    }
255165
function getReservation(resources, start, min, max) {
    var reservation, schedules = [], delays = {},
        maxTries = 50;

    initRanges(resources, start, schedules, delays);
    while(!(reservation = tryReservation(schedules, min, max)).success && --maxTries) {
      updateRanges(schedules, nextValidStart(schedules), delays);
    }

    reservation.delays = delays;
    return reservation;
  }
916517
public void setReservedInstances(java.util.Collection<ReservedInstances> reservedInstances) {
        if (reservedInstances == null) {
            this.reservedInstances = null;
            return;
        }

        this.reservedInstances = new com.amazonaws.internal.SdkInternalList<ReservedInstances>(reservedInstances);
    }
570616
public function reserve()
    {
        $queues = $this->queues();
        if(!is_array($queues)) {
            return;
        }

        foreach($queues as $queue) {
            $this->log('Checking ' . $queue, self::LOG_VERBOSE);
            $job = Job::reserve($queue);
            if($job) {
                $this->log('Found job on ' . $queue, self::LOG_VERBOSE);
                return $job;
            }
        }

        return false;
    }
1320024
protected void setAllocationAllowed()
                    throws ObjectManagerException {
        final String methodName = "setAllocationAllowed";
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this, cclass, methodName, new Object[] { new Long(storeFileSizeAllocated),
                                                                new Long(storeFileSizeUsed) });

        // Users of the store should have reserved space in the store for Objects that are allocated before
        // they finally add them to the store. We have already reserved enough space for a complete replacement 
        // of the directory which also implies there is already enough space to delete any number of 
        // ManagedObjects in the store.

        // Calculate how much file space we need to continue storing ManagedObjects.
        // We make the pessimistic assumption that the entire contents of the log might need to be written 
        // to this ObjectStore.

        // We have to take into account any pending request to increase the size of the log file, because this
        // would allow applications to over commit the store if they used the extra log space when it did not 
        // exist in the Object Store.

        long storeFileSizeRequired = storeFileSizeAllocated;

        if (simulateFullReservedSize > 0) {
            // We are simulating a a full filesystem.
            allocationAllowed = false;
            reservationThreshold = 0;

        }
        else
        {
            // do we have enough space to accomdate the whole log in the store plus reserved space in the store
            long currentReservedSize = reservedSize.get();

            long pesimisticSpaceRequired = Math.max(objectManagerState.logOutput.getLogFileSize(),
                                                    objectManagerState.logOutput.getLogFileSizeRequested())
                                           + directoryReservedSize
                                           + currentReservedSize;

            long largestFreeSpace = 0;
            if (freeSpaceByLength.size() > 0) {
                largestFreeSpace = ((FreeSpace) freeSpaceByLength.last()).length;
            }

            if (pesimisticSpaceRequired <= largestFreeSpace) {
                // we can at least fit the whole log plus reserved space in the largest free space entry
                // so we are ok
                allocationAllowed = true;
            }
            else
            {
                storeFileSizeRequired = storeFileSizeUsed +
                                        pesimisticSpaceRequired;

                // See if we need to change the size of the store file.
                if (storeFileSizeRequired <= storeFileSizeAllocated) {
                    // we have allocated more than is required, its just not in the free space map yet
                    allocationAllowed = true;

                } else if (storeFileSizeRequired <= maximumStoreFileSize) {
                    // we need more than we have allocated, and that is less than the maximum allowed, try grow to the required...
                    allocationAllowed = setStoreFileSizeInternal(storeFileSizeRequired);

                } else {
                    // We need greater than the maximum allowed, make sure we have all the space we are
                    // allowed to have.
                    if (storeFileSizeAllocated < maximumStoreFileSize)
                        setStoreFileSizeInternal(maximumStoreFileSize);
                    // TODO We could still allow allocation until we really are full when the reservation scheme will catch it!
                    allocationAllowed = false;
                    // Request a checkpoint, see if we can clear some space.
                    numberOfStoreFullCheckpointsTriggered++;
                    objectManagerState.requestCheckpoint(persistent);

                } // if ( storeFileSizeRequired...

                reservationThreshold = storeFileSizeAllocated - storeFileSizeUsed - directoryReservedSize;
                reservationCheckpointThreshold = Math.min(reservationThreshold,
                                                          currentReservedSize + reservationCheckpointMaximum);
            }
        }
        // Release at least one blocked reservation request.
        if (reservationPacing) {
            synchronized (reservationPacingLock) {
                reservationPacing = false;
                reservationPacingLock.notify();
            } // synchronized (reservationPacingLock).
        }

        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this,
                       cclass,
                       methodName,
                       new Object[] { new Boolean(allocationAllowed), new Long(storeFileSizeRequired) });
    }
1010637
public void setCapacity(String queue,float capacity) {
    rmConf.setFloat(toFullPropertyName(queue, CAPACITY_PROPERTY),capacity);
  }
623370
def apply_reserve_resource_constraint(machine, constraint):
    """"""
    if constraint.location is None:
        # Compensate for globally reserved resources
        machine.chip_resources \
            = resources_after_reservation(
                machine.chip_resources, constraint)
        if overallocated(machine.chip_resources):
            raise InsufficientResourceError(
                "Cannot meet {}".format(constraint))
        for location in machine.chip_resource_exceptions:
            machine.chip_resource_exceptions[location] \
                = resources_after_reservation(
                    machine.chip_resource_exceptions[location],
                    constraint)
            if overallocated(machine[location]):
                raise InsufficientResourceError(
                    "Cannot meet {}".format(constraint))
    else:
        # Compensate for reserved resources at a specified location
        machine[constraint.location] = resources_after_reservation(
            machine[constraint.location], constraint)
        if overallocated(machine[constraint.location]):
            raise InsufficientResourceError(
                "Cannot meet {}".format(constraint))