|
45 | 45 | import org.apache.iotdb.db.storageengine.rescon.memory.SystemInfo; |
46 | 46 | import org.apache.iotdb.db.utils.EnvironmentUtils; |
47 | 47 | import org.apache.iotdb.db.utils.constant.TestConstant; |
| 48 | +import org.apache.iotdb.db.utils.datastructure.AlignedTVList; |
48 | 49 | import org.apache.iotdb.rpc.RpcUtils; |
49 | 50 | import org.apache.iotdb.rpc.TSStatusCode; |
50 | 51 |
|
@@ -933,6 +934,31 @@ record = new TSRecord("root.vehicle.d2", 102); |
933 | 934 | Assert.assertEquals(memTable1.memSize(), memTable2.memSize()); |
934 | 935 | } |
935 | 936 |
|
| 937 | + @Test |
| 938 | + public void testAlignedSparseRowDoesNotChargeUnallocatedPrimitiveArrayOnNewBlock() |
| 939 | + throws IOException, WriteProcessException, IllegalPathException { |
| 940 | + processor = newTestProcessor(filePath); |
| 941 | + String sparseDevice = deviceId + ".sparse"; |
| 942 | + String denseDevice = deviceId + ".dense"; |
| 943 | + for (int i = 0; i < PrimitiveArrayManager.ARRAY_SIZE; i++) { |
| 944 | + insertAlignedRow(processor, sparseDevice, i, true); |
| 945 | + insertAlignedRow(processor, denseDevice, i, true); |
| 946 | + } |
| 947 | + |
| 948 | + IMemTable memTable = processor.getWorkMemTable(); |
| 949 | + long ramCostBeforeSparseRow = memTable.getTVListsRamCost(); |
| 950 | + insertAlignedRow(processor, sparseDevice, PrimitiveArrayManager.ARRAY_SIZE, false); |
| 951 | + long sparseRowRamIncrement = memTable.getTVListsRamCost() - ramCostBeforeSparseRow; |
| 952 | + |
| 953 | + long ramCostBeforeDenseRow = memTable.getTVListsRamCost(); |
| 954 | + insertAlignedRow(processor, denseDevice, PrimitiveArrayManager.ARRAY_SIZE, true); |
| 955 | + long denseRowRamIncrement = memTable.getTVListsRamCost() - ramCostBeforeDenseRow; |
| 956 | + |
| 957 | + Assert.assertEquals( |
| 958 | + AlignedTVList.primitiveArrayMemCost(dataType), |
| 959 | + denseRowRamIncrement - sparseRowRamIncrement); |
| 960 | + } |
| 961 | + |
936 | 962 | @Test |
937 | 963 | public void testAlignedRamCostIgnoresRelationalNonFieldAndNullFieldColumns() |
938 | 964 | throws IllegalPathException, WriteProcessException, IOException { |
@@ -1308,6 +1334,22 @@ private TsFileProcessor newTestProcessor(String path) throws IOException, WriteP |
1308 | 1334 | return newProcessor; |
1309 | 1335 | } |
1310 | 1336 |
|
| 1337 | + private void insertAlignedRow( |
| 1338 | + TsFileProcessor targetProcessor, |
| 1339 | + String targetDevice, |
| 1340 | + long timestamp, |
| 1341 | + boolean writeSecondColumn) |
| 1342 | + throws IllegalPathException, WriteProcessException { |
| 1343 | + TSRecord record = new TSRecord(targetDevice, timestamp); |
| 1344 | + record.addTuple(DataPoint.getDataPoint(dataType, measurementId, Long.toString(timestamp))); |
| 1345 | + if (writeSecondColumn) { |
| 1346 | + record.addTuple(DataPoint.getDataPoint(dataType, "s1", Long.toString(timestamp))); |
| 1347 | + } |
| 1348 | + InsertRowNode node = buildInsertRowNodeByTSRecord(record); |
| 1349 | + node.setAligned(true); |
| 1350 | + targetProcessor.insert(node, new long[5]); |
| 1351 | + } |
| 1352 | + |
1311 | 1353 | private InsertTabletNode genSingleMeasurementTablet(int rowCount, boolean isAligned) |
1312 | 1354 | throws IllegalPathException { |
1313 | 1355 | String[] measurements = new String[] {measurementId}; |
|
0 commit comments