private Integer seekToSubColumn( CFMetaData metadata, FileDataInput file, ByteBuffer sblockId, List<IndexHelper.IndexInfo> indexList) throws IOException { file.readInt(); // column count /* get the various column ranges we have to read */ AbstractType comparator = metadata.comparator; int index = IndexHelper.indexFor(sblockId, indexList, comparator, false); if (index == indexList.size()) return null; IndexHelper.IndexInfo indexInfo = indexList.get(index); if (comparator.compare(sblockId, indexInfo.firstName) < 0) return null; FileMark mark = file.mark(); FileUtils.skipBytesFully(file, indexInfo.offset); while (file.bytesPastMark(mark) < indexInfo.offset + indexInfo.width) { Integer dataLength = isSubBlockFound(metadata, file, sblockId); if (dataLength == null) return null; if (dataLength < 0) continue; return dataLength; } return null; }
private List<String> getKeyLocations(ByteBuffer key) { List<InetAddress> endpoints = StorageService.instance.getLiveNaturalEndpoints(cfsKeyspace, key); DatabaseDescriptor.getEndpointSnitch() .sortByProximity(FBUtilities.getLocalAddress(), endpoints); List<String> hosts = new ArrayList<String>(endpoints.size()); for (InetAddress endpoint : endpoints) { hosts.add(endpoint.getHostName()); } return hosts; }
private IColumn validateAndGetColumn(List<Row> rows, ByteBuffer columnName) throws NotFoundException { if (rows.isEmpty()) throw new NotFoundException(); if (rows.size() > 1) throw new RuntimeException("Block id returned more than one row"); Row row = rows.get(0); if (row.cf == null) throw new NotFoundException(); IColumn col = row.cf.getColumn(columnName); if (col == null || !col.isLive()) throw new NotFoundException(); return col; }
public List<List<String>> describe_keys(String keyspace, List<ByteBuffer> keys) throws TException { List<List<String>> keyEndpoints = new ArrayList<List<String>>(keys.size()); for (ByteBuffer key : keys) { keyEndpoints.add(getKeyLocations(key)); } return keyEndpoints; }
/** * Writes out a bunch of mutations for a single column family. * * @param mutations A group of Mutations for the same keyspace and column family. * @return The ColumnFamilyStore that was used. */ public static ColumnFamilyStore writeColumnFamily(List<Mutation> mutations) { IMutation first = mutations.get(0); String keyspaceName = first.getKeyspaceName(); UUID cfid = first.getColumnFamilyIds().iterator().next(); for (Mutation rm : mutations) rm.applyUnsafe(); ColumnFamilyStore store = Keyspace.open(keyspaceName).getColumnFamilyStore(cfid); store.forceBlockingFlush(); return store; }
public static Future<?> compactAll(ColumnFamilyStore cfs, int gcBefore) { List<Descriptor> descriptors = new ArrayList<>(); for (SSTableReader sstable : cfs.getSSTables()) descriptors.add(sstable.descriptor); return CompactionManager.instance.submitUserDefined(cfs, descriptors, gcBefore); }
/** Creates initial set of nodes and tokens. Nodes are added to StorageService as 'normal' */ public static void createInitialRing( StorageService ss, IPartitioner partitioner, List<Token> endpointTokens, List<Token> keyTokens, List<InetAddress> hosts, List<UUID> hostIds, int howMany) throws UnknownHostException { // Expand pool of host IDs as necessary for (int i = hostIdPool.size(); i < howMany; i++) hostIdPool.add(UUID.randomUUID()); for (int i = 0; i < howMany; i++) { endpointTokens.add(new BigIntegerToken(String.valueOf(10 * i))); keyTokens.add(new BigIntegerToken(String.valueOf(10 * i + 5))); hostIds.add(hostIdPool.get(i)); } for (int i = 0; i < endpointTokens.size(); i++) { InetAddress ep = InetAddress.getByName("127.0.0." + String.valueOf(i + 1)); Gossiper.instance.initializeNodeUnsafe(ep, hostIds.get(i), 1); Gossiper.instance.injectApplicationState( ep, ApplicationState.TOKENS, new VersionedValue.VersionedValueFactory(partitioner) .tokens(Collections.singleton(endpointTokens.get(i)))); ss.onChange( ep, ApplicationState.STATUS, new VersionedValue.VersionedValueFactory(partitioner) .normal(Collections.singleton(endpointTokens.get(i)))); hosts.add(ep); } // check that all nodes are in token metadata for (int i = 0; i < endpointTokens.size(); ++i) assertTrue(ss.getTokenMetadata().isMember(hosts.get(i))); }