Search in sources :

Example 71 with SolrInputDocument

use of org.apache.solr.common.SolrInputDocument in project lucene-solr by apache.

the class RecoveryAfterSoftCommitTest method test.

@Test
public void test() throws Exception {
    waitForRecoveriesToFinish(DEFAULT_COLLECTION, true);
    // flush twice
    int i = 0;
    for (; i < MAX_BUFFERED_DOCS + 1; i++) {
        SolrInputDocument document = new SolrInputDocument();
        document.addField("id", String.valueOf(i));
        document.addField("a_t", "text_" + i);
        cloudClient.add(document);
    }
    // soft-commit so searchers are open on un-committed but flushed segment files
    AbstractUpdateRequest request = new UpdateRequest().setAction(AbstractUpdateRequest.ACTION.COMMIT, true, true, true);
    cloudClient.request(request);
    Replica notLeader = ensureAllReplicasAreActive(DEFAULT_COLLECTION, "shard1", 1, 2, 30).get(0);
    // ok, now introduce a network partition between the leader and the replica
    SocketProxy proxy = getProxyForReplica(notLeader);
    proxy.close();
    // add more than ULOG_NUM_RECORDS_TO_KEEP docs so that peer sync cannot be used for recovery
    int MAX_DOCS = 2 + MAX_BUFFERED_DOCS + ULOG_NUM_RECORDS_TO_KEEP;
    for (; i < MAX_DOCS; i++) {
        SolrInputDocument document = new SolrInputDocument();
        document.addField("id", String.valueOf(i));
        document.addField("a_t", "text_" + i);
        cloudClient.add(document);
    }
    // Have the partition last at least 1 sec
    // While this gives the impression that recovery is timing related, this is
    // really only
    // to give time for the state to be written to ZK before the test completes.
    // In other words,
    // without a brief pause, the test finishes so quickly that it doesn't give
    // time for the recovery process to kick-in
    Thread.sleep(2000L);
    proxy.reopen();
    List<Replica> notLeaders = ensureAllReplicasAreActive(DEFAULT_COLLECTION, "shard1", 1, 2, 30);
}
Also used : AbstractUpdateRequest(org.apache.solr.client.solrj.request.AbstractUpdateRequest) SolrInputDocument(org.apache.solr.common.SolrInputDocument) AbstractUpdateRequest(org.apache.solr.client.solrj.request.AbstractUpdateRequest) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) Replica(org.apache.solr.common.cloud.Replica) Test(org.junit.Test)

Example 72 with SolrInputDocument

use of org.apache.solr.common.SolrInputDocument in project lucene-solr by apache.

the class MissingSegmentRecoveryTest method setup.

@Before
public void setup() throws SolrServerException, IOException {
    CollectionAdminRequest.createCollection(collection, "conf", 1, 2).setMaxShardsPerNode(1).process(cluster.getSolrClient());
    waitForState("Expected a collection with one shard and two replicas", collection, clusterShape(1, 2));
    cluster.getSolrClient().setDefaultCollection(collection);
    List<SolrInputDocument> docs = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        SolrInputDocument doc = new SolrInputDocument();
        doc.addField("id", i);
        docs.add(doc);
    }
    cluster.getSolrClient().add(docs);
    cluster.getSolrClient().commit();
    DocCollection state = getCollectionState(collection);
    leader = state.getLeader("shard1");
    replica = getRandomReplica(state.getSlice("shard1"), (r) -> leader != r);
}
Also used : AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) Files(java.nio.file.Files) Slow(org.apache.lucene.util.LuceneTestCase.Slow) DocCollection(org.apache.solr.common.cloud.DocCollection) SolrCore(org.apache.solr.core.SolrCore) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) StandardOpenOption(java.nio.file.StandardOpenOption) IOException(java.io.IOException) Test(org.junit.Test) File(java.io.File) Replica(org.apache.solr.common.cloud.Replica) ArrayList(java.util.ArrayList) SolrServerException(org.apache.solr.client.solrj.SolrServerException) List(java.util.List) SolrQuery(org.apache.solr.client.solrj.SolrQuery) After(org.junit.After) JettySolrRunner(org.apache.solr.client.solrj.embedded.JettySolrRunner) CollectionAdminRequest(org.apache.solr.client.solrj.request.CollectionAdminRequest) SolrInputDocument(org.apache.solr.common.SolrInputDocument) Before(org.junit.Before) SolrInputDocument(org.apache.solr.common.SolrInputDocument) ArrayList(java.util.ArrayList) DocCollection(org.apache.solr.common.cloud.DocCollection) Before(org.junit.Before)

Example 73 with SolrInputDocument

use of org.apache.solr.common.SolrInputDocument in project lucene-solr by apache.

the class LeaderFailureAfterFreshStartTest method indexDoc.

