Search in sources :

Example 6 with UncheckedIOException

use of java.io.UncheckedIOException in project elasticsearch by elastic.

the class AbstractSimpleTransportTestCase method testTcpHandshakeConnectionReset.

public void testTcpHandshakeConnectionReset() throws IOException, InterruptedException {
    try (ServerSocket socket = new MockServerSocket()) {
        socket.bind(new InetSocketAddress(InetAddress.getLocalHost(), 0), 1);
        socket.setReuseAddress(true);
        DiscoveryNode dummy = new DiscoveryNode("TEST", new TransportAddress(socket.getInetAddress(), socket.getLocalPort()), emptyMap(), emptySet(), version0);
        Thread t = new Thread() {

            @Override
            public void run() {
                try (Socket accept = socket.accept()) {
                    if (randomBoolean()) {
                        // sometimes wait until the other side sends the message
                        accept.getInputStream().read();
                    }
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
        };
        t.start();
        ConnectionProfile.Builder builder = new ConnectionProfile.Builder();
        builder.addConnections(1, TransportRequestOptions.Type.BULK, TransportRequestOptions.Type.PING, TransportRequestOptions.Type.RECOVERY, TransportRequestOptions.Type.REG, TransportRequestOptions.Type.STATE);
        builder.setHandshakeTimeout(TimeValue.timeValueHours(1));
        ConnectTransportException ex = expectThrows(ConnectTransportException.class, () -> serviceA.connectToNode(dummy, builder.build()));
        assertEquals(ex.getMessage(), "[][" + dummy.getAddress() + "] general node connection failure");
        assertThat(ex.getCause().getMessage(), startsWith("handshake failed"));
        t.join();
    }
}
Also used : DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) InetSocketAddress(java.net.InetSocketAddress) TransportAddress(org.elasticsearch.common.transport.TransportAddress) MockServerSocket(org.elasticsearch.mocksocket.MockServerSocket) ServerSocket(java.net.ServerSocket) MockServerSocket(org.elasticsearch.mocksocket.MockServerSocket) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket) MockServerSocket(org.elasticsearch.mocksocket.MockServerSocket)

Example 7 with UncheckedIOException

use of java.io.UncheckedIOException in project elasticsearch by elastic.

the class MapperServiceTests method testTotalFieldsExceedsLimit.

public void testTotalFieldsExceedsLimit() throws Throwable {
    Function<String, String> mapping = type -> {
        try {
            return XContentFactory.jsonBuilder().startObject().startObject(type).startObject("properties").startObject("field1").field("type", "keyword").endObject().endObject().endObject().endObject().string();
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    };
    createIndex("test1").mapperService().merge("type", new CompressedXContent(mapping.apply("type")), MergeReason.MAPPING_UPDATE, false);
    //set total number of fields to 1 to trigger an exception
    IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> {
        createIndex("test2", Settings.builder().put(MapperService.INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING.getKey(), 1).build()).mapperService().merge("type", new CompressedXContent(mapping.apply("type")), MergeReason.MAPPING_UPDATE, false);
    });
    assertTrue(e.getMessage(), e.getMessage().contains("Limit of total fields [1] in index [test2] has been exceeded"));
}
Also used : XContentFactory(org.elasticsearch.common.xcontent.XContentFactory) KeywordFieldType(org.elasticsearch.index.mapper.KeywordFieldMapper.KeywordFieldType) ESSingleNodeTestCase(org.elasticsearch.test.ESSingleNodeTestCase) Arrays(java.util.Arrays) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NumberFieldType(org.elasticsearch.index.mapper.NumberFieldMapper.NumberFieldType) XContentType(org.elasticsearch.common.xcontent.XContentType) IndexService(org.elasticsearch.index.IndexService) IOException(java.io.IOException) HashMap(java.util.HashMap) Function(java.util.function.Function) Matchers.startsWith(org.hamcrest.Matchers.startsWith) BytesArray(org.elasticsearch.common.bytes.BytesArray) UncheckedIOException(java.io.UncheckedIOException) HashSet(java.util.HashSet) ExecutionException(java.util.concurrent.ExecutionException) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ExceptionsHelper(org.elasticsearch.ExceptionsHelper) Settings(org.elasticsearch.common.settings.Settings) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Map(java.util.Map) MergeReason(org.elasticsearch.index.mapper.MapperService.MergeReason) Collections(java.util.Collections) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Example 8 with UncheckedIOException

