org.apache.cassandra.net.MessagingService Java Examples

The following examples show how to use org.apache.cassandra.net.MessagingService. 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: CommitLogSegmentManager.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
/**
 * Differs from the above because it can work on any file instead of just existing
 * commit log segments managed by this manager.
 *
 * @param file segment file that is no longer in use.
 */
void recycleSegment(final File file)
{
    if (isCapExceeded()
        || CommitLogDescriptor.fromFileName(file.getName()).getMessagingVersion() != MessagingService.current_version)
    {
        // (don't decrease managed size, since this was never a "live" segment)
        logger.debug("(Unopened) segment {} is no longer needed and will be deleted now", file);
        FileUtils.deleteWithConfirm(file);
        return;
    }

    logger.debug("Recycling {}", file);
    // this wasn't previously a live segment, so add it to the managed size when we make it live
    size.addAndGet(DatabaseDescriptor.getCommitLogSegmentSize());
    segmentManagementTasks.add(new Callable<CommitLogSegment>()
    {
        public CommitLogSegment call()
        {
            return new CommitLogSegment(file.getPath());
        }
    });
}
 
Example #2
Source File: ReadVerbHandler.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public void doVerb(MessageIn<ReadCommand> message, int id)
{
    if (StorageService.instance.isBootstrapMode())
    {
        throw new RuntimeException("Cannot service reads while bootstrapping!");
    }

    ReadCommand command = message.payload;
    Keyspace keyspace = Keyspace.open(command.ksName);
    Row row;
    try
    {
        row = command.getRow(keyspace);
    }
    catch (TombstoneOverwhelmingException e)
    {
        // error already logged.  Drop the request
        return;
    }

    MessageOut<ReadResponse> reply = new MessageOut<ReadResponse>(MessagingService.Verb.REQUEST_RESPONSE,
                                                                  getResponse(command, row),
                                                                  ReadResponse.serializer);
    Tracing.trace("Enqueuing response to {}", message.from);
    MessagingService.instance().sendReply(reply, id, message.from);
}
 
Example #3
Source File: TruncateVerbHandler.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public void doVerb(MessageIn<Truncation> message, int id)
{
    Truncation t = message.payload;
    Tracing.trace("Applying truncation of {}.{}", t.keyspace, t.columnFamily);
    try
    {
        ColumnFamilyStore cfs = Keyspace.open(t.keyspace).getColumnFamilyStore(t.columnFamily);
        cfs.truncateBlocking();
    }
    catch (Exception e)
    {
        logger.error("Error in truncation", e);
        respondError(t, message);

        if (FSError.findNested(e) != null)
            throw FSError.findNested(e);
    }
    Tracing.trace("Enqueuing response to truncate operation to {}", message.from);

    TruncateResponse response = new TruncateResponse(t.keyspace, t.columnFamily, true);
    logger.trace("{} applied.  Enqueuing response to {}@{} ", new Object[]{ t, id, message.from });
    MessagingService.instance().sendReply(response.createMessage(), id, message.from);
}
 
Example #4
Source File: Mutation.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public long serializedSize(Mutation mutation, int version)
{
    TypeSizes sizes = TypeSizes.NATIVE;
    int size = 0;

    if (version < MessagingService.VERSION_20)
        size += sizes.sizeof(mutation.getKeyspaceName());

    int keySize = mutation.key().remaining();
    size += sizes.sizeof((short) keySize) + keySize;

    size += sizes.sizeof(mutation.modifications.size());
    for (Map.Entry<UUID,ColumnFamily> entry : mutation.modifications.entrySet())
        size += ColumnFamily.serializer.serializedSize(entry.getValue(), TypeSizes.NATIVE, version);

    return size;
}
 
Example #5
Source File: RangeSliceVerbHandler.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public void doVerb(MessageIn<AbstractRangeCommand> message, int id)
{
    try
    {
        if (StorageService.instance.isBootstrapMode())
        {
            /* Don't service reads! */
            throw new RuntimeException("Cannot service reads while bootstrapping!");
        }
        RangeSliceReply reply = new RangeSliceReply(message.payload.executeLocally());
        Tracing.trace("Enqueuing response to {}", message.from);
        MessagingService.instance().sendReply(reply.createMessage(), id, message.from);
    }
    catch (TombstoneOverwhelmingException e)
    {
        // error already logged.  Drop the request
    }
    catch (Exception ex)
    {
        throw new RuntimeException(ex);
    }
}
 