protected void indexDoc(Object... fields) throws IOException, SolrServerException {
    SolrInputDocument doc = new SolrInputDocument();
    addFields(doc, fields);
    addFields(doc, "rnd_s", RandomStringUtils.random(random().nextInt(100) + 100));
    UpdateRequest ureq = new UpdateRequest();
    ureq.add(doc);
    ModifiableSolrParams params = new ModifiableSolrParams();
    ureq.setParams(params);
    ureq.process(cloudClient);
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) UpdateRequest(org.apache.solr.client.solrj.request.UpdateRequest) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams)

Example 74 with SolrInputDocument

use of org.apache.solr.common.SolrInputDocument in project lucene-solr by apache.

the class SegmentTerminateEarlyTestState method addDocuments.

void addDocuments(CloudSolrClient cloudSolrClient, int numCommits, int numDocsPerCommit, boolean optimize) throws Exception {
    for (int cc = 1; cc <= numCommits; ++cc) {
        for (int nn = 1; nn <= numDocsPerCommit; ++nn) {
            ++numDocs;
            final Integer docKey = new Integer(numDocs);
            SolrInputDocument doc = new SolrInputDocument();
            doc.setField(KEY_FIELD, "" + docKey);
            // minutes
            final int MM = rand.nextInt(60);
            if (minTimestampMM == null || MM <= minTimestampMM.intValue()) {
                if (minTimestampMM != null && MM < minTimestampMM.intValue()) {
                    minTimestampDocKeys.clear();
                }
                minTimestampMM = new Integer(MM);
                minTimestampDocKeys.add(docKey);
            }
            if (maxTimestampMM == null || maxTimestampMM.intValue() <= MM) {
                if (maxTimestampMM != null && maxTimestampMM.intValue() < MM) {
                    maxTimestampDocKeys.clear();
                }
                maxTimestampMM = new Integer(MM);
                maxTimestampDocKeys.add(docKey);
            }
            doc.setField(TIMESTAMP_FIELD, (Integer) MM);
            doc.setField(ODD_FIELD, "" + (numDocs % 2));
            doc.setField(QUAD_FIELD, "" + (numDocs % 4) + 1);
            cloudSolrClient.add(doc);
        }
        cloudSolrClient.commit();
    }
    if (optimize) {
        cloudSolrClient.optimize();
    }
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument)

Example 75 with SolrInputDocument

use of org.apache.solr.common.SolrInputDocument in project lucene-solr by apache.

the class BlobRepositoryCloudTest method setupCluster.

@BeforeClass
public static void setupCluster() throws Exception {
    // only sharing *within* a node
    configureCluster(1).addConfig("configname", TEST_PATH.resolve("resource-sharing")).configure();
    //    Thread.sleep(2000);
    HashMap<String, String> params = new HashMap<>();
    CollectionAdminRequest.createCollection(".system", null, 1, 1).process(cluster.getSolrClient());
    // test component will fail if it cant' find a blob with this data by this name
    TestBlobHandler.postData(cluster.getSolrClient(), findLiveNodeURI(), "testResource", ByteBuffer.wrap("foo,bar\nbaz,bam".getBytes(StandardCharsets.UTF_8)));
    //    Thread.sleep(2000);
    // if these don't load we probably failed to post the blob above
    CollectionAdminRequest.createCollection("col1", "configname", 1, 1).process(cluster.getSolrClient());
    CollectionAdminRequest.createCollection("col2", "configname", 1, 1).process(cluster.getSolrClient());
    SolrInputDocument document = new SolrInputDocument();
    document.addField("id", "1");
    document.addField("text", "col1");
    CloudSolrClient solrClient = cluster.getSolrClient();
    solrClient.add("col1", document);
    solrClient.commit("col1");
    document = new SolrInputDocument();
    document.addField("id", "1");
    document.addField("text", "col2");
    solrClient.add("col2", document);
    solrClient.commit("col2");
    Thread.sleep(2000);
}
Also used : SolrInputDocument(org.apache.solr.common.SolrInputDocument) HashMap(java.util.HashMap) CloudSolrClient(org.apache.solr.client.solrj.impl.CloudSolrClient) BeforeClass(org.junit.BeforeClass)

Aggregations

SolrInputDocument (org.apache.solr.common.SolrInputDocument)520 Test (org.junit.Test)166 ArrayList (java.util.ArrayList)98 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)76 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)69 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)63 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)55 SolrQuery (org.apache.solr.client.solrj.SolrQuery)54 IOException (java.io.IOException)47 SolrException (org.apache.solr.common.SolrException)47 IndexSchema (org.apache.solr.schema.IndexSchema)41 AddUpdateCommand (org.apache.solr.update.AddUpdateCommand)41 HashMap (java.util.HashMap)39 SolrQueryRequest (org.apache.solr.request.SolrQueryRequest)34 List (java.util.List)33 SolrServerException (org.apache.solr.client.solrj.SolrServerException)32 SolrDocument (org.apache.solr.common.SolrDocument)31 NamedList (org.apache.solr.common.util.NamedList)31 Map (java.util.Map)30 CloudSolrClient (org.apache.solr.client.solrj.impl.CloudSolrClient)29