Skip to content

Commit

Permalink
fix calculate memory in batch insert(#848)
Browse files Browse the repository at this point in the history
  • Loading branch information
SolomonAnn committed Feb 27, 2020
1 parent bcd6c22 commit 32c6fb0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void insertBatch(BatchInsertPlan batchInsertPlan, int start, int end)
throws QueryProcessException {
try {
write(batchInsertPlan, start, end);
long recordSizeInByte = MemUtils.getRecordSize(batchInsertPlan);
long recordSizeInByte = MemUtils.getRecordSize(batchInsertPlan, start, end);
memSize += recordSizeInByte;
} catch (RuntimeException e) {
throw new QueryProcessException(e.getMessage());
Expand Down
21 changes: 12 additions & 9 deletions server/src/main/java/org/apache/iotdb/db/utils/MemUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,31 @@ public static long getRecordSize(InsertPlan insertPlan) {
return memSize;
}

public static long getRecordSize(BatchInsertPlan batchInsertPlan) {
public static long getRecordSize(BatchInsertPlan batchInsertPlan, int start, int end) {
if (start >= end) {
return 0L;
}
long memSize = 0;
for (int i = 0; i < batchInsertPlan.getMeasurements().length; i++) {
switch (batchInsertPlan.getDataTypes()[i]) {
case INT32:
memSize += batchInsertPlan.getRowCount() * (8L + 4L); break;
memSize += (end - start) * (8L + 4L); break;
case INT64:
memSize += batchInsertPlan.getRowCount() * (8L + 8L); break;
memSize += (end - start) * (8L + 8L); break;
case FLOAT:
memSize += batchInsertPlan.getRowCount() * (8L + 4L); break;
memSize += (end - start) * (8L + 4L); break;
case DOUBLE:
memSize += batchInsertPlan.getRowCount() * (8L + 8L); break;
memSize += (end - start) * (8L + 8L); break;
case BOOLEAN:
memSize += batchInsertPlan.getRowCount() * (8L + 1L); break;
memSize += (end - start) * (8L + 1L); break;
case TEXT:
memSize += batchInsertPlan.getRowCount() * 8L;
for (int j = 0; j < batchInsertPlan.getRowCount(); j++) {
memSize += (end - start) * 8L;
for (int j = start; j < end; j++) {
memSize += ((Binary[]) batchInsertPlan.getColumns()[i])[j].getLength();
}
break;
default:
memSize += batchInsertPlan.getRowCount() * (8L + 8L);
memSize += (end - start) * (8L + 8L);
}
}
return memSize;
Expand Down

0 comments on commit 32c6fb0

Please sign in to comment.