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
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once
#include "randread.h"
#include <vespa/vespalib/util/ptrholder.h>
#include <vespa/vespalib/stllike/string.h>
class FastOS_FileInterface;
namespace search {
class DirectIORandRead : public FileRandRead
{
public:
DirectIORandRead(const vespalib::string & fileName);
FSP read(size_t offset, vespalib::DataBuffer & buffer, size_t sz) override;
int64_t getSize() const override;
private:
std::unique_ptr<FastOS_FileInterface> _file;
size_t _alignment;
size_t _granularity;
size_t _maxChunkSize;
};
class MMapRandRead : public FileRandRead
{
public:
MMapRandRead(const vespalib::string & fileName, int mmapFlags, int fadviseOptions);
FSP read(size_t offset, vespalib::DataBuffer & buffer, size_t sz) override;
int64_t getSize() const override;
const void * getMapping();
private:
std::unique_ptr<FastOS_FileInterface> _file;
};
class MMapRandReadDynamic : public FileRandRead
{
public:
MMapRandReadDynamic(const vespalib::string & fileName, int mmapFlags, int fadviseOptions);
FSP read(size_t offset, vespalib::DataBuffer & buffer, size_t sz) override;
int64_t getSize() const override;
private:
static bool contains(const FastOS_FileInterface & file, size_t sz);
void remap(size_t end);
vespalib::string _fileName;
vespalib::PtrHolder<FastOS_FileInterface> _holder;
int _mmapFlags;
int _fadviseOptions;
std::mutex _lock;
};
class NormalRandRead : public FileRandRead
{
public:
NormalRandRead(const vespalib::string & fileName);
FSP read(size_t offset, vespalib::DataBuffer & buffer, size_t sz) override;
int64_t getSize() const override;
private:
std::unique_ptr<FastOS_FileInterface> _file;
};
}
|