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

The following examples show how to use com.datastax.driver.core.policies.LoggingRetryPolicy. 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: 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 #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: 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 #6
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 #7
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 #8
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 #9
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 #10
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 #11
Source File: BackplaneConfiguration.java    From elasticactors with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void initialize() {
    String cassandraHosts = env.getProperty("ea.cassandra.hosts","localhost:9042");
    String cassandraClusterName = env.getProperty("ea.cassandra.cluster","ElasticActorsCluster");
    String cassandraKeyspaceName = env.getProperty("ea.cassandra.keyspace","\"ElasticActors\"");
    Integer cassandraPort = env.getProperty("ea.cassandra.port", Integer.class, 9042);

    Set<String> hostSet = StringUtils.commaDelimitedListToSet(cassandraHosts);

    String[] contactPoints = new String[hostSet.size()];
    int i=0;
    for (String host : hostSet) {
        if(host.contains(":")) {
            contactPoints[i] = host.substring(0,host.indexOf(":"));
        } else {
            contactPoints[i] = host;
        }
        i+=1;
    }

    PoolingOptions poolingOptions = new PoolingOptions();
    poolingOptions.setHeartbeatIntervalSeconds(60);
    poolingOptions.setConnectionsPerHost(HostDistance.LOCAL, 2, env.getProperty("ea.cassandra.maxActive",Integer.class,Runtime.getRuntime().availableProcessors() * 3));
    poolingOptions.setPoolTimeoutMillis(2000);

    Cluster cassandraCluster =
            Cluster.builder().withClusterName(cassandraClusterName)
                    .addContactPoints(contactPoints)
                    .withPort(cassandraPort)
            .withLoadBalancingPolicy(new RoundRobinPolicy())
            .withRetryPolicy(new LoggingRetryPolicy(DefaultRetryPolicy.INSTANCE))
            .withPoolingOptions(poolingOptions)
            .withReconnectionPolicy(new ConstantReconnectionPolicy(env.getProperty("ea.cassandra.retryDownedHostsDelayInSeconds",Integer.class,1) * 1000))
            .withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.QUORUM)).build();

    this.cassandraSession = cassandraCluster.connect(cassandraKeyspaceName);

    
}
 
Example #12
Source File: AppBase.java    From yb-sample-apps with Apache License 2.0 4 votes vote down vote up
/**
 * Private method that is thread-safe and creates the Cassandra client. Exactly one calling thread
 * will succeed in creating the client. This method does nothing for the other threads.
 * @param contactPoints list of contact points for the client.
 */
protected synchronized void createCassandraClient(List<ContactPoint> contactPoints) {
  Cluster.Builder builder;
  if (cassandra_cluster == null) {
    builder = Cluster.builder();
    if (appConfig.dbUsername != null) {
      if (appConfig.dbPassword == null) {
        throw new IllegalArgumentException("Password required when providing a username");
      }
      builder = builder
          .withCredentials(appConfig.dbUsername, appConfig.dbPassword);
    }
    if (appConfig.sslCert != null) {
      builder = builder
          .withSSL(createSSLHandler(appConfig.sslCert));
    }
    Integer port = null;
    SocketOptions socketOptions = new SocketOptions();
    if (appConfig.cqlConnectTimeoutMs > 0) {
      socketOptions.setConnectTimeoutMillis(appConfig.cqlConnectTimeoutMs);
    }
    if (appConfig.cqlReadTimeoutMs > 0) {
      socketOptions.setReadTimeoutMillis(appConfig.cqlReadTimeoutMs);
    }
    builder.withSocketOptions(socketOptions);
    for (ContactPoint cp : contactPoints) {
      if (port == null) {
        port = cp.getPort();
        builder.withPort(port);
      } else if (port != cp.getPort()) {
        throw new IllegalArgumentException("Using multiple CQL ports is not supported.");
      }
      builder.addContactPoint(cp.getHost());
    }
    LOG.info("Connecting with " + appConfig.concurrentClients + " clients to nodes: "
        + builder.getContactPoints()
            .stream().map(it -> it.toString()).collect(Collectors.joining(",")));
    PoolingOptions poolingOptions = new PoolingOptions();
    poolingOptions
        .setCoreConnectionsPerHost(HostDistance.LOCAL, appConfig.concurrentClients)
        .setMaxConnectionsPerHost(HostDistance.LOCAL, appConfig.concurrentClients)
        .setCoreConnectionsPerHost(HostDistance.REMOTE, appConfig.concurrentClients)
        .setMaxConnectionsPerHost(HostDistance.REMOTE, appConfig.concurrentClients);
    cassandra_cluster =
        builder.withLoadBalancingPolicy(getLoadBalancingPolicy())
               .withPoolingOptions(poolingOptions)
               .withQueryOptions(new QueryOptions().setDefaultIdempotence(true))
               .withRetryPolicy(new LoggingRetryPolicy(DefaultRetryPolicy.INSTANCE))
               .build();
    LOG.debug("Connected to cluster: " + cassandra_cluster.getClusterName());
  }
  if (cassandra_session == null) {
    LOG.debug("Creating a session...");
    cassandra_session = cassandra_cluster.connect();
    createKeyspace(cassandra_session, keyspace);
  }
}
 
Example #13
Source File: LoggingRetryPolicyFactory.java    From dropwizard-cassandra with Apache License 2.0 4 votes vote down vote up
@Override
public RetryPolicy build() {
    return new LoggingRetryPolicy(subPolicy.build());
}
 
Example #14
Source File: CorruptionTest.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
@BeforeClass()
public static void setup() throws ConfigurationException, IOException
{
    Schema.instance.clear();

    cassandra = new EmbeddedCassandraService();
    cassandra.start();

    cluster = Cluster.builder().addContactPoint("127.0.0.1")
                     .withRetryPolicy(new LoggingRetryPolicy(Policies.defaultRetryPolicy()))
                     .withPort(DatabaseDescriptor.getNativeTransportPort()).build();
    session = cluster.connect();

    session.execute("CREATE KEYSPACE IF NOT EXISTS " + KEYSPACE +" WITH replication " +
                    "= {'class':'SimpleStrategy', 'replication_factor':1};");
    session.execute("USE " + KEYSPACE);
    session.execute("CREATE TABLE IF NOT EXISTS " + TABLE + " (" +
                     "key blob," +
                     "value blob," +
                     "PRIMARY KEY (key));");


    // Prepared statements
    getStatement = session.prepare("SELECT value FROM " + TABLE + " WHERE key = ?;");
    getStatement.setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM);

    putStatement = session.prepare("INSERT INTO " + TABLE + " (key, value) VALUES (?, ?);");
    putStatement.setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM);



    StringBuilder s = new StringBuilder();
    char a='a';
    char z='z';
    for (int i = 0; i < 500*1024; i++)
    {
        char x = (char)((i%((z-a)+1))+a);
        if (x == 'a')
        {
            x = '\n';
        }
        s.append(x);
    }
    VALUE = s.toString();
}