Equalizes backup entry count with primary in order to have identical
memory occupancy.
192888
private void equalizeEntryCountWithPrimary() {
        int diff = recordStore.size() - primaryEntryCount;
        if (diff > 0) {
            recordStore.sampleAndForceRemoveEntries(diff);

            assert recordStore.size() == primaryEntryCount : String.format("Failed"
                            + " to remove %d entries while attempting to match"
                            + " primary entry count %d,"
                            + " recordStore size is now %d",
                    diff, primaryEntryCount, recordStore.size());
        }
    }
627144
public int writeDependencyEntry(Object id,
                                    Object entry) {
        int rc = NO_EXCEPTION;
        if (!this.disableDependencyId) {
            if (delayOffload) {
                ValueSet vs = auxDataDependencyTable.getEntries(id);
                if (vs == null) {
                    Result result = writeValueSetEntry(DEP_ID_DATA, id, entry, null, !ADD_IF_NEW);
                    rc = result.returnCode;
                    boolean bExist = result.bExist;
                    returnToResultPool(result);
                    if (rc != DISK_EXCEPTION && rc != DISK_SIZE_OVER_LIMIT_EXCEPTION && bExist == !EXIST) {
                        rc = auxDataDependencyTable.add(id, entry);
                    }
                } else {
                    rc = auxDataDependencyTable.add(id, vs, entry);
                }
            } else {
                Result result = writeValueSetEntry(DEP_ID_DATA, id, entry, null, ADD_IF_NEW);
                rc = result.returnCode;
                returnToResultPool(result);
            }
        }
        return rc;
    }
437348
def sunionstore(self, destkey, key, *keys):
        """"""
        return self.execute(b'SUNIONSTORE', destkey, key, *keys)
394937
private void ensureCapacity(int segmentIndex) {
        while(segmentIndex >= segments.length) {
            segments = Arrays.copyOf(segments, segments.length * 3 / 2);
        }

        long numSegmentsPopulated = length >> log2OfSegmentSize;

        for(long i=numSegmentsPopulated; i <= segmentIndex; i++) {
            segments[(int)i] = memoryPool.getSegment();
            length += 1 << log2OfSegmentSize;
        }
    }
51406
def _enforce_size_limit(self, capacity):
        """"""
        while len(self._cache) > capacity:
            key, value = self._cache.popitem(last=False)
            if self._on_evict is not None:
                self._on_evict(key, value)
564248
def delete_with_retention(self, num_to_retain):
        
        base_backup_sentinel_depth = self.layout.basebackups().count('/') + 1

        # Sweep over base backup files, collecting sentinel files from
        # completed backups.
        completed_basebackups = []
        for key in self._backup_list(prefix=self.layout.basebackups()):

            key_name = self.layout.key_name(key)
            key_parts = key_name.split('/')
            key_depth = len(key_parts)
            url = '{scheme}://{bucket}/{name}'.format(
                scheme=self.layout.scheme,
                bucket=self._container_name(key),
                name=key_name)

            if key_depth == base_backup_sentinel_depth:
                # This is a key at the depth of a base-backup-sentinel file.
                # Check to see if it matches the known form.
                match = re.match(storage.COMPLETE_BASE_BACKUP_REGEXP,
                                 key_parts[-1])

                # If this isn't a base-backup-sentinel file, just ignore it.
                if match is None:
                    continue

                # This key corresponds to a base-backup-sentinel file and
                # represents a completed backup. Grab its segment number.
                scanned_sn = \
                    self._groupdict_to_segment_number(match.groupdict())
                completed_basebackups.append(dict(
                    scanned_sn=scanned_sn,
                    url=url))

        # Sort the base backups from newest to oldest.
        basebackups = sorted(
                        completed_basebackups,
                        key=lambda backup: backup['scanned_sn'].as_an_integer,
                        reverse=True)
        last_retained = None
        if len(basebackups) <= num_to_retain:
            detail = None
            if len(basebackups) == 0:
                msg = 'Not deleting any data.'
                detail = 'No existing base backups.'
            elif len(basebackups) == 1:
                last_retained = basebackups[-1]
                msg = 'Retaining existing base backup.'
            else:
                last_retained = basebackups[-1]
                msg = "Retaining all %d base backups." % len(basebackups)
        else:
            last_retained = basebackups[num_to_retain - 1]
            num_deleting = len(basebackups) - num_to_retain
            msg = "Deleting %d oldest base backups." % num_deleting
            detail = "Found %d total base backups." % len(basebackups)
        log_message = dict(msg=msg)
        if detail is not None:
            log_message['detail'] = detail
        if last_retained is not None:
            log_message['hint'] = \
                "Deleting keys older than %s." % last_retained['url']
        logger.info(**log_message)

        # This will delete all base backup and WAL data before
        # last_retained['scanned_sn'].
        if last_retained is not None:
            self._delete_base_backups_before(last_retained['scanned_sn'])
            self._delete_wals_before(last_retained['scanned_sn'])

        if self.deleter:
            self.deleter.close()
878113
static int adjustByteCount(final int offset, final int count, final int memorySize) {
    final int available = Math.max(0, memorySize - offset);
    return Math.min(available, count);
  }
