aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/server/document_scan_iterator.cpp
blob: 35c4e34a15471a0143209c6edc73183bde529f1e (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "document_scan_iterator.h"
#include <vespa/searchcore/proton/documentmetastore/i_document_meta_store.h>

using search::DocumentMetaData;

namespace proton {

using Iterator = IDocumentMetaStore::Iterator;

DocumentScanIterator::DocumentScanIterator(const IDocumentMetaStore &metaStore)
    : _metaStore(metaStore),
      _lastLid(_metaStore.getCommittedDocIdLimit()),
      _itrValid(true)
{
}

bool
DocumentScanIterator::valid() const
{
    return _itrValid;
}

DocumentMetaData
DocumentScanIterator::next(uint32_t compactLidLimit)
{
    for (--_lastLid; _lastLid > compactLidLimit; --_lastLid) {
        if (_metaStore.validLid(_lastLid)) {
            const RawDocumentMetaData &metaData = _metaStore.getRawMetaData(_lastLid);
            return DocumentMetaData(_lastLid, metaData.getTimestamp(),
                                    metaData.getBucketId(), metaData.getGid());
        }
    }
    _itrValid = (_lastLid > compactLidLimit) ;
    return DocumentMetaData();
}

} // namespace proton