Example #6
Source File: ColumnFamily.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public static ColumnFamily fromBytes(ByteBuffer bytes)
{
    if (bytes == null)
        return null;

    try
    {
        return serializer.deserialize(new DataInputStream(ByteBufferUtil.inputStream(bytes)),
                                                          ArrayBackedSortedColumns.factory,
                                                          ColumnSerializer.Flag.LOCAL,
                                                          MessagingService.current_version);
    }
    catch (IOException e)
    {
        throw new RuntimeException(e);
    }
}
 
Example #7
Source File: StageManager.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
private static ExecuteOnlyExecutor tracingExecutor()
{
    RejectedExecutionHandler reh = new RejectedExecutionHandler()
    {
        public void rejectedExecution(Runnable r, ThreadPoolExecutor executor)
        {
            MessagingService.instance().incrementDroppedMessages(MessagingService.Verb._TRACE);
        }
    };
    return new ExecuteOnlyExecutor(1,
                                   1,
                                   KEEPALIVE,
                                   TimeUnit.SECONDS,
                                   new ArrayBlockingQueue<Runnable>(1000),
                                   new NamedThreadFactory(Stage.TRACING.getJmxName()),
                                   reh);
}
 
Example #8
Source File: MigrationManager.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
private static Future<?> announce(final Collection<Mutation> schema)
{
    Future<?> f = StageManager.getStage(Stage.MIGRATION).submit(new WrappedRunnable()
    {
        protected void runMayThrow() throws IOException, ConfigurationException
        {
            DefsTables.mergeSchema(schema);
        }
    });

    for (InetAddress endpoint : Gossiper.instance.getLiveMembers())
    {
        // only push schema to nodes with known and equal versions
        if (!endpoint.equals(FBUtilities.getBroadcastAddress()) &&
                MessagingService.instance().knowsVersion(endpoint) &&
                MessagingService.instance().getRawVersion(endpoint) == MessagingService.current_version)
            pushSchemaMutation(endpoint, schema);
    }

    return f;
}
 
Example #9
Source File: ColumnFamilySerializer.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public ColumnFamily deserialize(DataInput in, ColumnFamily.Factory factory, ColumnSerializer.Flag flag, int version) throws IOException
{
    if (!in.readBoolean())
        return null;

    ColumnFamily cf = factory.create(Schema.instance.getCFMetaData(deserializeCfId(in, version)));

    if (cf.metadata().isSuper() && version < MessagingService.VERSION_20)
    {
        SuperColumns.deserializerSuperColumnFamily(in, cf, flag, version);
    }
    else
    {
        cf.delete(cf.getComparator().deletionInfoSerializer().deserialize(in, version));

        ColumnSerializer columnSerializer = cf.getComparator().columnSerializer();
        int size = in.readInt();
        for (int i = 0; i < size; ++i)
            cf.addColumn(columnSerializer.deserialize(in, flag));
    }
    return cf;
}
 
Example #10
Source File: MerkleTreeTest.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Test
public void testSerialization() throws Exception
{
    Range<Token> full = new Range<>(tok(-1), tok(-1));

    // populate and validate the tree
    mt.maxsize(256);
    mt.init();
    for (TreeRange range : mt.invalids())
        range.addAll(new HIterator(range.right));

    byte[] initialhash = mt.hash(full);

    DataOutputBuffer out = new DataOutputBuffer();
    MerkleTree.serializer.serialize(mt, out, MessagingService.current_version);
    byte[] serialized = out.toByteArray();

    ByteArrayDataInput in = ByteStreams.newDataInput(serialized);
    MerkleTree restored = MerkleTree.serializer.deserialize(in, MessagingService.current_version);

    assertHashEquals(initialhash, restored.hash(full));
}
 
Example #11
Source File: StorageService.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
/**
 * Sends a notification to a node indicating we have finished replicating data.
 *
 * @param remote node to send notification to
 */
