Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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 com.datastax.oss.driver.internal.core.metadata.token;
import com.datastax.oss.driver.api.core.CqlIdentifier;
import com.datastax.oss.driver.api.core.metadata.Node;
import com.datastax.oss.driver.api.core.metadata.TokenMap;
import com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata;
import com.datastax.oss.driver.api.core.metadata.token.Token;
import com.datastax.oss.driver.api.core.metadata.token.TokenRange;
import com.datastax.oss.driver.internal.core.metadata.DefaultNode;
import com.datastax.oss.driver.internal.core.util.RoutingKey;
import com.datastax.oss.driver.shaded.guava.common.annotations.VisibleForTesting;
import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList;
import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap;
import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableSet;
import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableSetMultimap;
import com.datastax.oss.driver.shaded.guava.common.collect.SetMultimap;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.nio.ByteBuffer;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import net.jcip.annotations.Immutable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Immutable
public class DefaultTokenMap implements TokenMap {
private static final Logger LOG = LoggerFactory.getLogger(DefaultTokenMap.class);
public static DefaultTokenMap build(
@NonNull Collection nodes,
@NonNull Collection keyspaces,
@NonNull TokenFactory tokenFactory,
@NonNull ReplicationStrategyFactory replicationStrategyFactory,
@NonNull String logPrefix) {
TokenToPrimaryAndRing tmp = buildTokenToPrimaryAndRing(nodes, tokenFactory);
Map tokenToPrimary = tmp.tokenToPrimary;
List ring = tmp.ring;
LOG.debug("[{}] Rebuilt ring ({} tokens)", logPrefix, ring.size());
Set tokenRanges = buildTokenRanges(ring, tokenFactory);
ImmutableSetMultimap.Builder tokenRangesByPrimary =
ImmutableSetMultimap.builder();
for (TokenRange range : tokenRanges) {
if (range.isFullRing()) {
// The full ring is always ]min, min], so getEnd() doesn't match the node's token
assert tokenToPrimary.size() == 1;
tokenRangesByPrimary.put(tokenToPrimary.values().iterator().next(), range);
} else {
tokenRangesByPrimary.put(tokenToPrimary.get(range.getEnd()), range);
}
}
Map> replicationConfigs =
buildReplicationConfigs(keyspaces, logPrefix);
ImmutableMap.Builder