Search in sources :

Example 31 with ParsedDocument

use of org.elasticsearch.index.mapper.ParsedDocument in project elasticsearch by elastic.

the class InternalEngineTests method testForceMergeAndClose.

public void testForceMergeAndClose() throws IOException, InterruptedException {
    int numIters = randomIntBetween(2, 10);
    for (int j = 0; j < numIters; j++) {
        try (Store store = createStore()) {
            final InternalEngine engine = createEngine(store, createTempDir());
            final CountDownLatch startGun = new CountDownLatch(1);
            final CountDownLatch indexed = new CountDownLatch(1);
            Thread thread = new Thread() {

                @Override
                public void run() {
                    try {
                        try {
                            startGun.await();
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                        int i = 0;
                        while (true) {
                            int numDocs = randomIntBetween(1, 20);
                            for (int j = 0; j < numDocs; j++) {
                                i++;
                                ParsedDocument doc = testParsedDocument(Integer.toString(i), "test", null, testDocument(), B_1, null);
                                Engine.Index index = indexForDoc(doc);
                                engine.index(index);
                            }
                            engine.refresh("test");
                            indexed.countDown();
                            try {
                                engine.forceMerge(randomBoolean(), 1, false, randomBoolean(), randomBoolean());
                            } catch (IOException e) {
                                return;
                            }
                        }
                    } catch (AlreadyClosedException ex) {
                    // fine
                    } catch (IOException e) {
                        throw new AssertionError(e);
                    }
                }
            };
            thread.start();
            startGun.countDown();
            int someIters = randomIntBetween(1, 10);
            for (int i = 0; i < someIters; i++) {
                engine.forceMerge(randomBoolean(), 1, false, randomBoolean(), randomBoolean());
            }
            indexed.await();
            IOUtils.close(engine);
            thread.join();
        }
    }
}
Also used : Store(org.elasticsearch.index.store.Store) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) AlreadyClosedException(org.apache.lucene.store.AlreadyClosedException) CountDownLatch(java.util.concurrent.CountDownLatch) LongPoint(org.apache.lucene.document.LongPoint) ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument)

Example 32 with ParsedDocument

use of org.elasticsearch.index.mapper.ParsedDocument in project elasticsearch by elastic.

the class InternalEngineTests method testTranslogMultipleOperationsSameDocument.

public void testTranslogMultipleOperationsSameDocument() throws IOException {
    final int ops = randomIntBetween(1, 32);
    Engine initialEngine;
    final List<Engine.Operation> operations = new ArrayList<>();
    try {
        initialEngine = engine;
        for (int i = 0; i < ops; i++) {
            final ParsedDocument doc = testParsedDocument("1", "test", null, testDocumentWithTextField(), SOURCE, null);
            if (randomBoolean()) {
                final Engine.Index operation = new Engine.Index(newUid(doc), doc, SequenceNumbersService.UNASSIGNED_SEQ_NO, 0, i, VersionType.EXTERNAL, Engine.Operation.Origin.PRIMARY, System.nanoTime(), -1, false);
                operations.add(operation);
                initialEngine.index(operation);
            } else {
                final Engine.Delete operation = new Engine.Delete("test", "1", newUid(doc), SequenceNumbersService.UNASSIGNED_SEQ_NO, 0, i, VersionType.EXTERNAL, Engine.Operation.Origin.PRIMARY, System.nanoTime());
                operations.add(operation);
                initialEngine.delete(operation);
            }
        }
    } finally {
        IOUtils.close(engine);
    }
    Engine recoveringEngine = null;
    try {
        recoveringEngine = new InternalEngine(copy(engine.config(), EngineConfig.OpenMode.OPEN_INDEX_AND_TRANSLOG));
        recoveringEngine.recoverFromTranslog();
        try (Engine.Searcher searcher = recoveringEngine.acquireSearcher("test")) {
            final TotalHitCountCollector collector = new TotalHitCountCollector();
            searcher.searcher().search(new MatchAllDocsQuery(), collector);
            assertThat(collector.getTotalHits(), equalTo(operations.get(operations.size() - 1) instanceof Engine.Delete ? 0 : 1));
        }
    } finally {
        IOUtils.close(recoveringEngine);
    }
}
Also used : Searcher(org.elasticsearch.index.engine.Engine.Searcher) ArrayList(java.util.ArrayList) Index(org.elasticsearch.index.Index) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) LongPoint(org.apache.lucene.document.LongPoint) ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument) TotalHitCountCollector(org.apache.lucene.search.TotalHitCountCollector)

Example 33 with ParsedDocument

use of org.elasticsearch.index.mapper.ParsedDocument in project elasticsearch by elastic.

the class InternalEngineTests method testVersioningIndexConflict.