private void sendReplicationNotification(InetAddress remote)
{
    // notify the remote token
    MessageOut msg = new MessageOut(MessagingService.Verb.REPLICATION_FINISHED);
    IFailureDetector failureDetector = FailureDetector.instance;
    if (logger.isDebugEnabled())
        logger.debug("Notifying {} of replication completion\n", remote);
    while (failureDetector.isAlive(remote))
    {
        AsyncOneResponse iar = MessagingService.instance().sendRR(msg, remote);
        try
        {
            iar.get(DatabaseDescriptor.getRpcTimeout(), TimeUnit.MILLISECONDS);
            return; // done
        }
        catch(TimeoutException e)
        {
            // try again
        }
    }
}
 
Example #12
Source File: AbstractReadExecutor.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
private void makeRequests(ReadCommand readCommand, Iterable<InetAddress> endpoints)
{
    MessageOut<ReadCommand> message = null;
    boolean hasLocalEndpoint = false;

    for (InetAddress endpoint : endpoints)
    {
        if (isLocalRequest(endpoint))
        {
            hasLocalEndpoint = true;
            continue;
        }

        logger.trace("reading {} from {}", readCommand.isDigestQuery() ? "digest" : "data", endpoint);
        if (message == null)
            message = readCommand.createMessage();
        MessagingService.instance().sendRR(message, endpoint, handler);
    }

    // We delay the local (potentially blocking) read till the end to avoid stalling remote requests.
    if (hasLocalEndpoint)
    {
        logger.trace("reading {} locally", readCommand.isDigestQuery() ? "digest" : "data");
        StageManager.getStage(Stage.READ).maybeExecuteImmediately(new LocalReadRunnable(command, handler));
    }
}
 
Example #13
Source File: AbstractReadExecutor.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public void maybeTryAdditionalReplicas()
{
    // no latency information, or we're overloaded
    if (cfs.sampleLatencyNanos > TimeUnit.MILLISECONDS.toNanos(command.getTimeout()))
        return;

    if (!handler.await(cfs.sampleLatencyNanos, TimeUnit.NANOSECONDS))
    {
        // Could be waiting on the data, or on enough digests.
        ReadCommand retryCommand = command;
        if (resolver.getData() != null)
            retryCommand = command.copy().setIsDigestQuery(true);

        InetAddress extraReplica = Iterables.getLast(targetReplicas);
        logger.trace("speculating read retry on {}", extraReplica);
        MessagingService.instance().sendRR(retryCommand.createMessage(), extraReplica, handler);
        speculated = true;

        cfs.metric.speculativeRetries.inc();
    }
}
 
Example #14
Source File: HintsTool.java    From sstable-tools with Apache License 2.0 6 votes vote down vote up
protected void walkMutations(File target, PrintStream out, MutationReplayer replayer) throws Exception {
    int version = Integer.parseInt(System.getProperty("hints.version", "" + MessagingService.current_version));
    try (HintsReader reader = HintsReader.open(target)) {
        for (HintsReader.Page page : reader) {
            Iterator<ByteBuffer> hints = page.buffersIterator(); //hints iterator im pretty sure is busted
            while (hints.hasNext()) {
                ByteBuffer buf = hints.next();
                DataInputPlus in = new DataInputPlus.DataInputStreamPlus(new ByteArrayInputStream(buf.array()));
                Hint hint = Hint.serializer.deserialize(in, version);
                Mutation mutation = hint.mutation;
                for (PartitionUpdate partition : mutation.getPartitionUpdates()) {
                    out.println(partition);
                    for (Row row : partition) {
                        out.println(row);
                    }
                }
                if (replayer != null) {
                    replayer.sendMutation(mutation);
                }
            }
        }
    }
}
 
Example #15
Source File: Gossiper.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
public void stop()
{
    EndpointState mystate = endpointStateMap.get(FBUtilities.getBroadcastAddress());
    if (mystate != null && !isSilentShutdownState(mystate))
    {
        logger.info("Announcing shutdown");
        addLocalApplicationState(ApplicationState.STATUS, StorageService.instance.valueFactory.shutdown(true));
        MessageOut message = new MessageOut(MessagingService.Verb.GOSSIP_SHUTDOWN);
        for (InetAddress ep : liveEndpoints)
            MessagingService.instance().sendOneWay(message, ep);
        Uninterruptibles.sleepUninterruptibly(Integer.getInteger("cassandra.shutdown_announce_in_ms", 2000), TimeUnit.MILLISECONDS);
    }
    else
        logger.warn("No local state or state is in silent shutdown, not announcing shutdown");
    if (scheduledGossipTask != null)
        scheduledGossipTask.cancel(false);
}
 
