Search in sources :

Example 66 with InetAddressAndPort

use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.

the class AlterTest method testCreateAlterNetworkTopologyWithDefaults.

@Test
public void testCreateAlterNetworkTopologyWithDefaults() throws Throwable {
    TokenMetadata metadata = StorageService.instance.getTokenMetadata();
    metadata.clearUnsafe();
    InetAddressAndPort local = FBUtilities.getBroadcastAddressAndPort();
    InetAddressAndPort remote = InetAddressAndPort.getByName("127.0.0.4");
    metadata.updateHostId(UUID.randomUUID(), local);
    metadata.updateNormalToken(new OrderPreservingPartitioner.StringToken("A"), local);
    metadata.updateHostId(UUID.randomUUID(), remote);
    metadata.updateNormalToken(new OrderPreservingPartitioner.StringToken("B"), remote);
    // With two datacenters we should respect anything passed in as a manual override
    String ks1 = createKeyspace("CREATE KEYSPACE %s WITH replication={ 'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1, '" + DATA_CENTER_REMOTE + "': 3}");
    assertRowsIgnoringOrderAndExtra(execute("SELECT keyspace_name, durable_writes, replication FROM system_schema.keyspaces"), row(KEYSPACE, true, map("class", "org.apache.cassandra.locator.SimpleStrategy", "replication_factor", "1")), row(KEYSPACE_PER_TEST, true, map("class", "org.apache.cassandra.locator.SimpleStrategy", "replication_factor", "1")), row(ks1, true, map("class", "org.apache.cassandra.locator.NetworkTopologyStrategy", DATA_CENTER, "1", DATA_CENTER_REMOTE, "3")));
    // Should be able to remove data centers
    schemaChange("ALTER KEYSPACE " + ks1 + " WITH replication = { 'class' : 'NetworkTopologyStrategy', '" + DATA_CENTER + "' : 0, '" + DATA_CENTER_REMOTE + "': 3 }");
    assertRowsIgnoringOrderAndExtra(execute("SELECT keyspace_name, durable_writes, replication FROM system_schema.keyspaces"), row(KEYSPACE, true, map("class", "org.apache.cassandra.locator.SimpleStrategy", "replication_factor", "1")), row(KEYSPACE_PER_TEST, true, map("class", "org.apache.cassandra.locator.SimpleStrategy", "replication_factor", "1")), row(ks1, true, map("class", "org.apache.cassandra.locator.NetworkTopologyStrategy", DATA_CENTER_REMOTE, "3")));
    // The auto-expansion should not change existing replication counts; do not let the user shoot themselves in the foot
    schemaChange("ALTER KEYSPACE " + ks1 + " WITH replication = { 'class' : 'NetworkTopologyStrategy', 'replication_factor' : 1 } AND durable_writes=True");
    assertRowsIgnoringOrderAndExtra(execute("SELECT keyspace_name, durable_writes, replication FROM system_schema.keyspaces"), row(KEYSPACE, true, map("class", "org.apache.cassandra.locator.SimpleStrategy", "replication_factor", "1")), row(KEYSPACE_PER_TEST, true, map("class", "org.apache.cassandra.locator.SimpleStrategy", "replication_factor", "1")), row(ks1, true, map("class", "org.apache.cassandra.locator.NetworkTopologyStrategy", DATA_CENTER, "1", DATA_CENTER_REMOTE, "3")));
    // The keyspace should be fully functional
    execute("USE " + ks1);
    assertInvalidThrow(ConfigurationException.class, "CREATE TABLE tbl1 (a int PRIMARY KEY, b int) WITH compaction = { 'min_threshold' : 4 }");
    execute("CREATE TABLE tbl1 (a int PRIMARY KEY, b int) WITH compaction = { 'class' : 'SizeTieredCompactionStrategy', 'min_threshold' : 7 }");
    assertRows(execute("SELECT table_name, compaction FROM system_schema.tables WHERE keyspace_name='" + ks1 + "'"), row("tbl1", map("class", "org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy", "min_threshold", "7", "max_threshold", "32")));
    metadata.clearUnsafe();
}
Also used : OrderPreservingPartitioner(org.apache.cassandra.dht.OrderPreservingPartitioner) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) Test(org.junit.Test)

Example 67 with InetAddressAndPort

use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.

the class CleanupTest method defineSchema.

