org.apache.cassandra.utils.Pair Java Examples
The following examples show how to use
org.apache.cassandra.utils.Pair.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OldNetworkTopologyStrategyTest.java From stratio-cassandra with Apache License 2.0 | 6 votes |
/** * test basic methods to move a node. For sure, it's not the best place, but it's easy to test * * @throws UnknownHostException */ @Test public void testMoveLeft() throws UnknownHostException { // Moves to the left : nothing to fetch, last part to stream int movingNodeIdx = 1; BigIntegerToken newToken = new BigIntegerToken("21267647932558653966460912964485513216"); BigIntegerToken[] tokens = initTokens(); BigIntegerToken[] tokensAfterMove = initTokensAfterMove(tokens, movingNodeIdx, newToken); Pair<Set<Range<Token>>, Set<Range<Token>>> ranges = calculateStreamAndFetchRanges(tokens, tokensAfterMove, movingNodeIdx); assertEquals(ranges.left.iterator().next().left, tokensAfterMove[movingNodeIdx]); assertEquals(ranges.left.iterator().next().right, tokens[movingNodeIdx]); assertEquals("No data should be fetched", ranges.right.size(), 0); }
Example #2
Source File: StorageService.java From stratio-cassandra with Apache License 2.0 | 6 votes |
private List<Pair<Range<Token>, Long>> getSplits(List<Token> tokens, int splitCount, ColumnFamilyStore cfs) { double step = (double) (tokens.size() - 1) / splitCount; Token prevToken = tokens.get(0); List<Pair<Range<Token>, Long>> splits = Lists.newArrayListWithExpectedSize(splitCount); for (int i = 1; i <= splitCount; i++) { int index = (int) Math.round(i * step); Token token = tokens.get(index); Range<Token> range = new Range<>(prevToken, token); // always return an estimate > 0 (see CASSANDRA-7322) splits.add(Pair.create(range, Math.max(cfs.metadata.getMinIndexInterval(), cfs.estimatedKeysForRange(range)))); prevToken = token; } return splits; }
Example #3
Source File: Gossiper.java From stratio-cassandra with Apache License 2.0 | 6 votes |
public void addLocalApplicationStates(List<Pair<ApplicationState, VersionedValue>> states) { taskLock.lock(); try { for (Pair<ApplicationState, VersionedValue> pair : states) { addLocalApplicationState(pair.left, pair.right); } } finally { taskLock.unlock(); } }
Example #4
Source File: Maps.java From stratio-cassandra with Apache License 2.0 | 6 votes |
public Term prepare(String keyspace, ColumnSpecification receiver) throws InvalidRequestException { validateAssignableTo(keyspace, receiver); ColumnSpecification keySpec = Maps.keySpecOf(receiver); ColumnSpecification valueSpec = Maps.valueSpecOf(receiver); Map<Term, Term> values = new HashMap<Term, Term>(entries.size()); boolean allTerminal = true; for (Pair<Term.Raw, Term.Raw> entry : entries) { Term k = entry.left.prepare(keyspace, keySpec); Term v = entry.right.prepare(keyspace, valueSpec); if (k.containsBindMarker() || v.containsBindMarker()) throw new InvalidRequestException(String.format("Invalid map literal for %s: bind variables are not supported inside collection literals", receiver.name)); if (k instanceof Term.NonTerminal || v instanceof Term.NonTerminal) allTerminal = false; values.put(k, v); } DelayedValue value = new DelayedValue(((MapType)receiver.type).getKeysType(), values); return allTerminal ? value.bind(QueryOptions.DEFAULT) : value; }
Example #5
Source File: StorageService.java From stratio-cassandra with Apache License 2.0 | 6 votes |
/** * @return list of Token ranges (_not_ keys!) together with estimated key count, * breaking up the data this node is responsible for into pieces of roughly keysPerSplit */ public List<Pair<Range<Token>, Long>> getSplits(String keyspaceName, String cfName, Range<Token> range, int keysPerSplit) { Keyspace t = Keyspace.open(keyspaceName); ColumnFamilyStore cfs = t.getColumnFamilyStore(cfName); List<DecoratedKey> keys = keySamples(Collections.singleton(cfs), range); long totalRowCountEstimate = cfs.estimatedKeysForRange(range); // splitCount should be much smaller than number of key samples, to avoid huge sampling error int minSamplesPerSplit = 4; int maxSplitCount = keys.size() / minSamplesPerSplit + 1; int splitCount = Math.max(1, Math.min(maxSplitCount, (int)(totalRowCountEstimate / keysPerSplit))); List<Token> tokens = keysToTokens(range, keys); return getSplits(tokens, splitCount, cfs); }
Example #6
Source File: ColumnFamilyRecordReader.java From stratio-cassandra with Apache License 2.0 | 6 votes |
protected Pair<ByteBuffer, SortedMap<ByteBuffer, Cell>> computeNext() { maybeInit(); if (rows == null) return endOfData(); totalRead++; KeySlice ks = rows.get(i++); AbstractType<?> comp = isSuper ? CompositeType.getInstance(comparator, subComparator) : comparator; SortedMap<ByteBuffer, Cell> map = new TreeMap<ByteBuffer, Cell>(comp); for (ColumnOrSuperColumn cosc : ks.columns) { List<Cell> cells = unthriftify(cosc); for (Cell cell : cells) map.put(cell.name().toByteBuffer(), cell); } return Pair.create(ks.key, map); }
Example #7
Source File: StorageService.java From stratio-cassandra with Apache License 2.0 | 6 votes |
private void bootstrap(Collection<Token> tokens) { isBootstrapMode = true; SystemKeyspace.updateTokens(tokens); // DON'T use setToken, that makes us part of the ring locally which is incorrect until we are done bootstrapping if (!DatabaseDescriptor.isReplacing()) { // if not an existing token then bootstrap List<Pair<ApplicationState, VersionedValue>> states = new ArrayList<Pair<ApplicationState, VersionedValue>>(); states.add(Pair.create(ApplicationState.TOKENS, valueFactory.tokens(tokens))); states.add(Pair.create(ApplicationState.STATUS, valueFactory.bootstrapping(tokens))); Gossiper.instance.addLocalApplicationStates(states); setMode(Mode.JOINING, "sleeping " + RING_DELAY + " ms for pending range setup", true); Uninterruptibles.sleepUninterruptibly(RING_DELAY, TimeUnit.MILLISECONDS); } else { // Dont set any state for the node which is bootstrapping the existing token... tokenMetadata.updateNormalTokens(tokens, FBUtilities.getBroadcastAddress()); SystemKeyspace.removeEndpoint(DatabaseDescriptor.getReplaceAddress()); } if (!Gossiper.instance.seenAnySeed()) throw new IllegalStateException("Unable to contact any seeds!"); setMode(Mode.JOINING, "Starting to bootstrap...", true); new BootStrapper(FBUtilities.getBroadcastAddress(), tokens, tokenMetadata).bootstrap(); // handles token update logger.info("Bootstrap completed! for the tokens {}", tokens); }
Example #8
Source File: TokenTreeTest.java From sasi with Apache License 2.0 | 6 votes |
@Test public void buildAndIterate() throws Exception { final TokenTreeBuilder builder = new TokenTreeBuilder(tokens).finish(); final Iterator<Pair<Long, LongSet>> tokenIterator = builder.iterator(); final Iterator<Map.Entry<Long, LongSet>> listIterator = tokens.entrySet().iterator(); while (tokenIterator.hasNext() && listIterator.hasNext()) { Pair<Long, LongSet> tokenNext = tokenIterator.next(); Map.Entry<Long, LongSet> listNext = listIterator.next(); Assert.assertEquals(listNext.getKey(), tokenNext.left); Assert.assertEquals(listNext.getValue(), tokenNext.right); } Assert.assertFalse("token iterator not finished", tokenIterator.hasNext()); Assert.assertFalse("list iterator not finished", listIterator.hasNext()); }
Example #9
Source File: ColumnFamilyRecordWriter.java From stratio-cassandra with Apache License 2.0 | 6 votes |
/** * If the key is to be associated with a valid value, a mutation is created * for it with the given column family and columns. In the event the value * in the column is missing (i.e., null), then it is marked for * {@link Deletion}. Similarly, if the entire value for a key is missing * (i.e., null), then the entire key is marked for {@link Deletion}. * </p> * * @param keybuff * the key to write. * @param value * the value to write. * @throws IOException */ @Override public void write(ByteBuffer keybuff, List<Mutation> value) throws IOException { Range<Token> range = ringCache.getRange(keybuff); // get the client for the given range, or create a new one RangeClient client = clients.get(range); if (client == null) { // haven't seen keys for this range: create new client client = new RangeClient(ringCache.getEndpoint(range)); client.start(); clients.put(range, client); } for (Mutation amut : value) client.put(Pair.create(keybuff, amut)); if (progressable != null) progressable.progress(); if (context != null) HadoopCompat.progress(context); }
Example #10
Source File: SizeTieredCompactionStrategy.java From stratio-cassandra with Apache License 2.0 | 6 votes |
/** * @param buckets list of buckets from which to return the most interesting, where "interesting" is the total hotness for reads * @param minThreshold minimum number of sstables in a bucket to qualify as interesting * @param maxThreshold maximum number of sstables to compact at once (the returned bucket will be trimmed down to this) * @return a bucket (list) of sstables to compact */ public static List<SSTableReader> mostInterestingBucket(List<List<SSTableReader>> buckets, int minThreshold, int maxThreshold) { // skip buckets containing less than minThreshold sstables, and limit other buckets to maxThreshold sstables final List<Pair<List<SSTableReader>, Double>> prunedBucketsAndHotness = new ArrayList<>(buckets.size()); for (List<SSTableReader> bucket : buckets) { Pair<List<SSTableReader>, Double> bucketAndHotness = trimToThresholdWithHotness(bucket, maxThreshold); if (bucketAndHotness != null && bucketAndHotness.left.size() >= minThreshold) prunedBucketsAndHotness.add(bucketAndHotness); } if (prunedBucketsAndHotness.isEmpty()) return Collections.emptyList(); Pair<List<SSTableReader>, Double> hottest = Collections.max(prunedBucketsAndHotness, bucketsByHotnessComparator); return hottest.left; }
Example #11
Source File: QueryController.java From sasi with Apache License 2.0 | 6 votes |
private Pair<Expression, Set<SSTableIndex>> calculatePrimary(Collection<Expression> expressions) { Expression expression = null; Set<SSTableIndex> primaryIndexes = Collections.emptySet(); for (Expression e : expressions) { if (!e.isIndexed()) continue; View view = e.index.getView(); if (view == null) continue; Set<SSTableIndex> indexes = view.match(scope, e); if (primaryIndexes.size() > indexes.size()) { primaryIndexes = indexes; expression = e; } } return expression == null ? null : Pair.create(expression, primaryIndexes); }
Example #12
Source File: TriggerExecutor.java From stratio-cassandra with Apache License 2.0 | 6 votes |
private Collection<Mutation> mergeMutations(Iterable<Mutation> mutations) { Map<Pair<String, ByteBuffer>, Mutation> groupedMutations = new HashMap<>(); for (Mutation mutation : mutations) { Pair<String, ByteBuffer> key = Pair.create(mutation.getKeyspaceName(), mutation.key()); Mutation current = groupedMutations.get(key); if (current == null) { // copy in case the mutation's modifications map is backed by an immutable Collections#singletonMap(). groupedMutations.put(key, mutation.copy()); } else { current.addAll(mutation); } } return groupedMutations.values(); }
Example #13
Source File: IndexSummaryTest.java From stratio-cassandra with Apache License 2.0 | 6 votes |
@Test public void testSerialization() throws IOException { Pair<List<DecoratedKey>, IndexSummary> random = generateRandomIndex(100, 1); DataOutputBuffer dos = new DataOutputBuffer(); IndexSummary.serializer.serialize(random.right, dos, false); // write junk dos.writeUTF("JUNK"); dos.writeUTF("JUNK"); FileUtils.closeQuietly(dos); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(dos.toByteArray())); IndexSummary is = IndexSummary.serializer.deserialize(dis, DatabaseDescriptor.getPartitioner(), false, 1, 1); for (int i = 0; i < 100; i++) assertEquals(i, is.binarySearch(random.left.get(i))); // read the junk assertEquals(dis.readUTF(), "JUNK"); assertEquals(dis.readUTF(), "JUNK"); is.close(); FileUtils.closeQuietly(dis); }
Example #14
Source File: TokenTreeBuilder.java From sasi with Apache License 2.0 | 6 votes |
@Override public Pair<Long, LongSet> computeNext() { if (currentIterator != null && currentIterator.hasNext()) { Map.Entry<Long, LongSet> next = currentIterator.next(); return Pair.create(next.getKey(), next.getValue()); } else { if (!levelIterator.hasNext()) return endOfData(); else { currentIterator = ((Leaf) levelIterator.next()).tokenIterator(); return computeNext(); } } }
Example #15
Source File: CacheService.java From stratio-cassandra with Apache License 2.0 | 6 votes |
public Future<Pair<KeyCacheKey, RowIndexEntry>> deserialize(DataInputStream input, ColumnFamilyStore cfs) throws IOException { int keyLength = input.readInt(); if (keyLength > FBUtilities.MAX_UNSIGNED_SHORT) { throw new IOException(String.format("Corrupted key cache. Key length of %d is longer than maximum of %d", keyLength, FBUtilities.MAX_UNSIGNED_SHORT)); } ByteBuffer key = ByteBufferUtil.read(input, keyLength); int generation = input.readInt(); SSTableReader reader = findDesc(generation, cfs.getSSTables()); input.readBoolean(); // backwards compatibility for "promoted indexes" boolean if (reader == null) { RowIndexEntry.Serializer.skipPromotedIndex(input); return null; } RowIndexEntry entry = reader.metadata.comparator.rowIndexEntrySerializer().deserialize(input, reader.descriptor.version); return Futures.immediateFuture(Pair.create(new KeyCacheKey(cfs.metadata.cfId, reader.descriptor, key), entry)); }
Example #16
Source File: FileMessageHeader.java From stratio-cassandra with Apache License 2.0 | 6 votes |
public void serialize(FileMessageHeader header, DataOutputPlus out, int version) throws IOException { UUIDSerializer.serializer.serialize(header.cfId, out, version); out.writeInt(header.sequenceNumber); out.writeUTF(header.version); out.writeLong(header.estimatedKeys); out.writeInt(header.sections.size()); for (Pair<Long, Long> section : header.sections) { out.writeLong(section.left); out.writeLong(section.right); } CompressionInfo.serializer.serialize(header.compressionInfo, out, version); out.writeLong(header.repairedAt); }
Example #17
Source File: OldNetworkTopologyStrategyTest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
@Test public void testMoveMiddleOfRing() throws UnknownHostException { // moves to another position in the middle of the ring : should stream all its data, and fetch all its new data int movingNodeIdx = 1; int movingNodeIdxAfterMove = 4; BigIntegerToken newToken = new BigIntegerToken("90070591730234615865843651857942052864"); BigIntegerToken[] tokens = initTokens(); BigIntegerToken[] tokensAfterMove = initTokensAfterMove(tokens, movingNodeIdx, newToken); Pair<Set<Range<Token>>, Set<Range<Token>>> ranges = calculateStreamAndFetchRanges(tokens, tokensAfterMove, movingNodeIdx); // sort the results, so they can be compared Range[] toStream = ranges.left.toArray(new Range[0]); Range[] toFetch = ranges.right.toArray(new Range[0]); Arrays.sort(toStream); Arrays.sort(toFetch); // build expected ranges Range[] toStreamExpected = new Range[2]; toStreamExpected[0] = new Range(getToken(movingNodeIdx - 2, tokens), getToken(movingNodeIdx - 1, tokens)); toStreamExpected[1] = new Range(getToken(movingNodeIdx - 1, tokens), getToken(movingNodeIdx, tokens)); Arrays.sort(toStreamExpected); Range[] toFetchExpected = new Range[2]; toFetchExpected[0] = new Range(getToken(movingNodeIdxAfterMove - 1, tokens), getToken(movingNodeIdxAfterMove, tokens)); toFetchExpected[1] = new Range(getToken(movingNodeIdxAfterMove, tokensAfterMove), getToken(movingNodeIdx, tokensAfterMove)); Arrays.sort(toFetchExpected); assertEquals(Arrays.equals(toStream, toStreamExpected), true); assertEquals(Arrays.equals(toFetch, toFetchExpected), true); }
Example #18
Source File: Directories.java From stratio-cassandra with Apache License 2.0 | 5 votes |
/** * * @return Return a map of all snapshots to space being used * The pair for a snapshot has size on disk and true size. */ public Map<String, Pair<Long, Long>> getSnapshotDetails() { final Map<String, Pair<Long, Long>> snapshotSpaceMap = new HashMap<>(); for (final File dir : dataPaths) { final File snapshotDir = new File(dir,SNAPSHOT_SUBDIR); if (snapshotDir.exists() && snapshotDir.isDirectory()) { final File[] snapshots = snapshotDir.listFiles(); if (snapshots != null) { for (final File snapshot : snapshots) { if (snapshot.isDirectory()) { final long sizeOnDisk = FileUtils.folderSize(snapshot); final long trueSize = getTrueAllocatedSizeIn(snapshot); Pair<Long,Long> spaceUsed = snapshotSpaceMap.get(snapshot.getName()); if (spaceUsed == null) spaceUsed = Pair.create(sizeOnDisk,trueSize); else spaceUsed = Pair.create(spaceUsed.left + sizeOnDisk, spaceUsed.right + trueSize); snapshotSpaceMap.put(snapshot.getName(), spaceUsed); } } } } } return snapshotSpaceMap; }
Example #19
Source File: OldNetworkTopologyStrategyTest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
@Test public void testMoveAfterNextNeighbors() throws UnknownHostException { // moves after its next neighbor in the ring int movingNodeIdx = 1; int movingNodeIdxAfterMove = 2; BigIntegerToken newToken = new BigIntegerToken("52535295865117307932921825928971026432"); BigIntegerToken[] tokens = initTokens(); BigIntegerToken[] tokensAfterMove = initTokensAfterMove(tokens, movingNodeIdx, newToken); Pair<Set<Range<Token>>, Set<Range<Token>>> ranges = calculateStreamAndFetchRanges(tokens, tokensAfterMove, movingNodeIdx); // sort the results, so they can be compared Range[] toStream = ranges.left.toArray(new Range[0]); Range[] toFetch = ranges.right.toArray(new Range[0]); Arrays.sort(toStream); Arrays.sort(toFetch); // build expected ranges Range[] toStreamExpected = new Range[1]; toStreamExpected[0] = new Range(getToken(movingNodeIdx - 2, tokens), getToken(movingNodeIdx - 1, tokens)); Arrays.sort(toStreamExpected); Range[] toFetchExpected = new Range[2]; toFetchExpected[0] = new Range(getToken(movingNodeIdxAfterMove - 1, tokens), getToken(movingNodeIdxAfterMove, tokens)); toFetchExpected[1] = new Range(getToken(movingNodeIdxAfterMove, tokensAfterMove), getToken(movingNodeIdx, tokensAfterMove)); Arrays.sort(toFetchExpected); assertEquals(Arrays.equals(toStream, toStreamExpected), true); assertEquals(Arrays.equals(toFetch, toFetchExpected), true); }
Example #20
Source File: SnapshotDetailsTabularData.java From stratio-cassandra with Apache License 2.0 | 5 votes |
public static void from(final String snapshot, final String ks, final String cf, Map.Entry<String, Pair<Long,Long>> snapshotDetail, TabularDataSupport result) { try { final String totalSize = FileUtils.stringifyFileSize(snapshotDetail.getValue().left); final String liveSize = FileUtils.stringifyFileSize(snapshotDetail.getValue().right); result.put(new CompositeDataSupport(COMPOSITE_TYPE, ITEM_NAMES, new Object[]{ snapshot, ks, cf, liveSize, totalSize })); } catch (OpenDataException e) { throw new RuntimeException(e); } }
Example #21
Source File: UserType.java From stratio-cassandra with Apache License 2.0 | 5 votes |
public static UserType getInstance(TypeParser parser) throws ConfigurationException, SyntaxException { Pair<Pair<String, ByteBuffer>, List<Pair<ByteBuffer, AbstractType>>> params = parser.getUserTypeParameters(); String keyspace = params.left.left; ByteBuffer name = params.left.right; List<ByteBuffer> columnNames = new ArrayList<>(params.right.size()); List<AbstractType<?>> columnTypes = new ArrayList<>(params.right.size()); for (Pair<ByteBuffer, AbstractType> p : params.right) { columnNames.add(p.left); columnTypes.add(p.right.freeze()); } return new UserType(keyspace, name, columnNames, columnTypes); }
Example #22
Source File: StreamReader.java From stratio-cassandra with Apache License 2.0 | 5 votes |
/** * @param channel where this reads data from * @return SSTable transferred * @throws IOException if reading the remote sstable fails. Will throw an RTE if local write fails. */ public SSTableWriter read(ReadableByteChannel channel) throws IOException { logger.debug("reading file from {}, repairedAt = {}", session.peer, repairedAt); long totalSize = totalSize(); Pair<String, String> kscf = Schema.instance.getCF(cfId); if (kscf == null) { // schema was dropped during streaming throw new IOException("CF " + cfId + " was dropped during streaming"); } ColumnFamilyStore cfs = Keyspace.open(kscf.left).getColumnFamilyStore(kscf.right); SSTableWriter writer = createWriter(cfs, totalSize, repairedAt); DataInputStream dis = new DataInputStream(new LZFInputStream(Channels.newInputStream(channel))); BytesReadTracker in = new BytesReadTracker(dis); try { while (in.getBytesRead() < totalSize) { writeRow(writer, in, cfs); // TODO move this to BytesReadTracker session.progress(desc, ProgressInfo.Direction.IN, in.getBytesRead(), totalSize); } return writer; } catch (Throwable e) { writer.abort(); drain(dis, in.getBytesRead()); if (e instanceof IOException) throw (IOException) e; else throw Throwables.propagate(e); } }
Example #23
Source File: Directories.java From stratio-cassandra with Apache License 2.0 | 5 votes |
private FileFilter getFilter() { // Note: the prefix needs to include cfname + separator to distinguish between a cfs and it's secondary indexes final String sstablePrefix = getSSTablePrefix(); return new FileFilter() { // This function always return false since accepts adds to the components map public boolean accept(File file) { // we are only interested in the SSTable files that belong to the specific ColumnFamily if (file.isDirectory() || !file.getName().startsWith(sstablePrefix)) return false; Pair<Descriptor, Component> pair = SSTable.tryComponentFromFilename(file.getParentFile(), file.getName()); if (pair == null) return false; if (skipTemporary && pair.left.type.isTemporary) return false; Set<Component> previous = components.get(pair.left); if (previous == null) { previous = new HashSet<>(); components.put(pair.left, previous); } previous.add(pair.right); nbFiles++; return false; } }; }
Example #24
Source File: IndexSummaryTest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
@Test public void testBinarySearch() { Pair<List<DecoratedKey>, IndexSummary> random = generateRandomIndex(100, 1); for (int i = 0; i < 100; i++) assertEquals(i, random.right.binarySearch(random.left.get(i))); random.right.close(); }
Example #25
Source File: SSTable.java From stratio-cassandra with Apache License 2.0 | 5 votes |
/** * @return A Descriptor,Component pair. If component is of unknown type, returns CUSTOM component. */ public static Pair<Descriptor,Component> tryComponentFromFilename(File dir, String name) { try { return Component.fromFilename(dir, name); } catch (NoSuchElementException e) { // A NoSuchElementException is thrown if the name does not match the Descriptor format // This is the less impacting change (all calls to this method test for null return) return null; } }
Example #26
Source File: AbstractByteOrderedPartitioner.java From stratio-cassandra with Apache License 2.0 | 5 votes |
public BytesToken midpoint(Token lt, Token rt) { BytesToken ltoken = (BytesToken) lt; BytesToken rtoken = (BytesToken) rt; int sigbytes = Math.max(ltoken.token.length, rtoken.token.length); BigInteger left = bigForBytes(ltoken.token, sigbytes); BigInteger right = bigForBytes(rtoken.token, sigbytes); Pair<BigInteger,Boolean> midpair = FBUtilities.midpoint(left, right, 8*sigbytes); return new BytesToken(bytesForBig(midpair.left, sigbytes, midpair.right)); }
Example #27
Source File: RandomPartitioner.java From stratio-cassandra with Apache License 2.0 | 5 votes |
public Token midpoint(Token ltoken, Token rtoken) { // the symbolic MINIMUM token should act as ZERO: the empty bit array BigInteger left = ltoken.equals(MINIMUM) ? ZERO : ((BigIntegerToken)ltoken).token; BigInteger right = rtoken.equals(MINIMUM) ? ZERO : ((BigIntegerToken)rtoken).token; Pair<BigInteger,Boolean> midpair = FBUtilities.midpoint(left, right, 127); // discard the remainder return new BigIntegerToken(midpair.left); }
Example #28
Source File: PermissionsCache.java From stratio-cassandra with Apache License 2.0 | 5 votes |
public Set<Permission> getPermissions(AuthenticatedUser user, IResource resource) { if (cache == null) return authorizer.authorize(user, resource); try { return cache.get(Pair.create(user, resource)); } catch (ExecutionException e) { throw new RuntimeException(e); } }
Example #29
Source File: StorageService.java From stratio-cassandra with Apache License 2.0 | 5 votes |
public List<String> getMovingNodes() { List<String> endpoints = new ArrayList<>(); for (Pair<Token, InetAddress> node : tokenMetadata.getMovingEndpoints()) { endpoints.add(node.right.getHostAddress()); } return endpoints; }
Example #30
Source File: StorageService.java From stratio-cassandra with Apache License 2.0 | 5 votes |
public void setGossipTokens(Collection<Token> tokens) { List<Pair<ApplicationState, VersionedValue>> states = new ArrayList<Pair<ApplicationState, VersionedValue>>(); states.add(Pair.create(ApplicationState.TOKENS, valueFactory.tokens(tokens))); states.add(Pair.create(ApplicationState.STATUS, valueFactory.normal(tokens))); Gossiper.instance.addLocalApplicationStates(states); }