1

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 &quot;Iot{&quot; +
                &quot;timestamp=&quot; + timestamp +
                &quot;, data=&quot; + data +
                &quot;, temperature=&quot; + 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(&quot;host&quot;, &quot;192.168.1.134&quot;);
    props.setProperty(&quot;port&quot;, &quot;10001&quot;);
    props.setProperty(&quot;clusterName&quot;, &quot;myCluster&quot;);
    props.setProperty(&quot;user&quot;, &quot;admin&quot;);
    props.setProperty(&quot;password&quot;, &quot;admin&quot;);
    props.setProperty(&quot;database&quot;,&quot;public&quot;);
    props.setProperty(&quot;transactionTimeout&quot;,&quot;5000&quot;);
    props.setProperty(&quot;failoverTimeout&quot;,&quot;5000&quot;);
    GridStore store = GridStoreFactory.getInstance().getGridStore(props);
    TimeSeries&lt;test5.Iot&gt; lctime = store.putTimeSeries(&quot;lctime&quot;, test5.Iot.class);
    lctime.createIndex(&quot;data&quot;);
    lctime.setAutoCommit(false);
    DateTime now = DateTime.now();
    for(int i=0;i&lt;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(&quot;succcess&quot;);
    store.close();
}

/**
 * Concurrent query
 * @throws Exception
 */
public static void concurrentQuery() throws Exception{
    int concurrency=10;
    final Date start=getDate(&quot;2022-11-20&quot;);
    final Date end=getDate(&quot;2022-12-30&quot;);
    Set&lt;String&gt; culume=new HashSet&lt;String&gt;();
    culume.add(&quot;timestamp&quot;);
    culume.add(&quot;data&quot;);
    culume.add(&quot;temperature&quot;);

    Properties props = new Properties();
    props.setProperty(&quot;host&quot;, &quot;192.168.1.134&quot;);
    props.setProperty(&quot;port&quot;, &quot;10001&quot;);
    props.setProperty(&quot;clusterName&quot;, &quot;myCluster&quot;);
    props.setProperty(&quot;user&quot;, &quot;admin&quot;);
    props.setProperty(&quot;password&quot;, &quot;admin&quot;);
    props.setProperty(&quot;database&quot;,&quot;public&quot;);
    props.setProperty(&quot;transactionTimeout&quot;,&quot;5000&quot;);
    props.setProperty(&quot;failoverTimeout&quot;,&quot;5000&quot;);
    final GridStore store = GridStoreFactory.getInstance().getGridStore(props);

    ExecutorService executorService = Executors.newFixedThreadPool(20);
    List&lt;FutureTask&lt;List&lt;test5.Iot&gt;&gt;&gt; tasks=new ArrayList&lt;FutureTask&lt;List&lt;test5.Iot&gt;&gt;&gt;();

    for(int i=0;i&lt;concurrency;i++){
        FutureTask&lt;List&lt;test5.Iot&gt;&gt; task1=new FutureTask&lt;List&lt;test5.Iot&gt;&gt;(new Callable&lt;List&lt;test5.Iot&gt;&gt;() {
            public List&lt;test5.Iot&gt; call() throws Exception {
                return createTask(start,end,store);
            }
        });
        tasks.add(task1);
        executorService.submit(tasks.get(tasks.size()-1));
    }

    for(FutureTask&lt;List&lt;test5.Iot&gt;&gt; item:tasks){
        List&lt;test5.Iot&gt; iots = item.get();
        System.out.println(iots.size());
    }
    store.close();
}

private static List&lt;test5.Iot&gt; createTask(Date start, Date end, GridStore store) throws Exception{
    TimeSeries&lt;test5.Iot&gt; lctime = store.getTimeSeries(&quot;lctime&quot;, test5.Iot.class);
    String tql=&quot;select * where timestamp &gt; TIMESTAMP('&quot; + formatDate(start) + &quot;') and timestamp &lt; TIMESTAMP('&quot; + formatDate(end) + &quot;')&quot;;
    System.out.println(tql);
    RowSet&lt;test5.Iot&gt; query = lctime.query(tql, test5.Iot.class).fetch();
    List&lt;test5.Iot&gt; iots=new ArrayList&lt;test5.Iot&gt;();
    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(&quot;yyyy-MM-dd&quot;);
    return dateFormat1.parse(dataStr);
}

private static String formatDate(Date date){
    return DateUtil.format(date,UTC_MS_WITH_ZONE_OFFSET_PATTERN);
}

}

Alice
  • 163
  • 2

0 Answers0