Search in sources :

Example 1 with LoadType

use of com.yahoo.documentapi.messagebus.loadtypes.LoadType in project vespa by vespa-engine.

the class VespaFeedHandlerTestCase method testLoadTypes.

@Test
public void testLoadTypes() throws Exception {
    List<LoadTypeConfig.Type.Builder> typeBuilder = new ArrayList<>();
    typeBuilder.add(new LoadTypeConfig.Type.Builder().id(1234).name("foo").priority("VERY_LOW"));
    typeBuilder.add(new LoadTypeConfig.Type.Builder().id(4567).name("bar").priority("NORMAL_3"));
    setup(null, new LoadTypeConfig(new LoadTypeConfig.Builder().type(typeBuilder)), true, null);
    {
        Result res = testRequest(HttpRequest.createTestRequest("remove?id=doc:test:removeme&loadtype=foo", com.yahoo.jdisc.http.HttpRequest.Method.PUT));
        assertEquals(1, res.messages.size());
        Message m = res.messages.get(0);
        assertEquals(DocumentProtocol.MESSAGE_REMOVEDOCUMENT, m.getType());
        DocumentId d = ((RemoveDocumentMessage) m).getDocumentId();
        assertEquals("doc:test:removeme", d.toString());
        assertEquals(new LoadType(1234, "foo", DocumentProtocol.Priority.VERY_LOW), ((DocumentMessage) m).getLoadType());
        assertEquals(DocumentProtocol.Priority.VERY_LOW, ((DocumentMessage) m).getPriority());
    }
}
Also used : ArrayList(java.util.ArrayList) LoadType(com.yahoo.documentapi.messagebus.loadtypes.LoadType) LoadTypeConfig(com.yahoo.vespa.config.content.LoadTypeConfig) Test(org.junit.Test)

Example 2 with LoadType

use of com.yahoo.documentapi.messagebus.loadtypes.LoadType in project vespa by vespa-engine.

the class DocumentMessage method swapState.

@Override
public void swapState(Routable rhs) {
    super.swapState(rhs);
    if (rhs instanceof DocumentMessage) {
        DocumentMessage msg = (DocumentMessage) rhs;
        DocumentProtocol.Priority pri = this.priority;
        this.priority = msg.priority;
        msg.priority = pri;
        LoadType lt = this.loadType;
        this.loadType = msg.loadType;
        msg.loadType = lt;
    }
}
Also used : LoadType(com.yahoo.documentapi.messagebus.loadtypes.LoadType)

Example 3 with LoadType

use of com.yahoo.documentapi.messagebus.loadtypes.LoadType in project vespa by vespa-engine.

the class DocumentRetrieverTest method testSendSingleMessage.

@Test
public void testSendSingleMessage() throws DocumentRetrieverException {
    ClientParameters params = createParameters().setDocumentIds(asIterator(DOC_ID_1)).setPriority(DocumentProtocol.Priority.HIGH_1).setNoRetry(true).setLoadTypeName("loadtype").build();
    when(mockedSession.syncSend(any())).thenReturn(createDocumentReply(DOC_ID_1));
    LoadTypeSet loadTypeSet = new LoadTypeSet();
    loadTypeSet.addLoadType(1, "loadtype", DocumentProtocol.Priority.HIGH_1);
    DocumentRetriever documentRetriever = new DocumentRetriever(new ClusterList(), mockedFactory, loadTypeSet, params);
    documentRetriever.retrieveDocuments();
    verify(mockedSession, times(1)).syncSend(argThat(new ArgumentMatcher<GetDocumentMessage>() {

        @Override
        public boolean matches(Object o) {
            GetDocumentMessage msg = (GetDocumentMessage) o;
            return msg.getPriority().equals(DocumentProtocol.Priority.HIGH_1) && !msg.getRetryEnabled() && msg.getLoadType().equals(new LoadType(1, "loadtype", DocumentProtocol.Priority.HIGH_1));
        }
    }));
    assertContainsDocument(DOC_ID_1);
}
Also used : ClusterList(com.yahoo.vespaclient.ClusterList) ArgumentMatcher(org.mockito.ArgumentMatcher) GetDocumentMessage(com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage) LoadType(com.yahoo.documentapi.messagebus.loadtypes.LoadType) LoadTypeSet(com.yahoo.documentapi.messagebus.loadtypes.LoadTypeSet) Test(org.junit.Test)

Example 4 with LoadType

use of com.yahoo.documentapi.messagebus.loadtypes.LoadType in project vespa by vespa-engine.

the class MessageBusVisitorSessionTestCase method testMessageParameters.

