org.apache.cassandra.dht.Range Java Examples
The following examples show how to use
org.apache.cassandra.dht.Range.
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: WrappingCompactionStrategy.java From stratio-cassandra with Apache License 2.0 | 6 votes |
@Override public synchronized ScannerList getScanners(Collection<SSTableReader> sstables, Range<Token> range) { List<SSTableReader> repairedSSTables = new ArrayList<>(); List<SSTableReader> unrepairedSSTables = new ArrayList<>(); for (SSTableReader sstable : sstables) if (sstable.isRepaired()) repairedSSTables.add(sstable); else unrepairedSSTables.add(sstable); ScannerList repairedScanners = repaired.getScanners(repairedSSTables, range); ScannerList unrepairedScanners = unrepaired.getScanners(unrepairedSSTables, range); List<ISSTableScanner> scanners = new ArrayList<>(repairedScanners.scanners.size() + unrepairedScanners.scanners.size()); scanners.addAll(repairedScanners.scanners); scanners.addAll(unrepairedScanners.scanners); return new ScannerList(scanners); }
Example #2
Source File: MerkleTree.java From stratio-cassandra with Apache License 2.0 | 6 votes |
public MerkleTree deserialize(DataInput in, int version) throws IOException { byte hashdepth = in.readByte(); long maxsize = in.readLong(); long size = in.readLong(); IPartitioner partitioner; try { partitioner = FBUtilities.newPartitioner(in.readUTF()); } catch (ConfigurationException e) { throw new IOException(e); } // full range Token left = Token.serializer.deserialize(in); Token right = Token.serializer.deserialize(in); Range<Token> fullRange = new Range<>(left, right, partitioner); MerkleTree mt = new MerkleTree(partitioner, fullRange, hashdepth, maxsize); mt.size = size; mt.root = Hashable.serializer.deserialize(in, version); return mt; }
Example #3
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 #4
Source File: LeveledCompactionStrategy.java From stratio-cassandra with Apache License 2.0 | 6 votes |
public LeveledScanner(Collection<SSTableReader> sstables, Range<Token> range) { this.range = range; // add only sstables that intersect our range, and estimate how much data that involves this.sstables = new ArrayList<SSTableReader>(sstables.size()); long length = 0; for (SSTableReader sstable : sstables) { this.sstables.add(sstable); long estimatedKeys = sstable.estimatedKeys(); double estKeysInRangeRatio = 1.0; if (estimatedKeys > 0 && range != null) estKeysInRangeRatio = ((double) sstable.estimatedKeysForRanges(Collections.singleton(range))) / estimatedKeys; length += sstable.uncompressedLength() * estKeysInRangeRatio; } totalLength = length; Collections.sort(this.sstables, SSTableReader.sstableComparator); sstableIterator = this.sstables.iterator(); assert sstableIterator.hasNext(); // caller should check intersecting first currentScanner = sstableIterator.next().getScanner(range, CompactionManager.instance.getRateLimiter()); }
Example #5
Source File: MerkleTree.java From stratio-cassandra with Apache License 2.0 | 6 votes |
TreeRange getHelper(Hashable hashable, Token pleft, Token pright, byte depth, Token t) { if (hashable instanceof Leaf) { // we've reached a hash: wrap it up and deliver it return new TreeRange(this, pleft, pright, depth, hashable); } // else: node. Inner node = (Inner)hashable; if (Range.contains(pleft, node.token, t)) // left child contains token return getHelper(node.lchild, pleft, node.token, inc(depth), t); // else: right child contains token return getHelper(node.rchild, node.token, pright, inc(depth), t); }
Example #6
Source File: StorageService.java From stratio-cassandra with Apache License 2.0 | 6 votes |
public int forceRepairAsync(String keyspace, int parallelismDegree, Collection<String> dataCenters, Collection<String> hosts, boolean primaryRange, boolean fullRepair, String... columnFamilies) { if (parallelismDegree < 0 || parallelismDegree > RepairParallelism.values().length - 1) { throw new IllegalArgumentException("Invalid parallelism degree specified: " + parallelismDegree); } Collection<Range<Token>> ranges; if (primaryRange) { // when repairing only primary range, neither dataCenters nor hosts can be set if (dataCenters == null && hosts == null) ranges = getPrimaryRanges(keyspace); // except dataCenters only contain local DC (i.e. -local) else if (dataCenters != null && dataCenters.size() == 1 && dataCenters.contains(DatabaseDescriptor.getLocalDataCenter())) ranges = getPrimaryRangesWithinDC(keyspace); else throw new IllegalArgumentException("You need to run primary range repair on all nodes in the cluster."); } else { ranges = getLocalRanges(keyspace); } return forceRepairAsync(keyspace, RepairParallelism.values()[parallelismDegree], dataCenters, hosts, ranges, fullRepair, columnFamilies); }
Example #7
Source File: AntiCompactionTest.java From stratio-cassandra with Apache License 2.0 | 6 votes |
@Test public void antiCompactionSizeTest() throws ExecutionException, InterruptedException, IOException { Keyspace keyspace = Keyspace.open(KEYSPACE1); ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF); cfs.disableAutoCompaction(); SSTableReader s = writeFile(cfs, 1000); cfs.addSSTable(s); long origSize = s.bytesOnDisk(); Range<Token> range = new Range<Token>(new BytesToken(ByteBufferUtil.bytes(0)), new BytesToken(ByteBufferUtil.bytes(500))); Collection<SSTableReader> sstables = cfs.getSSTables(); CompactionManager.instance.performAnticompaction(cfs, Arrays.asList(range), Refs.tryRef(sstables), 12345); long sum = 0; for (SSTableReader x : cfs.getSSTables()) sum += x.bytesOnDisk(); assertEquals(sum, cfs.metric.liveDiskSpaceUsed.count()); assertEquals(origSize, cfs.metric.liveDiskSpaceUsed.count(), 100000); }
Example #8
Source File: TokenMetadata.java From stratio-cassandra with Apache License 2.0 | 6 votes |
/** @return the number of nodes bootstrapping into source's primary range */ public int pendingRangeChanges(InetAddress source) { int n = 0; Collection<Range<Token>> sourceRanges = getPrimaryRangesFor(getTokens(source)); lock.readLock().lock(); try { for (Token token : bootstrapTokens.keySet()) for (Range<Token> range : sourceRanges) if (range.contains(token)) n++; } finally { lock.readLock().unlock(); } return n; }
Example #9
Source File: SSTableScanner.java From stratio-cassandra with Apache License 2.0 | 6 votes |
/** * @param sstable SSTable to scan; must not be null * @param tokenRanges A set of token ranges to scan * @param limiter background i/o RateLimiter; may be null */ private SSTableScanner(SSTableReader sstable, Collection<Range<Token>> tokenRanges, RateLimiter limiter) { assert sstable != null; this.dfile = limiter == null ? sstable.openDataReader() : sstable.openDataReader(limiter); this.ifile = sstable.openIndexReader(); this.sstable = sstable; this.dataRange = null; List<AbstractBounds<RowPosition>> boundsList = new ArrayList<>(tokenRanges.size()); for (Range<Token> range : Range.normalize(tokenRanges)) addRange(range.toRowBounds(), boundsList); this.rangeIterator = boundsList.iterator(); }
Example #10
Source File: AntiEntropyServiceTestAbstract.java From stratio-cassandra with Apache License 2.0 | 6 votes |
@Test public void testGetNeighborsTimesTwoInSpecifiedHosts() throws Throwable { TokenMetadata tmd = StorageService.instance.getTokenMetadata(); // generate rf*2 nodes, and ensure that only neighbors specified by the hosts are returned addTokens(2 * Keyspace.open(keyspaceName).getReplicationStrategy().getReplicationFactor()); AbstractReplicationStrategy ars = Keyspace.open(keyspaceName).getReplicationStrategy(); List<InetAddress> expected = new ArrayList<>(); for (Range<Token> replicaRange : ars.getAddressRanges().get(FBUtilities.getBroadcastAddress())) { expected.addAll(ars.getRangeAddresses(tmd.cloneOnlyTokenMap()).get(replicaRange)); } expected.remove(FBUtilities.getBroadcastAddress()); Collection<String> hosts = Arrays.asList(FBUtilities.getBroadcastAddress().getCanonicalHostName(),expected.get(0).getCanonicalHostName()); assertEquals(expected.get(0), ActiveRepairService.getNeighbors(keyspaceName, StorageService.instance.getLocalRanges(keyspaceName).iterator().next(), null, hosts).iterator().next()); }
Example #11
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 #12
Source File: AntiCompactionTest.java From stratio-cassandra with Apache License 2.0 | 6 votes |
@Test public void shouldSkipAntiCompactionForNonIntersectingRange() throws InterruptedException, ExecutionException, IOException { ColumnFamilyStore store = prepareColumnFamilyStore(); Collection<SSTableReader> sstables = store.getUnrepairedSSTables(); assertEquals(store.getSSTables().size(), sstables.size()); Range<Token> range = new Range<Token>(new BytesToken("-10".getBytes()), new BytesToken("-1".getBytes())); List<Range<Token>> ranges = Arrays.asList(range); Refs<SSTableReader> refs = Refs.tryRef(sstables); if (refs == null) throw new IllegalStateException(); CompactionManager.instance.performAnticompaction(store, ranges, refs, 1); assertThat(store.getSSTables().size(), is(1)); assertThat(Iterables.get(store.getSSTables(), 0).isRepaired(), is(false)); assertThat(Iterables.get(store.getSSTables(), 0).selfRef().globalCount(), is(1)); assertThat(store.getDataTracker().getCompacting().size(), is(0)); }
Example #13
Source File: SizeEstimatesRecorder.java From stratio-cassandra with Apache License 2.0 | 5 votes |
public void run() { if (StorageService.instance.isStarting()) { logger.debug("Node has not yet joined; not recording size estimates"); return; } logger.debug("Recording size estimates"); // find primary token ranges for the local node. Collection<Token> localTokens = StorageService.instance.getLocalTokens(); Collection<Range<Token>> localRanges = StorageService.instance.getTokenMetadata().getPrimaryRangesFor(localTokens); for (Keyspace keyspace : Keyspace.nonSystem()) { for (ColumnFamilyStore table : keyspace.getColumnFamilyStores()) { long start = System.nanoTime(); recordSizeEstimates(table, localRanges); long passed = System.nanoTime() - start; logger.debug("Spent {} milliseconds on estimating {}.{} size", TimeUnit.NANOSECONDS.toMillis(passed), table.metadata.ksName, table.metadata.cfName); } } }
Example #14
Source File: SystemKeyspace.java From stratio-cassandra with Apache License 2.0 | 5 votes |
/** * @param schemaCfName The name of the ColumnFamily responsible for part of the schema (keyspace, ColumnFamily, columns) * @return low-level schema representation (each row represents individual Keyspace or ColumnFamily) */ public static List<Row> serializedSchema(String schemaCfName) { Token minToken = StorageService.getPartitioner().getMinimumToken(); return schemaCFS(schemaCfName).getRangeSlice(new Range<RowPosition>(minToken.minKeyBound(), minToken.maxKeyBound()), null, new IdentityQueryFilter(), Integer.MAX_VALUE, System.currentTimeMillis()); }
Example #15
Source File: StorageService.java From stratio-cassandra with Apache License 2.0 | 5 votes |
public int forceRepairRangeAsync(String beginToken, String endToken, String keyspaceName, boolean isSequential, boolean isLocal, boolean fullRepair, String... columnFamilies) { Collection<Range<Token>> repairingRange = createRepairRangeFrom(beginToken, endToken); logger.info("starting user-requested repair of range {} for keyspace {} and column families {}", repairingRange, keyspaceName, columnFamilies); return forceRepairAsync(keyspaceName, isSequential, isLocal, repairingRange, fullRepair, columnFamilies); }
Example #16
Source File: StorageService.java From stratio-cassandra with Apache License 2.0 | 5 votes |
private FutureTask<Object> createRepairTask(int cmd, String keyspace, Collection<Range<Token>> ranges, RepairParallelism parallelismDegree, boolean isLocal, boolean fullRepair, String... columnFamilies) { Set<String> dataCenters = null; if (isLocal) { dataCenters = Sets.newHashSet(DatabaseDescriptor.getLocalDataCenter()); } return createRepairTask(cmd, keyspace, ranges, parallelismDegree, dataCenters, null, fullRepair, columnFamilies); }
Example #17
Source File: ColumnFamilyStore.java From stratio-cassandra with Apache License 2.0 | 5 votes |
public Iterable<DecoratedKey> keySamples(Range<Token> range) { try (RefViewFragment view = selectAndReference(CANONICAL_SSTABLES)) { Iterable<DecoratedKey>[] samples = new Iterable[view.sstables.size()]; int i = 0; for (SSTableReader sstable: view.sstables) { samples[i++] = sstable.getKeySamples(range); } return Iterables.concat(samples); } }
Example #18
Source File: StreamRequest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
public StreamRequest(String keyspace, Collection<Range<Token>> ranges, Collection<String> columnFamilies, long repairedAt) { this.keyspace = keyspace; this.ranges = ranges; this.columnFamilies.addAll(columnFamilies); this.repairedAt = repairedAt; }
Example #19
Source File: DifferencerTest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
@Test public void testDifference() throws Throwable { Range<Token> range = new Range<>(partirioner.getMinimumToken(), partirioner.getRandomToken()); UUID parentRepairSession = UUID.randomUUID(); Keyspace keyspace = Keyspace.open("Keyspace1"); ColumnFamilyStore cfs = keyspace.getColumnFamilyStore("Standard1"); ActiveRepairService.instance.registerParentRepairSession(parentRepairSession, Arrays.asList(cfs), Arrays.asList(range)); RepairJobDesc desc = new RepairJobDesc(parentRepairSession, UUID.randomUUID(), "Keyspace1", "Standard1", range); MerkleTree tree1 = createInitialTree(desc); MerkleTree tree2 = createInitialTree(desc); // change a range in one of the trees Token token = partirioner.midpoint(range.left, range.right); tree1.invalidate(token); MerkleTree.TreeRange changed = tree1.get(token); changed.hash("non-empty hash!".getBytes()); Set<Range<Token>> interesting = new HashSet<>(); interesting.add(changed); // difference the trees // note: we reuse the same endpoint which is bogus in theory but fine here TreeResponse r1 = new TreeResponse(InetAddress.getByName("127.0.0.1"), tree1); TreeResponse r2 = new TreeResponse(InetAddress.getByName("127.0.0.2"), tree2); Differencer diff = new Differencer(desc, r1, r2); diff.run(); // ensure that the changed range was recorded assertEquals("Wrong differing ranges", interesting, new HashSet<>(diff.differences)); }
Example #20
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 #21
Source File: StorageService.java From stratio-cassandra with Apache License 2.0 | 5 votes |
/** * Finds living endpoints responsible for the given ranges * * @param keyspaceName the keyspace ranges belong to * @param ranges the ranges to find sources for * @return multimap of addresses to ranges the address is responsible for */ private Multimap<InetAddress, Range<Token>> getNewSourceRanges(String keyspaceName, Set<Range<Token>> ranges) { InetAddress myAddress = FBUtilities.getBroadcastAddress(); Multimap<Range<Token>, InetAddress> rangeAddresses = Keyspace.open(keyspaceName).getReplicationStrategy().getRangeAddresses(tokenMetadata.cloneOnlyTokenMap()); Multimap<InetAddress, Range<Token>> sourceRanges = HashMultimap.create(); IFailureDetector failureDetector = FailureDetector.instance; // find alive sources for our new ranges for (Range<Token> range : ranges) { Collection<InetAddress> possibleRanges = rangeAddresses.get(range); IEndpointSnitch snitch = DatabaseDescriptor.getEndpointSnitch(); List<InetAddress> sources = snitch.getSortedListByProximity(myAddress, possibleRanges); assert (!sources.contains(myAddress)); for (InetAddress source : sources) { if (failureDetector.isAlive(source)) { sourceRanges.put(source, range); break; } } } return sourceRanges; }
Example #22
Source File: StorageService.java From stratio-cassandra with Apache License 2.0 | 5 votes |
public int forceRepairAsync(String keyspace, RepairParallelism parallelismDegree, boolean isLocal, Collection<Range<Token>> ranges, boolean fullRepair, String... columnFamilies) { if (ranges.isEmpty() || Keyspace.open(keyspace).getReplicationStrategy().getReplicationFactor() < 2) return 0; int cmd = nextRepairCommand.incrementAndGet(); if (FBUtilities.isWindows() && parallelismDegree != RepairParallelism.PARALLEL) { logger.warn("Snapshot-based repair is not yet supported on Windows. Reverting to parallel repair."); parallelismDegree = RepairParallelism.PARALLEL; } new Thread(createRepairTask(cmd, keyspace, ranges, parallelismDegree, isLocal, fullRepair, columnFamilies)).start(); return cmd; }
Example #23
Source File: SerializationsTest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
private void testRangeSliceCommandWrite() throws IOException { IPartitioner part = StorageService.getPartitioner(); AbstractBounds<RowPosition> bounds = new Range<Token>(part.getRandomToken(), part.getRandomToken()).toRowBounds(); RangeSliceCommand namesCmd = new RangeSliceCommand(statics.KS, "Standard1", statics.readTs, namesPred, bounds, 100); MessageOut<RangeSliceCommand> namesCmdMsg = namesCmd.createMessage(); RangeSliceCommand emptyRangeCmd = new RangeSliceCommand(statics.KS, "Standard1", statics.readTs, emptyRangePred, bounds, 100); MessageOut<RangeSliceCommand> emptyRangeCmdMsg = emptyRangeCmd.createMessage(); RangeSliceCommand regRangeCmd = new RangeSliceCommand(statics.KS, "Standard1", statics.readTs, nonEmptyRangePred, bounds, 100); MessageOut<RangeSliceCommand> regRangeCmdMsg = regRangeCmd.createMessage(); RangeSliceCommand namesCmdSup = new RangeSliceCommand(statics.KS, "Super1", statics.readTs, namesSCPred, bounds, 100); MessageOut<RangeSliceCommand> namesCmdSupMsg = namesCmdSup.createMessage(); RangeSliceCommand emptyRangeCmdSup = new RangeSliceCommand(statics.KS, "Super1", statics.readTs, emptyRangePred, bounds, 100); MessageOut<RangeSliceCommand> emptyRangeCmdSupMsg = emptyRangeCmdSup.createMessage(); RangeSliceCommand regRangeCmdSup = new RangeSliceCommand(statics.KS, "Super1", statics.readTs, nonEmptyRangeSCPred, bounds, 100); MessageOut<RangeSliceCommand> regRangeCmdSupMsg = regRangeCmdSup.createMessage(); DataOutputStreamAndChannel out = getOutput("db.RangeSliceCommand.bin"); namesCmdMsg.serialize(out, getVersion()); emptyRangeCmdMsg.serialize(out, getVersion()); regRangeCmdMsg.serialize(out, getVersion()); namesCmdSupMsg.serialize(out, getVersion()); emptyRangeCmdSupMsg.serialize(out, getVersion()); regRangeCmdSupMsg.serialize(out, getVersion()); out.close(); // test serializedSize testSerializedSize(namesCmd, RangeSliceCommand.serializer); testSerializedSize(emptyRangeCmd, RangeSliceCommand.serializer); testSerializedSize(regRangeCmd, RangeSliceCommand.serializer); testSerializedSize(namesCmdSup, RangeSliceCommand.serializer); testSerializedSize(emptyRangeCmdSup, RangeSliceCommand.serializer); testSerializedSize(regRangeCmdSup, RangeSliceCommand.serializer); }
Example #24
Source File: StorageService.java From stratio-cassandra with Apache License 2.0 | 5 votes |
public Map<List<String>, List<String>> getPendingRangeToEndpointMap(String keyspace) { // some people just want to get a visual representation of things. Allow null and set it to the first // non-system keyspace. if (keyspace == null) keyspace = Schema.instance.getNonSystemKeyspaces().get(0); Map<List<String>, List<String>> map = new HashMap<>(); for (Map.Entry<Range<Token>, Collection<InetAddress>> entry : tokenMetadata.getPendingRanges(keyspace).entrySet()) { List<InetAddress> l = new ArrayList<>(entry.getValue()); map.put(entry.getKey().asList(), stringify(l)); } return map; }
Example #25
Source File: StreamingTransferTest.java From stratio-cassandra with Apache License 2.0 | 5 votes |
private void transferRanges(ColumnFamilyStore cfs) throws Exception { IPartitioner p = StorageService.getPartitioner(); List<Range<Token>> ranges = new ArrayList<>(); // wrapped range ranges.add(new Range<Token>(p.getToken(ByteBufferUtil.bytes("key1")), p.getToken(ByteBufferUtil.bytes("key0")))); new StreamPlan("StreamingTransferTest").transferRanges(LOCAL, cfs.keyspace.getName(), ranges, cfs.getColumnFamilyName()).execute().get(); }
Example #26
Source File: StreamSession.java From stratio-cassandra with Apache License 2.0 | 5 votes |
private List<SSTableStreamingSections> getSSTableSectionsForRanges(Collection<Range<Token>> ranges, Collection<ColumnFamilyStore> stores, long overriddenRepairedAt, boolean isIncremental) { Refs<SSTableReader> refs = new Refs<>(); try { for (ColumnFamilyStore cfStore : stores) { List<AbstractBounds<RowPosition>> rowBoundsList = new ArrayList<>(ranges.size()); for (Range<Token> range : ranges) rowBoundsList.add(range.toRowBounds()); refs.addAll(cfStore.selectAndReference(cfStore.viewFilter(rowBoundsList, !isIncremental)).refs); } List<SSTableStreamingSections> sections = new ArrayList<>(refs.size()); for (SSTableReader sstable : refs) { long repairedAt = overriddenRepairedAt; if (overriddenRepairedAt == ActiveRepairService.UNREPAIRED_SSTABLE) repairedAt = sstable.getSSTableMetadata().repairedAt; sections.add(new SSTableStreamingSections(sstable, refs.get(sstable), sstable.getPositionsForRanges(ranges), sstable.estimatedKeysForRanges(ranges), repairedAt)); } return sections; } catch (Throwable t) { refs.release(); throw t; } }
Example #27
Source File: StorageService.java From stratio-cassandra with Apache License 2.0 | 5 votes |
private Future<StreamState> streamHints() { // StreamPlan will not fail if there are zero files to transfer, so flush anyway (need to get any in-memory hints, as well) ColumnFamilyStore hintsCF = Keyspace.open(Keyspace.SYSTEM_KS).getColumnFamilyStore(SystemKeyspace.HINTS_CF); FBUtilities.waitOnFuture(hintsCF.forceFlush()); // gather all live nodes in the cluster that aren't also leaving List<InetAddress> candidates = new ArrayList<>(StorageService.instance.getTokenMetadata().cloneAfterAllLeft().getAllEndpoints()); candidates.remove(FBUtilities.getBroadcastAddress()); for (Iterator<InetAddress> iter = candidates.iterator(); iter.hasNext(); ) { InetAddress address = iter.next(); if (!FailureDetector.instance.isAlive(address)) iter.remove(); } if (candidates.isEmpty()) { logger.warn("Unable to stream hints since no live endpoints seen"); return Futures.immediateFuture(null); } else { // stream to the closest peer as chosen by the snitch DatabaseDescriptor.getEndpointSnitch().sortByProximity(FBUtilities.getBroadcastAddress(), candidates); InetAddress hintsDestinationHost = candidates.get(0); InetAddress preferred = SystemKeyspace.getPreferredIP(hintsDestinationHost); // stream all hints -- range list will be a singleton of "the entire ring" Token token = StorageService.getPartitioner().getMinimumToken(); List<Range<Token>> ranges = Collections.singletonList(new Range<>(token, token)); return new StreamPlan("Hints").transferRanges(hintsDestinationHost, preferred, Keyspace.SYSTEM_KS, ranges, SystemKeyspace.HINTS_CF) .execute(); } }
Example #28
Source File: SizeEstimatesRecorder.java From stratio-cassandra with Apache License 2.0 | 5 votes |
private void recordSizeEstimates(ColumnFamilyStore table, Collection<Range<Token>> localRanges) { // for each local primary range, estimate (crudely) mean partition size and partitions count. Map<Range<Token>, Pair<Long, Long>> estimates = new HashMap<>(localRanges.size()); for (Range<Token> range : localRanges) { // filter sstables that have partitions in this range. Refs<SSTableReader> refs = null; while (refs == null) { ColumnFamilyStore.ViewFragment view = table.select(table.viewFilter(range.toRowBounds())); refs = Refs.tryRef(view.sstables); } long partitionsCount, meanPartitionSize; try { // calculate the estimates. partitionsCount = estimatePartitionsCount(refs, range); meanPartitionSize = estimateMeanPartitionSize(refs); } finally { refs.release(); } estimates.put(range, Pair.create(partitionsCount, meanPartitionSize)); } // atomically update the estimates. SystemKeyspace.updateSizeEstimates(table.metadata.ksName, table.metadata.cfName, estimates); }
Example #29
Source File: SystemKeyspace.java From stratio-cassandra with Apache License 2.0 | 5 votes |
/** * Writes the current partition count and size estimates into SIZE_ESTIMATES_CF */ public static void updateSizeEstimates(String keyspace, String table, Map<Range<Token>, Pair<Long, Long>> estimates) { long timestamp = FBUtilities.timestampMicros(); CFMetaData estimatesTable = CFMetaData.SizeEstimatesCf; Mutation mutation = new Mutation(Keyspace.SYSTEM_KS, UTF8Type.instance.decompose(keyspace)); // delete all previous values with a single range tombstone. mutation.deleteRange(SIZE_ESTIMATES_CF, estimatesTable.comparator.make(table).start(), estimatesTable.comparator.make(table).end(), timestamp - 1); // add a CQL row for each primary token range. ColumnFamily cells = mutation.addOrGet(estimatesTable); for (Map.Entry<Range<Token>, Pair<Long, Long>> entry : estimates.entrySet()) { Range<Token> range = entry.getKey(); Pair<Long, Long> values = entry.getValue(); Composite prefix = estimatesTable.comparator.make(table, range.left.toString(), range.right.toString()); CFRowAdder adder = new CFRowAdder(cells, prefix, timestamp); adder.add("partitions_count", values.left) .add("mean_partition_size", values.right); } mutation.apply(); }
Example #30
Source File: ActiveRepairService.java From stratio-cassandra with Apache License 2.0 | 5 votes |
public ParentRepairSession(List<ColumnFamilyStore> columnFamilyStores, Collection<Range<Token>> ranges, long repairedAt) { for (ColumnFamilyStore cfs : columnFamilyStores) this.columnFamilyStores.put(cfs.metadata.cfId, cfs); this.ranges = ranges; this.sstableMap = new HashMap<>(); this.repairedAt = repairedAt; }