Java Code Examples for org.apache.solr.client.solrj.request.CollectionAdminRequest#SplitShard
The following examples show how to use
org.apache.solr.client.solrj.request.CollectionAdminRequest#SplitShard .
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: ShardSplitTest.java From lucene-solr with Apache License 2.0 | 6 votes |
private void doSplitShardWithRule(SolrIndexSplitter.SplitMethod splitMethod) throws Exception { waitForThingsToLevelOut(15, TimeUnit.SECONDS); log.info("Starting testSplitShardWithRule"); String collectionName = "shardSplitWithRule_" + splitMethod.toLower(); CollectionAdminRequest.Create createRequest = CollectionAdminRequest.createCollection(collectionName, "conf1", 1, 2) .setRule("shard:*,replica:<2,node:*"); CollectionAdminResponse response = createRequest.process(cloudClient); assertEquals(0, response.getStatus()); try { cloudClient.waitForState(collectionName, 30, TimeUnit.SECONDS, SolrCloudTestCase.activeClusterShape(1, 2)); } catch (TimeoutException e) { new RuntimeException("Timeout waiting for 1shards and 2 replicas.", e); } CollectionAdminRequest.SplitShard splitShardRequest = CollectionAdminRequest.splitShard(collectionName) .setShardName("shard1").setSplitMethod(splitMethod.toLower()); response = splitShardRequest.process(cloudClient); assertEquals(String.valueOf(response.getErrorMessages()), 0, response.getStatus()); }
Example 2
Source File: SplitShardSuggester.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings({"rawtypes"}) SolrRequest init() { @SuppressWarnings({"unchecked"}) Set<Pair<String, String>> shards = (Set<Pair<String, String>>) hints.getOrDefault(Hint.COLL_SHARD, Collections.emptySet()); if (shards.isEmpty()) { throw new RuntimeException("split-shard requires 'collection' and 'shard'"); } if (shards.size() > 1) { throw new RuntimeException("split-shard requires exactly one pair of 'collection' and 'shard'"); } Pair<String, String> collShard = shards.iterator().next(); @SuppressWarnings({"unchecked"}) Map<String, Object> params = (Map<String, Object>)hints.getOrDefault(Hint.PARAMS, Collections.emptyMap()); Float splitFuzz = (Float)params.get(CommonAdminParams.SPLIT_FUZZ); CollectionAdminRequest.SplitShard req = CollectionAdminRequest.splitShard(collShard.first()).setShardName(collShard.second()); if (splitFuzz != null) { req.setSplitFuzz(splitFuzz); } String splitMethod = (String)params.get(CommonAdminParams.SPLIT_METHOD); if (splitMethod != null) { req.setSplitMethod(splitMethod); } Boolean splitByPrefix = (Boolean)params.get(CommonAdminParams.SPLIT_BY_PREFIX); if (splitByPrefix != null) { req.setSplitByPrefix(splitByPrefix); } return req; }
Example 3
Source File: ShardSplitTest.java From lucene-solr with Apache License 2.0 | 5 votes |
private void doSplitMixedReplicaTypes(SolrIndexSplitter.SplitMethod splitMethod) throws Exception { waitForThingsToLevelOut(15, TimeUnit.SECONDS); String collectionName = "testSplitMixedReplicaTypes_" + splitMethod.toLower(); CollectionAdminRequest.Create create = CollectionAdminRequest.createCollection(collectionName, "conf1", 1, 2, 0, 2); // TODO tlog replicas disabled right now. create.setMaxShardsPerNode(5); // some high number so we can create replicas without hindrance create.process(cloudClient); cloudClient.waitForState(collectionName, 30, TimeUnit.SECONDS, SolrCloudTestCase.activeClusterShape(1, 4)); waitForRecoveriesToFinish(collectionName, false); for (int i = 0; i < 100; i++) { cloudClient.add(collectionName, getDoc("id", "id-" + i, "foo_s", "bar " + i)); } cloudClient.commit(collectionName); CollectionAdminRequest.SplitShard splitShard = CollectionAdminRequest.splitShard(collectionName); splitShard.setShardName(SHARD1); splitShard.setSplitMethod(splitMethod.toLower()); CollectionAdminResponse rsp = splitShard.process(cloudClient); waitForThingsToLevelOut(30, TimeUnit.SECONDS); cloudClient.waitForState(collectionName, 30, TimeUnit.SECONDS, SolrCloudTestCase.activeClusterShape(2, 12)); cloudClient.getZkStateReader().forceUpdateCollection(collectionName); ClusterState clusterState = cloudClient.getZkStateReader().getClusterState(); DocCollection coll = clusterState.getCollection(collectionName); log.info("coll: {}", coll); // verify the original shard verifyShard(coll, SHARD1, Slice.State.INACTIVE, 2, 0, 2); // verify new sub-shards verifyShard(coll, SHARD1_0, Slice.State.ACTIVE, 2, 0, 2); verifyShard(coll, SHARD1_1, Slice.State.ACTIVE, 2, 0, 2); }
Example 4
Source File: SplitShardTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void multipleOptionsSplitTest() throws IOException, SolrServerException { CollectionAdminRequest.SplitShard splitShard = CollectionAdminRequest.splitShard(COLLECTION_NAME) .setNumSubShards(5) .setRanges("0-c,d-7fffffff") .setShardName("shard1"); boolean expectedException = false; try { splitShard.process(cluster.getSolrClient()); fail("An exception should have been thrown"); } catch (SolrException ex) { expectedException = true; } assertTrue("Expected SolrException but it didn't happen", expectedException); }
Example 5
Source File: SplitShardTest.java From lucene-solr with Apache License 2.0 | 5 votes |
@Test public void testSplitFuzz() throws Exception { String collectionName = "splitFuzzCollection"; CollectionAdminRequest .createCollection(collectionName, "conf", 2, 1) .setMaxShardsPerNode(100) .process(cluster.getSolrClient()); cluster.waitForActiveCollection(collectionName, 2, 2); CollectionAdminRequest.SplitShard splitShard = CollectionAdminRequest.splitShard(collectionName) .setSplitFuzz(0.5f) .setShardName("shard1"); splitShard.process(cluster.getSolrClient()); waitForState("Timed out waiting for sub shards to be active. Number of active shards=" + cluster.getSolrClient().getZkStateReader().getClusterState().getCollection(collectionName).getActiveSlices().size(), collectionName, activeClusterShape(3, 4)); DocCollection coll = cluster.getSolrClient().getZkStateReader().getClusterState().getCollection(collectionName); Slice s1_0 = coll.getSlice("shard1_0"); Slice s1_1 = coll.getSlice("shard1_1"); long fuzz = ((long)Integer.MAX_VALUE >> 3) + 1L; long delta0 = s1_0.getRange().max - s1_0.getRange().min; long delta1 = s1_1.getRange().max - s1_1.getRange().min; long expected0 = (Integer.MAX_VALUE >> 1) + fuzz; long expected1 = (Integer.MAX_VALUE >> 1) - fuzz; assertEquals("wrong range in s1_0", expected0, delta0); assertEquals("wrong range in s1_1", expected1, delta1); }
Example 6
Source File: CollectionAdminRequestRequiredParamsTest.java From lucene-solr with Apache License 2.0 | 4 votes |
public void testSplitShard() { final CollectionAdminRequest.SplitShard request = CollectionAdminRequest.splitShard("collection") .setShardName("shard"); assertContainsParams(request.getParams(), ACTION, COLLECTION, SHARD); }
Example 7
Source File: AbstractCloudBackupRestoreTestCase.java From lucene-solr with Apache License 2.0 | 4 votes |
@Test public void test() throws Exception { setTestSuffix("testok"); boolean isImplicit = random().nextBoolean(); boolean doSplitShardOperation = !isImplicit && random().nextBoolean(); replFactor = TestUtil.nextInt(random(), 1, 2); numTlogReplicas = TestUtil.nextInt(random(), 0, 1); numPullReplicas = TestUtil.nextInt(random(), 0, 1); int backupReplFactor = replFactor + numPullReplicas + numTlogReplicas; CollectionAdminRequest.Create create = isImplicit ? // NOTE: use shard list with same # of shards as NUM_SHARDS; we assume this later CollectionAdminRequest.createCollectionWithImplicitRouter(getCollectionName(), "conf1", "shard1,shard2", replFactor, numTlogReplicas, numPullReplicas) : CollectionAdminRequest.createCollection(getCollectionName(), "conf1", NUM_SHARDS, replFactor, numTlogReplicas, numPullReplicas); if (random().nextBoolean()) { create.setMaxShardsPerNode(-1); } else if (doSplitShardOperation) { create.setMaxShardsPerNode((int) Math.ceil(NUM_SPLIT_SHARDS * backupReplFactor / (double) cluster.getJettySolrRunners().size())); } else if (NUM_SHARDS * (backupReplFactor) > cluster.getJettySolrRunners().size() || random().nextBoolean()) { create.setMaxShardsPerNode((int) Math.ceil(NUM_SHARDS * backupReplFactor / (double) cluster.getJettySolrRunners().size()));//just to assert it survives the restoration } if (random().nextBoolean()) { create.setAutoAddReplicas(true);//just to assert it survives the restoration } Properties coreProps = new Properties(); coreProps.put("customKey", "customValue");//just to assert it survives the restoration create.setProperties(coreProps); if (isImplicit) { //implicit router create.setRouterField("shard_s"); } else {//composite id router if (random().nextBoolean()) { create.setRouterField("shard_s"); } } CloudSolrClient solrClient = cluster.getSolrClient(); create.process(solrClient); indexDocs(getCollectionName(), false); if (doSplitShardOperation) { // shard split the first shard int prevActiveSliceCount = getActiveSliceCount(getCollectionName()); CollectionAdminRequest.SplitShard splitShard = CollectionAdminRequest.splitShard(getCollectionName()); splitShard.setShardName("shard1"); splitShard.process(solrClient); // wait until we see one more active slice... for (int i = 0; getActiveSliceCount(getCollectionName()) != prevActiveSliceCount + 1; i++) { assertTrue(i < 30); Thread.sleep(500); } // issue a hard commit. Split shard does a soft commit which isn't good enough for the backup/snapshooter to see solrClient.commit(getCollectionName()); } testBackupAndRestore(getCollectionName(), backupReplFactor); testConfigBackupOnly("conf1", getCollectionName()); testInvalidPath(getCollectionName()); }