Skip to content

Commit

Permalink
CBL-6335: LiteCore Replicator uses the previous logPrefix passed by t…
Browse files Browse the repository at this point in the history
…he platform replicator (#2169)

It was a mistake to have loggingClassName class static because the logPrefix passed in by the platform is static per object. We now make it object static, namely fixing it in the constructor.
  • Loading branch information
jianminzhao authored Oct 19, 2024
1 parent 7db2d5c commit fb6e666
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 31 deletions.
14 changes: 3 additions & 11 deletions Replicator/c4IncomingReplicator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ namespace litecore {
C4IncomingReplicator(C4Database* db NONNULL, const C4ReplicatorParameters& params,
WebSocket* openSocket NONNULL, slice logPrefix)
: C4ReplicatorImpl(db, params), _openSocket(openSocket) {
if ( !logPrefix.empty() ) { _logPrefix = logPrefix; }
std::string logName = "C4IncomingRepl";
if ( !logPrefix.empty() ) logName = logPrefix.asString() + "/" + logName;
setLoggingName(logName);
}

alloc_slice URL() const noexcept override { return _openSocket->url(); }
Expand All @@ -50,16 +52,6 @@ namespace litecore {
return true;
}

protected:
std::string loggingClassName() const override {
static std::string logName{};
if ( logName.empty() ) {
logName = "C4IncomingRepl";
if ( !_logPrefix.empty() ) { logName = _logPrefix.asString() + "/" + logName; }
}
return logName;
}

private:
WebSocket* _openSocket;
};
Expand Down
13 changes: 3 additions & 10 deletions Replicator/c4RemoteReplicator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ namespace litecore {
: C4ReplicatorImpl(db, params)
, _url(effectiveURL(serverAddress, remoteDatabaseName))
, _retryTimer([this] { retry(false); }) {
std::string logName = "C4RemoteRepl";
if ( !logPrefix.empty() ) { logName = logPrefix.asString() + "/" + logName; }
setLoggingName(logName);
if ( params.socketFactory ) {
// Keep a copy of the C4SocketFactory struct in case original is invalidated:
_customSocketFactory = *params.socketFactory;
_socketFactory = &_customSocketFactory;
}
if ( !logPrefix.empty() ) { _logPrefix = logPrefix; }
}

void start(bool reset) noexcept override {
Expand Down Expand Up @@ -108,15 +110,6 @@ namespace litecore {


protected:
std::string loggingClassName() const override {
static std::string logName{};
if ( logName.empty() ) {
logName = "C4RemoteRepl";
if ( !_logPrefix.empty() ) { logName = _logPrefix.asString() + "/" + logName; }
}
return logName;
}

alloc_slice URL() const noexcept override { return _url; }

void createReplicator() override {
Expand Down
15 changes: 5 additions & 10 deletions Replicator/c4ReplicatorImpl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ namespace litecore {
, _options(new Options(params))
, _onStatusChanged(params.onStatusChanged)
, _onDocumentsEnded(params.onDocumentsEnded)
, _onBlobProgress(params.onBlobProgress) {
, _onBlobProgress(params.onBlobProgress)
, _loggingName("C4Repl") {
_status.flags |= kC4HostReachable;
_options->verify();
}
Expand All @@ -228,14 +229,7 @@ namespace litecore {
if ( _replicator ) _replicator->terminate();
}

std::string loggingClassName() const override {
static std::string logName{};
if ( logName.empty() ) {
logName = "C4Repl";
if ( !_logPrefix.empty() ) { logName = _logPrefix.asString() + "/" + logName; }
}
return logName;
}
std::string loggingClassName() const override { return _loggingName; }

bool continuous(unsigned collectionIndex = 0) const noexcept {
return _options->push(collectionIndex) == kC4Continuous || _options->pull(collectionIndex) == kC4Continuous;
Expand Down Expand Up @@ -513,9 +507,10 @@ namespace litecore {
bool _cancelStop{false};

protected:
alloc_slice _logPrefix;
void setLoggingName(const string& loggingName) { _loggingName = loggingName; }

private:
std::string _loggingName;
alloc_slice _responseHeaders;
#ifdef COUCHBASE_ENTERPRISE
mutable alloc_slice _peerTLSCertificateData;
Expand Down

0 comments on commit fb6e666

Please sign in to comment.