aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/common/fileheadercontext.cpp
blob: 9f7773f4db2c81adc9947073ee03f7e8e1473f67 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "fileheadercontext.h"
#include <vespa/vespalib/data/fileheader.h>
#include <chrono>

using namespace std::chrono;

namespace search::common {

using vespalib::GenericHeader;

FileHeaderContext::FileHeaderContext() = default;

FileHeaderContext::~FileHeaderContext() = default;

void
FileHeaderContext::addCreateAndFreezeTime(GenericHeader &header)
{
    using Tag = GenericHeader::Tag;
    header.putTag(Tag("createTime", duration_cast<microseconds>(system_clock::now().time_since_epoch()).count()));
    header.putTag(Tag("freezeTime", 0));
}

void
FileHeaderContext::setFreezeTime(GenericHeader &header)
{
    using Tag = GenericHeader::Tag;
    if (header.hasTag("freezeTime") &&
        header.getTag("freezeTime").getType() == Tag::TYPE_INTEGER) {
        header.putTag(Tag("freezeTime", duration_cast<microseconds>(system_clock::now().time_since_epoch()).count()));
    }
}

}