Cassandra production scenarios/issues
Production issue: when we are trying to write a select query with 8 lacks ids “in condition “. then we got faced below issue, To solve the above exception, we used distributed calls in Java client as shown below,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import java.net.InetSocketAddress; import java.util.ArrayList; import java.util.List; import java.util.Map; import com.datastax.driver.core.Cluster; import com.datastax.driver.core.PreparedStatement; import com.datastax.driver.core.ResultSet; import com.datastax.driver.core.ResultSetFuture; import com.datastax.driver.core.Row; import com.datastax.driver.core.Session; import com.datastax.driver.core.exceptions.NoHostAvailableException; public class SelectCassandraDistrbuted { public static void main(String[] args) { Cluster cluster = null; try{ cluster = Cluster.builder().addContactPoints("node1 address/IP","node2 address/IP","node3 address/IP").build(); cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(600000000); Session session = cluster.connect("keyspace_name"); System.out.println("connected"); PreparedStatement statement = session.prepare("select * from table where tmp_time = ?"); List<String> idsList = new ArrayList<String>(); //Here we added 8 lacs ids to the idsList list List<ResultSetFuture> futures = new ArrayList<ResultSetFuture>(); //Here we are executing the query. for (String id:idsList) { ResultSetFuture resultSetFuture = session.executeAsync(statement.bind(id)); futures.add(resultSetFuture); } //Fetching the results for (ResultSetFuture future : futures){ ResultSet rows = future.getUninterruptibly(); Row row = rows.one(); System.out.println(row.getString("sys_serial_no")); System.out.println(row.getString("tmp_time")); } } |
Few Production configurations in cassandra RetryPolicy Three scenarios you can control retry policy for: Read time out: When a coordinator received the request and sent the read to replica(s) but the replica(s) […]