Example #16
Source File: Gossiper.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
/**
 * Removes the endpoint from Gossip but retains endpoint state
 */
public void removeEndpoint(InetAddress endpoint)
{
    // do subscribers first so anything in the subscriber that depends on gossiper state won't get confused
    for (IEndpointStateChangeSubscriber subscriber : subscribers)
        subscriber.onRemove(endpoint);

    if(seeds.contains(endpoint))
    {
        buildSeedsList();
        seeds.remove(endpoint);
        logger.info("removed {} from seeds, updated seeds list = {}", endpoint, seeds);
    }

    liveEndpoints.remove(endpoint);
    unreachableEndpoints.remove(endpoint);
    // do not remove endpointState until the quarantine expires
    FailureDetector.instance.remove(endpoint);
    MessagingService.instance().resetVersion(endpoint);
    quarantineEndpoint(endpoint);
    MessagingService.instance().destroyConnectionPool(endpoint);
    if (logger.isDebugEnabled())
        logger.debug("removing endpoint {}", endpoint);
}
 
Example #17
Source File: Gossiper.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
/**
 * Returns true if the chosen target was also a seed. False otherwise
 *
 * @param message
 * @param epSet   a set of endpoint from which a random endpoint is chosen.
 * @return true if the chosen endpoint is also a seed.
 */
private boolean sendGossip(MessageOut<GossipDigestSyn> message, Set<InetAddress> epSet)
{
    List<InetAddress> liveEndpoints = ImmutableList.copyOf(epSet);
    
    int size = liveEndpoints.size();
    if (size < 1)
        return false;
    /* Generate a random number from 0 -> size */
    int index = (size == 1) ? 0 : random.nextInt(size);
    InetAddress to = liveEndpoints.get(index);
    if (logger.isTraceEnabled())
        logger.trace("Sending a GossipDigestSyn to {} ...", to);
    MessagingService.instance().sendOneWay(message, to);
    return seeds.contains(to);
}
 
Example #18
Source File: StreamInitMessage.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public long serializedSize(StreamInitMessage message, int version)
{
    long size = CompactEndpointSerializationHelper.serializedSize(message.from);
    size += TypeSizes.NATIVE.sizeof(message.sessionIndex);
    size += UUIDSerializer.serializer.serializedSize(message.planId, MessagingService.current_version);
    size += TypeSizes.NATIVE.sizeof(message.description);
    size += TypeSizes.NATIVE.sizeof(message.isForOutgoing);
    return size;
}
 
Example #19
Source File: StreamInitMessage.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public StreamInitMessage deserialize(DataInput in, int version) throws IOException
{
    InetAddress from = CompactEndpointSerializationHelper.deserialize(in);
    int sessionIndex = in.readInt();
    UUID planId = UUIDSerializer.serializer.deserialize(in, MessagingService.current_version);
    String description = in.readUTF();
    boolean sentByInitiator = in.readBoolean();
    return new StreamInitMessage(from, sessionIndex, planId, description, sentByInitiator);
}
 
Example #20
Source File: CommitLogDescriptor.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public int getMessagingVersion()
{
    switch (version)
    {
        case VERSION_12:
            return MessagingService.VERSION_12;
        case VERSION_20:
            return MessagingService.VERSION_20;
        case VERSION_21:
            return MessagingService.VERSION_21;
        default:
            throw new IllegalStateException("Unknown commitlog version " + version);
    }
}
 
