Search in sources :

Example 1 with ConsistencyLevel

use of com.netflix.astyanax.model.ConsistencyLevel 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;
}
Also used : HashMap(java.util.HashMap) DrUtil(com.emc.storageos.coordinator.client.service.DrUtil) Host(com.netflix.astyanax.connectionpool.Host) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) ConsistencyLevel(com.netflix.astyanax.model.ConsistencyLevel) SSLConnectionContext(com.netflix.astyanax.connectionpool.SSLConnectionContext) ConnectionPoolConfigurationImpl(com.netflix.astyanax.connectionpool.impl.ConnectionPoolConfigurationImpl) AstyanaxContext(com.netflix.astyanax.AstyanaxContext) AstyanaxConfigurationImpl(com.netflix.astyanax.impl.AstyanaxConfigurationImpl) Murmur3Partitioner(com.netflix.astyanax.partitioner.Murmur3Partitioner) Partitioner(com.netflix.astyanax.partitioner.Partitioner)

Example 2 with ConsistencyLevel

use of com.netflix.astyanax.model.ConsistencyLevel in project coprhd-controller by CoprHD.

the class CustomizedDistributedRowLock method readLockColumns.

/**
 * Read all the lock columns. Will also ready data columns if withDataColumns(true) was called
 *
 * @param readDataColumns
 * @throws Exception
 */
private Map<String, Long> readLockColumns(boolean readDataColumns) throws Exception {
    Map<String, Long> result = Maps.newLinkedHashMap();
    ConsistencyLevel read_consistencyLevel = consistencyLevel;
    // CASSANDRA actually does not support EACH_QUORUM for read which is meaningless as well.
    if (consistencyLevel == ConsistencyLevel.CL_EACH_QUORUM) {
        read_consistencyLevel = ConsistencyLevel.CL_LOCAL_QUORUM;
    }
    // Read all the columns
    if (readDataColumns) {
        columns = new OrderedColumnMap<String>();
        ColumnList<String> lockResult = keyspace.prepareQuery(columnFamily).setConsistencyLevel(read_consistencyLevel).getKey(key).execute().getResult();
        for (Column<String> c : lockResult) {
            if (c.getName().startsWith(prefix)) {
                result.put(c.getName(), readTimeoutValue(c));
            } else {
                columns.add(c);
            }
        }
    } else // Read only the lock columns
    {
        ColumnList<String> lockResult = keyspace.prepareQuery(columnFamily).setConsistencyLevel(read_consistencyLevel).getKey(key).withColumnRange(new RangeBuilder().setStart(prefix + "\u0000").setEnd(prefix + "\uFFFF").build()).execute().getResult();
        for (Column<String> c : lockResult) {
            result.put(c.getName(), readTimeoutValue(c));
        }
    }
    return result;
}
Also used : ConsistencyLevel(com.netflix.astyanax.model.ConsistencyLevel) RangeBuilder(com.netflix.astyanax.util.RangeBuilder)

Example 3 with ConsistencyLevel

use of com.netflix.astyanax.model.ConsistencyLevel in project coprhd-controller by CoprHD.

the class DbClientContext method checkAndResetConsistencyLevel.

private void checkAndResetConsistencyLevel(DrUtil drUtil, String svcName) {
    if (isRetryFailedWriteWithLocalQuorum() && drUtil.isMultivdc()) {
        log.info("Disable retry for write failure in multiple vdc configuration");
        setRetryFailedWriteWithLocalQuorum(false);
        return;
    }
    ConsistencyLevel currentConsistencyLevel = getKeyspace().getConfig().getDefaultWriteConsistencyLevel();
    if (currentConsistencyLevel.equals(ConsistencyLevel.CL_EACH_QUORUM)) {
        log.debug("Write consistency level is EACH_QUORUM. No need adjust");
        return;
    }
    log.info("Db consistency level for {} is downgraded as LOCAL_QUORUM. Check if we need reset it back", svcName);
    for (Site site : drUtil.listStandbySites()) {
        if (site.getState().equals(SiteState.STANDBY_PAUSED) || site.getState().equals(SiteState.STANDBY_DEGRADED)) {
            // ignore a standby site which is paused by customer explicitly
            continue;
        }
        String siteUuid = site.getUuid();
        int count = drUtil.getNumberOfLiveServices(siteUuid, svcName);
        if (count <= site.getNodeCount() / 2) {
            log.info("Service {} of quorum nodes on site {} is down. Still keep write consistency level to LOCAL_QUORUM", svcName, siteUuid);
            return;
        }
    }
    log.info("Service {} of quorum nodes on all standby sites are up. Reset default write consistency level back to EACH_QUORUM", svcName);
    AstyanaxConfigurationImpl config = (AstyanaxConfigurationImpl) keyspaceContext.getAstyanaxConfiguration();
    config.setDefaultWriteConsistencyLevel(ConsistencyLevel.CL_EACH_QUORUM);
}
Also used : ConsistencyLevel(com.netflix.astyanax.model.ConsistencyLevel) Site(com.emc.storageos.coordinator.client.model.Site) AstyanaxConfigurationImpl(com.netflix.astyanax.impl.AstyanaxConfigurationImpl)

Aggregations

ConsistencyLevel (com.netflix.astyanax.model.ConsistencyLevel)3 AstyanaxConfigurationImpl (com.netflix.astyanax.impl.AstyanaxConfigurationImpl)2 Site (com.emc.storageos.coordinator.client.model.Site)1 DrUtil (com.emc.storageos.coordinator.client.service.DrUtil)1 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)1 AstyanaxContext (com.netflix.astyanax.AstyanaxContext)1 Host (com.netflix.astyanax.connectionpool.Host)1 SSLConnectionContext (com.netflix.astyanax.connectionpool.SSLConnectionContext)1 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)1 ConnectionPoolConfigurationImpl (com.netflix.astyanax.connectionpool.impl.ConnectionPoolConfigurationImpl)1 Murmur3Partitioner (com.netflix.astyanax.partitioner.Murmur3Partitioner)1 Partitioner (com.netflix.astyanax.partitioner.Partitioner)1 RangeBuilder (com.netflix.astyanax.util.RangeBuilder)1 HashMap (java.util.HashMap)1