aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcorespi/index/indexdisklayout.cpp
blob: ebe148e5c66270a77dfb0e150caaf4bba360ce4c (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "indexdisklayout.h"
#include "index_disk_dir.h"
#include <sstream>

namespace searchcorespi::index {

const vespalib::string
IndexDiskLayout::FlushDirPrefix = vespalib::string("index.flush.");

const vespalib::string
IndexDiskLayout::FusionDirPrefix = vespalib::string("index.fusion.");

const vespalib::string
IndexDiskLayout::SerialNumTag = vespalib::string("Serial num");

IndexDiskLayout::IndexDiskLayout(const vespalib::string &baseDir)
    : _baseDir(baseDir)
{
}

vespalib::string
IndexDiskLayout::getFlushDir(uint32_t sourceId) const
{
    std::ostringstream ost;
    ost << _baseDir << "/" << FlushDirPrefix << sourceId;
    return ost.str();
}

vespalib::string
IndexDiskLayout::getFusionDir(uint32_t sourceId) const
{
    std::ostringstream ost;
    ost << _baseDir << "/" << FusionDirPrefix << sourceId;
    return ost.str();
}

vespalib::string
IndexDiskLayout::getSerialNumFileName(const vespalib::string &dir)
{
    return dir + "/serial.dat";
}

vespalib::string
IndexDiskLayout::getSchemaFileName(const vespalib::string &dir)
{
    return dir + "/schema.txt";
}

vespalib::string
IndexDiskLayout::getSelectorFileName(const vespalib::string &dir)
{
    return dir + "/selector";
}

IndexDiskDir
IndexDiskLayout::get_index_disk_dir(const vespalib::string& dir)
{
    auto name = dir.substr(dir.rfind('/') + 1);
    const vespalib::string* prefix = nullptr;
    bool fusion = false;
    if (name.find(FlushDirPrefix) == 0) {
        prefix = &FlushDirPrefix;
    } else if (name.find(FusionDirPrefix) == 0) {
        prefix = &FusionDirPrefix;
        fusion = true;
    } else {
        return IndexDiskDir(); // invalid
    }
    std::istringstream ist(name.substr(prefix->size()));
    uint32_t id = 0;
    ist >> id;
    return IndexDiskDir(id, fusion); // invalid if id == 0u
}

}