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 Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "rpcmirror.h"
#include <vespa/fnet/frt/supervisor.h>
#include <vespa/fnet/frt/rpcrequest.h>
#include <vespa/log/log.h>
LOG_SETUP(".slobrok.server.rpcmirror");
namespace slobrok {
IncrementalFetch::IncrementalFetch(FRT_Supervisor *orb,
FRT_RPCRequest *req,
ServiceMapHistory &smh,
vespalib::GenCnt gen)
: FNET_Task(orb->GetScheduler()),
_req(req),
_smh(smh),
_gen(gen)
{ }
IncrementalFetch::~IncrementalFetch() { }
void IncrementalFetch::completeReq(MapDiff diff) {
FRT_Values &dst = *_req->GetReturn();
dst.AddInt32(diff.fromGen.getAsInt());
size_t sz = diff.removed.size();
FRT_StringValue *rem = dst.AddStringArray(sz);
for (uint32_t i = 0; i < sz; ++i) {
dst.SetString(&rem[i], diff.removed[i].c_str());
}
sz = diff.updated.size();
FRT_StringValue *names = dst.AddStringArray(sz);
FRT_StringValue *specs = dst.AddStringArray(sz);
for (uint32_t i = 0; i < sz; ++i) {
dst.SetString(&names[i], diff.updated[i].name.c_str());
dst.SetString(&specs[i], diff.updated[i].spec.c_str());
}
dst.AddInt32(diff.toGen.getAsInt());
LOG(debug, "mirrorFetch %p done (gen %d -> gen %d)",
this, diff.fromGen.getAsInt(), diff.toGen.getAsInt());
_req->Return();
}
void
IncrementalFetch::PerformTask()
{
if (_smh.cancel(this)) {
completeReq(MapDiff(_gen, {}, {}, _gen));
}
}
void IncrementalFetch::handle(MapDiff diff) {
Kill(); // unschedule timeout task
completeReq(std::move(diff));
}
void
IncrementalFetch::invoke(uint32_t msTimeout)
{
_req->Detach();
LOG(debug, "IncrementalFetch %p invoked from %s (gen %d, timeout %d ms)",
this, _req->GetConnection()->GetSpec(), _gen.getAsInt(), msTimeout);
if (msTimeout > 10000)
msTimeout = 10000;
Schedule(msTimeout * 0.001);
_smh.asyncGenerationDiff(this, _gen);
}
} // namespace slobrok
|