You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2019/07/24 20:04:45 UTC

[GitHub] [incubator-pinot] jenniferdai commented on a change in pull request #4464: Delete extra refreshed segments after segment push

jenniferdai commented on a change in pull request #4464: Delete extra refreshed segments after segment push
URL: https://github.com/apache/incubator-pinot/pull/4464#discussion_r306997175
 
 

 ##########
 File path: pinot-hadoop/src/main/java/org/apache/pinot/hadoop/job/SegmentTarPushJob.java
 ##########
 @@ -48,10 +54,45 @@ public void run()
       throws Exception {
     FileSystem fileSystem = FileSystem.get(_conf);
     try (ControllerRestApi controllerRestApi = getControllerRestApi()) {
-      controllerRestApi.pushSegments(fileSystem, getDataFilePaths(_segmentPattern));
+      // TODO: Deal with invalid prefixes in the future
+      if (_deleteExtraSegments) {
+        List<String> allSegments = controllerRestApi.getAllSegments("OFFLINE");
+        Set<String> uniqueSegmentPrefixes = new HashSet<>();
+
+        // Get all relevant segment prefixes that we are planning on pushing
+        List<Path> segmentsToPushPaths = getDataFilePaths(_segmentPattern);
+        List<String> segmentsToPushNames = segmentsToPushPaths.stream().map(s -> s.getName()).collect(Collectors.toList());
+        for (String segmentName : segmentsToPushNames) {
+          String segmentNamePrefix = removeSequenceId(segmentName);
+          uniqueSegmentPrefixes.add(segmentNamePrefix);
+        }
+
+        List<String> relevantSegments = new ArrayList<>();
+        // Get relevant segments already pushed that we are planning on refreshing
+        for (String segmentName : allSegments) {
+          if (uniqueSegmentPrefixes.contains(removeSequenceId(segmentName))) {
+            relevantSegments.add(segmentName);
+          }
+        }
+
+        relevantSegments.removeAll(segmentsToPushNames);
+        controllerRestApi.pushSegments(fileSystem, getDataFilePaths(_segmentPattern));
+        controllerRestApi.deleteSegmentUris(relevantSegments);
+      } else {
+        controllerRestApi.pushSegments(fileSystem, getDataFilePaths(_segmentPattern));
+      }
     }
   }
 
+  /**
+   * Remove trailing sequence id
+   * @param segmentName
+   * @return
+   */
+  private String removeSequenceId(String segmentName) {
+    return segmentName.replaceAll("\\d*$", "");
 
 Review comment:
   in the javadoc above i have the functionality but i will add an additional example

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org