Example #21
Source File: PagedRangeCommand.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public void serialize(PagedRangeCommand cmd, DataOutputPlus out, int version) throws IOException
{
    out.writeUTF(cmd.keyspace);
    out.writeUTF(cmd.columnFamily);
    out.writeLong(cmd.timestamp);

    AbstractBounds.serializer.serialize(cmd.keyRange, out, version);

    CFMetaData metadata = Schema.instance.getCFMetaData(cmd.keyspace, cmd.columnFamily);

    // SliceQueryFilter (the count is not used)
    SliceQueryFilter filter = (SliceQueryFilter)cmd.predicate;
    metadata.comparator.sliceQueryFilterSerializer().serialize(filter, out, version);

    // The start and stop of the page
    metadata.comparator.serializer().serialize(cmd.start, out);
    metadata.comparator.serializer().serialize(cmd.stop, out);

    out.writeInt(cmd.rowFilter.size());
    for (IndexExpression expr : cmd.rowFilter)
    {
        expr.writeTo(out);;
    }

    out.writeInt(cmd.limit);
    if (version >= MessagingService.VERSION_21)
        out.writeBoolean(cmd.countCQL3Rows);
}
 
Example #22
Source File: ReadMessageTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
private ReadCommand serializeAndDeserializeReadMessage(ReadCommand rm) throws IOException
{
    ReadCommandSerializer rms = ReadCommand.serializer;
    DataOutputBuffer out = new DataOutputBuffer();
    ByteArrayInputStream bis;

    rms.serialize(rm, out, MessagingService.current_version);
    bis = new ByteArrayInputStream(out.getData(), 0, out.getLength());
    return rms.deserialize(new DataInputStream(bis), MessagingService.current_version);
}
 
Example #23
Source File: RepairJobDesc.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public void serialize(RepairJobDesc desc, DataOutputPlus out, int version) throws IOException
{
    if (version >= MessagingService.VERSION_21)
    {
        out.writeBoolean(desc.parentSessionId != null);
        if (desc.parentSessionId != null)
            UUIDSerializer.serializer.serialize(desc.parentSessionId, out, version);
    }
    UUIDSerializer.serializer.serialize(desc.sessionId, out, version);
    out.writeUTF(desc.keyspace);
    out.writeUTF(desc.columnFamily);
    AbstractBounds.serializer.serialize(desc.range, out, version);
}
 
Example #24
Source File: Validator.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
/**
 * Called after the validation lifecycle to respond with the now valid tree. Runs in Stage.ANTIENTROPY.
 */
public void run()
{
    // respond to the request that triggered this validation
    if (!initiator.equals(FBUtilities.getBroadcastAddress()))
        logger.info(String.format("[repair #%s] Sending completed merkle tree to %s for %s/%s", desc.sessionId, initiator, desc.keyspace, desc.columnFamily));
    MessagingService.instance().sendOneWay(new ValidationComplete(desc, tree).createMessage(), initiator);
}
 
Example #25
Source File: Validator.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
/**
 * Called when some error during the validation happened.
 * This sends RepairStatus to inform the initiator that the validation has failed.
 * The actual reason for failure should be looked up in the log of the host calling this function.
 */
public void fail()
{
    logger.error("Failed creating a merkle tree for {}, {} (see log for details)", desc, initiator);
    // send fail message only to nodes >= version 2.0
    MessagingService.instance().sendOneWay(new ValidationComplete(desc).createMessage(), initiator);
}
 
Example #26
Source File: RangeTombstoneList.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public RangeTombstoneList deserialize(DataInput in, int version) throws IOException
{
    int size = in.readInt();
    if (size == 0)
        return null;

    RangeTombstoneList tombstones = new RangeTombstoneList(type, size);

    for (int i = 0; i < size; i++)
    {
        Composite start = type.serializer().deserialize(in);
        Composite end = type.serializer().deserialize(in);
        int delTime =  in.readInt();
        long markedAt = in.readLong();

        if (version >= MessagingService.VERSION_20)
        {
            tombstones.setInternal(i, start, end, markedAt, delTime);
        }
        else
        {
            /*
             * The old implementation used to have range sorted by left value, but with potentially
             * overlapping range. So we need to use the "slow" path.
             */
            tombstones.add(start, end, markedAt, delTime);
        }
    }

    // The "slow" path take care of updating the size, but not the fast one
    if (version >= MessagingService.VERSION_20)
        tombstones.size = size;
    return tombstones;
}
 
