I’m experiencing an issue with GridDB where the program becomes blocked during a query and logs a Sending heartbeat It seems that the issue is related to the connection management or the GridDB cluster's responsiveness
Following are the logs
select * where (name='message-count') AND count > 0 AND timestamp < TIMESTAMP('2022-12-30T11:02:01.567+0800') AND timestamp > TIMESTAMP('2022-12-29T11:02:01.567+0800') order by timestamp
Sending heartbeat (statement=CREATE_SESSION, address=/192.168.1.134:10001, partition=7, statementId=15, elapsedMillis=10000)
Sending heartbeat (statement=CREATE_SESSION, address=/192.168.1.134:10001, partition=7, statementId=15, elapsedMillis=20004)
This may be a concurrency problem. I try the following code to reproduce this problem
package com.griddb.client;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.toshiba.mwcloud.gs.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;
import static cn.hutool.core.date.DatePattern.UTC_MS_WITH_ZONE_OFFSET_PATTERN;
public class GriddbClient {
static class Iot {
@RowKey
Date timestamp;
double data;
double temperature;
@Override
public String toString() {
return "Iot{" +
"timestamp=" + timestamp +
", data=" + data +
", temperature=" + temperature +
'}';
}
}
public static void main(String[] args) throws Exception{
//bulkInsertData();
concurrentQuery();
}
/**
* Bulk Insert Data
* @throws Exception
*/
public static void bulkInsertData() throws Exception{
Properties props = new Properties();
props.setProperty("host", "192.168.1.134");
props.setProperty("port", "10001");
props.setProperty("clusterName", "myCluster");
props.setProperty("user", "admin");
props.setProperty("password", "admin");
props.setProperty("database","public");
props.setProperty("transactionTimeout","5000");
props.setProperty("failoverTimeout","5000");
GridStore store = GridStoreFactory.getInstance().getGridStore(props);
TimeSeries<test5.Iot> lctime = store.putTimeSeries("lctime", test5.Iot.class);
lctime.createIndex("data");
lctime.setAutoCommit(false);
DateTime now = DateTime.now();
for(int i=0;i<360;i++){
DateTime dateTime = now.offset(DateField.MINUTE, 1);
test5.Iot item1=new test5.Iot();
item1.timestamp=dateTime;
item1.data=i;
item1.temperature=i;
lctime.put(dateTime,item1);
System.out.println(DateUtil.formatDateTime(dateTime));
}
lctime.commit();
System.out.println("succcess");
store.close();
}
/**
* Concurrent query
* @throws Exception
*/
public static void concurrentQuery() throws Exception{
int concurrency=10;
final Date start=getDate("2022-11-20");
final Date end=getDate("2022-12-30");
Set<String> culume=new HashSet<String>();
culume.add("timestamp");
culume.add("data");
culume.add("temperature");
Properties props = new Properties();
props.setProperty("host", "192.168.1.134");
props.setProperty("port", "10001");
props.setProperty("clusterName", "myCluster");
props.setProperty("user", "admin");
props.setProperty("password", "admin");
props.setProperty("database","public");
props.setProperty("transactionTimeout","5000");
props.setProperty("failoverTimeout","5000");
final GridStore store = GridStoreFactory.getInstance().getGridStore(props);
ExecutorService executorService = Executors.newFixedThreadPool(20);
List<FutureTask<List<test5.Iot>>> tasks=new ArrayList<FutureTask<List<test5.Iot>>>();
for(int i=0;i<concurrency;i++){
FutureTask<List<test5.Iot>> task1=new FutureTask<List<test5.Iot>>(new Callable<List<test5.Iot>>() {
public List<test5.Iot> call() throws Exception {
return createTask(start,end,store);
}
});
tasks.add(task1);
executorService.submit(tasks.get(tasks.size()-1));
}
for(FutureTask<List<test5.Iot>> item:tasks){
List<test5.Iot> iots = item.get();
System.out.println(iots.size());
}
store.close();
}
private static List<test5.Iot> createTask(Date start, Date end, GridStore store) throws Exception{
TimeSeries<test5.Iot> lctime = store.getTimeSeries("lctime", test5.Iot.class);
String tql="select * where timestamp > TIMESTAMP('" + formatDate(start) + "') and timestamp < TIMESTAMP('" + formatDate(end) + "')";
System.out.println(tql);
RowSet<test5.Iot> query = lctime.query(tql, test5.Iot.class).fetch();
List<test5.Iot> iots=new ArrayList<test5.Iot>();
while (query.hasNext()){
test5.Iot next = query.next();
System.out.println(next.toString());
iots.add(next);
}
lctime.close();
return iots;
}
private static Date getDate(String dataStr) throws Exception{
DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd");
return dateFormat1.parse(dataStr);
}
private static String formatDate(Date date){
return DateUtil.format(date,UTC_MS_WITH_ZONE_OFFSET_PATTERN);
}
}