All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.cassandra.dht.tokenallocator.TokenAllocatorDiagnostics Maven / Gradle / Ivy

Go to download

The Apache Cassandra Project develops a highly scalable second-generation distributed database, bringing together Dynamo's fully distributed design and Bigtable's ColumnFamily-based data model.

There is a newer version: 5.0.0
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.cassandra.dht.tokenallocator;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.NavigableMap;
import java.util.Queue;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Multimap;

import org.apache.cassandra.dht.Token;
import org.apache.cassandra.dht.tokenallocator.TokenAllocatorBase.TokenInfo;
import org.apache.cassandra.dht.tokenallocator.TokenAllocatorBase.UnitInfo;
import org.apache.cassandra.dht.tokenallocator.TokenAllocatorBase.Weighted;
import org.apache.cassandra.dht.tokenallocator.TokenAllocatorEvent.TokenAllocatorEventType;
import org.apache.cassandra.diag.DiagnosticEventService;

/**
 * Utility methods for DiagnosticEvent around {@link TokenAllocator} activities.
 */
final class TokenAllocatorDiagnostics
{
    private static final DiagnosticEventService service = DiagnosticEventService.instance();

    private TokenAllocatorDiagnostics()
    {
    }

    static  void noReplicationTokenAllocatorInstanciated(NoReplicationTokenAllocator allocator)
    {
        if (isEnabled(TokenAllocatorEventType.NO_REPLICATION_AWARE_TOKEN_ALLOCATOR_INSTANCIATED))
            service.publish(new TokenAllocatorEvent<>(TokenAllocatorEventType.NO_REPLICATION_AWARE_TOKEN_ALLOCATOR_INSTANCIATED,
                                                      allocator, null, null, null, null, null, null, null));
    }

    static  void replicationTokenAllocatorInstanciated(ReplicationAwareTokenAllocator allocator)
    {
        if (isEnabled(TokenAllocatorEventType.REPLICATION_AWARE_TOKEN_ALLOCATOR_INSTANCIATED))
            service.publish(new TokenAllocatorEvent<>(TokenAllocatorEventType.REPLICATION_AWARE_TOKEN_ALLOCATOR_INSTANCIATED,
                                                      allocator, null, null, null,null, null, null, null));
    }

    static  void unitedAdded(TokenAllocatorBase allocator, int numTokens,
                                   Queue> sortedUnits, NavigableMap sortedTokens,
                                   List tokens, Unit unit)
    {
        if (isEnabled(TokenAllocatorEventType.UNIT_ADDED))
            service.publish(new TokenAllocatorEvent<>(TokenAllocatorEventType.UNIT_ADDED,
                                                      allocator,
                                                      numTokens,
                                                      ImmutableList.copyOf(sortedUnits),
                                                      null,
                                                      ImmutableMap.copyOf(sortedTokens),
                                                      ImmutableList.copyOf(tokens),
                                                      unit,
                                                      null));
    }

    static  void unitedAdded(TokenAllocatorBase allocator, int numTokens,
                                   Multimap unitToTokens, NavigableMap sortedTokens,
                                   List tokens, Unit unit)
    {
        if (isEnabled(TokenAllocatorEventType.UNIT_ADDED))
            service.publish(new TokenAllocatorEvent<>(TokenAllocatorEventType.UNIT_ADDED,
                                                      allocator,
                                                      numTokens,
                                                      null,
                                                      ImmutableMap.copyOf(unitToTokens.asMap()),
                                                      ImmutableMap.copyOf(sortedTokens),
                                                      ImmutableList.copyOf(tokens),
                                                      unit,
                                                      null));
    }


    static  void unitRemoved(TokenAllocatorBase allocator, Unit unit,
                                   Queue> sortedUnits, Map sortedTokens)
    {
        if (isEnabled(TokenAllocatorEventType.UNIT_REMOVED))
            service.publish(new TokenAllocatorEvent<>(TokenAllocatorEventType.UNIT_REMOVED,
                                                      allocator,
                                                      null,
                                                      ImmutableList.copyOf(sortedUnits),
                                                      null,
                                                      ImmutableMap.copyOf(sortedTokens),
                                                      null,
                                                      unit,
                                                      null));
    }

    static  void unitRemoved(TokenAllocatorBase allocator, Unit unit,
                                   Multimap unitToTokens, Map sortedTokens)
    {
        if (isEnabled(TokenAllocatorEventType.UNIT_REMOVED))
            service.publish(new TokenAllocatorEvent<>(TokenAllocatorEventType.UNIT_REMOVED,
                                                      allocator,
                                                      null,
                                                      null,
                                                      ImmutableMap.copyOf(unitToTokens.asMap()),
                                                      ImmutableMap.copyOf(sortedTokens),
                                                      null,
                                                      unit,
                                                      null));
    }

    static  void tokenInfosCreated(TokenAllocatorBase allocator, Queue> sortedUnits,
                                         Map sortedTokens, TokenInfo tokenInfo)
    {
        if (isEnabled(TokenAllocatorEventType.TOKEN_INFOS_CREATED))
            service.publish(new TokenAllocatorEvent<>(TokenAllocatorEventType.TOKEN_INFOS_CREATED,
                                                      allocator,
                                                      null,
                                                      ImmutableList.copyOf(sortedUnits),
                                                      null,
                                                      ImmutableMap.copyOf(sortedTokens),
                                                      null,
                                                      null,
                                                      tokenInfo));
    }

    static  void tokenInfosCreated(TokenAllocatorBase allocator, Multimap unitToTokens,
                                         TokenInfo tokenInfo)
    {
        if (isEnabled(TokenAllocatorEventType.TOKEN_INFOS_CREATED))
            service.publish(new TokenAllocatorEvent<>(TokenAllocatorEventType.TOKEN_INFOS_CREATED,
                                                      allocator,
                                                      null,
                                                      null,
                                                      ImmutableMap.copyOf(unitToTokens.asMap()),
                                                      null,
                                                      null,
                                                      null,
                                                      tokenInfo));
    }

    static  void splitsGenerated(TokenAllocatorBase allocator,
                                       int numTokens, Queue> sortedUnits,
                                       NavigableMap sortedTokens,
                                       Unit newUnit,
                                       Collection tokens)
    {
        if (isEnabled(TokenAllocatorEventType.RANDOM_TOKENS_GENERATED))
            service.publish(new TokenAllocatorEvent<>(TokenAllocatorEventType.RANDOM_TOKENS_GENERATED,
                                                      allocator,
                                                      numTokens,
                                                      ImmutableList.copyOf(sortedUnits),
                                                      null,
                                                      ImmutableMap.copyOf(sortedTokens),
                                                      ImmutableList.copyOf(tokens),
                                                      newUnit,
                                                      null));
    }

    static  void splitsGenerated(TokenAllocatorBase allocator,
                                       int numTokens, Multimap unitToTokens,
                                       NavigableMap sortedTokens, Unit newUnit,
                                       Collection tokens)
    {
        if (isEnabled(TokenAllocatorEventType.RANDOM_TOKENS_GENERATED))
            service.publish(new TokenAllocatorEvent<>(TokenAllocatorEventType.RANDOM_TOKENS_GENERATED,
                                                      allocator,
                                                      numTokens,
                                                      null,
                                                      ImmutableMap.copyOf(unitToTokens.asMap()),
                                                      ImmutableMap.copyOf(sortedTokens),
                                                      ImmutableList.copyOf(tokens),
                                                      newUnit,
                                                      null));
    }

    private static boolean isEnabled(TokenAllocatorEventType type)
    {
        return service.isEnabled(TokenAllocatorEvent.class, type);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy