com.datastax.driver.core.policies.DowngradingConsistencyRetryPolicy Java Examples

The following examples show how to use com.datastax.driver.core.policies.DowngradingConsistencyRetryPolicy. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UtilsUnitTest.java    From cassandra-jdbc-wrapper with Apache License 2.0 6 votes vote down vote up
@Test
public void testRetryPolicyParsing() throws Exception
{
	String retryPolicyStr = "DefaultRetryPolicy";
	System.out.println(retryPolicyStr);
	assertTrue(Utils.parseRetryPolicy(retryPolicyStr) instanceof DefaultRetryPolicy);
	System.out.println("====================");
	retryPolicyStr = "DowngradingConsistencyRetryPolicy";
	System.out.println(retryPolicyStr);
	assertTrue(Utils.parseRetryPolicy(retryPolicyStr) instanceof DowngradingConsistencyRetryPolicy);
	System.out.println("====================");
	retryPolicyStr = "FallthroughRetryPolicy";
	System.out.println(retryPolicyStr);
	assertTrue(Utils.parseRetryPolicy(retryPolicyStr) instanceof FallthroughRetryPolicy);
	System.out.println("====================");
	    	

}
 
Example #2
Source File: AbstractRecordingV2Table.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
@Inject
public AbstractRecordingV2Table(String ts, Session session) {
	super(ts, session);
	this.selectByRecordingId = CassandraQueryBuilder
				.select(getTableName())
				.addColumns(getTableColumns())
				.addWhereColumnEquals(COL_RECORDINGID)
				.prepare(session);
			
	this.deleteRecording =
			CassandraQueryBuilder
				.delete(getTableName())
				.addWhereColumnEquals(COL_RECORDINGID)
				.withRetryPolicy(new LoggingRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE))
				.prepare(session);
}
 
Example #3
Source File: VideoMetadataV2FavoriteTable.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
@Inject
public VideoMetadataV2FavoriteTable(String ts, Session session) {
	super(ts, session);
	this.deleteField =
			CassandraQueryBuilder
				.delete(getTableName())
				.addWhereColumnEquals(COL_RECORDINGID)
				.addWhereColumnEquals(COL_FIELD)
				.prepare(session);
	this.insertField =
			CassandraQueryBuilder
				.insert(getTableName())
				.addColumns(COLUMNS)
				.withRetryPolicy(new LoggingRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE))
				.prepare(session);
}
 
Example #4
Source File: AbstractVideoMetadataV2Table.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
@Inject
public AbstractVideoMetadataV2Table(String ts, Session session) {
	super(ts, session);
	this.selectByRecordingId =
			CassandraQueryBuilder
				.select(getTableName())
				.addColumns(getTableColumns())
				.addWhereColumnEquals(COL_RECORDINGID)
				.prepare(session);
	this.deleteRecording =
			CassandraQueryBuilder
				.delete(getTableName())
				.addWhereColumnEquals(COL_RECORDINGID)
				.withRetryPolicy(new LoggingRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE))
				.prepare(session);
}
 
Example #5
Source File: CassandraConfig.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private Builder populateRetrytPolicy(Map<String, String> properties, Builder builder) throws DataServiceFault {
    String retryPolicy = properties.get(DBConstants.Cassandra.RETRY_POLICY);
    if (retryPolicy != null) {
        if ("DefaultRetryPolicy".equals(retryPolicy)) {
            builder = builder.withRetryPolicy(DefaultRetryPolicy.INSTANCE);
        } else if ("DowngradingConsistencyRetryPolicy".equals(retryPolicy)) {
            builder = builder.withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE);
        } else if ("FallthroughRetryPolicy".equals(retryPolicy)) {
            builder = builder.withRetryPolicy(FallthroughRetryPolicy.INSTANCE);
        } else if ("LoggingDefaultRetryPolicy".equals(retryPolicy)) {
            builder = builder.withRetryPolicy(new LoggingRetryPolicy(DefaultRetryPolicy.INSTANCE));
        } else if ("LoggingDowngradingConsistencyRetryPolicy".equals(retryPolicy)) {
            builder = builder.withRetryPolicy(new LoggingRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE));                
        } else if ("LoggingFallthroughRetryPolicy".equals(retryPolicy)) {
            builder = builder.withRetryPolicy(new LoggingRetryPolicy(FallthroughRetryPolicy.INSTANCE));                
        } else {
            throw new DataServiceFault("Invalid Cassandra retry policy: " + retryPolicy);
        }
    }
    return builder;
}
 
Example #6
Source File: CassandraVideoV2Dao.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
private void complete(UUID placeId, UUID recordingId, long expiration, long actualTtlInSeconds, double duration, long size) {
	BatchStatement stmt = new BatchStatement(Type.UNLOGGED); // recording will be atomic, and place_recording will be atomic, but they will be independently atomic to save performance
	stmt.setRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE);
	
	addDurationAndSizeStatements(stmt, placeId, recordingId, duration, size, expiration, actualTtlInSeconds);
	// Recording Metadata Index Mutations
	stmt.add(placeRecordingIndex.insertRecording(placeId, recordingId, size, expiration, actualTtlInSeconds));

	executeAndUpdateTimer(session, stmt, CompleteTimer);		
}
 
Example #7
Source File: CassandraClusterCreatorTest.java    From spring-cloud-connectors with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldCreateClusterWithConfig() throws Exception {

	CassandraServiceInfo info = new CassandraServiceInfo("local",
			Collections.singletonList("127.0.0.1"), 9142);

	CassandraClusterConfig config = new CassandraClusterConfig();
	config.setCompression(ProtocolOptions.Compression.NONE);
	config.setPoolingOptions(new PoolingOptions().setPoolTimeoutMillis(1234));
	config.setQueryOptions(new QueryOptions());
	config.setProtocolVersion(ProtocolVersion.NEWEST_SUPPORTED);
	config.setLoadBalancingPolicy(new RoundRobinPolicy());
	config.setReconnectionPolicy(new ConstantReconnectionPolicy(1));
	config.setRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE);
	config.setSocketOptions(new SocketOptions());

	Cluster cluster = creator.create(info, config);

	Configuration configuration = cluster.getConfiguration();

	assertThat(configuration.getProtocolOptions().getCompression(),
			is(config.getCompression()));
	assertThat(configuration.getQueryOptions(), is(config.getQueryOptions()));
	assertThat(configuration.getSocketOptions(), is(config.getSocketOptions()));

	Policies policies = configuration.getPolicies();
	assertThat(policies.getLoadBalancingPolicy(),
			is(config.getLoadBalancingPolicy()));
	assertThat(policies.getReconnectionPolicy(), is(config.getReconnectionPolicy()));
	assertThat(policies.getRetryPolicy(), is(config.getRetryPolicy()));
}
 
Example #8
Source File: DowngradingConsistencyRetryPolicyFactoryTest.java    From dropwizard-cassandra with Apache License 2.0 5 votes vote down vote up
@Test
public void returnsDowngradingConsistencyRetryPolicyInstance() throws Exception {
    final DowngradingConsistencyRetryPolicyFactory factory = new DowngradingConsistencyRetryPolicyFactory();

    final DowngradingConsistencyRetryPolicy policy = (DowngradingConsistencyRetryPolicy) factory.build();

    assertThat(policy).isSameAs(DowngradingConsistencyRetryPolicy.INSTANCE);
}
 
Example #9
Source File: RecordingV2Table.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
public Statement insertIFrame(UUID recordingId, long expiration, long actualTtlInSeconds, double ts, long bo, ByteBuffer value) {
	Statement insert = QueryBuilder.insertInto(getTableSpace(), TABLE_NAME).using(QueryBuilder.ttl((int)actualTtlInSeconds))
		.values(COLUMNS, new Object[]{ts, bo, value, recordingId, expiration})
		.setRetryPolicy(new LoggingRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE))			
		;
	return insert;
}
 
Example #10
Source File: PlaceRecordingIndexV2FavoriteTable.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
private Statement doInsert(UUID placeId, UUID recordingId, String fieldName, String value, Long size) {
	Statement insert = QueryBuilder.insertInto(getTableSpace(), TABLE_NAME)
			.values(COLUMNS, new Object[]{placeId, fieldName, value, recordingId, size})
			.setRetryPolicy(new LoggingRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE))			
			;
	return insert;
}
 
Example #11
Source File: CassandraVideoV2Dao.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Override
public void completeAndDelete(UUID placeId, UUID recordingId, double duration, long size, Date purgeTime, int purgePartitionId, long ttlInSeconds) {
	BatchStatement stmt = new BatchStatement(Type.UNLOGGED); // recording will be atomic, and place_recording will be atomic, but they will be independently atomic to save performance
	stmt.setRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE);
	
	addDurationAndSizeStatements(stmt, placeId, recordingId, duration, size, ttlInSeconds);
	addDeleteStatements(stmt, placeId, recordingId, false, purgeTime, purgePartitionId);
	executeAndUpdateTimer(session, stmt, CompleteTimer);	
}
 
Example #12
Source File: PlaceRecordingIndexV2Table.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
private Statement doInsert(UUID placeId, UUID recordingId, long expiration, long actualTtlInSeconds, String fieldName, String value, Long size) {
	Statement insert = QueryBuilder.insertInto(getTableSpace(), TABLE_NAME).using(QueryBuilder.ttl((int)actualTtlInSeconds))
			.values(COLUMNS, new Object[]{placeId, fieldName, expiration, value, recordingId, size})
			.setRetryPolicy(new LoggingRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE))			
			;
	return insert;
}
 
Example #13
Source File: VideoMetadataV2Table.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
private Statement doInsertField(UUID recordingId, long expiration, long actualTtlInSeconds, String attributeName, String value) {
	Statement insert = QueryBuilder.insertInto(getTableSpace(), TABLE_NAME).using(QueryBuilder.ttl((int)actualTtlInSeconds))
			.values(COLUMNS, new Object[]{recordingId, expiration, attributeName, value})
			.setRetryPolicy(new LoggingRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE))			
			;
	return insert;		
}
 
Example #14
Source File: VideoMetadataV2Table.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
public Statement insertField(UUID recordingId, long expiration, long actualTtlInSeconds, MetadataAttribute attribute, String value) {
	Statement insert = QueryBuilder.insertInto(getTableSpace(), TABLE_NAME).using(QueryBuilder.ttl((int)actualTtlInSeconds))
			.values(COLUMNS, new Object[]{recordingId, expiration, attribute.name().toLowerCase(), value})
			.setRetryPolicy(new LoggingRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE))			
			;
	return insert;		
}
 
Example #15
Source File: RecordingV2FavoriteTable.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
public Statement insertIFrame(UUID recordingId, double ts, long bo, ByteBuffer value) {
	Statement insert = QueryBuilder.insertInto(getTableSpace(), TABLE_NAME)
		.values(COLUMNS, new Object[]{ts, bo, value, recordingId})
		.setRetryPolicy(new LoggingRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE))			
		;
	return insert;
}
 
Example #16
Source File: DowngradingConsistencyRetryPolicyFactory.java    From dropwizard-cassandra with Apache License 2.0 4 votes vote down vote up
@Override
public RetryPolicy build() {
    return DowngradingConsistencyRetryPolicy.INSTANCE;
}
 
Example #17
Source File: CassandraService.java    From disthene-reader with MIT License 4 votes vote down vote up
public CassandraService(StoreConfiguration storeConfiguration) {
    String query = "SELECT time, data FROM " +
                        storeConfiguration.getKeyspace() + "." + storeConfiguration.getColumnFamily() +
                        " where path = ? and tenant = ? and period = ? and rollup = ? and time >= ? and time <= ? order by time";

    SocketOptions socketOptions = new SocketOptions()
            .setReceiveBufferSize(1024 * 1024)
            .setSendBufferSize(1024 * 1024)
            .setTcpNoDelay(false)
            .setReadTimeoutMillis((int) (storeConfiguration.getReadTimeout() * 1000))
            .setConnectTimeoutMillis((int) (storeConfiguration.getConnectTimeout() * 1000));

    PoolingOptions poolingOptions = new PoolingOptions();
    poolingOptions.setMaxConnectionsPerHost(HostDistance.LOCAL, storeConfiguration.getMaxConnections());
    poolingOptions.setMaxConnectionsPerHost(HostDistance.REMOTE, storeConfiguration.getMaxConnections());
    poolingOptions.setMaxRequestsPerConnection(HostDistance.REMOTE, storeConfiguration.getMaxRequests());
    poolingOptions.setMaxRequestsPerConnection(HostDistance.LOCAL, storeConfiguration.getMaxRequests());

    Cluster.Builder builder = Cluster.builder()
            .withSocketOptions(socketOptions)
            .withCompression(ProtocolOptions.Compression.LZ4)
            .withLoadBalancingPolicy(CassandraLoadBalancingPolicies.getLoadBalancingPolicy(storeConfiguration.getLoadBalancingPolicyName()))
            .withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE)
            .withPoolingOptions(poolingOptions)
            .withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.valueOf(storeConfiguration.getConsistency())))
            .withProtocolVersion(ProtocolVersion.valueOf(storeConfiguration.getProtocolVersion()))
            .withPort(storeConfiguration.getPort());

    if ( storeConfiguration.getUserName() != null && storeConfiguration.getUserPassword() != null) {
        builder = builder.withCredentials(storeConfiguration.getUserName(), storeConfiguration.getUserPassword());
    }

    for (String cp : storeConfiguration.getCluster()) {
        builder.addContactPoint(cp);
    }

    cluster = builder.build();
    Metadata metadata = cluster.getMetadata();
    logger.debug("Connected to cluster: " + metadata.getClusterName());
    for (Host host : metadata.getAllHosts()) {
        logger.debug(String.format("Datacenter: %s; Host: %s; Rack: %s", host.getDatacenter(), host.getAddress(), host.getRack()));
    }

    session = cluster.connect();

    statement = session.prepare(query);
}