Print out the text (to stderr and as trace) of the failed condition on assert failure

This commit is contained in:
Russell Sears 2020-06-23 17:06:29 -07:00
parent 26a977ea29
commit 422003df34
7 changed files with 26 additions and 11 deletions

View File

@ -169,7 +169,7 @@ struct TransactionLogInfo : public ReferenceCounted<TransactionLogInfo>, NonCopy
template <typename T>
void addLog(const T& event) {
if(logLocation & TRACE_LOG) {
ASSERT(!identifier.empty())
ASSERT(!identifier.empty());
event.logEvent(identifier, maxFieldLength);
}

View File

@ -1577,7 +1577,7 @@ void ReadYourWritesTransaction::getWriteConflicts( KeyRangeMap<bool> *result ) {
Standalone<RangeResultRef> ReadYourWritesTransaction::getReadConflictRangeIntersecting(KeyRangeRef kr) {
TEST(true); // Special keys read conflict range
ASSERT(readConflictRangeKeysRange.contains(kr));
ASSERT(!tr.options.checkWritesEnabled)
ASSERT(!tr.options.checkWritesEnabled);
Standalone<RangeResultRef> result;
if (!options.readYourWritesDisabled) {
kr = kr.removePrefix(readConflictRangeKeysRange.begin);

View File

@ -89,7 +89,7 @@ public:
void registerKeyRange(SpecialKeySpace::MODULE module, const KeyRangeRef& kr, SpecialKeyRangeBaseImpl* impl) {
// module boundary check
if (module == SpecialKeySpace::MODULE::TESTONLY)
ASSERT(normalKeys.contains(kr))
ASSERT(normalKeys.contains(kr));
else
ASSERT(moduleToBoundary.at(module).contains(kr));
// make sure the registered range is not overlapping with existing ones

View File

@ -1326,7 +1326,7 @@ ACTOR Future<GetKeyValuesReply> readRange( StorageServer* data, Version version,
ASSERT(result.data.end()[-1].key == atStorageVersion.end()[-1].key);
readEnd = result.data.end()[-1].key;
} else if (vCurrent && vCurrent->isClearTo()) {
ASSERT(vCurrent.key() < readEnd)
ASSERT(vCurrent.key() < readEnd);
readEnd = vCurrent.key();
--vCurrent;
} else {

View File

@ -57,6 +57,19 @@ Error internal_error_impl( const char* file, int line ) {
return Error(error_code_internal_error);
}
Error internal_error_impl(const char* msg, const char* file, int line) {
fprintf(stderr, "Assertion %s failed @ %s %d:\n %s\n", msg, file, line, platform::get_backtrace().c_str());
TraceEvent(SevError, "InternalError")
.error(Error::fromCode(error_code_internal_error))
.detail("FailedAssertion", msg)
.detail("File", file)
.detail("Line", line)
.backtrace();
flushTraceFileVoid();
return Error(error_code_internal_error);
}
Error::Error(int error_code)
: error_code(error_code), flags(0)
{

View File

@ -75,6 +75,7 @@ Error systemErrorCodeToError();
#undef ERROR
#define ERROR(name, number, description) inline Error name() { return Error( number ); }; enum { error_code_##name = number };
#include "error_definitions.h"
//actor_cancelled has been renamed
@ -82,31 +83,32 @@ inline Error actor_cancelled() { return Error( error_code_operation_cancelled );
enum { error_code_actor_cancelled = error_code_operation_cancelled };
extern Error internal_error_impl( const char* file, int line );
#define internal_error() internal_error_impl( __FILE__, __LINE__ )
extern Error internal_error_impl(const char* msg, const char* file, int line);
#define inernal_error_msg(msg) internal_error_impl(msg, __FILE__, __LINE__)
extern bool isAssertDisabled( int line );
//#define ASSERT( condition ) ((void)0)
#define ASSERT(condition) \
do { \
if (!((condition) || isAssertDisabled(__LINE__))) { \
throw internal_error(); \
throw internal_error_impl(#condition, __FILE__, __LINE__); \
} \
} while (false);
} while (false)
#define ASSERT_ABORT(condition) \
do { \
if (!((condition) || isAssertDisabled(__LINE__))) { \
internal_error(); \
internal_error_impl(#condition, __FILE__, __LINE__); \
abort(); \
} \
} while (false) // For use in destructors, where throwing exceptions is extremely dangerous
#define UNSTOPPABLE_ASSERT(condition) \
do { \
if (!(condition)) { \
throw internal_error(); \
throw internal_error_impl(#condition, __FILE__, __LINE__); \
} \
} while (false)
#define UNREACHABLE() \
{ throw internal_error(); }
{ throw internal_error_impl("unreachable", __FILE__, __LINE__); }
// ASSERT_WE_THINK() is to be used for assertions that we want to validate in testing, but which are judged too
// risky to evaluate at runtime, because the code should work even if they are false and throwing internal_error() would

View File

@ -135,7 +135,7 @@ struct TransientThresholdMetricSample : MetricSample<T> {
int64_t val = this->sample.addMetric(T(key), delta);
if (val < thresholdLimit && (val + std::abs(delta)) >= thresholdLimit) {
auto iter = thresholdCrossedSet.find(key);
ASSERT(iter != thresholdCrossedSet.end())
ASSERT(iter != thresholdCrossedSet.end());
thresholdCrossedSet.erase(iter);
}
if (val == 0)