@Test
public void testMessageParameters() {
    MockSender sender = new MockSender();
    MockReceiver receiver = new MockReceiver();
    MockAsyncTaskExecutor executor = new MockAsyncTaskExecutor();
    // Test all parameters that can be forwarded except bucketsToVisit,
    // which is already explicitly tested in testSendSingleCreateVisitor().
    VisitorParameters params = new VisitorParameters("");
    params.setDocumentSelection("id.user=5678");
    params.setFromTimestamp(9001);
    params.setToTimestamp(10001);
    params.setVisitorLibrary("CoolVisitor");
    params.setLibraryParameter("groovy", "dudes");
    params.setLibraryParameter("ninja", "turtles");
    params.setMaxBucketsPerVisitor(55);
    params.setPriority(DocumentProtocol.Priority.HIGHEST);
    params.setRoute("extraterrestrial/highway");
    params.setTimeoutMs(1337);
    params.setMaxPending(111);
    params.setFieldSet("[header]");
    params.setVisitorOrdering(123);
    params.setLoadType(new LoadType(3, "samnmax", DocumentProtocol.Priority.HIGH_3));
    params.setVisitRemoves(true);
    params.setVisitInconsistentBuckets(true);
    params.setTraceLevel(9);
    MessageBusVisitorSession visitorSession = createVisitorSession(sender, receiver, executor, params);
    visitorSession.start();
    // Process initial task which sends a single CreateVisitor.
    executor.expectAndProcessTasks(1);
    CreateVisitorMessage msg = (CreateVisitorMessage) sender.getAndRemoveMessage(0);
    assertEquals("CreateVisitorMessage(buckets=[\n" + "BucketId(0x800000000000162e)\n" + "BucketId(0x0000000000000000)\n" + "]\n" + "selection='id.user=5678'\n" + "time remaining=1337\n" + "from timestamp=9001\n" + "to timestamp=10001\n" + "max pending=111\n" + "fieldset=[header]\n" + "visit inconsistent=true\n" + "visit removes=true\n" + "parameters=[\n" + "groovy -> dudes\n" + "ninja -> turtles\n" + "]\n" + "route=extraterrestrial/highway\n" + "ordering=123\n" + "max buckets per visitor=55\n" + "load type=samnmax\n" + "priority=HIGHEST\n" + "visitor library=CoolVisitor\n" + "trace level=9\n" + ")", createVisitorToString(msg));
    assertFalse(msg.getRetryEnabled());
}
Also used : MessageBusVisitorSession(com.yahoo.documentapi.messagebus.MessageBusVisitorSession) LoadType(com.yahoo.documentapi.messagebus.loadtypes.LoadType) Test(org.junit.Test)

Example 5 with LoadType

use of com.yahoo.documentapi.messagebus.loadtypes.LoadType in project vespa by vespa-engine.

the class VdsVisitor method setVisitorParameters.

