swamirishi commented on code in PR #4273: URL: https://github.com/apache/ozone/pull/4273#discussion_r1119398408
########## hadoop-hdds/rocksdb-checkpoint-differ/src/main/java/org/apache/ozone/rocksdiff/RocksDiffUtils.java: ########## @@ -35,20 +52,54 @@ public static boolean isKeyWithPrefixPresent(String prefixForColumnFamily, } public static String constructBucketKey(String keyName) { - if (!keyName.startsWith(OzoneConsts.OM_KEY_PREFIX)) { - keyName = OzoneConsts.OM_KEY_PREFIX.concat(keyName); + if (!keyName.startsWith(OM_KEY_PREFIX)) { + keyName = OM_KEY_PREFIX.concat(keyName); } - String[] elements = keyName.split(OzoneConsts.OM_KEY_PREFIX); + String[] elements = keyName.split(OM_KEY_PREFIX); String volume = elements[1]; String bucket = elements[2]; StringBuilder builder = - new StringBuilder().append(OzoneConsts.OM_KEY_PREFIX).append(volume); + new StringBuilder().append(OM_KEY_PREFIX).append(volume); if (StringUtils.isNotBlank(bucket)) { - builder.append(OzoneConsts.OM_KEY_PREFIX).append(bucket); + builder.append(OM_KEY_PREFIX).append(bucket); } return builder.toString(); } + public static void filterRelevantSstFiles(Set<String> inputFiles, + Map<String, String> tableToPrefixMap) throws RocksDBException { + for (Iterator<String> fileIterator = + inputFiles.iterator(); fileIterator.hasNext();) { + String filepath = fileIterator.next(); + if (!RocksDiffUtils.doesSstFileContainKeyRange(filepath, + tableToPrefixMap)) { + fileIterator.remove(); + } + } + } + + public static boolean doesSstFileContainKeyRange(String filepath, + Map<String, String> tableToPrefixMap) throws RocksDBException { + try (SstFileReader sstFileReader = new SstFileReader(new Options())) { + sstFileReader.open(filepath); + TableProperties properties = sstFileReader.getTableProperties(); + String tableName = new String(properties.getColumnFamilyName(), UTF_8); + if (tableToPrefixMap.containsKey(tableName)) { + String prefix = tableToPrefixMap.get(tableName) + OM_KEY_PREFIX; + try (SstFileReaderIterator iterator = sstFileReader.newIterator( + new ReadOptions())) { + iterator.seek(prefix.getBytes(UTF_8)); + String seekResultKey = new String(iterator.key(), UTF_8); + return seekResultKey.startsWith(prefix); + } + } + return false; + } catch (RocksDBException e) { + LOG.error("Failed to read SST File ", e); + throw e; Review Comment: nit: Do we need to Log if we are throwing an exception. BTW it would be better if we wrap this exception with one of our own exceptions. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@ozone.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@ozone.apache.org For additional commands, e-mail: issues-h...@ozone.apache.org