aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storage/visiting/dumpvisitorsingle.cpp
blob: 50d77634a78760d504f9a3c5021b8f8785fbe826 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "dumpvisitorsingle.h"
#include <vespa/persistence/spi/docentry.h>
#include <vespa/document/update/documentupdate.h>
#include <vespa/document/fieldvalue/document.h>
#include <vespa/documentapi/messagebus/messages/putdocumentmessage.h>
#include <vespa/documentapi/messagebus/messages/removedocumentmessage.h>

#include <vespa/log/log.h>
LOG_SETUP(".visitor.instance.dumpvisitorsingle");

namespace storage {

DumpVisitorSingle::DumpVisitorSingle(StorageComponent& component, const vdslib::Parameters&)
    : Visitor(component)
{
}

void DumpVisitorSingle::handleDocuments(const document::BucketId&,
                                        DocEntryList& entries,
                                        HitCounter& hitCounter)
{
    LOG(debug, "Visitor %s handling block of %zu documents.",
               _id.c_str(), entries.size());

    for (size_t i = 0; i < entries.size(); ++i) {
        spi::DocEntry& entry(*entries[i]);
        const uint32_t docSize = entry.getSize();
        if (entry.isRemove()) {
            hitCounter.addHit(*entry.getDocumentId(), docSize);
            sendMessage(std::make_unique<documentapi::RemoveDocumentMessage>(*entry.getDocumentId()));
        } else {
            hitCounter.addHit(*entry.getDocumentId(), docSize);
            auto msg = std::make_unique<documentapi::PutDocumentMessage>(entry.releaseDocument());
            msg->setApproxSize(docSize);
            sendMessage(std::move(msg));
        }
    }
}

}