Merge branch 'apple:main' into block-down

This commit is contained in:
Bharadwaj V.R 2022-04-20 06:13:01 -07:00 committed by GitHub
commit 89af5561f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 68 additions and 53 deletions

View File

@ -291,8 +291,6 @@ struct TLogData : NonCopyable {
// the set and for callers that unset will // the set and for callers that unset will
// be able to match it up // be able to match it up
std::string dataFolder; // folder where data is stored std::string dataFolder; // folder where data is stored
std::map<Tag, Version> toBePopped; // map of Tag->Version for all the pops
// that came when ignorePopRequest was set
Reference<AsyncVar<bool>> degraded; Reference<AsyncVar<bool>> degraded;
std::vector<TagsAndMessage> tempTagMessages; std::vector<TagsAndMessage> tempTagMessages;
@ -514,6 +512,9 @@ struct LogData : NonCopyable, public ReferenceCounted<LogData> {
bool execOpCommitInProgress; bool execOpCommitInProgress;
int txsTags; int txsTags;
std::map<Tag, Version> toBePopped; // map of Tag->Version for all the pops
// that came when ignorePopRequest was set
explicit LogData(TLogData* tLogData, explicit LogData(TLogData* tLogData,
TLogInterface interf, TLogInterface interf,
Tag remoteTag, Tag remoteTag,
@ -819,8 +820,8 @@ ACTOR Future<Void> tLogPopCore(TLogData* self, Tag inputTag, Version to, Referen
if (self->ignorePopRequest) { if (self->ignorePopRequest) {
TraceEvent(SevDebug, "IgnoringPopRequest").detail("IgnorePopDeadline", self->ignorePopDeadline); TraceEvent(SevDebug, "IgnoringPopRequest").detail("IgnorePopDeadline", self->ignorePopDeadline);
if (self->toBePopped.find(inputTag) == self->toBePopped.end() || to > self->toBePopped[inputTag]) { if (logData->toBePopped.find(inputTag) == logData->toBePopped.end() || to > logData->toBePopped[inputTag]) {
self->toBePopped[inputTag] = to; logData->toBePopped[inputTag] = to;
} }
// add the pop to the toBePopped map // add the pop to the toBePopped map
TraceEvent(SevDebug, "IgnoringPopRequest") TraceEvent(SevDebug, "IgnoringPopRequest")
@ -882,11 +883,11 @@ ACTOR Future<Void> tLogPop(TLogData* self, TLogPopRequest req, Reference<LogData
self->ignorePopRequest = false; self->ignorePopRequest = false;
self->ignorePopUid = ""; self->ignorePopUid = "";
self->ignorePopDeadline = 0.0; self->ignorePopDeadline = 0.0;
for (it = self->toBePopped.begin(); it != self->toBePopped.end(); it++) { for (it = logData->toBePopped.begin(); it != logData->toBePopped.end(); it++) {
TraceEvent("PlayIgnoredPop").detail("Tag", it->first.toString()).detail("Version", it->second); TraceEvent("PlayIgnoredPop").detail("Tag", it->first.toString()).detail("Version", it->second);
ignoredPops.push_back(tLogPopCore(self, it->first, it->second, logData)); ignoredPops.push_back(tLogPopCore(self, it->first, it->second, logData));
} }
self->toBePopped.clear(); logData->toBePopped.clear();
wait(waitForAll(ignoredPops)); wait(waitForAll(ignoredPops));
TraceEvent("ResetIgnorePopRequest") TraceEvent("ResetIgnorePopRequest")
.detail("Now", g_network->now()) .detail("Now", g_network->now())
@ -1937,7 +1938,7 @@ ACTOR Future<Void> tLogEnablePopReq(TLogEnablePopRequest enablePopReq, TLogData*
self->ignorePopRequest = false; self->ignorePopRequest = false;
self->ignorePopDeadline = 0.0; self->ignorePopDeadline = 0.0;
self->ignorePopUid = ""; self->ignorePopUid = "";
for (it = self->toBePopped.begin(); it != self->toBePopped.end(); it++) { for (it = logData->toBePopped.begin(); it != logData->toBePopped.end(); it++) {
TraceEvent("PlayIgnoredPop").detail("Tag", it->first.toString()).detail("Version", it->second); TraceEvent("PlayIgnoredPop").detail("Tag", it->first.toString()).detail("Version", it->second);
ignoredPops.push_back(tLogPopCore(self, it->first, it->second, logData)); ignoredPops.push_back(tLogPopCore(self, it->first, it->second, logData));
} }
@ -1951,7 +1952,7 @@ ACTOR Future<Void> tLogEnablePopReq(TLogEnablePopRequest enablePopReq, TLogData*
.detail("QueueCommittedVersion", logData->queueCommittedVersion.get()) .detail("QueueCommittedVersion", logData->queueCommittedVersion.get())
.detail("Version", logData->version.get()); .detail("Version", logData->version.get());
wait(waitForAll(ignoredPops)); wait(waitForAll(ignoredPops));
self->toBePopped.clear(); logData->toBePopped.clear();
enablePopReq.reply.send(Void()); enablePopReq.reply.send(Void());
return Void(); return Void();
} }

View File

@ -355,8 +355,6 @@ struct TLogData : NonCopyable {
// the set and for callers that unset will // the set and for callers that unset will
// be able to match it up // be able to match it up
std::string dataFolder; // folder where data is stored std::string dataFolder; // folder where data is stored
std::map<Tag, Version> toBePopped; // map of Tag->Version for all the pops
// that came when ignorePopRequest was set
Reference<AsyncVar<bool>> degraded; Reference<AsyncVar<bool>> degraded;
TLogData(UID dbgid, TLogData(UID dbgid,
@ -596,6 +594,9 @@ struct LogData : NonCopyable, public ReferenceCounted<LogData> {
bool execOpCommitInProgress; bool execOpCommitInProgress;
int txsTags; int txsTags;
std::map<Tag, Version> toBePopped; // map of Tag->Version for all the pops
// that came when ignorePopRequest was set
explicit LogData(TLogData* tLogData, explicit LogData(TLogData* tLogData,
TLogInterface interf, TLogInterface interf,
Tag remoteTag, Tag remoteTag,
@ -1400,8 +1401,8 @@ ACTOR Future<Void> tLogPopCore(TLogData* self, Tag inputTag, Version to, Referen
if (self->ignorePopRequest) { if (self->ignorePopRequest) {
TraceEvent(SevDebug, "IgnoringPopRequest").detail("IgnorePopDeadline", self->ignorePopDeadline); TraceEvent(SevDebug, "IgnoringPopRequest").detail("IgnorePopDeadline", self->ignorePopDeadline);
if (self->toBePopped.find(inputTag) == self->toBePopped.end() || to > self->toBePopped[inputTag]) { if (logData->toBePopped.find(inputTag) == logData->toBePopped.end() || to > logData->toBePopped[inputTag]) {
self->toBePopped[inputTag] = to; logData->toBePopped[inputTag] = to;
} }
// add the pop to the toBePopped map // add the pop to the toBePopped map
TraceEvent(SevDebug, "IgnoringPopRequest") TraceEvent(SevDebug, "IgnoringPopRequest")
@ -1478,11 +1479,11 @@ ACTOR Future<Void> tLogPop(TLogData* self, TLogPopRequest req, Reference<LogData
self->ignorePopRequest = false; self->ignorePopRequest = false;
self->ignorePopUid = ""; self->ignorePopUid = "";
self->ignorePopDeadline = 0.0; self->ignorePopDeadline = 0.0;
for (it = self->toBePopped.begin(); it != self->toBePopped.end(); it++) { for (it = logData->toBePopped.begin(); it != logData->toBePopped.end(); it++) {
TraceEvent("PlayIgnoredPop").detail("Tag", it->first.toString()).detail("Version", it->second); TraceEvent("PlayIgnoredPop").detail("Tag", it->first.toString()).detail("Version", it->second);
ignoredPops.push_back(tLogPopCore(self, it->first, it->second, logData)); ignoredPops.push_back(tLogPopCore(self, it->first, it->second, logData));
} }
self->toBePopped.clear(); logData->toBePopped.clear();
wait(waitForAll(ignoredPops)); wait(waitForAll(ignoredPops));
TraceEvent("ResetIgnorePopRequest") TraceEvent("ResetIgnorePopRequest")
.detail("Now", g_network->now()) .detail("Now", g_network->now())
@ -2382,7 +2383,7 @@ ACTOR Future<Void> tLogEnablePopReq(TLogEnablePopRequest enablePopReq, TLogData*
self->ignorePopRequest = false; self->ignorePopRequest = false;
self->ignorePopDeadline = 0.0; self->ignorePopDeadline = 0.0;
self->ignorePopUid = ""; self->ignorePopUid = "";
for (it = self->toBePopped.begin(); it != self->toBePopped.end(); it++) { for (it = logData->toBePopped.begin(); it != logData->toBePopped.end(); it++) {
TraceEvent("PlayIgnoredPop").detail("Tag", it->first.toString()).detail("Version", it->second); TraceEvent("PlayIgnoredPop").detail("Tag", it->first.toString()).detail("Version", it->second);
ignoredPops.push_back(tLogPopCore(self, it->first, it->second, logData)); ignoredPops.push_back(tLogPopCore(self, it->first, it->second, logData));
} }
@ -2396,7 +2397,7 @@ ACTOR Future<Void> tLogEnablePopReq(TLogEnablePopRequest enablePopReq, TLogData*
.detail("QueueCommittedVersion", logData->queueCommittedVersion.get()) .detail("QueueCommittedVersion", logData->queueCommittedVersion.get())
.detail("Version", logData->version.get()); .detail("Version", logData->version.get());
wait(waitForAll(ignoredPops)); wait(waitForAll(ignoredPops));
self->toBePopped.clear(); logData->toBePopped.clear();
enablePopReq.reply.send(Void()); enablePopReq.reply.send(Void());
return Void(); return Void();
} }

View File

@ -358,7 +358,6 @@ struct TLogData : NonCopyable {
FlowLock persistentDataCommitLock; FlowLock persistentDataCommitLock;
// Beginning of fields used by snapshot based backup and restore // Beginning of fields used by snapshot based backup and restore
bool ignorePopRequest; // ignore pop request from storage servers
double ignorePopDeadline; // time until which the ignorePopRequest will be double ignorePopDeadline; // time until which the ignorePopRequest will be
// honored // honored
std::string ignorePopUid; // callers that set ignorePopRequest will set this std::string ignorePopUid; // callers that set ignorePopRequest will set this
@ -366,8 +365,6 @@ struct TLogData : NonCopyable {
// the set and for callers that unset will // the set and for callers that unset will
// be able to match it up // be able to match it up
std::string dataFolder; // folder where data is stored std::string dataFolder; // folder where data is stored
std::map<Tag, Version> toBePopped; // map of Tag->Version for all the pops
// that came when ignorePopRequest was set
Reference<AsyncVar<bool>> degraded; Reference<AsyncVar<bool>> degraded;
// End of fields used by snapshot based backup and restore // End of fields used by snapshot based backup and restore
@ -388,11 +385,10 @@ struct TLogData : NonCopyable {
instanceID(deterministicRandom()->randomUniqueID().first()), bytesInput(0), bytesDurable(0), instanceID(deterministicRandom()->randomUniqueID().first()), bytesInput(0), bytesDurable(0),
targetVolatileBytes(SERVER_KNOBS->TLOG_SPILL_THRESHOLD), overheadBytesInput(0), overheadBytesDurable(0), targetVolatileBytes(SERVER_KNOBS->TLOG_SPILL_THRESHOLD), overheadBytesInput(0), overheadBytesDurable(0),
peekMemoryLimiter(SERVER_KNOBS->TLOG_SPILL_REFERENCE_MAX_PEEK_MEMORY_BYTES), peekMemoryLimiter(SERVER_KNOBS->TLOG_SPILL_REFERENCE_MAX_PEEK_MEMORY_BYTES),
concurrentLogRouterReads(SERVER_KNOBS->CONCURRENT_LOG_ROUTER_READS), ignorePopRequest(false), concurrentLogRouterReads(SERVER_KNOBS->CONCURRENT_LOG_ROUTER_READS), ignorePopDeadline(0), dataFolder(folder),
dataFolder(folder), degraded(degraded), degraded(degraded), commitLatencyDist(Histogram::getHistogram(LiteralStringRef("tLog"),
commitLatencyDist(Histogram::getHistogram(LiteralStringRef("tLog"), LiteralStringRef("commit"),
LiteralStringRef("commit"), Histogram::Unit::microseconds)) {
Histogram::Unit::microseconds)) {
cx = openDBOnServer(dbInfo, TaskPriority::DefaultEndpoint, LockAware::True); cx = openDBOnServer(dbInfo, TaskPriority::DefaultEndpoint, LockAware::True);
} }
}; };
@ -629,6 +625,9 @@ struct LogData : NonCopyable, public ReferenceCounted<LogData> {
bool execOpCommitInProgress; bool execOpCommitInProgress;
int txsTags; int txsTags;
std::map<Tag, Version> toBePopped; // map of Tag->Version for all the pops
// that came when ignorePopRequest was set
explicit LogData(TLogData* tLogData, explicit LogData(TLogData* tLogData,
TLogInterface interf, TLogInterface interf,
Tag remoteTag, Tag remoteTag,
@ -1234,14 +1233,17 @@ ACTOR Future<Void> processPopRequests(TLogData* self, Reference<LogData> logData
state std::map<Tag, Version>::const_iterator it; state std::map<Tag, Version>::const_iterator it;
state int ignoredPopsPlayed = 0; state int ignoredPopsPlayed = 0;
state std::map<Tag, Version> toBePopped; state std::map<Tag, Version> toBePopped;
toBePopped = std::move(self->toBePopped);
self->toBePopped.clear(); while (now() < self->ignorePopDeadline) {
self->ignorePopRequest = false; wait(delayUntil(self->ignorePopDeadline + 0.0001));
self->ignorePopDeadline = 0.0; }
toBePopped = std::move(logData->toBePopped);
logData->toBePopped.clear();
self->ignorePopUid = ""; self->ignorePopUid = "";
for (it = toBePopped.cbegin(); it != toBePopped.cend(); ++it) { for (it = toBePopped.cbegin(); it != toBePopped.cend(); ++it) {
const auto& [tag, version] = *it; const auto& [tag, version] = *it;
TraceEvent("PlayIgnoredPop").detail("Tag", tag.toString()).detail("Version", version); TraceEvent("PlayIgnoredPop", logData->logId).detail("Tag", tag.toString()).detail("Version", version);
ignoredPops.push_back(tLogPopCore(self, tag, version, logData)); ignoredPops.push_back(tLogPopCore(self, tag, version, logData));
if (++ignoredPopsPlayed % SERVER_KNOBS->TLOG_POP_BATCH_SIZE == 0) { if (++ignoredPopsPlayed % SERVER_KNOBS->TLOG_POP_BATCH_SIZE == 0) {
TEST(true); // Yielding while processing pop requests TEST(true); // Yielding while processing pop requests
@ -1249,20 +1251,22 @@ ACTOR Future<Void> processPopRequests(TLogData* self, Reference<LogData> logData
} }
} }
wait(waitForAll(ignoredPops)); wait(waitForAll(ignoredPops));
TraceEvent("ResetIgnorePopRequest") TraceEvent("ResetIgnorePopRequest", logData->logId).detail("IgnorePopDeadline", self->ignorePopDeadline);
.detail("IgnorePopRequest", self->ignorePopRequest)
.detail("IgnorePopDeadline", self->ignorePopDeadline);
return Void(); return Void();
} }
ACTOR Future<Void> tLogPop(TLogData* self, TLogPopRequest req, Reference<LogData> logData) { ACTOR Future<Void> tLogPop(TLogData* self, TLogPopRequest req, Reference<LogData> logData) {
if (self->ignorePopRequest) { if (now() < self->ignorePopDeadline) {
TraceEvent(SevDebug, "IgnoringPopRequest").detail("IgnorePopDeadline", self->ignorePopDeadline); TraceEvent(SevDebug, "IgnoringPopRequest", logData->logId).detail("IgnorePopDeadline", self->ignorePopDeadline);
auto& v = self->toBePopped[req.tag]; if (logData->toBePopped.empty()) {
logData->addActor.send(processPopRequests(self, logData));
}
auto& v = logData->toBePopped[req.tag];
v = std::max(v, req.to); v = std::max(v, req.to);
TraceEvent(SevDebug, "IgnoringPopRequest") TraceEvent(SevDebug, "IgnoringPopRequest", logData->logId)
.detail("IgnorePopDeadline", self->ignorePopDeadline) .detail("IgnorePopDeadline", self->ignorePopDeadline)
.detail("Tag", req.tag.toString()) .detail("Tag", req.tag.toString())
.detail("Version", req.to); .detail("Version", req.to);
@ -2571,15 +2575,15 @@ ACTOR Future<Void> tLogEnablePopReq(TLogEnablePopRequest enablePopReq, TLogData*
enablePopReq.reply.sendError(operation_failed()); enablePopReq.reply.sendError(operation_failed());
return Void(); return Void();
} }
TraceEvent("EnableTLogPlayAllIgnoredPops2") TraceEvent("EnableTLogPlayAllIgnoredPops2", logData->logId)
.detail("UidStr", enablePopReq.snapUID.toString()) .detail("UidStr", enablePopReq.snapUID.toString())
.detail("IgnorePopUid", self->ignorePopUid) .detail("IgnorePopUid", self->ignorePopUid)
.detail("IgnorePopRequest", self->ignorePopRequest)
.detail("IgnorePopDeadline", self->ignorePopDeadline) .detail("IgnorePopDeadline", self->ignorePopDeadline)
.detail("PersistentDataVersion", logData->persistentDataVersion) .detail("PersistentDataVersion", logData->persistentDataVersion)
.detail("PersistentDataDurableVersion", logData->persistentDataDurableVersion) .detail("PersistentDataDurableVersion", logData->persistentDataDurableVersion)
.detail("QueueCommittedVersion", logData->queueCommittedVersion.get()) .detail("QueueCommittedVersion", logData->queueCommittedVersion.get())
.detail("Version", logData->version.get()); .detail("Version", logData->version.get());
self->ignorePopDeadline = 0;
wait(processPopRequests(self, logData)); wait(processPopRequests(self, logData));
enablePopReq.reply.send(Void()); enablePopReq.reply.send(Void());
return Void(); return Void();
@ -2681,9 +2685,8 @@ ACTOR Future<Void> serveTLogInterface(TLogData* self,
req.reply.sendError(operation_failed()); req.reply.sendError(operation_failed());
} else { } else {
// FIXME: As part of reverting snapshot V1, make ignorePopUid a UID instead of string // FIXME: As part of reverting snapshot V1, make ignorePopUid a UID instead of string
self->ignorePopRequest = true;
self->ignorePopUid = req.snapUID.toString(); self->ignorePopUid = req.snapUID.toString();
self->ignorePopDeadline = g_network->now() + SERVER_KNOBS->TLOG_IGNORE_POP_AUTO_ENABLE_DELAY; self->ignorePopDeadline = now() + SERVER_KNOBS->TLOG_IGNORE_POP_AUTO_ENABLE_DELAY;
req.reply.send(Void()); req.reply.send(Void());
} }
} }
@ -2693,11 +2696,6 @@ ACTOR Future<Void> serveTLogInterface(TLogData* self,
when(TLogSnapRequest snapReq = waitNext(tli.snapRequest.getFuture())) { when(TLogSnapRequest snapReq = waitNext(tli.snapRequest.getFuture())) {
logData->addActor.send(tLogSnapCreate(snapReq, self, logData)); logData->addActor.send(tLogSnapCreate(snapReq, self, logData));
} }
when(wait(self->ignorePopRequest ? delayUntil(self->ignorePopDeadline) : Never())) {
TEST(true); // Hit ignorePopDeadline
TraceEvent("EnableTLogPlayAllIgnoredPops").detail("IgnoredPopDeadline", self->ignorePopDeadline);
logData->addActor.send(processPopRequests(self, logData));
}
} }
} }

View File

@ -519,7 +519,7 @@ void FastAllocator<Size>::getMagazine() {
--g_allocation_tracing_disabled; --g_allocation_tracing_disabled;
} }
#endif #endif
block = (void**)::allocate(magazine_size * Size, false); block = (void**)::allocate(magazine_size * Size, /*allowLargePages*/ false, /*includeGuardPages*/ true);
#endif #endif
// void** block = new void*[ magazine_size * PSize ]; // void** block = new void*[ magazine_size * PSize ];

View File

@ -2037,7 +2037,22 @@ static void enableLargePages() {
#endif #endif
} }
static void* allocateInternal(size_t length, bool largePages) { #ifndef _WIN32
static void* mmapInternal(size_t length, int flags, bool guardPages) {
if (guardPages) {
constexpr size_t pageSize = 4096;
length += 2 * pageSize; // Map enough for the guard pages
void* resultWithGuardPages = mmap(nullptr, length, PROT_READ | PROT_WRITE, flags, -1, 0);
mprotect(resultWithGuardPages, pageSize, PROT_NONE); // left guard page
mprotect((void*)(uintptr_t(resultWithGuardPages) + length - pageSize), pageSize, PROT_NONE); // right guard page
return (void*)(uintptr_t(resultWithGuardPages) + pageSize);
} else {
return mmap(nullptr, length, PROT_READ | PROT_WRITE, flags, -1, 0);
}
}
#endif
static void* allocateInternal(size_t length, bool largePages, bool guardPages) {
#ifdef _WIN32 #ifdef _WIN32
DWORD allocType = MEM_COMMIT | MEM_RESERVE; DWORD allocType = MEM_COMMIT | MEM_RESERVE;
@ -2052,31 +2067,31 @@ static void* allocateInternal(size_t length, bool largePages) {
if (largePages) if (largePages)
flags |= MAP_HUGETLB; flags |= MAP_HUGETLB;
return mmap(nullptr, length, PROT_READ | PROT_WRITE, flags, -1, 0); return mmapInternal(length, flags, guardPages);
#elif defined(__APPLE__) || defined(__FreeBSD__) #elif defined(__APPLE__) || defined(__FreeBSD__)
int flags = MAP_PRIVATE | MAP_ANON; int flags = MAP_PRIVATE | MAP_ANON;
return mmap(nullptr, length, PROT_READ | PROT_WRITE, flags, -1, 0); return mmapInternal(length, flags, guardPages);
#else #else
#error Port me! #error Port me!
#endif #endif
} }
static bool largeBlockFail = false; static bool largeBlockFail = false;
void* allocate(size_t length, bool allowLargePages) { void* allocate(size_t length, bool allowLargePages, bool includeGuardPages) {
if (allowLargePages) if (allowLargePages)
enableLargePages(); enableLargePages();
void* block = ALLOC_FAIL; void* block = ALLOC_FAIL;
if (allowLargePages && !largeBlockFail) { if (allowLargePages && !largeBlockFail) {
block = allocateInternal(length, true); block = allocateInternal(length, true, includeGuardPages);
if (block == ALLOC_FAIL) if (block == ALLOC_FAIL)
largeBlockFail = true; largeBlockFail = true;
} }
if (block == ALLOC_FAIL) if (block == ALLOC_FAIL)
block = allocateInternal(length, false); block = allocateInternal(length, false, includeGuardPages);
// FIXME: SevWarnAlways trace if "close" to out of memory // FIXME: SevWarnAlways trace if "close" to out of memory

View File

@ -284,7 +284,7 @@ std::string epochsToGMTString(double epochs);
void setMemoryQuota(size_t limit); void setMemoryQuota(size_t limit);
void* allocate(size_t length, bool allowLargePages); void* allocate(size_t length, bool allowLargePages, bool includeGuardPages);
void setAffinity(int proc); void setAffinity(int proc);