aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/matching/sessionmanager.h
blob: afeacfe6a4f8e5f4442e37fd6140e968eb9d9933 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include "search_session.h"
#include <vespa/searchcore/grouping/groupingsession.h>
#include <vespa/searchcore/grouping/sessionid.h>
#include <vespa/vespalib/stllike/lrucache_map.h>

namespace vespalib { class ThreadExecutor; }
namespace proton::matching {

using SessionId = vespalib::string;

struct GroupingSessionCache;
struct SearchSessionCache;

class SessionManager {
public:
    struct Stats {
        Stats()
            : numInsert(0),
              numPick(0),
              numDropped(0),
              numCached(0),
              numTimedout(0)
        {}
        uint32_t numInsert;
        uint32_t numPick;
        uint32_t numDropped;
        uint32_t numCached;
        uint32_t numTimedout;
    };

    struct SearchSessionInfo {
        vespalib::string id;
        vespalib::steady_time created;
        vespalib::steady_time doom;
        SearchSessionInfo(const vespalib::string &id_in,
                          vespalib::steady_time created_in,
                          vespalib::steady_time doom_in) noexcept
            : id(id_in), created(created_in), doom(doom_in) {}
    };

private:
    std::unique_ptr<GroupingSessionCache> _grouping_cache;
    std::unique_ptr<SearchSessionCache> _search_map;

public:
    SessionManager(uint32_t maxSizeGrouping);
    ~SessionManager();

    void insert(search::grouping::GroupingSession::UP session);
    search::grouping::GroupingSession::UP pickGrouping(const SessionId &id);
    Stats getGroupingStats();

    void insert(SearchSession::SP session);
    SearchSession::SP pickSearch(const SessionId &id);
    Stats getSearchStats();
    size_t getNumSearchSessions() const;
    std::vector<SearchSessionInfo> getSortedSearchSessionInfo() const;

    void pruneTimedOutSessions(vespalib::steady_time currentTime, vespalib::ThreadExecutor & executor);
    // Only used for testing
    void pruneTimedOutSessions(vespalib::steady_time currentTime);
};

}