use of java.io.UncheckedIOException in project elasticsearch by elastic.

the class Mapping method toString.

@Override
public String toString() {
    try {
        XContentBuilder builder = XContentFactory.jsonBuilder().startObject();
        toXContent(builder, new ToXContent.MapParams(emptyMap()));
        return builder.endObject().string();
    } catch (IOException bogus) {
        throw new UncheckedIOException(bogus);
    }
}
Also used : ToXContent(org.elasticsearch.common.xcontent.ToXContent) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 9 with UncheckedIOException

use of java.io.UncheckedIOException in project elasticsearch by elastic.

the class DfsQueryPhaseTests method testFailPhaseOnException.

public void testFailPhaseOnException() throws IOException {
    AtomicArray<DfsSearchResult> results = new AtomicArray<>(2);
    AtomicReference<AtomicArray<QuerySearchResultProvider>> responseRef = new AtomicReference<>();
    results.set(0, new DfsSearchResult(1, new SearchShardTarget("node1", new Index("test", "na"), 0)));
    results.set(1, new DfsSearchResult(2, new SearchShardTarget("node2", new Index("test", "na"), 0)));
    results.get(0).termsStatistics(new Term[0], new TermStatistics[0]);
    results.get(1).termsStatistics(new Term[0], new TermStatistics[0]);
    SearchPhaseController controller = new SearchPhaseController(Settings.EMPTY, BigArrays.NON_RECYCLING_INSTANCE, null);
    SearchTransportService searchTransportService = new SearchTransportService(Settings.builder().put("search.remote.connect", false).build(), null, null) {

        @Override
        public void sendExecuteQuery(Transport.Connection connection, QuerySearchRequest request, SearchTask task, ActionListener<QuerySearchResult> listener) {
            if (request.id() == 1) {
                QuerySearchResult queryResult = new QuerySearchResult(123, new SearchShardTarget("node1", new Index("test", "na"), 0));
                queryResult.topDocs(new TopDocs(1, new ScoreDoc[] { new ScoreDoc(42, 1.0F) }, 2.0F), new DocValueFormat[0]);
                // the size of the result set
                queryResult.size(2);
                listener.onResponse(queryResult);
            } else if (request.id() == 2) {
                throw new UncheckedIOException(new MockDirectoryWrapper.FakeIOException());
            } else {
                fail("no such request ID: " + request.id());
            }
        }
    };
    MockSearchPhaseContext mockSearchPhaseContext = new MockSearchPhaseContext(2);
    mockSearchPhaseContext.searchTransport = searchTransportService;
    DfsQueryPhase phase = new DfsQueryPhase(results, controller, (response) -> new SearchPhase("test") {

        @Override
        public void run() throws IOException {
            responseRef.set(response.results);
        }
    }, mockSearchPhaseContext);
    assertEquals("dfs_query", phase.getName());
    expectThrows(UncheckedIOException.class, () -> phase.run());
    // phase execution will clean up on the contexts
    assertTrue(mockSearchPhaseContext.releasedSearchContexts.isEmpty());
}
Also used : AtomicArray(org.elasticsearch.common.util.concurrent.AtomicArray) DfsSearchResult(org.elasticsearch.search.dfs.DfsSearchResult) AtomicReference(java.util.concurrent.atomic.AtomicReference) Index(org.elasticsearch.index.Index) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) ScoreDoc(org.apache.lucene.search.ScoreDoc) TopDocs(org.apache.lucene.search.TopDocs) ActionListener(org.elasticsearch.action.ActionListener) QuerySearchResult(org.elasticsearch.search.query.QuerySearchResult) SearchShardTarget(org.elasticsearch.search.SearchShardTarget) QuerySearchRequest(org.elasticsearch.search.query.QuerySearchRequest)

Example 10 with UncheckedIOException

use of java.io.UncheckedIOException in project elasticsearch by elastic.

the class DefaultSearchContext method preProcess.

/**
     * Should be called before executing the main query and after all other parameters have been set.
     */
