Skip to content

Move blob search logic in Replicator into a new method to prevent code duplication #8651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 21 additions & 30 deletions src/jrd/replication/Replicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,21 +306,7 @@ void Replicator::insertRecord(CheckStatusWrapper* status,
{
try
{
for (unsigned id = 0; id < record->getCount(); id++)
{
IReplicatedField* field = record->getField(id);
if (field != nullptr)
{
auto type = field->getType();
if (type == SQL_ARRAY || type == SQL_BLOB)
{
const auto blobId = (ISC_QUAD*) field->getData();

if (blobId && !BlobWrapper::blobIsNull(*blobId))
storeBlob(transaction, *blobId);
}
}
}
storeBlobs(transaction, record);

const auto length = record->getRawLength();
const auto data = record->getRawData();
Expand Down Expand Up @@ -353,21 +339,7 @@ void Replicator::updateRecord(CheckStatusWrapper* status,
{
try
{
for (unsigned id = 0; id < newRecord->getCount(); id++)
{
IReplicatedField* field = newRecord->getField(id);
if (field != nullptr)
{
auto type = field->getType();
if (type == SQL_ARRAY || type == SQL_BLOB)
{
const auto blobId = (ISC_QUAD*) field->getData();

if (blobId && !BlobWrapper::blobIsNull(*blobId))
storeBlob(transaction, *blobId);
}
}
}
storeBlobs(transaction, newRecord);

const auto orgLength = orgRecord->getRawLength();
const auto orgData = orgRecord->getRawData();
Expand Down Expand Up @@ -454,6 +426,25 @@ void Replicator::executeSqlIntl(CheckStatusWrapper* status,
}
}

void Replicator::storeBlobs(Transaction* transaction, Firebird::IReplicatedRecord* record)
{
for (unsigned id = 0; id < record->getCount(); id++)
{
IReplicatedField* field = record->getField(id);
if (field == nullptr)
continue;

auto type = field->getType();
if (type == SQL_ARRAY || type == SQL_BLOB)
{
const auto blobId = (ISC_QUAD*) field->getData();

if (blobId && !BlobWrapper::blobIsNull(*blobId))
storeBlob(transaction, *blobId);
}
}
}

void Replicator::cleanupTransaction(CheckStatusWrapper* status,
SINT64 number)
{
Expand Down
2 changes: 2 additions & 0 deletions src/jrd/replication/Replicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ namespace Replication
unsigned charset,
const char* schemaSearchPath,
const char* sql);

void storeBlobs(Transaction* transaction, Firebird::IReplicatedRecord* record);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to keep declaration of all overloads in one place so they can be seen with one glance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I didn't quite understand the remark. The method does not overload anything

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, my bad. storeBlobs and storeBlob are different names. Sorry.

};

} // namespace
Expand Down
Loading