@Test
  public void testDeleteDataDirectlyUnseqWriteModsOrDeleteFiles()
      throws IllegalPathException, WriteProcessException, IOException {
    for (int j = 100; j < 200; j++) {
      TSRecord record = new TSRecord(deviceId, j);
      record.addTuple(DataPoint.getDataPoint(TSDataType.INT32, measurementId, String.valueOf(j)));
      dataRegion.insert(buildInsertRowNodeByTSRecord(record));
    }
    TsFileResource tsFileResourceSeq = dataRegion.getTsFileManager().getTsFileList(true).get(0);
    dataRegion.syncCloseAllWorkingTsFileProcessors();
    for (int j = 30; j < 100; j++) {
      TSRecord record = new TSRecord(deviceId, j);
      record.addTuple(DataPoint.getDataPoint(TSDataType.INT32, measurementId, String.valueOf(j)));
      dataRegion.insert(buildInsertRowNodeByTSRecord(record));
    }

    dataRegion.syncCloseWorkingTsFileProcessors(true);
    TsFileResource tsFileResourceUnSeq = dataRegion.getTsFileManager().getTsFileList(false).get(0);

    Assert.assertTrue(tsFileResourceSeq.getTsFile().exists());
    Assert.assertTrue(tsFileResourceUnSeq.getTsFile().exists());

    // already closed, will have a mods file.
    MeasurementPath path = new MeasurementPath("root.vehicle.d0.**");
    DeleteDataNode deleteDataNode1 =
        new DeleteDataNode(new PlanNodeId("1"), Collections.singletonList(path), 40, 60);
    deleteDataNode1.setSearchIndex(0);
    dataRegion.deleteDataDirectly(new MeasurementPath("root.vehicle.d0.**"), deleteDataNode1);
    // not close yet, just delete in memory.
    DeleteDataNode deleteDataNode2 =
        new DeleteDataNode(new PlanNodeId("2"), Collections.singletonList(path), 140, 160);
    deleteDataNode2.setSearchIndex(0);
    dataRegion.deleteDataDirectly(new MeasurementPath("root.vehicle.d0.**"), deleteDataNode2);

    // delete data in mem table, there is no mods
    Assert.assertTrue(tsFileResourceSeq.getTsFile().exists());
    Assert.assertTrue(tsFileResourceUnSeq.getTsFile().exists());
    Assert.assertTrue(tsFileResourceSeq.anyModFileExists());
    Assert.assertFalse(tsFileResourceUnSeq.anyModFileExists());
    dataRegion.syncCloseAllWorkingTsFileProcessors();

    DeleteDataNode deleteDataNode3 =
        new DeleteDataNode(new PlanNodeId("3"), Collections.singletonList(path), 40, 80);
    deleteDataNode3.setSearchIndex(0);
    dataRegion.deleteDataDirectly(new MeasurementPath("root.vehicle.d0.**"), deleteDataNode3);
    Assert.assertTrue(tsFileResourceUnSeq.getTsFile().exists());
    Assert.assertTrue(tsFileResourceUnSeq.anyModFileExists());

    // seq file and unseq file have data file and mod file now,
    // this deletion will remove data file and mod file.
    DeleteDataNode deleteDataNode4 =
        new DeleteDataNode(new PlanNodeId("4"), Collections.singletonList(path), 30, 100);
    deleteDataNode4.setSearchIndex(0);
    DeleteDataNode deleteDataNode5 =
        new DeleteDataNode(new PlanNodeId("5"), Collections.singletonList(path), 100, 199);
    deleteDataNode5.setSearchIndex(0);
    dataRegion.deleteDataDirectly(new MeasurementPath("root.vehicle.d0.**"), deleteDataNode4);
    dataRegion.deleteDataDirectly(new MeasurementPath("root.vehicle.d0.**"), deleteDataNode5);

    Assert.assertFalse(tsFileResourceSeq.getTsFile().exists());
    Assert.assertFalse(tsFileResourceUnSeq.getTsFile().exists());
    Assert.assertFalse(tsFileResourceSeq.anyModFileExists());
    Assert.assertFalse(tsFileResourceUnSeq.anyModFileExists());
  }
Totally 5 tsfiles<br>
file 0, file 2 and file 4 has d0 ~ d1, time range is 0 ~ 99, 200 ~ 299, 400 ~ 499<br>
file 1, file 3 has d0 ~ d2, time range is 100 ~ 199, 300 ~ 399<br>
delete d2 in time range 50 ~ 150 and 150 ~ 450. Therefore, only file 1 and file 3 has mods.
iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/DataRegionTest.java