@Override
public void preProcess(boolean rewrite) {
    if (hasOnlySuggest()) {
        return;
    }
    long from = from() == -1 ? 0 : from();
    long size = size() == -1 ? 10 : size();
    long resultWindow = from + size;
    int maxResultWindow = indexService.getIndexSettings().getMaxResultWindow();
    if (resultWindow > maxResultWindow) {
        if (scrollContext == null) {
            throw new QueryPhaseExecutionException(this, "Result window is too large, from + size must be less than or equal to: [" + maxResultWindow + "] but was [" + resultWindow + "]. See the scroll api for a more efficient way to request large data sets. " + "This limit can be set by changing the [" + IndexSettings.MAX_RESULT_WINDOW_SETTING.getKey() + "] index level setting.");
        }
        throw new QueryPhaseExecutionException(this, "Batch size is too large, size must be less than or equal to: [" + maxResultWindow + "] but was [" + resultWindow + "]. Scroll batch sizes cost as much memory as result windows so they are controlled by the [" + IndexSettings.MAX_RESULT_WINDOW_SETTING.getKey() + "] index level setting.");
    }
    if (rescore != null) {
        int maxWindow = indexService.getIndexSettings().getMaxRescoreWindow();
        for (RescoreSearchContext rescoreContext : rescore) {
            if (rescoreContext.window() > maxWindow) {
                throw new QueryPhaseExecutionException(this, "Rescore window [" + rescoreContext.window() + "] is too large. It must " + "be less than [" + maxWindow + "]. This prevents allocating massive heaps for storing the results to be " + "rescored. This limit can be set by changing the [" + IndexSettings.MAX_RESCORE_WINDOW_SETTING.getKey() + "] index level setting.");
            }
        }
    }
    if (sliceBuilder != null) {
        int sliceLimit = indexService.getIndexSettings().getMaxSlicesPerScroll();
        int numSlices = sliceBuilder.getMax();
        if (numSlices > sliceLimit) {
            throw new QueryPhaseExecutionException(this, "The number of slices [" + numSlices + "] is too large. It must " + "be less than [" + sliceLimit + "]. This limit can be set by changing the [" + IndexSettings.MAX_SLICES_PER_SCROLL.getKey() + "] index level setting.");
        }
    }
    // initialize the filtering alias based on the provided filters
    try {
        final QueryBuilder queryBuilder = request.filteringAliases();
        aliasFilter = queryBuilder == null ? null : queryBuilder.toFilter(queryShardContext);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    if (query() == null) {
        parsedQuery(ParsedQuery.parsedMatchAllQuery());
    }
    if (queryBoost() != AbstractQueryBuilder.DEFAULT_BOOST) {
        parsedQuery(new ParsedQuery(new FunctionScoreQuery(query(), new WeightFactorFunction(queryBoost)), parsedQuery()));
    }
    this.query = buildFilteredQuery(query);
    if (rewrite) {
        try {
            this.query = searcher.rewrite(query);
        } catch (IOException e) {
            throw new QueryPhaseExecutionException(this, "Failed to rewrite main query", e);
        }
    }
}
Also used : WeightFactorFunction(org.elasticsearch.common.lucene.search.function.WeightFactorFunction) RescoreSearchContext(org.elasticsearch.search.rescore.RescoreSearchContext) ParsedQuery(org.elasticsearch.index.query.ParsedQuery) FunctionScoreQuery(org.elasticsearch.common.lucene.search.function.FunctionScoreQuery) QueryPhaseExecutionException(org.elasticsearch.search.query.QueryPhaseExecutionException) UncheckedIOException(java.io.UncheckedIOException) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) AbstractQueryBuilder(org.elasticsearch.index.query.AbstractQueryBuilder) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException)

Aggregations

UncheckedIOException (java.io.UncheckedIOException)64 IOException (java.io.IOException)60 Path (java.nio.file.Path)12 File (java.io.File)6 ArrayList (java.util.ArrayList)6 Arrays (java.util.Arrays)6 Test (org.junit.Test)6 InputStream (java.io.InputStream)5 HashMap (java.util.HashMap)5 BufferedReader (java.io.BufferedReader)4 URL (java.net.URL)4 List (java.util.List)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 IntStream (java.util.stream.IntStream)4 Protein (de.bioforscher.jstructure.model.structure.Protein)3 InterruptedIOException (java.io.InterruptedIOException)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Stream (java.util.stream.Stream)3 ServletException (javax.servlet.ServletException)3