[ 
https://issues.apache.org/jira/browse/IOTDB-1401?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17358330#comment-17358330
 ] 

刘珍 commented on IOTDB-1401:
---------------------------

已解决。

> Tablet's rowsize = 0 ,insertTablets throws an exception ,gives an unfriendly 
> error message
> ------------------------------------------------------------------------------------------
>
>                 Key: IOTDB-1401
>                 URL: https://issues.apache.org/jira/browse/IOTDB-1401
>             Project: Apache IoTDB
>          Issue Type: Bug
>          Components: Server
>    Affects Versions: 0.12.0
>            Reporter: 刘珍
>            Priority: Minor
>         Attachments: image-2021-05-27-16-05-45-882.png
>
>
> [rel/0.12]  05/18  99822c7feb7797f33b0e740b0f3ea38803d11d17
> iotdb log :
>  !image-2021-05-27-16-05-45-882.png|thumbnail! 
> org.apache.iotdb.db.exception.BatchProcessException: {color:red}*Batch 
> process failed:[]*{color}
>         at 
> org.apache.iotdb.db.engine.storagegroup.StorageGroupProcessor.insertTablet(StorageGroupProcessor.java:858)
> test case:
> import org.apache.iotdb.rpc.IoTDBConnectionException;
> import org.apache.iotdb.rpc.StatementExecutionException;
> import org.apache.iotdb.rpc.TSStatusCode;
> import org.apache.iotdb.session.Session;
> import org.apache.iotdb.session.SessionDataSet;
> import org.apache.iotdb.session.SessionDataSet.DataIterator;
> import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType;
> import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
> import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
> import org.apache.iotdb.tsfile.write.record.Tablet;
> import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
> import java.util.ArrayList;
> import java.util.HashMap;
> import java.util.List;
> import java.util.Map;
> import java.util.Random;
> @SuppressWarnings("squid:S106")
> public class SessionExample {
>   private static Session session;
>   private static Session sessionEnableRedirect;
>   private static final String ROOT_SG1_D1_S1 = "root.sg1.d1.s1";
>   private static final String ROOT_SG1_D1_S2 = "root.sg1.d1.s2";
>   private static final String ROOT_SG1_D1_S3 = "root.sg1.d1.s3";
>   private static final String ROOT_SG1_D1_S4 = "root.sg1.d1.s4";
>   private static final String ROOT_SG1_D1_S5 = "root.sg1.d1.s5";
>   private static final String ROOT_SG1_D1 = "root.sg1.d1";
>   private static final String LOCAL_HOST = "127.0.0.1";
>   public static void main(String[] args)
>       throws IoTDBConnectionException, StatementExecutionException {
>     session = new Session(LOCAL_HOST, 6667, "root", "root");
>     session.open(false);
>     // set session fetchSize
>     session.setFetchSize(10000);
>     try {
>       session.setStorageGroup("root.sg1");
>     } catch (StatementExecutionException e) {
>       if (e.getStatusCode() != 
> TSStatusCode.PATH_ALREADY_EXIST_ERROR.getStatusCode()) {
>         throw e;
>       }
>     }
>     createTimeseries();
>     createMultiTimeseries();
>     insertTablets();
>     session.close();
>   }
>   private static void createTimeseries()
>       throws IoTDBConnectionException, StatementExecutionException {
>     if (!session.checkTimeseriesExists(ROOT_SG1_D1_S1)) {
>       session.createTimeseries(
>           ROOT_SG1_D1_S1, TSDataType.INT64, TSEncoding.RLE, 
> CompressionType.SNAPPY);
>     }
>     if (!session.checkTimeseriesExists(ROOT_SG1_D1_S2)) {
>       session.createTimeseries(
>           ROOT_SG1_D1_S2, TSDataType.INT64, TSEncoding.RLE, 
> CompressionType.SNAPPY);
>     }
>     if (!session.checkTimeseriesExists(ROOT_SG1_D1_S3)) {
>       session.createTimeseries(
>           ROOT_SG1_D1_S3, TSDataType.INT64, TSEncoding.RLE, 
> CompressionType.SNAPPY);
>     }
>     // create timeseries with tags and attributes
>     if (!session.checkTimeseriesExists(ROOT_SG1_D1_S4)) {
>       Map<String, String> tags = new HashMap<>();
>       tags.put("tag1", "v1");
>       Map<String, String> attributes = new HashMap<>();
>       tags.put("description", "v1");
>       session.createTimeseries(
>           ROOT_SG1_D1_S4,
>           TSDataType.INT64,
>           TSEncoding.RLE,
>           CompressionType.SNAPPY,
>           null,
>           tags,
>           attributes,
>           "temperature");
>     }
>     // create timeseries with SDT property, SDT will take place when flushing
>     if (!session.checkTimeseriesExists(ROOT_SG1_D1_S5)) {
>       // COMPDEV is required
>       // COMPMAXTIME and COMPMINTIME are optional and their unit is ms
>       Map<String, String> props = new HashMap<>();
>       props.put("LOSS", "sdt");
>       props.put("COMPDEV", "0.01");
>       props.put("COMPMINTIME", "2");
>       props.put("COMPMAXTIME", "10");
>       session.createTimeseries(
>           ROOT_SG1_D1_S5,
>           TSDataType.INT64,
>           TSEncoding.RLE,
>           CompressionType.SNAPPY,
>           props,
>           null,
>           null,
>           null);
>     }
>   }
>   private static void createMultiTimeseries()
>       throws IoTDBConnectionException, StatementExecutionException {
>     if (!session.checkTimeseriesExists("root.sg1.d2.s1")
>         && !session.checkTimeseriesExists("root.sg1.d2.s2")) {
>       List<String> paths = new ArrayList<>();
>       paths.add("root.sg1.d2.s1");
>       paths.add("root.sg1.d2.s2");
>       List<TSDataType> tsDataTypes = new ArrayList<>();
>       tsDataTypes.add(TSDataType.INT64);
>       tsDataTypes.add(TSDataType.INT64);
>       List<TSEncoding> tsEncodings = new ArrayList<>();
>       tsEncodings.add(TSEncoding.RLE);
>       tsEncodings.add(TSEncoding.RLE);
>       List<CompressionType> compressionTypes = new ArrayList<>();
>       compressionTypes.add(CompressionType.SNAPPY);
>       compressionTypes.add(CompressionType.SNAPPY);
>       List<Map<String, String>> tagsList = new ArrayList<>();
>       Map<String, String> tags = new HashMap<>();
>       tags.put("unit", "kg");
>       tagsList.add(tags);
>       tagsList.add(tags);
>       List<Map<String, String>> attributesList = new ArrayList<>();
>       Map<String, String> attributes = new HashMap<>();
>       attributes.put("minValue", "1");
>       attributes.put("maxValue", "100");
>       attributesList.add(attributes);
>       attributesList.add(attributes);
>       List<String> alias = new ArrayList<>();
>       alias.add("weight1");
>       alias.add("weight2");
>       session.createMultiTimeseries(
>           paths, tsDataTypes, tsEncodings, compressionTypes, null, tagsList, 
> attributesList, alias);
>     }
>   }
>   private static void insertTablets() throws IoTDBConnectionException, 
> StatementExecutionException {
>     // The schema of measurements of one device
>     // only measurementId and data type in MeasurementSchema take effects in 
> Tablet
>     List<MeasurementSchema> schemaList = new ArrayList<>();
>     schemaList.add(new MeasurementSchema("s1", TSDataType.INT64));
>     schemaList.add(new MeasurementSchema("s2", TSDataType.INT64));
>     schemaList.add(new MeasurementSchema("s3", TSDataType.INT64));
>     Tablet tablet1 = new Tablet(ROOT_SG1_D1, schemaList, 100);
>     Tablet tablet2 = new Tablet("root.sg1.d2", schemaList, 100);
>     Tablet tablet3 = new Tablet("root.sg1.d3", schemaList, 100);
>     Map<String, Tablet> tabletMap = new HashMap<>();
>     tabletMap.put(ROOT_SG1_D1, tablet1);
>     tabletMap.put("root.sg1.d2", tablet2);
>     tabletMap.put("root.sg1.d3", tablet3);
>     // Method 1 to add tablet data
>     long timestamp = System.currentTimeMillis();
>     for (long row = 0; row < 100; row++) {
>       int row1 = tablet1.rowSize++;
>       //int row2 = tablet2.rowSize++;
>       int row3 = tablet3.rowSize++;
>       tablet1.addTimestamp(row1, timestamp);
>       //tablet2.addTimestamp(row2, timestamp);
>       tablet3.addTimestamp(row3, timestamp);
>       for (int i = 0; i < 3; i++) {
>         long value = new Random().nextLong();
>         tablet1.addValue(schemaList.get(i).getMeasurementId(), row1, value);
>         //tablet2.addValue(schemaList.get(i).getMeasurementId(), row2, value);
>         tablet3.addValue(schemaList.get(i).getMeasurementId(), row3, value);
>       }
>       if (tablet1.rowSize == tablet1.getMaxRowNumber()) {
>         session.insertTablets(tabletMap, true);
>         tablet1.reset();
>         tablet2.reset();
>         tablet3.reset();
>       }
>       timestamp++;
>     }
>     if (tablet1.rowSize != 0) {
>       session.insertTablets(tabletMap, true);
>       tablet1.reset();
>       tablet2.reset();
>       tablet3.reset();
>     }
>   }
> }



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to