@BeforeClass
public static void defineSchema() throws ConfigurationException {
    SchemaLoader.prepareServer();
    SchemaLoader.createKeyspace(KEYSPACE1, KeyspaceParams.simple(1), SchemaLoader.standardCFMD(KEYSPACE1, CF_STANDARD1), SchemaLoader.compositeIndexCFMD(KEYSPACE1, CF_INDEXED1, true));
    DatabaseDescriptor.setEndpointSnitch(new AbstractNetworkTopologySnitch() {

        @Override
        public String getRack(InetAddressAndPort endpoint) {
            return "RC1";
        }

        @Override
        public String getDatacenter(InetAddressAndPort endpoint) {
            return "DC1";
        }
    });
    SchemaLoader.createKeyspace(KEYSPACE2, KeyspaceParams.nts("DC1", 1), SchemaLoader.standardCFMD(KEYSPACE2, CF_STANDARD2), SchemaLoader.compositeIndexCFMD(KEYSPACE2, CF_INDEXED2, true));
    SchemaLoader.createKeyspace(KEYSPACE3, KeyspaceParams.nts("DC1", 1), SchemaLoader.standardCFMD(KEYSPACE3, CF_STANDARD3));
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) AbstractNetworkTopologySnitch(org.apache.cassandra.locator.AbstractNetworkTopologySnitch) BeforeClass(org.junit.BeforeClass)

Example 68 with InetAddressAndPort

use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.

the class InternodeOutboundTable method data.

@Override
public DataSet data(DecoratedKey partitionKey) {
    ByteBuffer[] addressAndPortBytes = ((CompositeType) metadata().partitionKeyType).split(partitionKey.getKey());
    InetAddress address = InetAddressType.instance.compose(addressAndPortBytes[0]);
    int port = Int32Type.instance.compose(addressAndPortBytes[1]);
    InetAddressAndPort addressAndPort = InetAddressAndPort.getByAddressOverrideDefaults(address, port);
    SimpleDataSet result = new SimpleDataSet(metadata());
    OutboundConnections connections = MessagingService.instance().channelManagers.get(addressAndPort);
    if (null != connections)
        addRow(result, addressAndPort, connections);
    return result;
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) OutboundConnections(org.apache.cassandra.net.OutboundConnections) ByteBuffer(java.nio.ByteBuffer) InetAddress(java.net.InetAddress) CompositeType(org.apache.cassandra.db.marshal.CompositeType)

Example 69 with InetAddressAndPort

use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.

the class LocalSessions method cancelSession.

/**
 * hook for operators to cancel sessions, cancelling from a non-coordinator is an error, unless
 * force is set to true. Messages are sent out to other participants, but we don't wait for a response
 */
public void cancelSession(UUID sessionID, boolean force) {
    logger.info("Cancelling local repair session {}", sessionID);
    LocalSession session = getSession(sessionID);
    Preconditions.checkArgument(session != null, "Session {} does not exist", sessionID);
    Preconditions.checkArgument(force || session.coordinator.equals(getBroadcastAddressAndPort()), "Cancel session %s from it's coordinator (%s) or use --force", sessionID, session.coordinator);
    setStateAndSave(session, FAILED);
    Message<FailSession> message = Message.out(FAILED_SESSION_MSG, new FailSession(sessionID));
    for (InetAddressAndPort participant : session.participants) {
        if (!participant.equals(getBroadcastAddressAndPort()))
            sendMessage(participant, message);
    }
}
Also used : InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) FailSession(org.apache.cassandra.repair.messages.FailSession)

Example 70 with InetAddressAndPort

use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.

the class LocalSessions method handlePrepareMessage.

/**
 * The PrepareConsistentRequest promotes the parent repair session to a consistent incremental
 * session, and isolates the data to be repaired from the rest of the table's data
 *
 * No response is sent to the repair coordinator until the data preparation / isolation has completed
 * successfully. If the data preparation fails, a failure message is sent to the coordinator,
 * cancelling the session.
 */
