thomasmueller commented on a change in pull request #492: URL: https://github.com/apache/jackrabbit-oak/pull/492#discussion_r809083299
########## File path: oak-run-commons/src/main/java/org/apache/jackrabbit/oak/index/IndexImporterSupportBase.java ########## @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.jackrabbit.oak.index; + +import org.apache.jackrabbit.oak.api.CommitFailedException; +import org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider; +import org.apache.jackrabbit.oak.plugins.index.importer.AsyncIndexerLock; +import org.apache.jackrabbit.oak.plugins.index.importer.ClusterNodeStoreLock; +import org.apache.jackrabbit.oak.plugins.index.importer.IndexImporter; +import org.apache.jackrabbit.oak.spi.state.Clusterable; +import org.apache.jackrabbit.oak.spi.state.NodeStore; + +import java.io.File; +import java.io.IOException; + +public abstract class IndexImporterSupportBase { + + protected final NodeStore nodeStore; + protected final IndexHelper indexHelper; + + public IndexImporterSupportBase(IndexHelper indexHelper) { + this.nodeStore = indexHelper.getNodeStore(); + this.indexHelper = indexHelper; + } + + public void importIndex(File importDir) throws IOException, CommitFailedException { + IndexImporter importer = new IndexImporter(nodeStore, importDir, createIndexEditorProvider(), createLock()); + addImportProviders(importer); + importer.importIndex(); + } + + private AsyncIndexerLock createLock() { + if (nodeStore instanceof Clusterable) { Review comment: I generally try to avoid using "instanceof"... I see the same "instanceof" check is used in oak-core IndexerMBeanImpl.createLock. I think it is OK. The alternative would be to either change the NodeStore interface, but that's not nice either; or add a method to ClusterNodeStoreLock to do the instanceof check there... but both isn't much better. ########## File path: oak-run-elastic/src/main/java/org/apache/jackrabbit/oak/index/ElasticIndexerSupport.java ########## @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.jackrabbit.oak.index; + + +import org.apache.commons.io.FileUtils; +import org.apache.jackrabbit.oak.api.CommitFailedException; +import org.apache.jackrabbit.oak.plugins.index.importer.IndexerInfo; +import org.apache.jackrabbit.oak.spi.state.NodeStore; + +import java.io.*; Review comment: I would avoid star imports ########## File path: oak-run-elastic/src/main/java/org/apache/jackrabbit/oak/index/ElasticIndexCommand.java ########## @@ -216,33 +207,25 @@ private void reindex(ElasticIndexOptions indexOpts, IndexHelper indexHelper, Str indexOpts.getElasticScheme(), indexOpts.getElasticHost(), indexOpts.getElasticPort(), indexOpts.getApiKeyId(), indexOpts.getApiKeySecret())) { indexer.reindex(); - // Wait for default flush interval before exiting the try block - // to make sure the client is not closed before the last flush - // TODO : See if this can be handled in a better manner - Thread.sleep(ElasticIndexDefinition.BULK_FLUSH_INTERVAL_MS_DEFAULT * 2); - } catch (InterruptedException e) { - log.debug("Exception while waiting for Elastic connection to close", e); } } else { try (ElasticOutOfBandIndexer indexer = new ElasticOutOfBandIndexer(indexHelper, indexerSupport, indexOpts.getIndexPrefix(), indexOpts.getElasticScheme(), indexOpts.getElasticHost(), indexOpts.getElasticPort(), indexOpts.getApiKeyId(), indexOpts.getApiKeySecret())) { indexer.reindex(); - // Wait for default flush interval before exiting the try block - // to make sure the client is not closed before the last flush - Thread.sleep(ElasticIndexDefinition.BULK_FLUSH_INTERVAL_MS_DEFAULT * 2); - } catch (InterruptedException e) { - log.debug("Exception while waiting for Elastic connection to close", e); } } indexerSupport.writeMetaInfo(checkpoint); + File destDir = indexerSupport.copyIndexFilesToOutput(); Review comment: This is copying the metadata file, right? (Not sure if I understand the logic) ########## File path: oak-run-elastic/src/main/java/org/apache/jackrabbit/oak/index/ElasticIndexCommand.java ########## @@ -216,33 +207,25 @@ private void reindex(ElasticIndexOptions indexOpts, IndexHelper indexHelper, Str indexOpts.getElasticScheme(), indexOpts.getElasticHost(), indexOpts.getElasticPort(), indexOpts.getApiKeyId(), indexOpts.getApiKeySecret())) { indexer.reindex(); - // Wait for default flush interval before exiting the try block - // to make sure the client is not closed before the last flush - // TODO : See if this can be handled in a better manner - Thread.sleep(ElasticIndexDefinition.BULK_FLUSH_INTERVAL_MS_DEFAULT * 2); Review comment: Great that this is gone! -- 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]
