use of com.netflix.astyanax.partitioner.Partitioner in project coprhd-controller by CoprHD.
the class DbClientContext method init.
public void init(final HostSupplierImpl hostSupplier) {
String svcName = hostSupplier.getDbSvcName();
log.info("Initializing hosts for {}", svcName);
List<Host> hosts = hostSupplier.get();
if ((hosts != null) && (hosts.isEmpty())) {
throw new IllegalStateException(String.format("DbClientContext.init() : host list in hostsupplier for %s is empty", svcName));
} else {
int hostCount = hosts == null ? 0 : hosts.size();
log.info(String.format("number of hosts in the hostsupplier for %s is %d", svcName, hostCount));
}
Partitioner murmur3partitioner = Murmur3Partitioner.get();
Map<String, Partitioner> partitioners = new HashMap<>();
partitioners.put("org.apache.cassandra.dht.Murmur3Partitioner.class.getCanonicalName()", murmur3partitioner);
ConsistencyLevel readCL = ConsistencyLevel.CL_LOCAL_QUORUM;
ConsistencyLevel writeCL = ConsistencyLevel.CL_EACH_QUORUM;
ConnectionPoolConfigurationImpl cfg = new ConnectionPoolConfigurationImpl(DEFAULT_CN_POOL_NANE).setMaxConns(maxConnections).setMaxConnsPerHost(maxConnectionsPerHost).setConnectTimeout(DEFAULT_CONN_TIMEOUT).setMaxBlockedThreadsPerHost(DEFAULT_MAX_BLOCKED_THREADS).setPartitioner(murmur3partitioner);
log.info("The client to node is encrypted={}", isClientToNodeEncrypted);
if (isClientToNodeEncrypted) {
SSLConnectionContext sslContext = getSSLConnectionContext();
cfg.setSSLConnectionContext(sslContext);
}
// TODO revisit it to see if we need set different retry policy, timeout, discovery delay etc for geodb
keyspaceContext = new AstyanaxContext.Builder().withHostSupplier(hostSupplier).forCluster(clusterName).forKeyspace(keyspaceName).withAstyanaxConfiguration(new AstyanaxConfigurationImpl().setConnectionPoolType(ConnectionPoolType.ROUND_ROBIN).setDiscoveryDelayInSeconds(svcListPoolIntervalSec).setDefaultReadConsistencyLevel(readCL).setDefaultWriteConsistencyLevel(writeCL).setTargetCassandraVersion("2.0").setPartitioners(partitioners).setRetryPolicy(retryPolicy)).withConnectionPoolConfiguration(cfg).withTracerFactory(new KeyspaceTracerFactoryImpl()).withConnectionPoolMonitor(new CustomConnectionPoolMonitor(monitorIntervalSecs)).buildKeyspace(ThriftFamilyFactory.getInstance());
keyspaceContext.start();
keyspace = keyspaceContext.getClient();
// Check and reset default write consistency level
final DrUtil drUtil = new DrUtil(hostSupplier.getCoordinatorClient());
if (drUtil.isMultivdc()) {
// geodb in mutlivdc should be EACH_QUORUM always. Never retry for write failures
setRetryFailedWriteWithLocalQuorum(false);
log.info("Retry for failed write with LOCAL_QUORUM: {}", retryFailedWriteWithLocalQuorum);
} else {
setRetryFailedWriteWithLocalQuorum(true);
}
if (drUtil.isActiveSite() && !drUtil.isMultivdc()) {
log.info("Schedule db consistency level monitor on DR active site");
exe.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
try {
checkAndResetConsistencyLevel(drUtil, hostSupplier.getDbSvcName());
} catch (Exception ex) {
log.warn("Encounter Unexpected exception during check consistency level. Retry in next run", ex);
}
}
}, 60, DEFAULT_CONSISTENCY_LEVEL_CHECK_SEC, TimeUnit.SECONDS);
}
initDone = true;
}
use of com.netflix.astyanax.partitioner.Partitioner in project coprhd-controller by CoprHD.
the class DbClientImpl method scanRowsByType.
private <T extends DataObject> Iterable<Row<String, CompositeColumnName>> scanRowsByType(Class<T> clazz, Boolean inactiveValue, URI startId, int count) {
DataObjectType doType = TypeMap.getDoType(clazz);
if (doType == null) {
throw new IllegalArgumentException();
}
try {
ColumnFamily<String, CompositeColumnName> cf = doType.getCF();
Keyspace ks = getKeyspace(clazz);
ColumnFamilyQuery<String, CompositeColumnName> query = ks.prepareQuery(cf);
// Column filter, get only last .inactive column, or get any column
ByteBufferRange columnRange = inactiveValue == null ? CompositeColumnNameSerializer.get().buildRange().limit(1).build() : CompositeColumnNameSerializer.get().buildRange().greaterThanEquals(DataObject.INACTIVE_FIELD_NAME).lessThanEquals(DataObject.INACTIVE_FIELD_NAME).reverse().limit(1).build();
Execution<Rows<String, CompositeColumnName>> exec;
if (count == Integer.MAX_VALUE) {
exec = query.getAllRows().withColumnRange(columnRange);
} else {
Partitioner partitioner = ks.getPartitioner();
String strKey = startId != null ? startId.toString() : null;
String startToken = strKey != null ? partitioner.getTokenForKey(cf.getKeySerializer().toByteBuffer(strKey)) : partitioner.getMinToken();
exec = query.getRowRange(strKey, null, startToken, partitioner.getMaxToken(), count).withColumnRange(columnRange);
}
return exec.execute().getResult();
} catch (ConnectionException e) {
throw DatabaseException.retryables.connectionFailed(e);
}
}
Aggregations