Example #27
Source File: CounterMutationVerbHandler.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public void doVerb(final MessageIn<CounterMutation> message, final int id)
{
    try
    {
        final CounterMutation cm = message.payload;
        logger.debug("Applying forwarded {}", cm);

        String localDataCenter = DatabaseDescriptor.getEndpointSnitch().getDatacenter(FBUtilities.getBroadcastAddress());
        // We should not wait for the result of the write in this thread,
        // otherwise we could have a distributed deadlock between replicas
        // running this VerbHandler (see #4578).
        // Instead, we use a callback to send the response. Note that the callback
        // will not be called if the request timeout, but this is ok
        // because the coordinator of the counter mutation will timeout on
        // it's own in that case.
        StorageProxy.applyCounterMutationOnLeader(cm, localDataCenter, new Runnable()
        {
            public void run()
            {
                MessagingService.instance().sendReply(new WriteResponse().createMessage(), id, message.from);
            }
        });
    }
    catch (RequestExecutionException e)
    {
        // The coordinator will timeout on it's own so ignore
        logger.debug("counter error", e);
    }
}
 
Example #28
Source File: RepairJob.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
/**
 * Create repair job to run on specific columnfamily
 */
public RepairJob(IRepairJobEventListener listener,
                 UUID parentSessionId,
                 UUID sessionId,
                 String keyspace,
                 String columnFamily,
                 Range<Token> range,
                 RepairParallelism parallelismDegree,
                 ListeningExecutorService taskExecutor)
{
    this.listener = listener;
    this.desc = new RepairJobDesc(parentSessionId, sessionId, keyspace, columnFamily, range);
    this.parallelismDegree = parallelismDegree;
    this.taskExecutor = taskExecutor;

    IRequestProcessor<InetAddress> processor = new IRequestProcessor<InetAddress>()
    {
        @Override
        public void process(InetAddress endpoint)
        {
            ValidationRequest request = new ValidationRequest(desc, gcBefore);
            MessagingService.instance().sendOneWay(request.createMessage(), endpoint);
        }
    };

    switch (parallelismDegree)
    {
        case SEQUENTIAL:
            this.treeRequests = new SequentialRequestCoordinator<>(processor);
            break;
        case PARALLEL:
            this.treeRequests = new ParallelRequestCoordinator<>(processor);
            break;
        case DATACENTER_AWARE:
            this.treeRequests = new DatacenterAwareRequestCoordinator(processor);
            break;
        default:
            throw new AssertionError("Unknown degree of parallelism specified");
    }
}
 
Example #29
Source File: RemoveTest.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveHostId() throws InterruptedException
{
    // start removal in background and send replication confirmations
    final AtomicBoolean success = new AtomicBoolean(false);
    Thread remover = new Thread()
    {
        public void run()
        {
            try
            {
                ss.removeNode(removalId.toString());
            }
            catch (Exception e)
            {
                System.err.println(e);
                e.printStackTrace();
                return;
            }
            success.set(true);
        }
    };
    remover.start();

    Thread.sleep(1000); // make sure removal is waiting for confirmation

    assertTrue(tmd.isLeaving(removalhost));
    assertEquals(1, tmd.getLeavingEndpoints().size());

    for (InetAddress host : hosts)
    {
        MessageOut msg = new MessageOut(host, MessagingService.Verb.REPLICATION_FINISHED, null, null, Collections.<String, byte[]>emptyMap());
        MessagingService.instance().sendRR(msg, FBUtilities.getBroadcastAddress());
    }

    remover.join();

    assertTrue(success.get());
    assertTrue(tmd.getLeavingEndpoints().isEmpty());
}
 
Example #30
Source File: RepairJobDesc.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public long serializedSize(RepairJobDesc desc, int version)
{
    int size = 0;
    if (version >= MessagingService.VERSION_21)
    {
        size += TypeSizes.NATIVE.sizeof(desc.parentSessionId != null);
        if (desc.parentSessionId != null)
            size += UUIDSerializer.serializer.serializedSize(desc.parentSessionId, version);
    }
    size += UUIDSerializer.serializer.serializedSize(desc.sessionId, version);
    size += TypeSizes.NATIVE.sizeof(desc.keyspace);
    size += TypeSizes.NATIVE.sizeof(desc.columnFamily);
    size += AbstractBounds.serializer.serializedSize(desc.range, version);
    return size;
}