aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/common/tunefileinfo.h
blob: 8466252306a98cfa99d9c601858fdd1058ceb130 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include <memory>

namespace search {

class TuneFileSeqRead
{
public:
    enum TuneControl {
        NORMAL,
        DIRECTIO
    };

private:

    TuneControl _tuneControl;

public:
    TuneFileSeqRead() noexcept : _tuneControl(NORMAL) { }
    void setWantDirectIO() { _tuneControl = DIRECTIO; }
    bool getWantDirectIO() const { return _tuneControl == DIRECTIO; }

    template <typename Config>
    void setFromConfig(const enum Config::Io &config) {
        switch (config) {
        case Config::Io::NORMAL:
            _tuneControl = NORMAL;
            break;
        case Config::Io::DIRECTIO:
            _tuneControl = DIRECTIO;
            break;
        default:
            _tuneControl = NORMAL;
            break;
        }
    }

    bool operator==(const TuneFileSeqRead &rhs) const {
        return _tuneControl == rhs._tuneControl;
    }

    bool operator!=(const TuneFileSeqRead &rhs) const {
        return _tuneControl != rhs._tuneControl;
    }
};


class TuneFileSeqWrite
{
public:
    enum TuneControl {
        NORMAL,
        OSYNC,
        DIRECTIO
    };

private:

    TuneControl _tuneControl;

public:
    TuneFileSeqWrite() noexcept : _tuneControl(NORMAL) { }
    void setWantDirectIO() { _tuneControl = DIRECTIO; }
    bool getWantDirectIO() const { return _tuneControl == DIRECTIO; }
    bool getWantSyncWrites() const { return _tuneControl == OSYNC; }

    template <typename Config>
    void setFromConfig(const enum Config::Io &config) {
        switch (config) {
        case Config::Io::NORMAL:
            _tuneControl = NORMAL;
            break;
        case Config::Io::OSYNC:
            _tuneControl = OSYNC;
            break;
        case Config::Io::DIRECTIO:
            _tuneControl = DIRECTIO;
            break;
        default:
            _tuneControl = NORMAL;
            break;
        }
    }

    bool operator==(const TuneFileSeqWrite &rhs) const { return _tuneControl == rhs._tuneControl; }
    bool operator!=(const TuneFileSeqWrite &rhs) const { return _tuneControl != rhs._tuneControl; }
};


class TuneFileRandRead
{
public:
    enum TuneControl { NORMAL, DIRECTIO, MMAP };
private:
    TuneControl _tuneControl;
    int         _mmapFlags;
    int         _advise;
public:
    TuneFileRandRead() noexcept
        : _tuneControl(NORMAL),
          _mmapFlags(0),
          _advise(0)
    { }

    void setAdvise(int advise)        { _advise = advise; }
    void setWantMemoryMap() { _tuneControl = MMAP; }
    void setWantDirectIO()  { _tuneControl = DIRECTIO; }
    void setWantNormal()    { _tuneControl = NORMAL; }
    bool getWantDirectIO()   const { return _tuneControl == DIRECTIO; }
    bool getWantMemoryMap()  const { return _tuneControl == MMAP; }
    int  getMemoryMapFlags() const { return _mmapFlags; }
    int  getAdvise()         const { return _advise; }

    template <typename TuneControlConfig, typename MMapConfig>
    void setFromConfig(const enum TuneControlConfig::Io & tuneControlConfig, const MMapConfig & mmapFlags);
    template <typename MMapConfig>
    void setFromMmapConfig(const MMapConfig & mmapFlags);

    bool operator==(const TuneFileRandRead &rhs) const {
        return (_tuneControl == rhs._tuneControl) && (_mmapFlags == rhs._mmapFlags);
    }

    bool operator!=(const TuneFileRandRead &rhs) const {
        return (_tuneControl != rhs._tuneControl) && (_mmapFlags == rhs._mmapFlags);
    }
};


/**
 * Controls file access for indexed fields, word list and dictionary
 * during memory dump and fusion.
 */
class TuneFileIndexing
{
public:
    TuneFileSeqRead _read;
    TuneFileSeqWrite _write;

    TuneFileIndexing() noexcept : _read(), _write() {}

    TuneFileIndexing(const TuneFileSeqRead &r, const TuneFileSeqWrite &w) noexcept : _read(r), _write(w) { }

    bool operator==(const TuneFileIndexing &rhs) const {
        return _read == rhs._read && _write == rhs._write;
    }

    bool operator!=(const TuneFileIndexing &rhs) const {
        return _read != rhs._read || _write != rhs._write;
    }
};

/**
 * Controls file access for indexed fields and dictionary during
 * search.
 */
class TuneFileSearch
{
public:
    TuneFileRandRead _read;

    TuneFileSearch() noexcept : _read() { }
    TuneFileSearch(const TuneFileRandRead &r) noexcept : _read(r) { }
    bool operator==(const TuneFileSearch &rhs) const { return _read == rhs._read; }
    bool operator!=(const TuneFileSearch &rhs) const { return _read != rhs._read; }
};


/**
 * Controls file access for indexed fields and dictionary during
 * memory dump, fusion and search.
 */
class TuneFileIndexManager
{
public:
    TuneFileIndexing _indexing;
    TuneFileSearch   _search;

    TuneFileIndexManager() noexcept : _indexing(), _search() { }

    bool operator==(const TuneFileIndexManager &rhs) const {
        return _indexing == rhs._indexing && _search == rhs._search;
    }

    bool operator!=(const TuneFileIndexManager &rhs) const {
        return _indexing != rhs._indexing || _search != rhs._search;
    }
};


/**
 * Controls file access for writing attributes to disk.
 */
class TuneFileAttributes
{
public:
    TuneFileSeqWrite _write;

    TuneFileAttributes() noexcept : _write() { }

    bool operator==(const TuneFileAttributes &rhs) const {
        return _write == rhs._write;
    }

    bool operator!=(const TuneFileAttributes &rhs) const {
        return _write != rhs._write;
    }
};


/**
 * Controls file access for summaries (docstore).
 */
class TuneFileSummary
{
public:
    TuneFileSeqRead  _seqRead;
    TuneFileSeqWrite _write;
    TuneFileRandRead _randRead;

    TuneFileSummary() noexcept : _seqRead(), _write(), _randRead() { }

    bool operator==(const TuneFileSummary &rhs) const {
        return _seqRead == rhs._seqRead &&
                 _write == rhs._write &&
              _randRead == rhs._randRead;
    }

    bool operator!=(const TuneFileSummary &rhs) const {
        return _seqRead != rhs._seqRead ||
                 _write != rhs._write ||
              _randRead != rhs._randRead;
    }
};


/**
 * Controls file access for document db, i.e. "everything".
 */
class TuneFileDocumentDB
{
public:
    using SP = std::shared_ptr<TuneFileDocumentDB>;

    TuneFileIndexManager _index;
    TuneFileAttributes _attr;
    TuneFileSummary _summary;

    TuneFileDocumentDB() noexcept : _index(), _attr(), _summary() { }

    bool operator==(const TuneFileDocumentDB &rhs) const {
        return _index == rhs._index &&
                _attr == rhs._attr &&
                _summary == rhs._summary;
    }

    bool operator!=(const TuneFileDocumentDB &rhs) const {
        return _index != rhs._index ||
                _attr != rhs._attr ||
                _summary != rhs._summary;
    }
};

}