Refine search
public static void cleanup() throws IOException { // clean up commitlog String[] directoryNames = { DatabaseDescriptor.getCommitLogLocation(), }; for (String dirName : directoryNames) { File dir = new File(dirName); if (!dir.exists()) throw new RuntimeException("No such directory: " + dir.getAbsolutePath()); FileUtils.deleteRecursive(dir); } // clean up data directory which are stored as data directory/table/data files for (String dirName : DatabaseDescriptor.getAllDataFileLocations()) { File dir = new File(dirName); if (!dir.exists()) throw new RuntimeException("No such directory: " + dir.getAbsolutePath()); FileUtils.deleteRecursive(dir); } }
public static void mkdirs() { DatabaseDescriptor.createAllDirectories(); }
List<InetAddress> endpoints = StorageService.instance.getLiveNaturalEndpoints(CassandraUtils.keySpace, subIndex); DatabaseDescriptor.getEndpointSnitch().sortByProximity(FBUtilities.getLocalAddress(), endpoints); String shard = addr.getHostAddress() + ":" + CassandraUtils.port + "/solandra/" + indexName + "~" + i;
/** * Please use getBroadcastAddress instead. You need this only when you have to listen/connect. */ public static InetAddress getLocalAddress() { if (localInetAddress == null) try { localInetAddress = DatabaseDescriptor.getListenAddress() == null ? InetAddress.getLocalHost() : DatabaseDescriptor.getListenAddress(); } catch (UnknownHostException e) { throw new RuntimeException(e); } return localInetAddress; }
/** * Get embedded cassandra host. * * @return the cassandra host */ public static String getHost() { return DatabaseDescriptor.getRpcAddress().getHostName(); }
public String getRack(String host) throws UnknownHostException { return DatabaseDescriptor.getEndpointSnitch().getRack(InetAddress.getByName(host)); }
public Settings nodeSettings(Settings settings) { return Settings.builder() // overloadable settings from elasticsearch.yml // by default, HTTP is bound to C* rpc address, Transport is bound to C* internal listen address. .put("network.bind_host", DatabaseDescriptor.getRpcAddress().getHostAddress()) .put("network.publish_host", FBUtilities.getBroadcastRpcAddress().getHostAddress()) .put("transport.bind_host", FBUtilities.getLocalAddress().getHostAddress()) .put("transport.publish_host", FBUtilities.getBroadcastAddress().getHostAddress()) .put("path.data",getElasticsearchDataDir()) .put(settings) // not overloadable settings. .put("discovery.type","cassandra") .put("node.data",true) .put("node.master",true) .put("node.name", CassandraDiscovery.buildNodeName(DatabaseDescriptor.getListenAddress())) .put("node.attr.dc", DatabaseDescriptor.getLocalDataCenter()) .put("node.attr.rack", DatabaseDescriptor.getEndpointSnitch().getRack(FBUtilities.getBroadcastAddress())) .put("cluster.name", ClusterService.getElasticsearchClusterName(env.settings())) .build(); }
private static void dropKeyspaces() { String host = DatabaseDescriptor.getRpcAddress().getHostName(); int port = DatabaseDescriptor.getRpcPort(); log.debug("Cleaning cassandra keyspaces on " + host + ":" + port); Cluster cluster = HFactory.getOrCreateCluster("TestCluster", new CassandraHostConfigurator(host + ":" + port)); /* get all keyspace */ List<KeyspaceDefinition> keyspaces = cluster.describeKeyspaces(); /* drop all keyspace except internal cassandra keyspace */ for (KeyspaceDefinition keyspaceDefinition : keyspaces) { String keyspaceName = keyspaceDefinition.getName(); if (!INTERNAL_CASSANDRA_KEYSPACE.equals(keyspaceName)) { cluster.dropKeyspace(keyspaceName); } } }
private static void dropKeyspaces() { String host = DatabaseDescriptor.getRpcAddress().getHostName(); int port = DatabaseDescriptor.getNativeTransportPort(); try (com.datastax.driver.core.Cluster cluster = com.datastax.driver.core.Cluster.builder().addContactPoint(host) .withPort(port).build(); com.datastax.driver.core.Session session = cluster.connect()) { List<String> keyspaces = new ArrayList<String>(); for (com.datastax.driver.core.KeyspaceMetadata keyspace : cluster.getMetadata().getKeyspaces()) { if (!isSystemKeyspaceName(keyspace.getName())) { keyspaces.add(keyspace.getName()); } } for (String keyspace : keyspaces) { session.execute("DROP KEYSPACE " + keyspace); } } }
String localDataCenter = DatabaseDescriptor.getEndpointSnitch().getDatacenter(FBUtilities.getBroadcastAddress()); List<InetAddress> baseEndpoints = new ArrayList<>(); List<InetAddress> viewEndpoints = new ArrayList<>(); DatabaseDescriptor.getEndpointSnitch().getDatacenter(baseEndpoint).equals(localDataCenter)) baseEndpoints.add(baseEndpoint); if (viewEndpoint.equals(FBUtilities.getBroadcastAddress())) return Optional.of(viewEndpoint); baseEndpoints.remove(viewEndpoint); else if (!(replicationStrategy instanceof NetworkTopologyStrategy) || DatabaseDescriptor.getEndpointSnitch().getDatacenter(viewEndpoint).equals(localDataCenter)) viewEndpoints.add(viewEndpoint); int baseIdx = baseEndpoints.indexOf(FBUtilities.getBroadcastAddress());
final String localDataCenter = DatabaseDescriptor.getEndpointSnitch().getDatacenter(FBUtilities.getBroadcastAddress()); if (StorageService.instance.isStarting() || StorageService.instance.isJoining() || StorageService.instance.isMoving()) BatchlogManager.store(Batch.createLocal(batchUUID, FBUtilities.timestampMicros(), mutations), writeCommitLog); final Collection<InetAddress> batchlogEndpoints = Collections.singleton(FBUtilities.getBroadcastAddress()); BatchlogResponseHandler.BatchlogCleanup cleanup = new BatchlogResponseHandler.BatchlogCleanup(mutations.size(), () -> asyncRemoveFromBatchlog(batchlogEndpoints, batchUUID)); if (pairedEndpoint.get().equals(FBUtilities.getBroadcastAddress()) && StorageService.instance.isJoined() && pendingEndpoints.isEmpty())
StorageService.instance.populateTokenMetadata(); StorageService.instance.populateTokenMetadata(); new LegacyHintsMigrator(DatabaseDescriptor.getHintsDirectory(), DatabaseDescriptor.getMaxHintsFileSize()).migrate(); StorageService.instance.registerDaemon(this); try if (!FBUtilities.getBroadcastAddress().equals(InetAddress.getLoopbackAddress())) Gossiper.waitToSettle(); InetAddress rpcAddr = DatabaseDescriptor.getRpcAddress(); int rpcPort = DatabaseDescriptor.getRpcPort(); int listenBacklog = DatabaseDescriptor.getRpcListenBacklog(); thriftServer = new ThriftServer(rpcAddr, rpcPort, listenBacklog);
final String localDataCenter = DatabaseDescriptor.getEndpointSnitch().getDatacenter(FBUtilities.getBroadcastAddress()); continue; Token tk = StorageService.getPartitioner().getToken(mutation.key()); List<InetAddress> naturalEndpoints = StorageService.instance.getNaturalEndpoints(mutation.getKeyspaceName(), tk); Collection<InetAddress> pendingEndpoints = StorageService.instance.getTokenMetadata().pendingEndpointsFor(tk, mutation.getKeyspaceName()); for (InetAddress target : Iterables.concat(naturalEndpoints, pendingEndpoints)) if (!target.equals(FBUtilities.getBroadcastAddress()) && shouldHint(target)) submitHint((Mutation) mutation, target, null);
public int completed(InetAddress request) { String dc = DatabaseDescriptor.getEndpointSnitch().getDatacenter(request); Queue<InetAddress> requests = requestsByDatacenter.get(dc); assert requests != null; assert request.equals(requests.peek()); requests.poll(); if (!requests.isEmpty()) processor.process(requests.peek()); return --remaining; } }
public static List<InetAddress> getLiveSortedEndpoints(Keyspace keyspace, RingPosition pos) { List<InetAddress> liveEndpoints = StorageService.instance.getLiveNaturalEndpoints(keyspace, pos); DatabaseDescriptor.getEndpointSnitch().sortByProximity(FBUtilities.getBroadcastAddress(), liveEndpoints); return liveEndpoints; }
@VisibleForTesting CommitLog(CommitLogArchiver archiver) { this.configuration = new Configuration(DatabaseDescriptor.getCommitLogCompression(), DatabaseDescriptor.getEncryptionContext()); DatabaseDescriptor.createAllDirectories(); this.archiver = archiver; metrics = new CommitLogMetrics(); executor = DatabaseDescriptor.getCommitLogSync() == Config.CommitLogSync.batch ? new BatchCommitLogService(this) : new PeriodicCommitLogService(this); segmentManager = DatabaseDescriptor.isCDCEnabled() ? new CommitLogSegmentManagerCDC(this, DatabaseDescriptor.getCommitLogLocation()) : new CommitLogSegmentManagerStandard(this, DatabaseDescriptor.getCommitLogLocation()); // register metrics metrics.attach(executor, segmentManager); }
CLibrary.tryMlockall(); listenPort = DatabaseDescriptor.getRpcPort(); listenAddr = DatabaseDescriptor.getRpcAddress(); for (CFMetaData cfm : DatabaseDescriptor.getTableMetaData(Table.SYSTEM_TABLE).values()) { ColumnFamilyStore.scrubDataDirectories(Table.SYSTEM_TABLE, cfm.cfName); DatabaseDescriptor.loadSchemas(); for (String table : DatabaseDescriptor.getTables()) { for (CFMetaData cfm : DatabaseDescriptor.getTableMetaData(table).values()) { ColumnFamilyStore.scrubDataDirectories(table, cfm.cfName); for (String table : DatabaseDescriptor.getTables()) { log.debug("opening keyspace " + table); Table.open(table); UUID currentMigration = DatabaseDescriptor.getDefsVersion(); UUID lastMigration = Migration.getLastMigrationId(); if ((lastMigration != null) && (lastMigration.timestamp() > currentMigration.timestamp())) { StorageService.instance.registerDaemon(this); StorageService.instance.initServer();
private static BatchlogEndpoints getBatchlogEndpoints(String localDataCenter, ConsistencyLevel consistencyLevel) throws UnavailableException { TokenMetadata.Topology topology = StorageService.instance.getTokenMetadata().cachedOnlyTokenMap().getTopology(); Multimap<String, InetAddress> localEndpoints = HashMultimap.create(topology.getDatacenterRacks().get(localDataCenter)); String localRack = DatabaseDescriptor.getEndpointSnitch().getRack(FBUtilities.getBroadcastAddress()); Collection<InetAddress> chosenEndpoints = new BatchlogManager.EndpointFilter(localRack, localEndpoints).filter(); if (chosenEndpoints.isEmpty()) { if (consistencyLevel == ConsistencyLevel.ANY) return new BatchlogEndpoints(Collections.singleton(FBUtilities.getBroadcastAddress())); throw new UnavailableException(ConsistencyLevel.ONE, 1, 0); } return new BatchlogEndpoints(chosenEndpoints); }
public static InetAddress getBroadcastRpcAddress() { if (broadcastRpcAddress == null) broadcastRpcAddress = DatabaseDescriptor.getBroadcastRpcAddress() == null ? DatabaseDescriptor.getRpcAddress() : DatabaseDescriptor.getBroadcastRpcAddress(); return broadcastRpcAddress; }
@VisibleForTesting static void resetDataDirectoriesAfterTest() { String[] locations = DatabaseDescriptor.getAllDataFileLocations(); for (int i = 0; i < locations.length; ++i) dataDirectories[i] = new DataDirectory(new File(locations[i])); }