Java Code Examples for org.apache.solr.client.solrj.request.CollectionAdminRequest#ReindexCollection
The following examples show how to use
org.apache.solr.client.solrj.request.CollectionAdminRequest#ReindexCollection .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReindexCollectionTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testBasicReindexing() throws Exception { final String sourceCollection = "basicReindexing"; createCollection(sourceCollection, "conf1", 2, 2); indexDocs(sourceCollection, NUM_DOCS, i -> new SolrInputDocument("id", String.valueOf(i), "string_s", String.valueOf(i))); final String targetCollection = "basicReindexingTarget"; CollectionAdminRequest.ReindexCollection req = CollectionAdminRequest.reindexCollection(sourceCollection) .setTarget(targetCollection); CollectionAdminResponse rsp = req.process(solrClient); assertNotNull(rsp.toString(), rsp.getResponse().get(ReindexCollectionCmd.REINDEX_STATUS)); @SuppressWarnings({"unchecked"}) Map<String, Object> status = (Map<String, Object>)rsp.getResponse().get(ReindexCollectionCmd.REINDEX_STATUS); assertEquals(status.toString(), (long)NUM_DOCS, ((Number)status.get("inputDocs")).longValue()); assertEquals(status.toString(), (long)NUM_DOCS, ((Number)status.get("processedDocs")).longValue()); CloudUtil.waitForState(cloudManager, "did not finish copying in time", targetCollection, (liveNodes, coll) -> { ReindexCollectionCmd.State state = ReindexCollectionCmd.State.get(coll.getStr(ReindexCollectionCmd.REINDEXING_STATE)); return ReindexCollectionCmd.State.FINISHED == state; }); // verify the target docs exist QueryResponse queryResponse = solrClient.query(targetCollection, params(CommonParams.Q, "*:*")); assertEquals("copied num docs", NUM_DOCS, queryResponse.getResults().getNumFound()); }
Example 2
Source File: ReindexCollectionTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testLossySchema() throws Exception { final String sourceCollection = "sourceLossyReindexing"; final String targetCollection = "targetLossyReindexing"; createCollection(sourceCollection, "conf2", 2, 2); indexDocs(sourceCollection, NUM_DOCS, i -> new SolrInputDocument( "id", String.valueOf(i), "string_s", String.valueOf(i), "sind", "this is a test " + i)); // "sind": indexed=true, stored=false, will be lost... CollectionAdminRequest.ReindexCollection req = CollectionAdminRequest.reindexCollection(sourceCollection) .setTarget(targetCollection) .setConfigName("conf3"); req.process(solrClient); CloudUtil.waitForState(cloudManager, "did not finish copying in time", targetCollection, (liveNodes, coll) -> { ReindexCollectionCmd.State state = ReindexCollectionCmd.State.get(coll.getStr(ReindexCollectionCmd.REINDEXING_STATE)); return ReindexCollectionCmd.State.FINISHED == state; }); // verify the target docs exist QueryResponse rsp = solrClient.query(targetCollection, params(CommonParams.Q, "*:*")); assertEquals("copied num docs", NUM_DOCS, rsp.getResults().getNumFound()); for (SolrDocument doc : rsp.getResults()) { String id = (String)doc.getFieldValue("id"); assertEquals(id, doc.getFieldValue("string_s")); assertFalse(doc.containsKey("sind")); // lost in translation ... } }
Example 3
Source File: ReindexCollectionTest.java From lucene-solr with Apache License 2.0 | 4 votes |
@Test public void testFailure() throws Exception { final String sourceCollection = "failReindexing"; final String targetCollection = "failReindexingTarget"; final String aliasTarget = "failAlias"; createCollection(sourceCollection, "conf1", 2, 2); createCollection(targetCollection, "conf1", 1, 1); CollectionAdminRequest.createAlias(aliasTarget, targetCollection).process(solrClient); indexDocs(sourceCollection, NUM_DOCS, i -> new SolrInputDocument( "id", String.valueOf(i), "string_s", String.valueOf(i))); CollectionAdminRequest.ReindexCollection req = CollectionAdminRequest.reindexCollection(sourceCollection) .setTarget(targetCollection); CollectionAdminResponse rsp = req.process(solrClient); assertNotNull(rsp.getResponse().get("error")); assertTrue(rsp.toString(), rsp.getResponse().get("error").toString().contains("already exists")); req = CollectionAdminRequest.reindexCollection(sourceCollection) .setTarget(aliasTarget); rsp = req.process(solrClient); assertNotNull(rsp.getResponse().get("error")); assertTrue(rsp.toString(), rsp.getResponse().get("error").toString().contains("already exists")); CollectionAdminRequest.deleteAlias(aliasTarget).process(solrClient); CollectionAdminRequest.deleteCollection(targetCollection).process(solrClient); req = CollectionAdminRequest.reindexCollection(sourceCollection) .setTarget(targetCollection); TestInjection.reindexFailure = "true:100"; rsp = req.process(solrClient); assertNotNull(rsp.getResponse().get("error")); assertTrue(rsp.toString(), rsp.getResponse().get("error").toString().contains("waiting for daemon")); // verify that the target and checkpoint collections don't exist cloudManager.getClusterStateProvider().getClusterState().forEachCollection(coll -> { assertFalse(coll.getName() + " still exists", coll.getName().startsWith(ReindexCollectionCmd.TARGET_COL_PREFIX)); assertFalse(coll.getName() + " still exists", coll.getName().startsWith(ReindexCollectionCmd.CHK_COL_PREFIX)); }); // verify that the source collection is read-write and has no reindexing flags CloudUtil.waitForState(cloudManager, "collection state is incorrect", sourceCollection, ((liveNodes, collectionState) -> !collectionState.isReadOnly() && collectionState.getStr(ReindexCollectionCmd.REINDEXING_STATE) == null && getState(sourceCollection) == null)); }
Example 4
Source File: ReindexCollectionTest.java From lucene-solr with Apache License 2.0 | 4 votes |
@Test @SuppressWarnings({"unchecked"}) public void testAbort() throws Exception { final String sourceCollection = "abortReindexing"; final String targetCollection = "abortReindexingTarget"; createCollection(sourceCollection, "conf1", 2, 1); TestInjection.reindexLatch = new CountDownLatch(1); CollectionAdminRequest.ReindexCollection req = CollectionAdminRequest.reindexCollection(sourceCollection) .setTarget(targetCollection); String asyncId = req.processAsync(solrClient); // wait for the source collection to be put in readOnly mode CloudUtil.waitForState(cloudManager, "source collection didn't become readOnly", sourceCollection, (liveNodes, coll) -> coll.isReadOnly()); req = CollectionAdminRequest.reindexCollection(sourceCollection); req.setCommand("abort"); CollectionAdminResponse rsp = req.process(solrClient); Map<String, Object> status = (Map<String, Object>)rsp.getResponse().get(ReindexCollectionCmd.REINDEX_STATUS); assertNotNull(rsp.toString(), status); assertEquals(status.toString(), "aborting", status.get("state")); CloudUtil.waitForState(cloudManager, "incorrect collection state", sourceCollection, ((liveNodes, collectionState) -> collectionState.isReadOnly() && getState(sourceCollection) == ReindexCollectionCmd.State.ABORTED)); // verify status req.setCommand("status"); rsp = req.process(solrClient); status = (Map<String, Object>)rsp.getResponse().get(ReindexCollectionCmd.REINDEX_STATUS); assertNotNull(rsp.toString(), status); assertEquals(status.toString(), "aborted", status.get("state")); // let the process continue TestInjection.reindexLatch.countDown(); CloudUtil.waitForState(cloudManager, "source collection is in wrong state", sourceCollection, (liveNodes, docCollection) -> !docCollection.isReadOnly() && getState(sourceCollection) == null); // verify the response rsp = CollectionAdminRequest.requestStatus(asyncId).process(solrClient); status = (Map<String, Object>)rsp.getResponse().get(ReindexCollectionCmd.REINDEX_STATUS); assertNotNull(rsp.toString(), status); assertEquals(status.toString(), "aborted", status.get("state")); }