Skip to content

Commit cb73352

Browse files
committed
Don't pop every generation of old log router
1 parent 6bf1e39 commit cb73352

File tree

2 files changed

+65
-28
lines changed

2 files changed

+65
-28
lines changed

fdbserver/TagPartitionedLogSystem.actor.cpp

+59-27
Original file line numberDiff line numberDiff line change
@@ -1357,42 +1357,67 @@ Future<Void> TagPartitionedLogSystem::onKnownCommittedVersionChange() {
13571357
return waitForAny(result);
13581358
}
13591359

1360-
void TagPartitionedLogSystem::popLogRouter(
1361-
Version upTo,
1362-
Tag tag,
1363-
Version durableKnownCommittedVersion,
1364-
int8_t popLocality) { // FIXME: do not need to pop all generations of old logs
1360+
void TagPartitionedLogSystem::popLogRouter(Version upTo,
1361+
Tag tag,
1362+
Version durableKnownCommittedVersion,
1363+
int8_t popLocality) {
13651364
if (!upTo)
13661365
return;
1367-
for (auto& t : tLogs) {
1368-
if (t->locality == popLocality) {
1369-
for (auto& log : t->logRouters) {
1370-
Version prev = outstandingPops[std::make_pair(log->get().id(), tag)].first;
1371-
if (prev < upTo)
1372-
outstandingPops[std::make_pair(log->get().id(), tag)] =
1373-
std::make_pair(upTo, durableKnownCommittedVersion);
1374-
if (prev == 0) {
1375-
popActors.add(popFromLog(
1376-
this, log, tag, 0.0)); // Fast pop time because log routers can only hold 5 seconds of data.
1377-
}
1378-
}
1379-
}
1380-
}
13811366

1382-
for (auto& old : oldLogData) {
1383-
for (auto& t : old.tLogs) {
1367+
Version lastGenerationStartVersion = TagPartitionedLogSystem::getMaxLocalStartVersion(tLogs);
1368+
if (upTo >= lastGenerationStartVersion) {
1369+
for (auto& t : tLogs) {
13841370
if (t->locality == popLocality) {
13851371
for (auto& log : t->logRouters) {
13861372
Version prev = outstandingPops[std::make_pair(log->get().id(), tag)].first;
1387-
if (prev < upTo)
1373+
if (prev < upTo) {
13881374
outstandingPops[std::make_pair(log->get().id(), tag)] =
13891375
std::make_pair(upTo, durableKnownCommittedVersion);
1390-
if (prev == 0)
1391-
popActors.add(popFromLog(this, log, tag, 0.0));
1376+
}
1377+
if (prev == 0) {
1378+
popActors.add(popFromLog(this,
1379+
log,
1380+
tag,
1381+
/*delayBeforePop=*/0.0,
1382+
/*popLogRouter=*/true)); // Fast pop time because log routers can only
1383+
// hold 5 seconds of data.
1384+
}
13921385
}
13931386
}
13941387
}
13951388
}
1389+
1390+
Version nextGenerationStartVersion = lastGenerationStartVersion;
1391+
for (const auto& old : oldLogData) {
1392+
Version generationStartVersion = TagPartitionedLogSystem::getMaxLocalStartVersion(old.tLogs);
1393+
if (generationStartVersion <= upTo) {
1394+
for (auto& t : old.tLogs) {
1395+
if (t->locality == popLocality) {
1396+
for (auto& log : t->logRouters) {
1397+
auto logRouterIdTagPair = std::make_pair(log->get().id(), tag);
1398+
1399+
// We pop the log router only if the popped version is within this generation's version range.
1400+
// That is between the current generation's start version and the next generation's start
1401+
// version.
1402+
if (logRouterLastPops.find(logRouterIdTagPair) == logRouterLastPops.end() ||
1403+
logRouterLastPops[logRouterIdTagPair] < nextGenerationStartVersion) {
1404+
Version prev = outstandingPops[logRouterIdTagPair].first;
1405+
if (prev < upTo) {
1406+
outstandingPops[logRouterIdTagPair] =
1407+
std::make_pair(upTo, durableKnownCommittedVersion);
1408+
}
1409+
if (prev == 0) {
1410+
popActors.add(
1411+
popFromLog(this, log, tag, /*delayBeforePop=*/0.0, /*popLogRouter=*/true));
1412+
}
1413+
}
1414+
}
1415+
}
1416+
}
1417+
}
1418+
1419+
nextGenerationStartVersion = generationStartVersion;
1420+
}
13961421
}
13971422

13981423
void TagPartitionedLogSystem::popTxs(Version upTo, int8_t popLocality) {
@@ -1424,7 +1449,8 @@ void TagPartitionedLogSystem::pop(Version upTo, Tag tag, Version durableKnownCom
14241449
}
14251450
if (prev == 0) {
14261451
// pop tag from log upto version defined in outstandingPops[].first
1427-
popActors.add(popFromLog(this, log, tag, 1.0)); //< FIXME: knob
1452+
popActors.add(
1453+
popFromLog(this, log, tag, /*delayBeforePop*/ 1.0, /*popLogRouter=*/false)); //< FIXME: knob
14281454
}
14291455
}
14301456
}
@@ -1434,10 +1460,11 @@ void TagPartitionedLogSystem::pop(Version upTo, Tag tag, Version durableKnownCom
14341460
ACTOR Future<Void> TagPartitionedLogSystem::popFromLog(TagPartitionedLogSystem* self,
14351461
Reference<AsyncVar<OptionalInterface<TLogInterface>>> log,
14361462
Tag tag,
1437-
double time) {
1463+
double delayBeforePop,
1464+
bool popLogRouter) {
14381465
state Version last = 0;
14391466
loop {
1440-
wait(delay(time, TaskPriority::TLogPop));
1467+
wait(delay(delayBeforePop, TaskPriority::TLogPop));
14411468

14421469
// to: first is upto version, second is durableKnownComittedVersion
14431470
state std::pair<Version, Version> to = self->outstandingPops[std::make_pair(log->get().id(), tag)];
@@ -1453,6 +1480,10 @@ ACTOR Future<Void> TagPartitionedLogSystem::popFromLog(TagPartitionedLogSystem*
14531480
wait(log->get().interf().popMessages.getReply(TLogPopRequest(to.first, to.second, tag),
14541481
TaskPriority::TLogPop));
14551482

1483+
if (popLogRouter) {
1484+
self->logRouterLastPops[std::make_pair(log->get().id(), tag)] = to.first;
1485+
}
1486+
14561487
last = to.first;
14571488
} catch (Error& e) {
14581489
if (e.code() == error_code_actor_cancelled)
@@ -2843,6 +2874,7 @@ ACTOR Future<Reference<ILogSystem>> TagPartitionedLogSystem::newEpoch(
28432874
.detail("OldLogRouterTags", oldLogSystem->logRouterTags);
28442875
if (oldLogSystem->logRouterTags > 0 ||
28452876
logSystem->tLogs[0]->startVersion < oldLogSystem->knownCommittedVersion + 1) {
2877+
// Use log routers to recover [knownCommittedVersion, recoveryVersion] from the old generation.
28462878
oldRouterRecruitment = TagPartitionedLogSystem::recruitOldLogRouters(oldLogSystem.getPtr(),
28472879
recr.oldLogRouters,
28482880
recoveryCount,

fdbserver/TagPartitionedLogSystem.actor.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ struct TagPartitionedLogSystem final : ILogSystem, ReferenceCounted<TagPartition
115115
// sending a pop for anything less than durableKnownCommittedVersion for the TLog will be absurd.
116116
std::map<std::pair<UID, Tag>, std::pair<Version, Version>> outstandingPops;
117117

118+
// Stores each <log router, tag> pair's last popped version. This is used to determine whether we need to pop an old
119+
// generation log router.
120+
std::map<std::pair<UID, Tag>, Version> logRouterLastPops;
121+
118122
Optional<PromiseStream<Future<Void>>> addActor;
119123
ActorCollection popActors;
120124
std::vector<OldLogData> oldLogData; // each element has the log info. in one old epoch.
@@ -246,7 +250,8 @@ struct TagPartitionedLogSystem final : ILogSystem, ReferenceCounted<TagPartition
246250
ACTOR static Future<Void> popFromLog(TagPartitionedLogSystem* self,
247251
Reference<AsyncVar<OptionalInterface<TLogInterface>>> log,
248252
Tag tag,
249-
double time);
253+
double delayBeforePop,
254+
bool popLogRouter);
250255

251256
ACTOR static Future<Version> getPoppedFromTLog(Reference<AsyncVar<OptionalInterface<TLogInterface>>> log, Tag tag);
252257

0 commit comments

Comments
 (0)