aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storage/visiting/testvisitor.cpp
blob: 10c79ea6f1859ee3eb7a31727905016382cb400e (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
78
79
80
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "testvisitor.h"
#include <vespa/persistence/spi/docentry.h>
#include <vespa/documentapi/messagebus/messages/visitor.h>
#include <sstream>

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

namespace storage {

TestVisitor::TestVisitor(StorageComponent& c,
                         const vdslib::Parameters& params)
    : Visitor(c),
      _params()
{
    std::ostringstream ost;
    for (vdslib::Parameters::ParametersMap::const_iterator
             it(params.begin()), mt(params.end()); it != mt; ++it)
    {
        ost << "\n  " << it->first << " = " << it->second.c_str();
    }
    _params = ost.str();
    LOG(debug, "Created TestVisitor: %s", _params.c_str());
}

void
TestVisitor::startingVisitor(const std::vector<document::BucketId>& buckets)
{
    std::ostringstream ost;
    ost << "Starting visitor with given parameters:" << _params << "\n"
        << "Visiting the following bucket time intervals:\n";
    for (uint32_t i=0, n=buckets.size(); i<n; ++i) {
        ost << "  " << buckets[i] << "\n";
    }
    LOG(debug, "%s", ost.str().c_str());
    report(ost.str());
}

void
TestVisitor::handleDocuments(const document::BucketId& /*bucketId*/,
                             DocEntryList & entries,
                             HitCounter& /*hitCounter*/)
{
    std::ostringstream ost;
    ost << "Handling block of " << entries.size() << " documents.\n";
    LOG(debug, "%s", ost.str().c_str());
    report(ost.str());
}

void TestVisitor::completedBucket(const document::BucketId& bucket, HitCounter&)
{
    std::ostringstream ost;
    ost << "completedBucket(" << bucket.getId() << ")\n";
    LOG(debug, "%s", ost.str().c_str());
    report(ost.str());
}

void TestVisitor::completedVisiting(HitCounter&)
{
    LOG(debug, "completedVisiting()");
    report("completedVisiting()\n");
}

void TestVisitor::abortedVisiting()
{
    LOG(debug, "abortedVisiting()");
    report("abortedVisiting()\n");
}

void TestVisitor::report(const std::string& message) {
    // As we have no existing way of sending a single message back to the
    // client, use a map visitor command
    documentapi::MapVisitorMessage* cmd = new documentapi::MapVisitorMessage();
    cmd->getData().set("msg", message);
    sendMessage(documentapi::DocumentMessage::UP(cmd));
}

}