milleruntime commented on code in PR #2716:
URL: https://github.com/apache/accumulo/pull/2716#discussion_r875771320
##########
server/gc/src/main/java/org/apache/accumulo/gc/GarbageCollectionAlgorithm.java:
##########
@@ -51,64 +51,91 @@ public class GarbageCollectionAlgorithm {
private static final Logger log =
LoggerFactory.getLogger(GarbageCollectionAlgorithm.class);
+ /**
+ * This method takes a file or directory path and returns a relative path in
1 of 2 forms:
+ *
+ * <pre>
+ * 1- For files: table-id/tablet-directory/filename.rf
+ * 2- For directories: table-id/tablet-directory
+ * </pre>
+ *
+ * For example, for full file path like
hdfs://foo:6000/accumulo/tables/4/t0/F000.rf it will
+ * return 4/t0/F000.rf. For a directory that already is relative, like 4/t0,
it will just return
+ * the original path. This method will also remove prefixed relative path.
+ */
private String makeRelative(String path, int expectedLen) {
String relPath = path;
+ // remove prefixed old relative path
if (relPath.startsWith("../"))
relPath = relPath.substring(3);
+ // remove trailing slash
while (relPath.endsWith("/"))
relPath = relPath.substring(0, relPath.length() - 1);
+ // remove beginning slash
while (relPath.startsWith("/"))
relPath = relPath.substring(1);
- String[] tokens = relPath.split("/");
-
- // handle paths like a//b///c
- boolean containsEmpty = false;
- for (String token : tokens) {
- if (token.equals("")) {
- containsEmpty = true;
- break;
- }
- }
-
- if (containsEmpty) {
- ArrayList<String> tmp = new ArrayList<>();
- for (String token : tokens) {
- if (!token.equals("")) {
- tmp.add(token);
- }
- }
-
- tokens = tmp.toArray(new String[tmp.size()]);
- }
+ String[] tokens = removeEmptyTokensFromPath(relPath);
Review Comment:
Cool, I will take a look, thanks.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]