use of com.datastax.oss.driver.internal.core.metadata.token.ReplicationStrategyFactory in project java-driver by datastax.
the class DefaultMetadata method rebuildTokenMap.
@Nullable
protected TokenMap rebuildTokenMap(Map<UUID, Node> newNodes, Map<CqlIdentifier, KeyspaceMetadata> newKeyspaces, boolean tokenMapEnabled, boolean forceFullRebuild, TokenFactory tokenFactory, InternalDriverContext context) {
String logPrefix = context.getSessionName();
ReplicationStrategyFactory replicationStrategyFactory = context.getReplicationStrategyFactory();
if (!tokenMapEnabled) {
LOG.debug("[{}] Token map is disabled, skipping", logPrefix);
return this.tokenMap;
}
long start = System.nanoTime();
try {
DefaultTokenMap oldTokenMap = (DefaultTokenMap) this.tokenMap;
if (oldTokenMap == null) {
// Initial build, we need the token factory
if (tokenFactory == null) {
LOG.debug("[{}] Building initial token map but the token factory is missing, skipping", logPrefix);
return null;
} else {
LOG.debug("[{}] Building initial token map", logPrefix);
return DefaultTokenMap.build(newNodes.values(), newKeyspaces.values(), tokenFactory, replicationStrategyFactory, logPrefix);
}
} else if (forceFullRebuild) {
LOG.debug("[{}] Updating token map but some nodes/tokens have changed, full rebuild", logPrefix);
return DefaultTokenMap.build(newNodes.values(), newKeyspaces.values(), oldTokenMap.getTokenFactory(), replicationStrategyFactory, logPrefix);
} else {
LOG.debug("[{}] Refreshing token map (only schema has changed)", logPrefix);
return oldTokenMap.refresh(newNodes.values(), newKeyspaces.values(), replicationStrategyFactory);
}
} catch (Throwable t) {
Loggers.warnWithException(LOG, "[{}] Unexpected error while refreshing token map, keeping previous version", logPrefix, t);
return this.tokenMap;
} finally {
LOG.debug("[{}] Rebuilding token map took {}", logPrefix, NanoTime.formatTimeSince(start));
}
}
Aggregations