|
21 | 21 |
|
22 | 22 | import org.apache.iotdb.commons.exception.IllegalPathException; |
23 | 23 | import org.apache.iotdb.commons.path.MeasurementPath; |
| 24 | +import org.apache.iotdb.db.service.metrics.FileMetrics; |
24 | 25 | import org.apache.iotdb.db.storageengine.dataregion.compaction.execute.recover.CompactionRecoverManager; |
25 | 26 | import org.apache.iotdb.db.storageengine.dataregion.modification.IDPredicate.FullExactMatch; |
26 | 27 | import org.apache.iotdb.db.storageengine.dataregion.modification.IDPredicate.NOP; |
|
50 | 51 |
|
51 | 52 | public class ModificationFileTest { |
52 | 53 |
|
| 54 | + @Test |
| 55 | + public void testRemoveUpdatesMetrics() throws IOException { |
| 56 | + String tempFileName = TestConstant.BASE_OUTPUT_PATH.concat("mod.remove.metrics.temp"); |
| 57 | + int modFileNumBefore = FileMetrics.getInstance().getModFileNum(); |
| 58 | + long modFileSizeBefore = FileMetrics.getInstance().getModFileSize(); |
| 59 | + try (ModificationFile modificationFile = new ModificationFile(tempFileName, true)) { |
| 60 | + modificationFile.write( |
| 61 | + new TreeDeletionEntry( |
| 62 | + new MeasurementPath(new String[] {"root", "sg", "d1", "s1"}), 1, 10)); |
| 63 | + long fileLength = modificationFile.getFileLength(); |
| 64 | + assertEquals(modFileNumBefore + 1, FileMetrics.getInstance().getModFileNum()); |
| 65 | + assertEquals(modFileSizeBefore + fileLength, FileMetrics.getInstance().getModFileSize()); |
| 66 | + |
| 67 | + modificationFile.remove(); |
| 68 | + assertEquals(modFileNumBefore, FileMetrics.getInstance().getModFileNum()); |
| 69 | + assertEquals(modFileSizeBefore, FileMetrics.getInstance().getModFileSize()); |
| 70 | + } finally { |
| 71 | + Files.deleteIfExists(new File(tempFileName).toPath()); |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + public void testCompactUpdatesMetricsAndAllowFurtherWrite() throws IOException { |
| 77 | + String tempFileName = TestConstant.BASE_OUTPUT_PATH.concat("mod.compact.metrics.temp"); |
| 78 | + int modFileNumBefore = FileMetrics.getInstance().getModFileNum(); |
| 79 | + long modFileSizeBefore = FileMetrics.getInstance().getModFileSize(); |
| 80 | + long time = 1000; |
| 81 | + try (ModificationFile modificationFile = new ModificationFile(tempFileName, true)) { |
| 82 | + while (modificationFile.getFileLength() < 1024 * 1024) { |
| 83 | + modificationFile.write( |
| 84 | + new TreeDeletionEntry( |
| 85 | + new MeasurementPath(new String[] {"root", "sg", "d1", "s1"}), |
| 86 | + Long.MIN_VALUE, |
| 87 | + time += 5000)); |
| 88 | + } |
| 89 | + |
| 90 | + assertEquals(modFileNumBefore + 1, FileMetrics.getInstance().getModFileNum()); |
| 91 | + modificationFile.compact(); |
| 92 | + assertEquals(modFileNumBefore + 1, FileMetrics.getInstance().getModFileNum()); |
| 93 | + assertEquals( |
| 94 | + modFileSizeBefore + modificationFile.getFileLength(), |
| 95 | + FileMetrics.getInstance().getModFileSize()); |
| 96 | + |
| 97 | + modificationFile.write( |
| 98 | + new TreeDeletionEntry( |
| 99 | + new MeasurementPath(new String[] {"root", "sg", "d1", "s2"}), |
| 100 | + Long.MIN_VALUE, |
| 101 | + time + 5000)); |
| 102 | + assertEquals(modFileNumBefore + 1, FileMetrics.getInstance().getModFileNum()); |
| 103 | + assertEquals( |
| 104 | + modFileSizeBefore + modificationFile.getFileLength(), |
| 105 | + FileMetrics.getInstance().getModFileSize()); |
| 106 | + |
| 107 | + modificationFile.remove(); |
| 108 | + assertEquals(modFileNumBefore, FileMetrics.getInstance().getModFileNum()); |
| 109 | + assertEquals(modFileSizeBefore, FileMetrics.getInstance().getModFileSize()); |
| 110 | + } finally { |
| 111 | + Files.deleteIfExists(new File(tempFileName).toPath()); |
| 112 | + } |
| 113 | + } |
| 114 | + |
53 | 115 | @Test |
54 | 116 | public void readMyWrite() { |
55 | 117 | String tempFileName = TestConstant.BASE_OUTPUT_PATH.concat("mod.temp"); |
|
0 commit comments