2017-06-30 06:50:19 +08:00
|
|
|
/*
|
|
|
|
* LogRouter.actor.cpp
|
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
|
|
|
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "flow/actorcompiler.h"
|
|
|
|
#include "flow/ActorCollection.h"
|
|
|
|
#include "fdbclient/NativeAPI.h"
|
|
|
|
#include "WorkerInterface.h"
|
|
|
|
#include "WaitFailure.h"
|
|
|
|
#include "Knobs.h"
|
|
|
|
#include "ServerDBInfo.h"
|
|
|
|
#include "LogSystem.h"
|
|
|
|
#include "fdbclient/SystemData.h"
|
|
|
|
#include "ApplyMetadataMutation.h"
|
|
|
|
#include "RecoveryState.h"
|
|
|
|
#include "fdbclient/Atomic.h"
|
|
|
|
#include "flow/TDMetric.actor.h"
|
|
|
|
#include "flow/Stats.h"
|
|
|
|
|
|
|
|
struct LogRouterData {
|
2018-03-18 02:08:37 +08:00
|
|
|
struct TagData : NonCopyable, public ReferenceCounted<TagData> {
|
2017-06-30 06:50:19 +08:00
|
|
|
std::deque<std::pair<Version, LengthPrefixedStringRef>> version_messages;
|
|
|
|
Version popped;
|
2018-04-19 03:07:29 +08:00
|
|
|
Version knownCommittedVersion;
|
2018-03-18 02:08:37 +08:00
|
|
|
Tag tag;
|
2017-06-30 06:50:19 +08:00
|
|
|
|
2018-04-19 03:07:29 +08:00
|
|
|
TagData( Tag tag, Version popped, Version knownCommittedVersion ) : tag(tag), popped(popped), knownCommittedVersion(knownCommittedVersion) {}
|
2017-06-30 06:50:19 +08:00
|
|
|
|
2018-04-19 03:07:29 +08:00
|
|
|
TagData(TagData&& r) noexcept(true) : version_messages(std::move(r.version_messages)), tag(r.tag), popped(r.popped), knownCommittedVersion(r.knownCommittedVersion) {}
|
2017-06-30 06:50:19 +08:00
|
|
|
void operator= (TagData&& r) noexcept(true) {
|
|
|
|
version_messages = std::move(r.version_messages);
|
2018-03-18 02:08:37 +08:00
|
|
|
tag = r.tag;
|
2017-06-30 06:50:19 +08:00
|
|
|
popped = r.popped;
|
2018-04-19 03:07:29 +08:00
|
|
|
knownCommittedVersion = r.knownCommittedVersion;
|
2017-06-30 06:50:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Erase messages not needed to update *from* versions >= before (thus, messages with toversion <= before)
|
|
|
|
ACTOR Future<Void> eraseMessagesBefore( TagData *self, Version before, LogRouterData *tlogData, int taskID ) {
|
|
|
|
while(!self->version_messages.empty() && self->version_messages.front().first < before) {
|
|
|
|
Version version = self->version_messages.front().first;
|
|
|
|
int64_t messagesErased = 0;
|
|
|
|
|
|
|
|
while(!self->version_messages.empty() && self->version_messages.front().first == version) {
|
|
|
|
auto const& m = self->version_messages.front();
|
|
|
|
++messagesErased;
|
|
|
|
|
|
|
|
self->version_messages.pop_front();
|
|
|
|
}
|
|
|
|
|
|
|
|
Void _ = wait(yield(taskID));
|
|
|
|
}
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<Void> eraseMessagesBefore(Version before, LogRouterData *tlogData, int taskID) {
|
|
|
|
return eraseMessagesBefore(this, before, tlogData, taskID);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
UID dbgid;
|
|
|
|
Reference<AsyncVar<Reference<ILogSystem>>> logSystem;
|
|
|
|
NotifiedVersion version;
|
2018-03-30 06:12:38 +08:00
|
|
|
NotifiedVersion minPopped;
|
2018-04-13 07:15:17 +08:00
|
|
|
Version startVersion;
|
2018-06-22 06:29:46 +08:00
|
|
|
Version minKnownCommittedVersion;
|
2017-06-30 06:50:19 +08:00
|
|
|
Deque<std::pair<Version, Standalone<VectorRef<uint8_t>>>> messageBlocks;
|
|
|
|
Tag routerTag;
|
2018-04-18 06:03:22 +08:00
|
|
|
bool allowPops;
|
2018-04-29 09:04:57 +08:00
|
|
|
LogSet logSet;
|
2017-06-30 06:50:19 +08:00
|
|
|
|
2018-03-18 02:08:37 +08:00
|
|
|
std::vector<Reference<TagData>> tag_data; //we only store data for the remote tag locality
|
|
|
|
|
|
|
|
Reference<TagData> getTagData(Tag tag) {
|
|
|
|
ASSERT(tag.locality == tagLocalityRemoteLog);
|
|
|
|
if(tag.id >= tag_data.size()) {
|
|
|
|
tag_data.resize(tag.id+1);
|
|
|
|
}
|
|
|
|
return tag_data[tag.id];
|
|
|
|
}
|
|
|
|
|
|
|
|
//only callable after getTagData returns a null reference
|
2018-04-19 03:07:29 +08:00
|
|
|
Reference<TagData> createTagData(Tag tag, Version popped, Version knownCommittedVersion) {
|
|
|
|
Reference<TagData> newTagData = Reference<TagData>( new TagData(tag, popped, knownCommittedVersion) );
|
2018-03-18 02:08:37 +08:00
|
|
|
tag_data[tag.id] = newTagData;
|
|
|
|
return newTagData;
|
|
|
|
}
|
|
|
|
|
2018-06-22 06:29:46 +08:00
|
|
|
LogRouterData(UID dbgid, InitializeLogRouterRequest req) : dbgid(dbgid), routerTag(req.routerTag), logSystem(new AsyncVar<Reference<ILogSystem>>()), version(req.startVersion-1), minPopped(req.startVersion-1), startVersion(req.startVersion), allowPops(false), minKnownCommittedVersion(0) {
|
2018-04-29 09:04:57 +08:00
|
|
|
//setup just enough of a logSet to be able to call getPushLocations
|
|
|
|
logSet.logServers.resize(req.tLogLocalities.size());
|
|
|
|
logSet.tLogPolicy = req.tLogPolicy;
|
2018-04-30 04:47:32 +08:00
|
|
|
logSet.locality = req.locality;
|
2018-04-29 09:04:57 +08:00
|
|
|
logSet.updateLocalitySet(req.tLogLocalities);
|
2018-05-01 01:58:41 +08:00
|
|
|
|
|
|
|
for(int i = 0; i < req.tLogLocalities.size(); i++) {
|
|
|
|
Tag tag(tagLocalityRemoteLog, i);
|
|
|
|
auto tagData = getTagData(tag);
|
|
|
|
if(!tagData) {
|
|
|
|
tagData = createTagData(tag, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
2018-04-29 09:04:57 +08:00
|
|
|
}
|
2017-06-30 06:50:19 +08:00
|
|
|
};
|
|
|
|
|
2018-03-17 02:40:21 +08:00
|
|
|
void commitMessages( LogRouterData* self, Version version, const std::vector<TagsAndMessage>& taggedMessages ) {
|
|
|
|
if(!taggedMessages.size()) {
|
2017-06-30 06:50:19 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-17 02:40:21 +08:00
|
|
|
int msgSize = 0;
|
|
|
|
for(auto& i : taggedMessages) {
|
|
|
|
msgSize += i.message.size();
|
|
|
|
}
|
2017-06-30 06:50:19 +08:00
|
|
|
|
|
|
|
// Grab the last block in the blocks list so we can share its arena
|
|
|
|
// We pop all of the elements of it to create a "fresh" vector that starts at the end of the previous vector
|
|
|
|
Standalone<VectorRef<uint8_t>> block;
|
|
|
|
if(self->messageBlocks.empty()) {
|
|
|
|
block = Standalone<VectorRef<uint8_t>>();
|
2018-03-17 02:40:21 +08:00
|
|
|
block.reserve(block.arena(), std::max<int64_t>(SERVER_KNOBS->TLOG_MESSAGE_BLOCK_BYTES, msgSize));
|
2017-06-30 06:50:19 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
block = self->messageBlocks.back().second;
|
|
|
|
}
|
|
|
|
|
|
|
|
block.pop_front(block.size());
|
|
|
|
|
2018-03-17 02:40:21 +08:00
|
|
|
for(auto& msg : taggedMessages) {
|
|
|
|
if(msg.message.size() > block.capacity() - block.size()) {
|
2017-06-30 06:50:19 +08:00
|
|
|
self->messageBlocks.push_back( std::make_pair(version, block) );
|
2018-03-17 02:40:21 +08:00
|
|
|
block = Standalone<VectorRef<uint8_t>>();
|
|
|
|
block.reserve(block.arena(), std::max<int64_t>(SERVER_KNOBS->TLOG_MESSAGE_BLOCK_BYTES, msgSize));
|
2017-06-30 06:50:19 +08:00
|
|
|
}
|
|
|
|
|
2018-03-17 02:40:21 +08:00
|
|
|
block.append(block.arena(), msg.message.begin(), msg.message.size());
|
|
|
|
for(auto& tag : msg.tags) {
|
2018-03-18 02:08:37 +08:00
|
|
|
auto tagData = self->getTagData(tag);
|
|
|
|
if(!tagData) {
|
2018-04-19 03:07:29 +08:00
|
|
|
tagData = self->createTagData(tag, 0, 0);
|
2018-03-17 02:40:21 +08:00
|
|
|
}
|
2017-06-30 06:50:19 +08:00
|
|
|
|
2018-03-18 02:08:37 +08:00
|
|
|
if (version >= tagData->popped) {
|
|
|
|
tagData->version_messages.push_back(std::make_pair(version, LengthPrefixedStringRef((uint32_t*)(block.end() - msg.message.size()))));
|
|
|
|
if(tagData->version_messages.back().second.expectedSize() > SERVER_KNOBS->MAX_MESSAGE_SIZE) {
|
|
|
|
TraceEvent(SevWarnAlways, "LargeMessage").detail("Size", tagData->version_messages.back().second.expectedSize());
|
2017-06-30 06:50:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-06-22 06:29:46 +08:00
|
|
|
|
2018-03-17 02:40:21 +08:00
|
|
|
msgSize -= msg.message.size();
|
2017-06-30 06:50:19 +08:00
|
|
|
}
|
2018-03-17 02:40:21 +08:00
|
|
|
self->messageBlocks.push_back( std::make_pair(version, block) );
|
2017-06-30 06:50:19 +08:00
|
|
|
}
|
|
|
|
|
2018-04-29 09:04:57 +08:00
|
|
|
ACTOR Future<Void> pullAsyncData( LogRouterData *self ) {
|
2017-06-30 06:50:19 +08:00
|
|
|
state Future<Void> dbInfoChange = Void();
|
|
|
|
state Reference<ILogSystem::IPeekCursor> r;
|
2018-04-18 02:16:48 +08:00
|
|
|
state Version tagAt = self->version.get() + 1;
|
2017-06-30 06:50:19 +08:00
|
|
|
state Version tagPopped = 0;
|
|
|
|
state Version lastVer = 0;
|
2017-07-10 05:46:16 +08:00
|
|
|
state std::vector<int> tags;
|
2017-06-30 06:50:19 +08:00
|
|
|
|
|
|
|
loop {
|
|
|
|
loop {
|
|
|
|
choose {
|
2018-06-19 08:36:40 +08:00
|
|
|
when(Void _ = wait( r ? r->getMore(TaskTLogCommit) : Never() ) ) {
|
2017-06-30 06:50:19 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
when( Void _ = wait( dbInfoChange ) ) { //FIXME: does this actually happen?
|
|
|
|
if(r) tagPopped = std::max(tagPopped, r->popped());
|
|
|
|
if( self->logSystem->get() )
|
2018-05-01 04:36:35 +08:00
|
|
|
r = self->logSystem->get()->peekLogRouter( self->dbgid, tagAt, self->routerTag );
|
2017-06-30 06:50:19 +08:00
|
|
|
else
|
|
|
|
r = Reference<ILogSystem::IPeekCursor>();
|
|
|
|
dbInfoChange = self->logSystem->onChange();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-22 06:29:46 +08:00
|
|
|
self->minKnownCommittedVersion = std::max(self->minKnownCommittedVersion, r->getMinKnownCommittedVersion());
|
|
|
|
|
2018-03-30 06:12:38 +08:00
|
|
|
state Version ver = 0;
|
|
|
|
state std::vector<TagsAndMessage> messages;
|
2017-06-30 06:50:19 +08:00
|
|
|
while (true) {
|
2018-03-30 06:12:38 +08:00
|
|
|
state bool foundMessage = r->hasMessage();
|
2017-06-30 06:50:19 +08:00
|
|
|
if (!foundMessage || r->version().version != ver) {
|
|
|
|
ASSERT(r->version().version > lastVer);
|
|
|
|
if (ver) {
|
2018-04-09 12:24:05 +08:00
|
|
|
Void _ = wait(self->minPopped.whenAtLeast(std::min(self->version.get(), ver - SERVER_KNOBS->MAX_READ_TRANSACTION_LIFE_VERSIONS)));
|
2018-03-17 02:40:21 +08:00
|
|
|
commitMessages(self, ver, messages);
|
2017-06-30 06:50:19 +08:00
|
|
|
self->version.set( ver );
|
2018-06-09 02:11:08 +08:00
|
|
|
//TraceEvent("LogRouterVersion").detail("Ver",ver);
|
2017-06-30 06:50:19 +08:00
|
|
|
}
|
|
|
|
lastVer = ver;
|
|
|
|
ver = r->version().version;
|
2018-03-17 02:40:21 +08:00
|
|
|
messages.clear();
|
2017-06-30 06:50:19 +08:00
|
|
|
|
|
|
|
if (!foundMessage) {
|
|
|
|
ver--; //ver is the next possible version we will get data for
|
|
|
|
if(ver > self->version.get()) {
|
2018-04-09 12:24:05 +08:00
|
|
|
Void _ = wait(self->minPopped.whenAtLeast(std::min(self->version.get(), ver - SERVER_KNOBS->MAX_READ_TRANSACTION_LIFE_VERSIONS)));
|
2017-06-30 06:50:19 +08:00
|
|
|
self->version.set( ver );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-17 02:40:21 +08:00
|
|
|
TagsAndMessage tagAndMsg;
|
|
|
|
tagAndMsg.message = r->getMessageWithTags();
|
2017-06-30 06:50:19 +08:00
|
|
|
tags.clear();
|
2018-04-29 09:04:57 +08:00
|
|
|
self->logSet.getPushLocations(r->getTags(), tags, 0);
|
2017-10-06 08:09:44 +08:00
|
|
|
for(auto t : tags) {
|
2018-03-17 02:40:21 +08:00
|
|
|
tagAndMsg.tags.push_back(Tag(tagLocalityRemoteLog, t));
|
2017-06-30 06:50:19 +08:00
|
|
|
}
|
2018-03-17 02:40:21 +08:00
|
|
|
messages.push_back(std::move(tagAndMsg));
|
2017-06-30 06:50:19 +08:00
|
|
|
|
|
|
|
r->nextMessage();
|
|
|
|
}
|
|
|
|
|
2018-04-20 05:33:31 +08:00
|
|
|
tagAt = std::max( r->version().version, self->version.get() + 1 );
|
2017-06-30 06:50:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::deque<std::pair<Version, LengthPrefixedStringRef>> & get_version_messages( LogRouterData* self, Tag tag ) {
|
2018-03-18 02:08:37 +08:00
|
|
|
auto tagData = self->getTagData(tag);
|
|
|
|
if (!tagData) {
|
2017-06-30 06:50:19 +08:00
|
|
|
static std::deque<std::pair<Version, LengthPrefixedStringRef>> empty;
|
|
|
|
return empty;
|
|
|
|
}
|
2018-03-18 02:08:37 +08:00
|
|
|
return tagData->version_messages;
|
2017-06-30 06:50:19 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void peekMessagesFromMemory( LogRouterData* self, TLogPeekRequest const& req, BinaryWriter& messages, Version& endVersion ) {
|
|
|
|
ASSERT( !messages.getLength() );
|
|
|
|
|
|
|
|
auto& deque = get_version_messages(self, req.tag);
|
2018-06-09 02:11:08 +08:00
|
|
|
//TraceEvent("TLogPeekMem", self->dbgid).detail("Tag", printable(req.tag1)).detail("PDS", self->persistentDataSequence).detail("PDDS", self->persistentDataDurableSequence).detail("Oldest", map1.empty() ? 0 : map1.begin()->key ).detail("OldestMsgCount", map1.empty() ? 0 : map1.begin()->value.size());
|
2017-06-30 06:50:19 +08:00
|
|
|
|
|
|
|
auto it = std::lower_bound(deque.begin(), deque.end(), std::make_pair(req.begin, LengthPrefixedStringRef()), CompareFirst<std::pair<Version, LengthPrefixedStringRef>>());
|
|
|
|
|
|
|
|
Version currentVersion = -1;
|
|
|
|
for(; it != deque.end(); ++it) {
|
|
|
|
if(it->first != currentVersion) {
|
|
|
|
if (messages.getLength() >= SERVER_KNOBS->DESIRED_TOTAL_BYTES) {
|
2018-04-19 07:06:44 +08:00
|
|
|
endVersion = currentVersion + 1;
|
2018-06-09 02:11:08 +08:00
|
|
|
//TraceEvent("TLogPeekMessagesReached2", self->dbgid);
|
2017-06-30 06:50:19 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
currentVersion = it->first;
|
|
|
|
messages << int32_t(-1) << currentVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
messages << it->second.toStringRef();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Version poppedVersion( LogRouterData* self, Tag tag) {
|
2018-03-18 02:08:37 +08:00
|
|
|
auto tagData = self->getTagData(tag);
|
|
|
|
if (!tagData)
|
2017-06-30 06:50:19 +08:00
|
|
|
return Version(0);
|
2018-03-18 02:08:37 +08:00
|
|
|
return tagData->popped;
|
2017-06-30 06:50:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR Future<Void> logRouterPeekMessages( LogRouterData* self, TLogPeekRequest req ) {
|
|
|
|
state BinaryWriter messages(Unversioned());
|
|
|
|
|
2018-06-09 02:11:08 +08:00
|
|
|
//TraceEvent("LogRouterPeek1", self->dbgid).detail("From", req.reply.getEndpoint().address).detail("Ver", self->version.get()).detail("Begin", req.begin);
|
2017-06-30 06:50:19 +08:00
|
|
|
if( req.returnIfBlocked && self->version.get() < req.begin ) {
|
|
|
|
//TraceEvent("LogRouterPeek2", self->dbgid);
|
|
|
|
req.reply.sendError(end_of_stream());
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( self->version.get() < req.begin ) {
|
|
|
|
Void _ = wait( self->version.whenAtLeast( req.begin ) );
|
|
|
|
Void _ = wait( delay(SERVER_KNOBS->TLOG_PEEK_DELAY, g_network->getCurrentTask()) );
|
|
|
|
}
|
|
|
|
|
|
|
|
Version poppedVer = poppedVersion(self, req.tag);
|
|
|
|
|
2018-04-13 07:15:17 +08:00
|
|
|
if(poppedVer > req.begin || req.begin < self->startVersion) {
|
2018-04-09 12:24:05 +08:00
|
|
|
//This should only happen if a packet is sent multiple times and the reply is not needed.
|
|
|
|
// Since we are using popped differently, do not send a reply.
|
2018-06-09 02:11:08 +08:00
|
|
|
TraceEvent(SevWarnAlways, "LogRouterPeekPopped", self->dbgid).detail("Begin", req.begin).detail("Popped", poppedVer).detail("Start", self->startVersion);
|
2018-04-09 12:24:05 +08:00
|
|
|
req.reply.send( Never() );
|
2017-06-30 06:50:19 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
Version endVersion = self->version.get() + 1;
|
|
|
|
peekMessagesFromMemory( self, req, messages, endVersion );
|
|
|
|
|
|
|
|
TLogPeekReply reply;
|
|
|
|
reply.maxKnownVersion = self->version.get();
|
2018-06-22 06:29:46 +08:00
|
|
|
reply.minKnownCommittedVersion = self->minKnownCommittedVersion;
|
2017-06-30 06:50:19 +08:00
|
|
|
reply.messages = messages.toStringRef();
|
2018-05-07 00:32:41 +08:00
|
|
|
reply.popped = self->minPopped.get() >= self->startVersion ? self->minPopped.get() : 0;
|
2017-06-30 06:50:19 +08:00
|
|
|
reply.end = endVersion;
|
|
|
|
|
|
|
|
req.reply.send( reply );
|
|
|
|
//TraceEvent("LogRouterPeek4", self->dbgid);
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR Future<Void> logRouterPop( LogRouterData* self, TLogPopRequest req ) {
|
2018-03-18 02:08:37 +08:00
|
|
|
auto tagData = self->getTagData(req.tag);
|
|
|
|
if (!tagData) {
|
2018-04-19 03:07:29 +08:00
|
|
|
tagData = self->createTagData(req.tag, req.to, req.knownCommittedVersion);
|
2018-03-18 02:08:37 +08:00
|
|
|
} else if (req.to > tagData->popped) {
|
|
|
|
tagData->popped = req.to;
|
2018-04-19 03:07:29 +08:00
|
|
|
tagData->knownCommittedVersion = req.knownCommittedVersion;
|
2018-03-18 02:08:37 +08:00
|
|
|
Void _ = wait(tagData->eraseMessagesBefore( req.to, self, TaskTLogPop ));
|
2017-06-30 06:50:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
state Version minPopped = std::numeric_limits<Version>::max();
|
2018-04-19 03:07:29 +08:00
|
|
|
state Version minKnownCommittedVersion = std::numeric_limits<Version>::max();
|
2018-03-18 02:08:37 +08:00
|
|
|
for( auto it : self->tag_data ) {
|
|
|
|
if(it) {
|
|
|
|
minPopped = std::min( it->popped, minPopped );
|
2018-04-19 03:07:29 +08:00
|
|
|
minKnownCommittedVersion = std::min( it->knownCommittedVersion, minKnownCommittedVersion );
|
2018-03-18 02:08:37 +08:00
|
|
|
}
|
2017-06-30 06:50:19 +08:00
|
|
|
}
|
|
|
|
|
2018-06-06 04:42:48 +08:00
|
|
|
while(!self->messageBlocks.empty() && self->messageBlocks.front().first < minPopped) {
|
2017-06-30 06:50:19 +08:00
|
|
|
self->messageBlocks.pop_front();
|
2018-06-19 08:36:40 +08:00
|
|
|
Void _ = wait(yield(TaskTLogPop));
|
2017-06-30 06:50:19 +08:00
|
|
|
}
|
|
|
|
|
2018-04-18 06:03:22 +08:00
|
|
|
if(self->logSystem->get() && self->allowPops) {
|
2018-06-22 06:29:46 +08:00
|
|
|
self->logSystem->get()->pop(std::min(minKnownCommittedVersion, self->minKnownCommittedVersion), self->routerTag);
|
2017-07-16 06:15:03 +08:00
|
|
|
}
|
2017-06-30 06:50:19 +08:00
|
|
|
req.reply.send(Void());
|
2018-04-09 12:24:05 +08:00
|
|
|
self->minPopped.set(std::max(minPopped, self->minPopped.get()));
|
2017-06-30 06:50:19 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR Future<Void> logRouterCore(
|
|
|
|
TLogInterface interf,
|
2018-04-29 09:04:57 +08:00
|
|
|
InitializeLogRouterRequest req,
|
2017-06-30 06:50:19 +08:00
|
|
|
Reference<AsyncVar<ServerDBInfo>> db)
|
|
|
|
{
|
2018-04-29 09:04:57 +08:00
|
|
|
state LogRouterData logRouterData(interf.id(), req);
|
2017-06-30 06:50:19 +08:00
|
|
|
state PromiseStream<Future<Void>> addActor;
|
|
|
|
state Future<Void> error = actorCollection( addActor.getFuture() );
|
|
|
|
state Future<Void> dbInfoChange = Void();
|
|
|
|
|
2018-04-29 09:04:57 +08:00
|
|
|
addActor.send( pullAsyncData(&logRouterData) );
|
2017-06-30 06:50:19 +08:00
|
|
|
|
|
|
|
loop choose {
|
|
|
|
when( Void _ = wait( dbInfoChange ) ) {
|
|
|
|
dbInfoChange = db->onChange();
|
2018-05-09 08:17:17 +08:00
|
|
|
logRouterData.allowPops = db->get().recoveryState == RecoveryState::REMOTE_RECOVERED;
|
2018-06-02 09:42:48 +08:00
|
|
|
logRouterData.logSystem->set(ILogSystem::fromServerDBInfo( logRouterData.dbgid, db->get(), true ));
|
2017-06-30 06:50:19 +08:00
|
|
|
}
|
|
|
|
when( TLogPeekRequest req = waitNext( interf.peekMessages.getFuture() ) ) {
|
|
|
|
addActor.send( logRouterPeekMessages( &logRouterData, req ) );
|
|
|
|
}
|
|
|
|
when( TLogPopRequest req = waitNext( interf.popMessages.getFuture() ) ) {
|
|
|
|
addActor.send( logRouterPop( &logRouterData, req ) );
|
|
|
|
}
|
|
|
|
when (Void _ = wait(error)) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-09 12:24:05 +08:00
|
|
|
ACTOR Future<Void> checkRemoved(Reference<AsyncVar<ServerDBInfo>> db, uint64_t recoveryCount, TLogInterface myInterface) {
|
2017-06-30 06:50:19 +08:00
|
|
|
loop{
|
2018-05-09 08:17:17 +08:00
|
|
|
bool isDisplaced = ( (db->get().recoveryCount > recoveryCount && db->get().recoveryState != RecoveryState::UNINITIALIZED) || (db->get().recoveryCount == recoveryCount && db->get().recoveryState == RecoveryState::REMOTE_RECOVERED) );
|
2018-03-30 06:12:38 +08:00
|
|
|
if(isDisplaced) {
|
|
|
|
for(auto& log : db->get().logSystemConfig.tLogs) {
|
|
|
|
if( std::count( log.logRouters.begin(), log.logRouters.end(), myInterface.id() ) ) {
|
|
|
|
isDisplaced = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(isDisplaced) {
|
|
|
|
for(auto& old : db->get().logSystemConfig.oldTLogs) {
|
|
|
|
for(auto& log : old.tLogs) {
|
|
|
|
if( std::count( log.logRouters.begin(), log.logRouters.end(), myInterface.id() ) ) {
|
|
|
|
isDisplaced = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isDisplaced) {
|
2017-07-10 05:46:16 +08:00
|
|
|
throw worker_removed();
|
|
|
|
}
|
2017-06-30 06:50:19 +08:00
|
|
|
Void _ = wait(db->onChange());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR Future<Void> logRouter(
|
|
|
|
TLogInterface interf,
|
|
|
|
InitializeLogRouterRequest req,
|
|
|
|
Reference<AsyncVar<ServerDBInfo>> db)
|
|
|
|
{
|
|
|
|
try {
|
2018-06-16 03:36:19 +08:00
|
|
|
TraceEvent("LogRouterStart", interf.id()).detail("Start", req.startVersion).detail("Tag", req.routerTag.toString()).detail("Localities", req.tLogLocalities.size()).detail("Locality", req.locality);
|
2018-04-29 09:04:57 +08:00
|
|
|
state Future<Void> core = logRouterCore(interf, req, db);
|
2017-06-30 06:50:19 +08:00
|
|
|
loop choose{
|
|
|
|
when(Void _ = wait(core)) { return Void(); }
|
2018-04-09 12:24:05 +08:00
|
|
|
when(Void _ = wait(checkRemoved(db, req.recoveryCount, interf))) {}
|
2017-06-30 06:50:19 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Error& e) {
|
|
|
|
if (e.code() == error_code_actor_cancelled || e.code() == error_code_worker_removed)
|
|
|
|
{
|
|
|
|
TraceEvent("LogRouterTerminated", interf.id()).error(e, true);
|
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|