我正在使用Cassandra Driver 3.0。当我异步读取数据时,我得到的数据是一致的。
例如:在给定的员工ID列表[id1,id2]中,我正在请求id1和id2的数据。我正在获取ID1和ID2,有时还有ID1和ID1的数据。这是不一致的。我提供了下面的代码。你能帮忙吗?
public List<Employee> getEmployeeShortProfile(List<String> employeeIds) throws InterruptedException,
ExecutionException {
List<ResultSetFuture> rsFutureList = new ArrayList<ResultSetFuture>();
List<Employee> EmployeeList = new ArrayList<Employee>();
for (String EmployeeId : EmployeeIds) {
//Please NOTE
//preparedStatement.getbStGetShortProfileById() below in the code returns the following prepared statement
//client.getSession().prepare(
//"select employee_id, company_name, company_icon_url, product_icon_image, company_display_name, employee_information, detail_description from samplekeysapce.tbl_master_employees where employee_id = ? limit 15");
// FYI, I did not set the consistency level in the execute.
BoundStatement bStGetShortProfileById = preparedStatement.getbStGetShortProfileById();
logger.debug("... setting the short profile id ..."+EmployeeId);
bStGetShortProfileById.bind(EmployeeId);
Session session = client.getSession();
ResultSetFuture rs = session.executeAsync(bStGetShortProfileById);
rsFutureList.add(rs);
}
for(ResultSetFuture rsF : rsFutureList){
ResultSet rs = rsF.getUninterruptibly();
Iterator<Row> rowIterator = rs.iterator();
Employee c = extractEmployee(rowIterator);
if(c!= null){
EmployeeList.add(c);
}
}
return EmployeeList;
}
最佳答案
来自Datastax团队(https://datastax-oss.atlassian.net/secure/ViewProfile.jspa?name=omichallat)的Olivier Michallat能够帮助我们指出,BoundStatement每次都必须是不同的实例。
我们验证了代码,没有返回其他BoundStatement实例。我们更正了代码,问题得以解决。
我们与Datastax团队之间的对话在此处https://datastax-oss.atlassian.net/browse/JAVA-1198。
谢谢
https://stackoverflow.com/users/438154/sotirios-delimanolis获得支持。
关于java - Datastax Cassandra Java驱动程序, future 结果集似乎返回一致的数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37369603/