|
158 | 158 | import org.apache.iotdb.db.utils.DateTimeUtils; |
159 | 159 | import org.apache.iotdb.db.utils.EncryptDBUtils; |
160 | 160 | import org.apache.iotdb.db.utils.ModificationUtils; |
| 161 | +import org.apache.iotdb.db.utils.ObjectTypeUtils; |
161 | 162 | import org.apache.iotdb.db.utils.ObjectWriter; |
162 | 163 | import org.apache.iotdb.metrics.utils.MetricLevel; |
163 | 164 | import org.apache.iotdb.rpc.RpcUtils; |
164 | 165 | import org.apache.iotdb.rpc.TSStatusCode; |
165 | 166 |
|
166 | 167 | import com.github.benmanes.caffeine.cache.Cache; |
167 | 168 | import com.github.benmanes.caffeine.cache.Caffeine; |
| 169 | +import com.google.common.io.BaseEncoding; |
168 | 170 | import org.apache.thrift.TException; |
169 | 171 | import org.apache.tsfile.external.commons.io.FileUtils; |
170 | 172 | import org.apache.tsfile.external.commons.lang3.tuple.Triple; |
171 | 173 | import org.apache.tsfile.file.metadata.ChunkMetadata; |
172 | 174 | import org.apache.tsfile.file.metadata.IDeviceID; |
| 175 | +import org.apache.tsfile.file.metadata.IDeviceID.Factory; |
173 | 176 | import org.apache.tsfile.file.metadata.TableSchema; |
174 | 177 | import org.apache.tsfile.fileSystem.FSFactoryProducer; |
175 | 178 | import org.apache.tsfile.fileSystem.FSType; |
|
186 | 189 | import java.io.File; |
187 | 190 | import java.io.IOException; |
188 | 191 | import java.nio.ByteBuffer; |
| 192 | +import java.nio.charset.StandardCharsets; |
189 | 193 | import java.nio.file.Files; |
190 | 194 | import java.nio.file.Path; |
191 | 195 | import java.nio.file.Paths; |
@@ -2762,8 +2766,10 @@ public void deleteByTable(RelationalDeleteDataNode node) throws IOException { |
2762 | 2766 | } |
2763 | 2767 | } |
2764 | 2768 |
|
2765 | | - if (TierManager.getInstance().checkObjectPathExist(dataRegionIdString, tableName)) { |
2766 | | - deleteObjectFiles(tableName, modEntries); |
| 2769 | + List<File> matchedObjectDirs = |
| 2770 | + TierManager.getInstance().getAllMatchedObjectDirs(dataRegionIdString, tableName); |
| 2771 | + if (!matchedObjectDirs.isEmpty()) { |
| 2772 | + deleteObjectFiles(matchedObjectDirs, modEntries); |
2767 | 2773 | } |
2768 | 2774 |
|
2769 | 2775 | List<List<TsFileResource>> sealedTsFileResourceLists = new ArrayList<>(modEntries.size()); |
@@ -2934,9 +2940,58 @@ private List<WALFlushListener> logDeletionInWAL( |
2934 | 2940 | return walFlushListeners; |
2935 | 2941 | } |
2936 | 2942 |
|
2937 | | - private void deleteObjectFiles(String tableName, List<TableDeletionEntry> modEntries) { |
2938 | | - for (TableDeletionEntry modEntry : modEntries) { |
2939 | | - |
| 2943 | + private void deleteObjectFiles(List<File> matchedObjectDirs, List<TableDeletionEntry> modEntries) |
| 2944 | + throws IOException { |
| 2945 | + for (File matchedObjectDir : matchedObjectDirs) { |
| 2946 | + try (Stream<Path> paths = Files.walk(matchedObjectDir.toPath())) { |
| 2947 | + paths |
| 2948 | + .filter(Files::isRegularFile) |
| 2949 | + .filter( |
| 2950 | + path -> { |
| 2951 | + String name = path.getFileName().toString(); |
| 2952 | + return name.endsWith(".bin"); |
| 2953 | + }) |
| 2954 | + .forEach( |
| 2955 | + path -> { |
| 2956 | + Path relativePath = matchedObjectDir.getParentFile().toPath().relativize(path); |
| 2957 | + String[] ideviceIdSegments = new String[relativePath.getNameCount() - 2]; |
| 2958 | + for (int i = 0; i < ideviceIdSegments.length; i++) { |
| 2959 | + ideviceIdSegments[i] = |
| 2960 | + config.getRestrictObjectLimit() |
| 2961 | + ? relativePath.getName(i).toString() |
| 2962 | + : new String( |
| 2963 | + BaseEncoding.base32() |
| 2964 | + .omitPadding() |
| 2965 | + .decode(relativePath.getName(i).toString()), |
| 2966 | + StandardCharsets.UTF_8); |
| 2967 | + } |
| 2968 | + IDeviceID iDeviceID = Factory.DEFAULT_FACTORY.create(ideviceIdSegments); |
| 2969 | + String measurementId = |
| 2970 | + config.getRestrictObjectLimit() |
| 2971 | + ? relativePath.getName(relativePath.getNameCount() - 2).toString() |
| 2972 | + : new String( |
| 2973 | + BaseEncoding.base32() |
| 2974 | + .omitPadding() |
| 2975 | + .decode( |
| 2976 | + relativePath |
| 2977 | + .getName(relativePath.getNameCount() - 2) |
| 2978 | + .toString()), |
| 2979 | + StandardCharsets.UTF_8); |
| 2980 | + String fileName = path.getFileName().toString(); |
| 2981 | + long timestamp = Long.parseLong(fileName.substring(0, fileName.lastIndexOf('.'))); |
| 2982 | + logger.info( |
| 2983 | + "timestamp {}, measurementId {}, ideviceId {}", |
| 2984 | + timestamp, |
| 2985 | + measurementId, |
| 2986 | + iDeviceID); |
| 2987 | + for (TableDeletionEntry modEntry : modEntries) { |
| 2988 | + if (modEntry.affects(iDeviceID, timestamp, timestamp) |
| 2989 | + && modEntry.affects(measurementId)) { |
| 2990 | + ObjectTypeUtils.deleteObjectPath(path.toFile()); |
| 2991 | + } |
| 2992 | + } |
| 2993 | + }); |
| 2994 | + } |
2940 | 2995 | } |
2941 | 2996 | } |
2942 | 2997 |
|
|
0 commit comments