Search in sources :

Example 56 with TokenMetadata

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

the class BootStrapperTest method testAllocateTokens.

@Test
public void testAllocateTokens() throws UnknownHostException {
    int vn = 16;
    String ks = "BootStrapperTestKeyspace3";
    TokenMetadata tm = new TokenMetadata();
    generateFakeEndpoints(tm, 10, vn);
    InetAddress addr = FBUtilities.getBroadcastAddress();
    allocateTokensForNode(vn, ks, tm, addr);
}
Also used : TokenMetadata(org.apache.cassandra.locator.TokenMetadata) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 57 with TokenMetadata

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

the class BootStrapperTest method testAllocateTokensNetworkStrategy.

public void testAllocateTokensNetworkStrategy(int rackCount, int replicas) throws UnknownHostException {
    IEndpointSnitch oldSnitch = DatabaseDescriptor.getEndpointSnitch();
    try {
        DatabaseDescriptor.setEndpointSnitch(new RackInferringSnitch());
        int vn = 16;
        String ks = "BootStrapperTestNTSKeyspace" + rackCount + replicas;
        String dc = "1";
        // Register peers with expected DC for NetworkTopologyStrategy.
        TokenMetadata metadata = StorageService.instance.getTokenMetadata();
        metadata.clearUnsafe();
        metadata.updateHostId(UUID.randomUUID(), InetAddress.getByName("127.1.0.99"));
        metadata.updateHostId(UUID.randomUUID(), InetAddress.getByName("127.15.0.99"));
        SchemaLoader.createKeyspace(ks, KeyspaceParams.nts(dc, replicas, "15", 15), SchemaLoader.standardCFMD(ks, "Standard1"));
        TokenMetadata tm = StorageService.instance.getTokenMetadata();
        tm.clearUnsafe();
        for (int i = 0; i < rackCount; ++i) generateFakeEndpoints(tm, 10, vn, dc, Integer.toString(i));
        InetAddress addr = InetAddress.getByName("127." + dc + ".0.99");
        allocateTokensForNode(vn, ks, tm, addr);
    // Note: Not matching replication factor in second datacentre, but this should not affect us.
    } finally {
        DatabaseDescriptor.setEndpointSnitch(oldSnitch);
    }
}
Also used : TokenMetadata(org.apache.cassandra.locator.TokenMetadata) InetAddress(java.net.InetAddress) IEndpointSnitch(org.apache.cassandra.locator.IEndpointSnitch) RackInferringSnitch(org.apache.cassandra.locator.RackInferringSnitch)

Example 58 with TokenMetadata

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

the class DiskBoundaryManagerTest method setup.

@Before
public void setup() {
    DisallowedDirectories.clearUnwritableUnsafe();
    TokenMetadata metadata = StorageService.instance.getTokenMetadata();
    metadata.updateNormalTokens(BootStrapper.getRandomTokens(metadata, 10), FBUtilities.getBroadcastAddressAndPort());
    createTable("create table %s (id int primary key, x text)");
    dirs = new Directories(getCurrentColumnFamilyStore().metadata(), Lists.newArrayList(new Directories.DataDirectory(new File("/tmp/1")), new Directories.DataDirectory(new File("/tmp/2")), new Directories.DataDirectory(new File("/tmp/3"))));
    mock = new MockCFS(getCurrentColumnFamilyStore(), dirs);
    dbm = mock.diskBoundaryManager;
}
Also used : TokenMetadata(org.apache.cassandra.locator.TokenMetadata) File(org.apache.cassandra.io.util.File) Before(org.junit.Before)

Example 59 with TokenMetadata

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

the class RowCacheTest method testRowCacheCleanup.

@Test
public void testRowCacheCleanup() throws Exception {
    StorageService.instance.initServer(0);
    CacheService.instance.setRowCacheCapacityInMB(1);
    rowCacheLoad(100, Integer.MAX_VALUE, 1000);
    ColumnFamilyStore store = Keyspace.open(KEYSPACE_CACHED).getColumnFamilyStore(CF_CACHED);
    assertEquals(CacheService.instance.rowCache.size(), 100);
    store.cleanupCache();
    assertEquals(CacheService.instance.rowCache.size(), 100);
    TokenMetadata tmd = StorageService.instance.getTokenMetadata();
    byte[] tk1, tk2;
    tk1 = "key1000".getBytes();
    tk2 = "key1050".getBytes();
    tmd.updateNormalToken(new BytesToken(tk1), InetAddressAndPort.getByName("127.0.0.1"));
    tmd.updateNormalToken(new BytesToken(tk2), InetAddressAndPort.getByName("127.0.0.2"));
    store.cleanupCache();
    assertEquals(50, CacheService.instance.rowCache.size());
    CacheService.instance.setRowCacheCapacityInMB(0);
}
Also used : BytesToken(org.apache.cassandra.dht.ByteOrderedPartitioner.BytesToken) TokenMetadata(org.apache.cassandra.locator.TokenMetadata) Test(org.junit.Test)

Example 60 with TokenMetadata

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

the class ReadCommandVerbHandlerTest method init.

@BeforeClass
public static void init() throws Throwable {
    SchemaLoader.loadSchema();
    SchemaLoader.schemaDefinition(TEST_NAME);
    metadata = Schema.instance.getTableMetadata(KEYSPACE, TABLE);
    metadata_with_transient = Schema.instance.getTableMetadata(KEYSPACE_WITH_TRANSIENT, TABLE);
    KEY = key(metadata, 1);
    TokenMetadata tmd = StorageService.instance.getTokenMetadata();
    tmd.updateNormalToken(KEY.getToken(), InetAddressAndPort.getByName("127.0.0.2"));
    tmd.updateNormalToken(key(metadata, 2).getToken(), InetAddressAndPort.getByName("127.0.0.3"));
    tmd.updateNormalToken(key(metadata, 3).getToken(), FBUtilities.getBroadcastAddressAndPort());
}
Also used : TokenMetadata(org.apache.cassandra.locator.TokenMetadata) BeforeClass(org.junit.BeforeClass)

Aggregations

TokenMetadata (org.apache.cassandra.locator.TokenMetadata)109 Test (org.junit.Test)66 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)43 Token (org.apache.cassandra.dht.Token)37 VersionedValue (org.apache.cassandra.gms.VersionedValue)22 InetAddress (java.net.InetAddress)21 Range (org.apache.cassandra.dht.Range)19 AbstractReplicationStrategy (org.apache.cassandra.locator.AbstractReplicationStrategy)19 StringToken (org.apache.cassandra.dht.OrderPreservingPartitioner.StringToken)13 BigIntegerToken (org.apache.cassandra.dht.RandomPartitioner.BigIntegerToken)13 Replica (org.apache.cassandra.locator.Replica)13 RangesAtEndpoint (org.apache.cassandra.locator.RangesAtEndpoint)11 IPartitioner (org.apache.cassandra.dht.IPartitioner)10 LongToken (org.apache.cassandra.dht.Murmur3Partitioner.LongToken)10 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)8 IEndpointSnitch (org.apache.cassandra.locator.IEndpointSnitch)8 RangesByEndpoint (org.apache.cassandra.locator.RangesByEndpoint)8 BeforeClass (org.junit.BeforeClass)8 Multimap (com.google.common.collect.Multimap)7 EndpointsForToken (org.apache.cassandra.locator.EndpointsForToken)7