public void testVersioningIndexConflict() throws IOException {
    ParsedDocument doc = testParsedDocument("1", "test", null, testDocument(), B_1, null);
    Engine.Index index = indexForDoc(doc);
    Engine.IndexResult indexResult = engine.index(index);
    assertThat(indexResult.getVersion(), equalTo(1L));
    index = indexForDoc(doc);
    indexResult = engine.index(index);
    assertThat(indexResult.getVersion(), equalTo(2L));
    index = new Engine.Index(newUid(doc), doc, SequenceNumbersService.UNASSIGNED_SEQ_NO, 0, 1L, VersionType.INTERNAL, Engine.Operation.Origin.PRIMARY, 0, -1, false);
    indexResult = engine.index(index);
    assertTrue(indexResult.hasFailure());
    assertThat(indexResult.getFailure(), instanceOf(VersionConflictEngineException.class));
    // future versions should not work as well
    index = new Engine.Index(newUid(doc), doc, SequenceNumbersService.UNASSIGNED_SEQ_NO, 0, 3L, VersionType.INTERNAL, PRIMARY, 0, -1, false);
    indexResult = engine.index(index);
    assertTrue(indexResult.hasFailure());
    assertThat(indexResult.getFailure(), instanceOf(VersionConflictEngineException.class));
}
Also used : ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument)

Example 34 with ParsedDocument

use of org.elasticsearch.index.mapper.ParsedDocument in project elasticsearch by elastic.

the class InternalEngineTests method testVersioningCreateExistsException.

public void testVersioningCreateExistsException() throws IOException {
    ParsedDocument doc = testParsedDocument("1", "test", null, testDocument(), B_1, null);
    Engine.Index create = new Engine.Index(newUid(doc), doc, SequenceNumbersService.UNASSIGNED_SEQ_NO, 0, Versions.MATCH_DELETED, VersionType.INTERNAL, PRIMARY, 0, -1, false);
    Engine.IndexResult indexResult = engine.index(create);
    assertThat(indexResult.getVersion(), equalTo(1L));
    create = new Engine.Index(newUid(doc), doc, SequenceNumbersService.UNASSIGNED_SEQ_NO, 0, Versions.MATCH_DELETED, VersionType.INTERNAL, PRIMARY, 0, -1, false);
    indexResult = engine.index(create);
    assertTrue(indexResult.hasFailure());
    assertThat(indexResult.getFailure(), instanceOf(VersionConflictEngineException.class));
}
Also used : ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument) Index(org.elasticsearch.index.Index)

Example 35 with ParsedDocument

use of org.elasticsearch.index.mapper.ParsedDocument in project elasticsearch by elastic.

the class InternalEngineTests method testVersioningDeleteConflict.

public void testVersioningDeleteConflict() throws IOException {
    ParsedDocument doc = testParsedDocument("1", "test", null, testDocument(), B_1, null);
    Engine.Index index = indexForDoc(doc);
    Engine.IndexResult indexResult = engine.index(index);
    assertThat(indexResult.getVersion(), equalTo(1L));
    index = indexForDoc(doc);
    indexResult = engine.index(index);
    assertThat(indexResult.getVersion(), equalTo(2L));
    Engine.Delete delete = new Engine.Delete("test", "1", newUid(doc), SequenceNumbersService.UNASSIGNED_SEQ_NO, 0, 1L, VersionType.INTERNAL, PRIMARY, 0);
    Engine.DeleteResult result = engine.delete(delete);
    assertTrue(result.hasFailure());
    assertThat(result.getFailure(), instanceOf(VersionConflictEngineException.class));
    // future versions should not work as well
    delete = new Engine.Delete("test", "1", newUid(doc), SequenceNumbersService.UNASSIGNED_SEQ_NO, 0, 3L, VersionType.INTERNAL, PRIMARY, 0);
    result = engine.delete(delete);
    assertTrue(result.hasFailure());
    assertThat(result.getFailure(), instanceOf(VersionConflictEngineException.class));
    // now actually delete
    delete = new Engine.Delete("test", "1", newUid(doc), SequenceNumbersService.UNASSIGNED_SEQ_NO, 0, 2L, VersionType.INTERNAL, PRIMARY, 0);
    result = engine.delete(delete);
    assertThat(result.getVersion(), equalTo(3L));
    // now check if we can index to a delete doc with version
    index = new Engine.Index(newUid(doc), doc, SequenceNumbersService.UNASSIGNED_SEQ_NO, 0, 2L, VersionType.INTERNAL, PRIMARY, 0, -1, false);
    indexResult = engine.index(index);
    assertTrue(indexResult.hasFailure());
    assertThat(indexResult.getFailure(), instanceOf(VersionConflictEngineException.class));
}
Also used : ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument)

Aggregations

ParsedDocument (org.elasticsearch.index.mapper.ParsedDocument)211 Test (org.junit.Test)85 LongPoint (org.apache.lucene.document.LongPoint)59 BytesArray (org.elasticsearch.common.bytes.BytesArray)58 Matchers.containsString (org.hamcrest.Matchers.containsString)57 Store (org.elasticsearch.index.store.Store)52 Searcher (org.elasticsearch.index.engine.Engine.Searcher)46 DocumentMapper (org.elasticsearch.index.mapper.DocumentMapper)35 IOException (java.io.IOException)32 AtomicLong (java.util.concurrent.atomic.AtomicLong)31 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)31 IndexableField (org.apache.lucene.index.IndexableField)30 Term (org.apache.lucene.index.Term)28 TopDocs (org.apache.lucene.search.TopDocs)28 NumericDocValuesField (org.apache.lucene.document.NumericDocValuesField)27 Index (org.elasticsearch.index.Index)27 UncheckedIOException (java.io.UncheckedIOException)26 Field (org.apache.lucene.document.Field)26 TextField (org.apache.lucene.document.TextField)26 ArrayList (java.util.ArrayList)25