/** * Creates pair out of given two objects. * * @param t1 First object in pair. * @param t2 Second object in pair. * @param <T> Type of objects in pair. * @return Pair of objects. * @deprecated Use {@link T2} instead. */ @Deprecated public static <T> IgnitePair<T> pair(@Nullable T t1, @Nullable T t2) { return new IgnitePair<>(t1, t2); }
/** * @param b Builder. * @param pairs Pairs to format. * @param dateFmt Formatter. */ private void format(StringBuilder b, Collection<IgnitePair<Long>> pairs, SimpleDateFormat dateFmt) { for (IgnitePair<Long> p : pairs) { b.append(String.format("%15d", p.get1())).append(" ") .append(dateFmt.format(new Date(p.get2()))).append(U.nl()); } }
/** * @param del DELETE statement. * @return {@code true} if given statement filters by single non expression key. */ public static FastUpdate getFastDeleteArgs(GridSqlDelete del) { IgnitePair<GridSqlElement> filter = findKeyValueEqualityCondition(del.where()); if (filter == null) return null; return FastUpdate.create(filter.getKey(), filter.getValue(), null); }
/** * @param from From node ID. * @param to To node ID. * @param msg Message. * @param sent Sent or received. */ public static void addMessage(UUID from, UUID to, Message msg, boolean sent) { IgnitePair<UUID> key = new IgnitePair<>(from, to); IgnitePair<Queue<Message>> val = msgMap.get(key); if (val == null) { IgnitePair<Queue<Message>> old = msgMap.putIfAbsent(key, val = new IgnitePair<Queue<Message>>( new ConcurrentLinkedQueue<Message>(), new ConcurrentLinkedQueue<Message>())); if (old != null) val = old; } (sent ? val.get1() : val.get2()).add(msg); }
/** * Test single node batch write-read-remove * * @param instanceToPut Ignite instance to put test data. * @param instanceToGet Ignite instance to get test data. */ private void singleNodeBatchWriteReadRemoveTest(Ignite instanceToPut, Ignite instanceToGet) { IgnitePair<Integer> keys = evaluatePrimaryAndBackupKeys(primaryKey + 1, backupKey + 1); Map<Integer, Integer> keyValuesMap = new HashMap<>(); keyValuesMap.put(primaryKey, 1); keyValuesMap.put(keys.get1(), 2); runTransactionally(instanceToPut, (Ignite ign) -> { ign.cache(CACHE_NAME).putAll(keyValuesMap); }); runTransactionally(instanceToGet, (Ignite ign) -> { ign.cache(CACHE_NAME).getAll(keyValuesMap.keySet()); }); runTransactionally(instanceToGet, (Ignite ign) -> { ign.cache(CACHE_NAME).removeAll(keyValuesMap.keySet()); }); checkResult("oneNodeBatchWriteReadRemoveTest", instanceToPut, instanceToGet); }
/** * Dumps all messages tracked with {@link #addMessage(UUID, UUID, Message, boolean)} to std out. */ public static void dumpMessages() { for (Map.Entry<IgnitePair<UUID>, IgnitePair<Queue<Message>>> entry : msgMap.entrySet()) { U.debug("\n" + entry.getKey().get1() + " [sent to] " + entry.getKey().get2()); for (Message message : entry.getValue().get1()) U.debug("\t" + message); U.debug(entry.getKey().get2() + " [received from] " + entry.getKey().get1()); for (Message message : entry.getValue().get2()) U.debug("\t" + message); } }
/** * @param pid PID of the other party. * @param size Size of the space. * @return Token pair. */ private IgnitePair<String> inOutToken(int pid, int size) { while (true) { long idx = tokIdxGen.get(); if (tokIdxGen.compareAndSet(idx, idx + 2)) return new IgnitePair<>( new File(tokDir, TOKEN_FILE_NAME + idx + "-" + pid + "-" + size).getAbsolutePath(), new File(tokDir, TOKEN_FILE_NAME + (idx + 1) + "-" + pid + "-" + size).getAbsolutePath() ); } }
/** * @param update UPDATE statement. * @return {@code null} if given statement directly updates {@code _val} column with a literal or param value * and filters by single non expression key (and, optionally, by single non expression value). */ public static FastUpdate getFastUpdateArgs(GridSqlUpdate update) { IgnitePair<GridSqlElement> filter = findKeyValueEqualityCondition(update.where()); if (filter == null) return null; if (update.cols().size() != 1) return null; Table tbl = update.cols().get(0).column().getTable(); if (!(tbl instanceof GridH2Table)) return null; GridH2RowDescriptor desc = ((GridH2Table)tbl).rowDescriptor(); if (!desc.isValueColumn(update.cols().get(0).column().getColumnId())) return null; GridSqlElement set = update.set().get(update.cols().get(0).columnName()); if (!(set instanceof GridSqlConst || set instanceof GridSqlParameter)) return null; return FastUpdate.create(filter.getKey(), filter.getValue(), set); }
/** * @param tx Transaction. */ private void processCompletedEntries(IgniteInternalTx tx) { if (tx.needsCompletedVersions()) { GridCacheVersion min = minVersion(tx.readEntries(), tx.xidVersion(), tx); min = minVersion(tx.writeEntries(), min, tx); assert min != null; IgnitePair<Collection<GridCacheVersion>> versPair = versions(min); tx.completedVersions(min, versPair.get1(), versPair.get2()); } }
/** * @param min Minimum version. * @return Pair [committed, rolledback] - never {@code null}, elements potentially empty, * but also never {@code null}. */ public IgnitePair<Collection<GridCacheVersion>> versions(GridCacheVersion min) { Collection<GridCacheVersion> committed = null; Collection<GridCacheVersion> rolledback = null; for (Map.Entry<GridCacheVersion, Boolean> e : completedVersSorted.tailMap(min, true).entrySet()) { if (e.getValue()) { if (committed == null) committed = new ArrayList<>(); committed.add(e.getKey()); } else { if (rolledback == null) rolledback = new ArrayList<>(); rolledback.add(e.getKey()); } } return new IgnitePair<>( committed == null ? Collections.<GridCacheVersion>emptyList() : committed, rolledback == null ? Collections.<GridCacheVersion>emptyList() : rolledback); }
/** * @param del DELETE statement. * @return {@code true} if given statement filters by single non expression key. */ public static FastUpdate getFastDeleteArgs(GridSqlDelete del) { IgnitePair<GridSqlElement> filter = findKeyValueEqualityCondition(del.where()); if (filter == null) return null; return FastUpdate.create(filter.getKey(), filter.getValue(), null); }
return new IgnitePair<>((GridSqlElement)whereOp.child(1), null); return null; return new IgnitePair<>((GridSqlElement)leftOp.child(1), (GridSqlElement)rightOp.child(1)); return null; return new IgnitePair<>((GridSqlElement)rightOp.child(1), (GridSqlElement)leftOp.child(1));
/** * @param update UPDATE statement. * @return {@code null} if given statement directly updates {@code _val} column with a literal or param value * and filters by single non expression key (and, optionally, by single non expression value). */ public static FastUpdate getFastUpdateArgs(GridSqlUpdate update) { IgnitePair<GridSqlElement> filter = findKeyValueEqualityCondition(update.where()); if (filter == null) return null; if (update.cols().size() != 1) return null; Table tbl = update.cols().get(0).column().getTable(); if (!(tbl instanceof GridH2Table)) return null; GridH2RowDescriptor desc = ((GridH2Table)tbl).rowDescriptor(); if (!desc.isValueColumn(update.cols().get(0).column().getColumnId())) return null; GridSqlElement set = update.set().get(update.cols().get(0).columnName()); if (!(set instanceof GridSqlConst || set instanceof GridSqlParameter)) return null; return FastUpdate.create(filter.getKey(), filter.getValue(), set); }
@Override public IgnitePair<?> call() { try (Transaction ignored = node.transactions().txStart()) { // First result that we'll later check w/respect to REPEATABLE READ semantic. Object res1 = clo.apply(null, null); Object res2 = clo.apply(startLatch, endLatch); return new IgnitePair<>(res1, res2); } } });
/** {@inheritDoc} */ @Override public IgnitePair<Long> call(Ignite ignite, IgniteCache<String, Integer> cache) throws Exception { GridCacheAdapter<?, ?> internalCache = internalCache0(cache); if (internalCache.context().isNear()) internalCache = internalCache.context().near().dht(); GridCacheEntryEx entry = internalCache.entryEx(key); entry.unswap(); if (!entry.hasValue()) { assertEquals(0, entry.ttl()); assertEquals(0, entry.expireTime()); return null; } IgnitePair<Long> pair = new IgnitePair<>(entry.ttl(), entry.expireTime()); if (!entry.isNear()) entry.context().cache().removeEntry(entry); return pair; } }
/** * Evaluate primary and backup keys. * * @param primaryKeyStart Value from need to start calculate primary key. * @param backupKeyStart Value from need to start calculate backup key. * @return Pair of result. The first result is found primary key. The second is found backup key. */ private IgnitePair<Integer> evaluatePrimaryAndBackupKeys(final int primaryKeyStart, final int backupKeyStart) { int primaryKey = primaryKeyStart; int backupKey = backupKeyStart; while (!client().affinity(CACHE_NAME).isPrimary(((IgniteKernal)primary()).localNode(), primaryKey)) primaryKey++; while (!client().affinity(CACHE_NAME).isBackup(((IgniteKernal)primary()).localNode(), backupKey) && backupKey < 100 + backupKeyStart) backupKey++; return new IgnitePair<>(primaryKey, backupKey); }