public void handlePrepareMessage(InetAddressAndPort from, PrepareConsistentRequest request) {
    logger.trace("received {} from {}", request, from);
    UUID sessionID = request.parentSession;
    InetAddressAndPort coordinator = request.coordinator;
    Set<InetAddressAndPort> peers = request.participants;
    ActiveRepairService.ParentRepairSession parentSession;
    try {
        parentSession = getParentRepairSession(sessionID);
    } catch (Throwable e) {
        logger.error("Error retrieving ParentRepairSession for session {}, responding with failure", sessionID);
        sendMessage(coordinator, Message.out(PREPARE_CONSISTENT_RSP, new PrepareConsistentResponse(sessionID, getBroadcastAddressAndPort(), false)));
        return;
    }
    LocalSession session = createSessionUnsafe(sessionID, parentSession, peers);
    putSessionUnsafe(session);
    logger.info("Beginning local incremental repair session {}", session);
    ExecutorService executor = executorFactory().pooled("Repair-" + sessionID, parentSession.getColumnFamilyStores().size());
    KeyspaceRepairManager repairManager = parentSession.getKeyspace().getRepairManager();
    RangesAtEndpoint tokenRanges = filterLocalRanges(parentSession.getKeyspace().getName(), parentSession.getRanges());
    Future<List<Void>> repairPreparation = prepareSession(repairManager, sessionID, parentSession.getColumnFamilyStores(), tokenRanges, executor, () -> session.getState() != PREPARING);
    repairPreparation.addCallback(new FutureCallback<List<Void>>() {

        public void onSuccess(@Nullable List<Void> result) {
            try {
                logger.info("Prepare phase for incremental repair session {} completed", sessionID);
                if (session.getState() != FAILED)
                    setStateAndSave(session, PREPARED);
                else
                    logger.info("Session {} failed before anticompaction completed", sessionID);
                Message<PrepareConsistentResponse> message = Message.out(PREPARE_CONSISTENT_RSP, new PrepareConsistentResponse(sessionID, getBroadcastAddressAndPort(), session.getState() != FAILED));
                sendMessage(coordinator, message);
            } finally {
                executor.shutdown();
            }
        }

        public void onFailure(Throwable t) {
            try {
                if (Throwables.anyCauseMatches(t, (throwable) -> throwable instanceof CompactionInterruptedException))
                    logger.info("Anticompaction interrupted for session {}: {}", sessionID, t.getMessage());
                else if (Throwables.anyCauseMatches(t, (throwable) -> throwable instanceof NoSuchRepairSessionException))
                    logger.warn("No such repair session: {}", sessionID);
                else
                    logger.error("Prepare phase for incremental repair session {} failed", sessionID, t);
                sendMessage(coordinator, Message.out(PREPARE_CONSISTENT_RSP, new PrepareConsistentResponse(sessionID, getBroadcastAddressAndPort(), false)));
                failSession(sessionID, false);
            } finally {
                executor.shutdown();
            }
        }
    });
}
Also used : NoSuchRepairSessionException(org.apache.cassandra.repair.NoSuchRepairSessionException) KeyspaceRepairManager(org.apache.cassandra.repair.KeyspaceRepairManager) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) STATUS_REQ(org.apache.cassandra.net.Verb.STATUS_REQ) CompactionInterruptedException(org.apache.cassandra.db.compaction.CompactionInterruptedException) ByteBuffer(java.nio.ByteBuffer) BooleanSupplier(java.util.function.BooleanSupplier) Map(java.util.Map) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) PendingStats(org.apache.cassandra.repair.consistent.admin.PendingStats) Verify(com.google.common.base.Verify) ImmutableSet(com.google.common.collect.ImmutableSet) FBUtilities(org.apache.cassandra.utils.FBUtilities) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) Collection(java.util.Collection) FinalizeCommit(org.apache.cassandra.repair.messages.FinalizeCommit) Set(java.util.Set) UUID(java.util.UUID) Instant(java.time.Instant) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) FinalizePropose(org.apache.cassandra.repair.messages.FinalizePropose) State(org.apache.cassandra.repair.consistent.ConsistentSession.State) List(java.util.List) FAILED_SESSION_MSG(org.apache.cassandra.net.Verb.FAILED_SESSION_MSG) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) Future(org.apache.cassandra.utils.concurrent.Future) Throwables(org.apache.cassandra.utils.Throwables) FINALIZE_PROMISE_MSG(org.apache.cassandra.net.Verb.FINALIZE_PROMISE_MSG) FailureDetector(org.apache.cassandra.gms.FailureDetector) SchemaConstants(org.apache.cassandra.schema.SchemaConstants) DataInputBuffer(org.apache.cassandra.io.util.DataInputBuffer) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) Iterables(com.google.common.collect.Iterables) PendingStat(org.apache.cassandra.repair.consistent.admin.PendingStat) PrepareConsistentResponse(org.apache.cassandra.repair.messages.PrepareConsistentResponse) DataOutputBuffer(org.apache.cassandra.io.util.DataOutputBuffer) TableId(org.apache.cassandra.schema.TableId) PREPARE_CONSISTENT_RSP(org.apache.cassandra.net.Verb.PREPARE_CONSISTENT_RSP) Range(org.apache.cassandra.dht.Range) HashMap(java.util.HashMap) Message(org.apache.cassandra.net.Message) QueryProcessor(org.apache.cassandra.cql3.QueryProcessor) FinalizePromise(org.apache.cassandra.repair.messages.FinalizePromise) SystemKeyspace(org.apache.cassandra.db.SystemKeyspace) ArrayList(java.util.ArrayList) Schema(org.apache.cassandra.schema.Schema) HashSet(java.util.HashSet) UTF8Type(org.apache.cassandra.db.marshal.UTF8Type) Token(org.apache.cassandra.dht.Token) ActiveRepairService(org.apache.cassandra.service.ActiveRepairService) Lists(com.google.common.collect.Lists) CleanupSummary(org.apache.cassandra.repair.consistent.admin.CleanupSummary) STATUS_RSP(org.apache.cassandra.net.Verb.STATUS_RSP) ExecutorService(java.util.concurrent.ExecutorService) Nullable(javax.annotation.Nullable) MessagingService(org.apache.cassandra.net.MessagingService) Logger(org.slf4j.Logger) BytesType(org.apache.cassandra.db.marshal.BytesType) StatusResponse(org.apache.cassandra.repair.messages.StatusResponse) StorageService(org.apache.cassandra.service.StorageService) IOException(java.io.IOException) PrepareConsistentRequest(org.apache.cassandra.repair.messages.PrepareConsistentRequest) UnknownHostException(java.net.UnknownHostException) Ints(com.google.common.primitives.Ints) FutureCallback(com.google.common.util.concurrent.FutureCallback) Replica(org.apache.cassandra.locator.Replica) FailSession(org.apache.cassandra.repair.messages.FailSession) TimeUnit(java.util.concurrent.TimeUnit) RepairMessage(org.apache.cassandra.repair.messages.RepairMessage) UUIDType(org.apache.cassandra.db.marshal.UUIDType) IPartitioner(org.apache.cassandra.dht.IPartitioner) Global.executorFactory(org.apache.cassandra.concurrent.ExecutorFactory.Global.executorFactory) UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) StatusRequest(org.apache.cassandra.repair.messages.StatusRequest) InetAddressAndPort(org.apache.cassandra.locator.InetAddressAndPort) RangesAtEndpoint(org.apache.cassandra.locator.RangesAtEndpoint) ActiveRepairService(org.apache.cassandra.service.ActiveRepairService) PrepareConsistentResponse(org.apache.cassandra.repair.messages.PrepareConsistentResponse) Message(org.apache.cassandra.net.Message) RepairMessage(org.apache.cassandra.repair.messages.RepairMessage) CompactionInterruptedException(org.apache.cassandra.db.compaction.CompactionInterruptedException) KeyspaceRepairManager(org.apache.cassandra.repair.KeyspaceRepairManager) ExecutorService(java.util.concurrent.ExecutorService) NoSuchRepairSessionException(org.apache.cassandra.repair.NoSuchRepairSessionException) List(java.util.List) ArrayList(java.util.ArrayList) UUID(java.util.UUID)

Aggregations

InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)281 Test (org.junit.Test)129 Token (org.apache.cassandra.dht.Token)65 TokenMetadata (org.apache.cassandra.locator.TokenMetadata)43 EndpointsForRange (org.apache.cassandra.locator.EndpointsForRange)39 Range (org.apache.cassandra.dht.Range)28 Replica (org.apache.cassandra.locator.Replica)25 ArrayList (java.util.ArrayList)24 ByteBuffer (java.nio.ByteBuffer)23 HashMap (java.util.HashMap)23 UUID (java.util.UUID)22 HashSet (java.util.HashSet)20 Map (java.util.Map)20 Mutation (org.apache.cassandra.db.Mutation)17 PartitionIterator (org.apache.cassandra.db.partitions.PartitionIterator)17 UnfilteredPartitionIterator (org.apache.cassandra.db.partitions.UnfilteredPartitionIterator)16 VersionedValue (org.apache.cassandra.gms.VersionedValue)16 VisibleForTesting (com.google.common.annotations.VisibleForTesting)15 IPartitioner (org.apache.cassandra.dht.IPartitioner)15 BigIntegerToken (org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken)15