8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-23 02:03:04 +01:00

Improve error reporting a little

This commit is contained in:
Dmitry Yemanov 2021-10-11 10:55:28 +03:00
parent 1ab4064912
commit 74d349bfbd

View File

@ -332,9 +332,9 @@ namespace
public:
explicit Target(const Replication::Config* config)
: m_config(config),
m_lastError(getPool()),
m_attachment(nullptr), m_replicator(nullptr),
m_sequence(0), m_connected(false)
m_sequence(0), m_connected(false),
m_lastError(getPool()), m_errorSequence(0), m_errorOffset(0)
{
}
@ -416,14 +416,16 @@ namespace
m_connected = false;
}
bool replicate(FbLocalStatus& status, ULONG length, const UCHAR* data)
void replicate(FB_UINT64 sequence, ULONG offset, ULONG length, const UCHAR* data)
{
#ifdef NO_DATABASE
return true;
#else
fb_assert(m_replicator);
m_replicator->process(&status, length, data);
return status.isSuccess();
FbLocalStatus localStatus;
m_replicator->process(&localStatus, length, data);
checkCompletion(localStatus, sequence, offset);
#endif
}
@ -439,13 +441,37 @@ namespace
void logError(const string& message)
{
if (message != m_lastError)
if (m_config->verboseLogging || message != m_lastError)
{
logReplicaError(m_config->dbName, message);
string error = message;
if (m_errorSequence)
{
string position;
position.printf("\n\tAt segment %" UQUADFORMAT ", offset %u",
m_errorSequence, m_errorOffset);
error += position;
}
logReplicaError(m_config->dbName, error);
m_lastError = message;
}
}
void checkCompletion(const FbLocalStatus& status, FB_UINT64 sequence, ULONG offset)
{
if (!status.isSuccess())
{
m_errorSequence = sequence;
m_errorOffset = offset;
status.raise();
}
m_lastError.clear();
m_errorSequence = 0;
m_errorOffset = 0;
}
void verbose(const char* msg, ...) const
{
if (m_config->verboseLogging)
@ -463,11 +489,13 @@ namespace
private:
AutoPtr<const Replication::Config> m_config;
string m_lastError;
RefPtr<IAttachment> m_attachment;
RefPtr<IReplicator> m_replicator;
FB_UINT64 m_sequence;
bool m_connected;
string m_lastError;
FB_UINT64 m_errorSequence;
ULONG m_errorOffset;
};
typedef Array<Target*> TargetList;
@ -561,9 +589,10 @@ namespace
return true;
}
bool replicate(FbLocalStatus& status, FB_UINT64 sequence,
Target* target, TransactionList& transactions,
ULONG offset, ULONG length, const UCHAR* data,
void replicate(Target* target,
TransactionList& transactions,
FB_UINT64 sequence, ULONG offset,
ULONG length, const UCHAR* data,
bool rewind)
{
const Block* const header = (Block*) data;
@ -572,8 +601,7 @@ namespace
if (!rewind || !traNumber || transactions.exist(traNumber))
{
if (!target->replicate(status, length, data))
return false;
target->replicate(sequence, offset, length, data);
}
if (header->flags & BLOCK_END_TRANS)
@ -596,16 +624,12 @@ namespace
if (!rewind && !transactions.exist(traNumber))
transactions.add(ActiveTransaction(traNumber, sequence));
}
return true;
}
enum ProcessStatus { PROCESS_SUSPEND, PROCESS_CONTINUE, PROCESS_ERROR };
ProcessStatus process_archive(MemoryPool& pool, Target* target)
{
FbLocalStatus localStatus;
ProcessQueue queue(pool);
ProcessStatus ret = PROCESS_SUSPEND;
@ -839,22 +863,8 @@ namespace
if (read(file, data + sizeof(Block), blockLength) != blockLength)
raiseError("Journal file %s read failed (error %d)", segment->filename.c_str(), ERRNO);
const bool success =
replicate(localStatus, sequence,
target, transactions,
totalLength, length, data,
rewind);
if (!success)
{
oldest = findOldest(transactions);
oldest_sequence = oldest ? oldest->sequence : 0;
target->verbose("Segment %" UQUADFORMAT " replication failure at offset %u",
sequence, totalLength);
localStatus.raise();
}
replicate(target, transactions, sequence, totalLength,
length, data, rewind);
}
totalLength += length;
@ -919,14 +929,13 @@ namespace
}
catch (const Exception& ex)
{
LocalStatus localStatus;
CheckStatusWrapper statusWrapper(&localStatus);
ex.stuffException(&statusWrapper);
FbLocalStatus localStatus;
ex.stuffException(&localStatus);
string message;
char temp[BUFFER_LARGE];
const ISC_STATUS* statusPtr = localStatus.getErrors();
const ISC_STATUS* statusPtr = localStatus->getErrors();
while (fb_interpret(temp, sizeof(temp), &statusPtr))
{
if (!message.isEmpty())
@ -937,8 +946,7 @@ namespace
target->logError(message);
target->verbose("Suspending for %u seconds",
config->applyErrorTimeout);
target->verbose("Suspending for %u seconds", config->applyErrorTimeout);
ret = PROCESS_ERROR;
}