/** * @param l List to add all elements of. */ public void addAll(GridLongList l) { assert l != null; if (l.isEmpty()) return; if (arr == null) arr = new long[4]; int len = arr.length; while (len < idx + l.size()) len <<= 1; arr = Arrays.copyOf(arr, len); System.arraycopy(l.arr, 0, arr, idx, l.size()); idx += l.size(); }
/** {@inheritDoc} */ @Override public long ttl(int idx) { if (ttls != null) { assert idx >= 0 && idx < ttls.size(); return ttls.get(idx); } return CU.TTL_NOT_CHANGED; }
/** {@inheritDoc} */ @Override public long conflictExpireTime(int idx) { if (conflictExpireTimes != null) { assert idx >= 0 && idx < conflictExpireTimes.size(); return conflictExpireTimes.get(idx); } return CU.EXPIRE_TIME_CALCULATE; }
/** {@inheritDoc} */ @Override public long conflictExpireTime(int idx) { if (conflictExpireTimes != null) { assert idx >= 0 && idx < conflictExpireTimes.size(); return conflictExpireTimes.get(idx); } return CU.EXPIRE_TIME_CALCULATE; }
/** {@inheritDoc} */ @Override public long nearExpireTime(int idx) { if (nearExpireTimes != null) { assert idx >= 0 && idx < nearExpireTimes.size(); return nearExpireTimes.get(idx); } return CU.EXPIRE_TIME_CALCULATE; }
/** * @param idx Index. * @return Expire time for near cache update. */ long nearExpireTime(int idx) { if (nearExpireTimes != null) { assert idx >= 0 && idx < nearExpireTimes.size(); return nearExpireTimes.get(idx); } return -1L; }
/** * @param idx Index. * @return TTL for near cache update. */ long nearTtl(int idx) { if (nearTtls != null) { assert idx >= 0 && idx < nearTtls.size(); return nearTtls.get(idx); } return -1L; }
/** {@inheritDoc} */ @Override public long conflictTtl(int idx) { if (conflictTtls != null) { assert idx >= 0 && idx < conflictTtls.size(); return conflictTtls.get(idx); } return CU.TTL_NOT_CHANGED; }
/** {@inheritDoc} */ @Override public Long updateCounter(int updCntr) { if (updateCntrs != null && updCntr < updateCntrs.size()) return updateCntrs.get(updCntr); return null; }
/** {@inheritDoc} */ @Override public long nearTtl(int idx) { if (nearTtls != null) { assert idx >= 0 && idx < nearTtls.size(); return nearTtls.get(idx); } return CU.TTL_NOT_CHANGED; }
/** * @param assign Nodes orders. * @param nodesByOrder Nodes by order cache. * @param discoCache Discovery data cache. * @return Nodes list. */ public static List<ClusterNode> toNodes(GridLongList assign, Map<Long, ClusterNode> nodesByOrder, DiscoCache discoCache) { List<ClusterNode> assign0 = new ArrayList<>(assign.size()); for (int n = 0; n < assign.size(); n++) { long order = assign.get(n); ClusterNode affNode = nodesByOrder.computeIfAbsent(order, o -> discoCache.serverNodeByOrder(order)); assert affNode != null : "Failed to find node by order [order=" + order + ", topVer=" + discoCache.version() + ']'; assign0.add(affNode); } return assign0; }
/** * @param l List to check. * @return {@code True} if this list contains all the elements of passed in list. */ public boolean containsAll(GridLongList l) { for (int i = 0; i < l.size(); i++) { if (!contains(l.get(i))) return false; } return true; }
/** * For cache updates in shared cache group need notify others caches CQ listeners * that generated counter should be skipped. * * @param cctx Cache context. * @param part Partition. * @param topVer Topology version. * @param gaps Even-length array of pairs [start, end] for each gap. */ @Nullable public void closeBackupUpdateCountersGaps(GridCacheContext cctx, int part, AffinityTopologyVersion topVer, GridLongList gaps) { assert gaps != null && gaps.size() % 2 == 0; for (int i = 0; i < gaps.size() / 2; i++) { long gapStart = gaps.get(i * 2); long gapStop = gaps.get(i * 2 + 1); /* * No user listeners should be called by this invocation. In the common case of partitioned cache or * replicated cache with non-local-only listener gaps (dummy filtered CQ events) will be added to the * backup queue without passing it to any listener. In the special case of local-only listener on * replicated cache there is no backup queues used at all and therefore no gaps occur - all unfiltered * events are passed to listeners upon arrive. */ for (long cntr = gapStart; cntr <= gapStop; cntr++) skipUpdateEvent(lsnrs, null, part, cntr, false, topVer); } }
/** * @param to To list. * @param from From list. * @return To list (passed in or created). */ public static GridLongList addAll(@Nullable GridLongList to, GridLongList from) { if (to == null) { GridLongList res = new GridLongList(from.size()); res.addAll(from); return res; } else { to.addAll(from); return to; } }
@Override public boolean hasNext() { if (!valIter.hasNext()) { if (++idx == vals.size()) return false; valIter.head(vals.get(idx)); assert valIter.hasNext(); } return true; }
/** * Returns (possibly reordered) copy of this list, excluding all elements of given list. * * @param l List of elements to remove. * @return New list without all elements from {@code l}. */ public GridLongList copyWithout(GridLongList l) { assert l != null; if (idx == 0) return new GridLongList(); if (l.idx == 0) return new GridLongList(Arrays.copyOf(arr, idx)); long[] newArr = Arrays.copyOf(arr, idx); int newIdx = idx; for (int i = 0; i < l.size(); i++) { long rmVal = l.get(i); for (int j = 0; j < newIdx; j++) { if (newArr[j] == rmVal) { while (newIdx > 0 && newArr[newIdx - 1] == rmVal) newIdx--; if (newIdx > 0) { newArr[j] = newArr[newIdx - 1]; newIdx--; } } } } return new GridLongList(newArr, newIdx); }
/** * @param part Partition. * @param primaryId Primary ID. * @param futId Future ID. */ private void sendDeferredUpdateResponse(int part, UUID primaryId, long futId) { Map<UUID, GridDhtAtomicDeferredUpdateResponse> resMap = defRes.get(); GridDhtAtomicDeferredUpdateResponse msg = resMap.get(primaryId); if (msg == null) { msg = new GridDhtAtomicDeferredUpdateResponse(ctx.cacheId(), new GridLongList(DEFERRED_UPDATE_RESPONSE_BUFFER_SIZE)); if (DEFERRED_UPDATE_RESPONSE_TIMEOUT > 0) { GridTimeoutObject timeoutSnd = new DeferredUpdateTimeout(part, primaryId); msg.timeoutSender(timeoutSnd); ctx.time().addTimeoutObject(timeoutSnd); } resMap.put(primaryId, msg); } GridLongList futIds = msg.futureIds(); assert futIds.size() < DEFERRED_UPDATE_RESPONSE_BUFFER_SIZE : futIds.size(); futIds.add(futId); if (futIds.size() >= DEFERRED_UPDATE_RESPONSE_BUFFER_SIZE) { resMap.remove(primaryId); sendDeferredUpdateResponse(primaryId, msg); } }
/** * @param nodeId Sender node ID. * @param res Deferred atomic update response. */ private void processDhtAtomicDeferredUpdateResponse(UUID nodeId, GridDhtAtomicDeferredUpdateResponse res) { GridLongList futIds = res.futureIds(); assert futIds != null && !futIds.isEmpty() : futIds; for (int i = 0; i < futIds.size(); i++) { long id = futIds.get(i); GridDhtAtomicAbstractUpdateFuture updateFut = (GridDhtAtomicAbstractUpdateFuture)ctx.mvcc().atomicFuture(id); if (updateFut != null) { if (msgLog.isDebugEnabled()) { msgLog.debug("Received DHT atomic deferred update response [futId=" + id + ", writeVer=" + res + ", node=" + nodeId + ']'); } updateFut.onDeferredResponse(nodeId); } else { U.warn(msgLog, "Failed to find DHT update future for deferred update response [futId=" + id + ", nodeId=" + nodeId + ", res=" + res + ']'); } } }
/** * Assert {@link GridLongList#copyWithout(GridLongList)} on given lists. * * @param lst Source lists. * @param rmv Exclude list. */ private void assertCopy(GridLongList lst, GridLongList rmv) { GridLongList res = lst.copyWithout(rmv); for (int i = 0; i < lst.size(); i++) { long v = lst.get(i); if (rmv.contains(v)) assertFalse(res.contains(v)); else assertTrue(res.contains(v)); } }