amit-jain commented on code in PR #826:
URL: https://github.com/apache/jackrabbit-oak/pull/826#discussion_r1082253306


##########
oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/indexer/document/flatfile/FlatFileNodeStoreBuilder.java:
##########
@@ -222,26 +235,53 @@ public List<FlatFileStore> buildList(IndexHelper 
indexHelper, IndexerSupport ind
         return storeList;
     }
 
-    private File createdSortedStoreFile() throws IOException, 
CompositeException {
+    /**
+     * Returns the existing list of store files if it can read from system 
property OAK_INDEXER_SORTED_FILE_PATH which 
+     * defines the existing folder where the flat file store files are 
present. Will throw an exception if it cannot 
+     * read or the path in the system property is not a directory.
+     * If the system property OAK_INDEXER_SORTED_FILE_PATH in undefined, or it 
cannot read relevant files it 
+     * initializes the flat file store.
+     * 
+     * @return list of flat files
+     * @throws IOException 
+     * @throws CompositeException
+     */
+    private List<File> createdSortedStoreFiles() throws IOException, 
CompositeException {
+        // Check system property defined path
         String sortedFilePath = 
System.getProperty(OAK_INDEXER_SORTED_FILE_PATH);
-        if (sortedFilePath != null) {
-            File sortedFile = new File(sortedFilePath);
-            if (sortedFile.exists() && sortedFile.isFile() && 
sortedFile.canRead()) {
-                log.info("Reading from provided sorted file [{}] (via system 
property '{}')",
-                        sortedFile.getAbsolutePath(), 
OAK_INDEXER_SORTED_FILE_PATH);
-                return sortedFile;
-            } else {
-                String msg = String.format("Cannot read sorted file at [%s] 
configured via system property '%s'",
-                        sortedFile.getAbsolutePath(), 
OAK_INDEXER_SORTED_FILE_PATH);
-                throw new IllegalArgumentException(msg);
+        if (StringUtils.isNotBlank(sortedFilePath)) {
+            List<File> files = getFiles(sortedFilePath);
+            if (files != null) {
+                return files;
+            }
+        } 
+        
+        // Initialize the flat file store again
+        
+        createStoreDir();
+        org.apache.jackrabbit.oak.index.indexer.document.flatfile.SortStrategy 
strategy = createSortStrategy(flatFileStoreDir);
+        File result = strategy.createSortedStoreFile();
+        entryCount = strategy.getEntryCount();
+        return Collections.singletonList(result);
+    }
+
+    @Nullable
+    private List<File> getFiles(String sortedFilePath) {
+        File sortedDir = new File(sortedFilePath);
+        if (sortedDir.exists() && sortedDir.canRead() && 
sortedDir.isDirectory()) {
+            log.info("Reading from provided sorted files directory [{}] (via 
system property '{}')",
+                sortedDir.getAbsolutePath(), OAK_INDEXER_SORTED_FILE_PATH);

Review Comment:
   The caller (createdSortedStoreFiles()) as well as the definition of the 
system property is in the same class.



-- 
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: dev-unsubscr...@jackrabbit.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to