593087
def add_copies(self, node, parent, elem, minel):
        """"""
        rep = 0 if minel is None else int(minel.arg) - 1
        for i in range(rep):
            parent.append(copy.deepcopy(elem))
559716
def sunionstore(self, dest, keys, *args):
        """"""
        result = self.sunion(keys, *args)
        self.redis[self._encode(dest)] = result
        return len(result)
823453
protected void ensureCapacity(int minNbRuns) {
    final int minCapacity = 2 * minNbRuns;
    if (valueslength.capacity() < minCapacity) {
      int newCapacity = valueslength.capacity();
      while (newCapacity < minCapacity) {
        newCapacity = (newCapacity == 0) ? DEFAULT_INIT_SIZE
            : newCapacity < 64 ? newCapacity * 2
                : newCapacity < 1024 ? newCapacity * 3 / 2 : newCapacity * 5 / 4;
      }
      final ShortBuffer nv = ShortBuffer.allocate(newCapacity);
      valueslength.rewind();
      nv.put(valueslength);
      valueslength = nv;
    }
  }
1123378
protected void compareSpaces(String primaryStoreId, DuplicationInfo info) {
        String spaces = dupHosts.get(info.getHost());
        Map<String, Long> primarySpaces = info.getSpaceCounts(primaryStoreId);
        for (String storeId : info.getStoreIds()) {
            Map<String, Long> secondarySpaces = info.getSpaceCounts(storeId);

            for (String spaceId : primarySpaces.keySet()) {
                // Determine if a space comparison should occur
                boolean doCompare = false;
                if (null == spaces || spaces.equals(ALL_SPACES)) {
                    doCompare = true;
                } else {
                    String[] spacesToCompare = spaces.split(",");
                    List<String> spaceList = Arrays.asList(spacesToCompare);
                    if (spaceList.contains(spaceId)) {
                        doCompare = true;
                    } else { // Check space and store IDs
                        for (String spacesSpaceId : spaceList) {
                            String[] spaceAndStoreId = spacesSpaceId.split(":");
                            if (spaceId.equals(spaceAndStoreId[0]) &&
                                storeId.equals(spaceAndStoreId[1])) {
                                doCompare = true;
                            }
                        }
                    }
                }

                // Do the comparison
                if (doCompare) {
                    Long primaryCount = primarySpaces.get(spaceId);
                    Long secondaryCount = secondarySpaces.get(spaceId);

                    if (null == secondaryCount) {
                        info.addIssue("The secondary provider (ID=" + storeId +
                                      ") is missing space: " + spaceId);
                    } else if (!primaryCount.equals(secondaryCount)) {
                        info.addIssue("The content item counts for the space " +
                                      spaceId + " do not match between primary and secondary " +
                                      "providers. Primary count: " + primaryCount +
                                      ". Secondary (ID=" + storeId + ") " +
                                      "count: " + secondaryCount + ".");
                    }
                }
            }
        }
    }
758911
def backup_value(self, value, up_to):
        
        self.N += 1
        self.W += value
        if self.parent is None or self is up_to:
            return
        self.parent.backup_value(value, up_to)
175604
def _ensure_counter(self):
        """"""
        if not isinstance(self.sync_counter, self._SynchronizationManager):
            self.sync_counter = self._SynchronizationManager()
878443
public synchronized int getPartitionStoreMoves() {
        int count = 0;
        for (List<Integer> entry : storeToPartitionIds.values())
            count += entry.size();
        return count;
    }
1023296
def on_backup_degradation(self, degraded_backups) -> None:
        '''
        
        '''
        self.__remove_replicas(degraded_backups,
                               Suspicions.BACKUP_PRIMARY_DEGRADED,
                               self.node.config.REPLICAS_REMOVING_WITH_DEGRADATION)
292355
private function _memoryadditional()
    {
        $pagesize = $this->grabkey("hw.pagesize");
        $this->sys->setMemCache($this->grabkey("vm.stats.vm.v_cache_count") * $pagesize);
        $this->sys->setMemApplication(($this->grabkey("vm.stats.vm.v_active_count") + $this->grabkey("vm.stats.vm.v_wire_count")) * $pagesize);
        $this->sys->setMemBuffer($this->sys->getMemUsed() - $this->sys->getMemApplication() - $this->sys->getMemCache());
    }
481921
public void ensureSize(int bufSize, int pre, int post)
        throws IOException
    {
        // Do we have space?
        if (bufSize>_buf.length || pre>_preReserve || post>_postReserve)
        {
            // Make a bigger buffer if we are allowed.
            if (_fixed)
                throw new IllegalStateException("Fixed");

            byte[] old=_buf;
            _buf=ByteArrayPool.getByteArray(bufSize);

            if (_pos>_start)
                System.arraycopy(old,_start,_buf,pre,_pos-_start);
            if (!_resized)
                ByteArrayPool.returnByteArray(old);
            
            _end=_buf.length-post;
            _preReserve=pre;
            _start=pre;
            _pos=pre;
            _postReserve=post;
        }
    }