private void setVisitorParameters(String searchCluster, Route route) {
    if (query.properties().getString(streamingUserid) != null) {
        params.setDocumentSelection("id.user==" + query.properties().getString(streamingUserid));
    } else if (query.properties().getString(streamingGroupname) != null) {
        params.setDocumentSelection("id.group==\"" + query.properties().getString(streamingGroupname) + "\"");
    } else if (query.properties().getString(streamingSelection) != null) {
        params.setDocumentSelection(query.properties().getString(streamingSelection));
    }
    // Per bucket visitor timeout
    params.setTimeoutMs(query.getTimeout());
    params.setSessionTimeoutMs(query.getTimeout());
    params.setVisitorLibrary("searchvisitor");
    params.setLocalDataHandler(this);
    params.setVisitHeadersOnly(query.properties().getBoolean(streamingHeadersonly));
    if (query.properties().getDouble(streamingFromtimestamp) != null) {
        params.setFromTimestamp(query.properties().getDouble(streamingFromtimestamp).longValue());
    }
    if (query.properties().getDouble(streamingTotimestamp) != null) {
        params.setToTimestamp(query.properties().getDouble(streamingTotimestamp).longValue());
    }
    params.visitInconsistentBuckets(true);
    params.setPriority(DocumentProtocol.Priority.VERY_HIGH);
    if (query.properties().getString(streamingLoadtype) != null) {
        LoadType loadType = visitorSessionFactory.getLoadTypeSet().getNameMap().get(query.properties().getString(streamingLoadtype));
        if (loadType != null) {
            params.setLoadType(loadType);
            params.setPriority(loadType.getPriority());
        }
    }
    if (query.properties().getString(streamingPriority) != null) {
        params.setPriority(DocumentProtocol.getPriorityByName(query.properties().getString(streamingPriority)));
    }
    params.setMaxPending(Integer.MAX_VALUE);
    params.setMaxBucketsPerVisitor(Integer.MAX_VALUE);
    params.setTraceLevel(inferSessionTraceLevel(query));
    String ordering = query.properties().getString(streamingOrdering);
    if (ordering != null) {
        params.setVisitorOrdering(getOrdering(ordering));
        params.setMaxFirstPassHits(query.getOffset() + query.getHits());
        params.setMaxBucketsPerVisitor(1);
        params.setDynamicallyIncreaseMaxBucketsPerVisitor(true);
    }
    String maxbuckets = query.properties().getString(streamingMaxbucketspervisitor);
    if (maxbuckets != null) {
        params.setMaxBucketsPerVisitor(Integer.parseInt(maxbuckets));
    }
    EncodedData ed = new EncodedData();
    encodeQueryData(query, 0, ed);
    params.setLibraryParameter("query", ed.getEncodedData());
    params.setLibraryParameter("querystackcount", String.valueOf(ed.getReturned()));
    params.setLibraryParameter("searchcluster", searchCluster.getBytes());
    if (query.getPresentation().getSummary() != null) {
        params.setLibraryParameter("summaryclass", query.getPresentation().getSummary());
    } else {
        params.setLibraryParameter("summaryclass", "default");
    }
    params.setLibraryParameter("summarycount", String.valueOf(query.getOffset() + query.getHits()));
    params.setLibraryParameter("rankprofile", query.getRanking().getProfile());
    params.setLibraryParameter("allowslimedocsums", "true");
    params.setLibraryParameter("queryflags", String.valueOf(getQueryFlags(query)));
    ByteBuffer buf = ByteBuffer.allocate(1024);
    if (query.getRanking().getLocation() != null) {
        buf.clear();
        query.getRanking().getLocation().encode(buf);
        buf.flip();
        byte[] af = new byte[buf.remaining()];
        buf.get(af);
        params.setLibraryParameter("location", af);
    }
    if (query.hasEncodableProperties()) {
        encodeQueryData(query, 1, ed);
        params.setLibraryParameter("rankproperties", ed.getEncodedData());
    }
    List<Grouping> groupingList = GroupingExecutor.getGroupingList(query);
    if (groupingList.size() > 0) {
        BufferSerializer gbuf = new BufferSerializer(new GrowableByteBuffer());
        gbuf.putInt(null, groupingList.size());
        for (Grouping g : groupingList) {
            g.serialize(gbuf);
        }
        gbuf.flip();
        byte[] blob = gbuf.getBytes(null, gbuf.getBuf().limit());
        params.setLibraryParameter("aggregation", blob);
    }
    if (query.getRanking().getSorting() != null) {
        encodeQueryData(query, 3, ed);
        params.setLibraryParameter("sort", ed.getEncodedData());
    }
    params.setRoute(route);
}
Also used : BufferSerializer(com.yahoo.vespa.objects.BufferSerializer) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer) Grouping(com.yahoo.searchlib.aggregation.Grouping) LoadType(com.yahoo.documentapi.messagebus.loadtypes.LoadType) ByteBuffer(java.nio.ByteBuffer) GrowableByteBuffer(com.yahoo.io.GrowableByteBuffer)

Aggregations

LoadType (com.yahoo.documentapi.messagebus.loadtypes.LoadType)8 Test (org.junit.Test)3 GetDocumentMessage (com.yahoo.documentapi.messagebus.protocol.GetDocumentMessage)2 SyncParameters (com.yahoo.documentapi.SyncParameters)1 MessageBusParams (com.yahoo.documentapi.messagebus.MessageBusParams)1 MessageBusVisitorSession (com.yahoo.documentapi.messagebus.MessageBusVisitorSession)1 LoadTypeSet (com.yahoo.documentapi.messagebus.loadtypes.LoadTypeSet)1 DocumentProtocol (com.yahoo.documentapi.messagebus.protocol.DocumentProtocol)1 GetDocumentReply (com.yahoo.documentapi.messagebus.protocol.GetDocumentReply)1 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)1 Message (com.yahoo.messagebus.Message)1 Reply (com.yahoo.messagebus.Reply)1 Route (com.yahoo.messagebus.routing.Route)1 Grouping (com.yahoo.searchlib.aggregation.Grouping)1 Utf8String (com.yahoo.text.Utf8String)1 LoadTypeConfig (com.yahoo.vespa.config.content.LoadTypeConfig)1 BufferSerializer (com.yahoo.vespa.objects.BufferSerializer)1 ClusterList (com.yahoo.vespaclient.ClusterList)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1