Skip to content

Commit bddb88b

Browse files
snejjianminzhao
andauthored
CBL-2720 : Remove kC4ReplicatorOptionProgressLevel, simplify setting progress level (#1322)
* repl::Worker cleanup and documentation - Lots of doc-comments in Worker.hh - Changed progressNotificationLevel from int to C4ReplicatorProgressLevel. - Renamed _important to _importance. * Put C4ReplicatorProgressLevel in Options struct, not Fleece Dict * Removed the already-deprecated `kC4ReplicatorOptionProgressLevel`. * Added a `progressLevel` field to litecore::repl::Options. * Made Options ref-counted. * Worker objects store a shared RetainedConst<Options> instead of their own copies of the object. * Removed Worker::progressNotificationLevel(), its setter, and the several overrides of its setter. * C4Replicator::setProgressLevel() now just sets Options::progressLevel. - Do not wipe Options' data and remove the related test case. CBL-2720 Co-authored-by: Jianmin Zhao <[email protected]>
1 parent 2ccc2fc commit bddb88b

26 files changed

+275
-270
lines changed

C/include/c4ReplicatorTypes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ C4API_BEGIN_DECLS
213213
#define kC4ReplicatorOptionNoIncomingConflicts "noIncomingConflicts" ///< Reject incoming conflicts (bool)
214214
#define kC4ReplicatorCheckpointInterval "checkpointInterval" ///< How often to checkpoint, in seconds (number)
215215
#define kC4ReplicatorOptionRemoteDBUniqueID "remoteDBUniqueID" ///< Stable ID for remote db with unstable URL (string)
216-
#define kC4ReplicatorOptionProgressLevel "progress" ///< If >=1, notify on every doc; if >=2, on every attachment (int)
217216
#define kC4ReplicatorOptionDisableDeltas "noDeltas" ///< Disables delta sync (bool)
218217
#define kC4ReplicatorOptionDisablePropertyDecryption "noDecryption" ///< Disables property decryption (bool)
219218
#define kC4ReplicatorOptionMaxRetries "maxRetries" ///< Max number of retry attempts (int)

Replicator/ChangesFeed.cc

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,18 @@ using namespace fleece;
3636
namespace litecore { namespace repl {
3737

3838

39-
ChangesFeed::ChangesFeed(Delegate &delegate, Options &options,
39+
ChangesFeed::ChangesFeed(Delegate &delegate, const Options *options,
4040
DBAccess &db, Checkpointer *checkpointer)
4141
:Logging(SyncLog)
4242
,_delegate(delegate)
4343
,_options(options)
4444
,_db(db)
4545
,_checkpointer(checkpointer)
46-
,_continuous(_options.push == kC4Continuous)
47-
,_passive(_options.push <= kC4Passive)
48-
,_skipDeleted(_options.skipDeleted())
46+
,_continuous(_options->push == kC4Continuous)
47+
,_passive(_options->push <= kC4Passive)
48+
,_skipDeleted(_options->skipDeleted())
4949
{
50-
filterByDocIDs(_options.docIDs());
50+
filterByDocIDs(_options->docIDs());
5151
}
5252

5353

@@ -113,7 +113,7 @@ namespace litecore { namespace repl {
113113

114114
// Run a by-sequence enumerator to find the changed docs:
115115
C4EnumeratorOptions options = kC4DefaultEnumeratorOptions;
116-
if (!_getForeignAncestors && !_options.pushFilter)
116+
if (!_getForeignAncestors && !_options->pushFilter)
117117
options.flags &= ~kC4IncludeBodies;
118118
if (!_skipDeleted)
119119
options.flags |= kC4IncludeDeleted;
@@ -255,7 +255,7 @@ namespace litecore { namespace repl {
255255
bool ChangesFeed::shouldPushRev(RevToSend *rev, C4DocEnumerator *e) const {
256256
bool needRemoteRevID = _getForeignAncestors && !rev->remoteAncestorRevID
257257
&& _isCheckpointValid;
258-
if (needRemoteRevID || _options.pushFilter) {
258+
if (needRemoteRevID || _options->pushFilter) {
259259
C4Error error;
260260
Retained<C4Document> doc;
261261
try {
@@ -284,14 +284,14 @@ namespace litecore { namespace repl {
284284
if (!getRemoteRevID(rev, doc))
285285
return false; // skip or fail rev: it's already on the peer
286286
}
287-
if (_options.pushFilter) {
287+
if (_options->pushFilter) {
288288
// If there's a push filter, ask it whether to push the doc:
289-
if (!_options.pushFilter(nullslice, // TODO: Collection support
289+
if (!_options->pushFilter(nullslice, // TODO: Collection support
290290
doc->docID(),
291291
doc->selectedRev().revID,
292292
doc->selectedRev().flags,
293293
doc->getProperties(),
294-
_options.callbackContext)) {
294+
_options->callbackContext)) {
295295
logVerbose("Doc '%.*s' rejected by push filter", SPLAT(doc->docID()));
296296
return false; // skip rev: rejected by push filter
297297
}
@@ -310,7 +310,8 @@ namespace litecore { namespace repl {
310310
#pragma mark - REPLICATOR CHANGES FEED:
311311

312312

313-
ReplicatorChangesFeed::ReplicatorChangesFeed(Delegate &delegate, Options &options, DBAccess &db, Checkpointer *cp)
313+
ReplicatorChangesFeed::ReplicatorChangesFeed(Delegate &delegate, const Options *options,
314+
DBAccess &db, Checkpointer *cp)
314315
:ChangesFeed(delegate, options, db, cp) // DBAccess is a subclass of access_lock<C4Database*>
315316
,_usingVersionVectors(db.usingVersionVectors())
316317
{ }
@@ -329,7 +330,7 @@ namespace litecore { namespace repl {
329330
if (foreignAncestor && !_usingVersionVectors
330331
&& C4Document::getRevIDGeneration(foreignAncestor)
331332
>= C4Document::getRevIDGeneration(doc->revID())) {
332-
if (_options.pull <= kC4Passive) {
333+
if (_options->pull <= kC4Passive) {
333334
C4Error error = C4Error::make(WebSocketDomain, 409,
334335
"conflicts with newer server revision"_sl);
335336
_delegate.failedToGetChange(rev, error, false);

Replicator/ChangesFeed.hh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace fleece {
2626

2727
namespace litecore::repl {
2828
class DBAccess;
29-
struct Options;
29+
class Options;
3030
class Checkpointer;
3131

3232
using DocIDSet = std::shared_ptr<std::unordered_set<std::string>>;
@@ -47,7 +47,7 @@ namespace litecore::repl {
4747
virtual void failedToGetChange(ReplicatedRev *rev, C4Error error, bool transient) =0;
4848
};
4949

50-
ChangesFeed(Delegate&, Options&, DBAccess &db, Checkpointer*);
50+
ChangesFeed(Delegate&, const Options* NONNULL, DBAccess &db, Checkpointer*);
5151
~ChangesFeed();
5252

5353
// Setup:
@@ -94,7 +94,7 @@ namespace litecore::repl {
9494

9595
protected:
9696
Delegate& _delegate;
97-
Options &_options;
97+
RetainedConst<Options> _options;
9898
DBAccess& _db;
9999
bool _getForeignAncestors {false}; // True in propose-changes mode
100100
private:
@@ -114,7 +114,8 @@ namespace litecore::repl {
114114

115115
class ReplicatorChangesFeed final : public ChangesFeed {
116116
public:
117-
ReplicatorChangesFeed(Delegate &delegate, Options &options, DBAccess &db, Checkpointer *cp);
117+
ReplicatorChangesFeed(Delegate &delegate, const Options *options,
118+
DBAccess &db, Checkpointer *cp);
118119

119120
void setFindForeignAncestors(bool use) {_getForeignAncestors = use;}
120121

Replicator/Checkpointer.cc

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace litecore { namespace repl {
3737
#pragma mark - CHECKPOINT ACCESSORS:
3838

3939

40-
Checkpointer::Checkpointer(const Options &opt, fleece::slice remoteURL)
40+
Checkpointer::Checkpointer(const Options *opt, fleece::slice remoteURL)
4141
:_options(opt)
4242
,_remoteURL(remoteURL)
4343
{ }
@@ -204,7 +204,7 @@ namespace litecore { namespace repl {
204204

205205

206206
slice Checkpointer::remoteDBIDString() const {
207-
return _options.remoteDBIDString(_remoteURL);
207+
return _options->remoteDBIDString(_remoteURL);
208208
}
209209

210210

@@ -221,10 +221,10 @@ namespace litecore { namespace repl {
221221
// Computes the ID of the checkpoint document.
222222
string Checkpointer::docIDForUUID(const C4UUID &localUUID, URLTransformStrategy urlStrategy) {
223223
// Derive docID from from db UUID, remote URL, channels, filter, and docIDs.
224-
Array channels = _options.channels();
225-
Value filter = _options.properties[kC4ReplicatorOptionFilter];
226-
const Value filterParams = _options.properties[kC4ReplicatorOptionFilterParams];
227-
Array docIDs = _options.docIDs();
224+
Array channels = _options->channels();
225+
Value filter = _options->properties[kC4ReplicatorOptionFilter];
226+
const Value filterParams = _options->properties[kC4ReplicatorOptionFilterParams];
227+
Array docIDs = _options->docIDs();
228228

229229
// Compute the ID by writing the values to a Fleece array, then taking a SHA1 digest:
230230
fleece::Encoder enc;
@@ -326,11 +326,11 @@ namespace litecore { namespace repl {
326326

327327

328328
void Checkpointer::initializeDocIDs() {
329-
if(!_docIDs.empty() || !_options.docIDs() || _options.docIDs().empty()) {
329+
if(!_docIDs.empty() || !_options->docIDs() || _options->docIDs().empty()) {
330330
return;
331331
}
332332

333-
Array::iterator i(_options.docIDs());
333+
Array::iterator i(_options->docIDs());
334334
while(i) {
335335
string docID = i.value().asString().asString();
336336
if(!docID.empty()) {
@@ -344,12 +344,12 @@ namespace litecore { namespace repl {
344344

345345
bool Checkpointer::isDocumentAllowed(C4Document* doc) {
346346
return isDocumentIDAllowed(doc->docID())
347-
&& (!_options.pushFilter || _options.pushFilter(nullslice, // TODO: Collection support
347+
&& (!_options->pushFilter || _options->pushFilter(nullslice, // TODO: Collection support
348348
doc->docID(),
349349
doc->selectedRev().revID,
350350
doc->selectedRev().flags,
351351
doc->getProperties(),
352-
_options.callbackContext));
352+
_options->callbackContext));
353353
}
354354

355355

@@ -363,7 +363,7 @@ namespace litecore { namespace repl {
363363

364364

365365
void Checkpointer::pendingDocumentIDs(C4Database* db, PendingDocCallback callback) {
366-
if(_options.push < kC4OneShot) {
366+
if(_options->push < kC4OneShot) {
367367
// Couchbase Lite should not allow this case
368368
C4Error::raise(LiteCoreDomain, kC4ErrorUnsupported);
369369
}
@@ -377,8 +377,8 @@ namespace litecore { namespace repl {
377377
}
378378

379379
C4EnumeratorOptions opts { kC4IncludeNonConflicted | kC4IncludeDeleted };
380-
const auto hasDocIDs = bool(_options.docIDs());
381-
if(!hasDocIDs && _options.pushFilter) {
380+
const auto hasDocIDs = bool(_options->docIDs());
381+
if(!hasDocIDs && _options->pushFilter) {
382382
// docIDs has precedence over push filter
383383
opts.flags |= kC4IncludeBodies;
384384
}
@@ -393,7 +393,7 @@ namespace litecore { namespace repl {
393393
if(!isDocumentIDAllowed(info.docID))
394394
continue;
395395

396-
if (!hasDocIDs && _options.pushFilter) {
396+
if (!hasDocIDs && _options->pushFilter) {
397397
// If there is a push filter, we have to get the doc body for it to peruse:
398398
Retained<C4Document> nextDoc = e.getDocument();
399399
if(!nextDoc) {
@@ -416,7 +416,7 @@ namespace litecore { namespace repl {
416416

417417

418418
bool Checkpointer::isDocumentPending(C4Database* db, slice docId) {
419-
if(_options.push < kC4OneShot) {
419+
if(_options->push < kC4OneShot) {
420420
// Couchbase Lite should not allow this case
421421
C4Error::raise(LiteCoreDomain, kC4ErrorUnsupported);
422422
}

Replicator/Checkpointer.hh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace litecore { namespace repl {
3535
using namespace fleece;
3636

3737
class Checkpoint;
38-
struct Options;
38+
class Options;
3939
class RemoteSequence;
4040

4141

@@ -44,7 +44,7 @@ namespace litecore { namespace repl {
4444
Replicator, Pusher and Puller. */
4545
class Checkpointer {
4646
public:
47-
Checkpointer(const Options&, fleece::slice remoteURL);
47+
Checkpointer(const Options* NONNULL, fleece::slice remoteURL);
4848

4949
~Checkpointer();
5050

@@ -170,7 +170,7 @@ namespace litecore { namespace repl {
170170
void saveSoon();
171171

172172
Logging* _logger;
173-
const Options& _options;
173+
RetainedConst<Options> _options;
174174
alloc_slice const _remoteURL;
175175
std::unordered_set<std::string> _docIDs;
176176

Replicator/IncomingRev.cc

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ namespace litecore { namespace repl {
3838
:Worker(puller, "inc")
3939
,_puller(puller)
4040
{
41-
_passive = _options.pull <= kC4Passive;
42-
_important = false;
41+
_passive = _options->pull <= kC4Passive;
42+
_importance = false;
4343
static atomic<uint32_t> sRevSignpostCount {0};
4444
_serialNumber = ++sRevSignpostCount;
4545
}
@@ -71,7 +71,7 @@ namespace litecore { namespace repl {
7171
_revMessage->property("history"_sl),
7272
_revMessage->boolProperty("deleted"_sl),
7373
_revMessage->boolProperty("noconflicts"_sl)
74-
|| _options.noIncomingConflicts());
74+
|| _options->noIncomingConflicts());
7575
_rev->deltaSrcRevID = _revMessage->property("deltaSrc"_sl);
7676
slice sequenceStr = _revMessage->property(slice("sequence"));
7777
_remoteSequence = RemoteSequence(sequenceStr);
@@ -121,11 +121,11 @@ namespace litecore { namespace repl {
121121
_revMessage = nullptr;
122122

123123
_mayContainBlobs = jsonBody.containsBytes("\"digest\""_sl);
124-
_mayContainEncryptedProperties = !_options.disablePropertyDecryption()
124+
_mayContainEncryptedProperties = !_options->disablePropertyDecryption()
125125
&& MayContainPropertiesToDecrypt(jsonBody);
126126

127127
// Decide whether to continue now (on the Puller thread) or asynchronously on my own:
128-
if (_options.pullValidator|| jsonBody.size > kMaxImmediateParseSize
128+
if (_options->pullValidator|| jsonBody.size > kMaxImmediateParseSize
129129
|| _mayContainBlobs || _mayContainEncryptedProperties)
130130
enqueue(FUNCTION_TO_QUEUE(IncomingRev::parseAndInsert), move(jsonBody));
131131
else
@@ -140,13 +140,13 @@ namespace litecore { namespace repl {
140140
rev->owner = this;
141141

142142
// Do not purge if the auto-purge is not enabled:
143-
if (!_options.enableAutoPurge()) {
143+
if (!_options->enableAutoPurge()) {
144144
finish();
145145
return;
146146
}
147147

148148
// Call the custom validation function if any:
149-
if (_options.pullValidator) {
149+
if (_options->pullValidator) {
150150
// Revoked rev body is empty when sent to the filter:
151151
auto body = Dict::emptyDict();
152152
if (!performPullValidation(body))
@@ -168,7 +168,7 @@ namespace litecore { namespace repl {
168168
if (!fleeceDoc)
169169
err = C4Error::make(FleeceDomain, (int)encodeErr, "Incoming rev failed to encode"_sl);
170170

171-
} else if (_options.pullValidator || _mayContainBlobs || _mayContainEncryptedProperties) {
171+
} else if (_options->pullValidator || _mayContainBlobs || _mayContainEncryptedProperties) {
172172
// It's a delta, but we need the entire document body now because either it has to be
173173
// passed to the validation function, it may contain new blobs to download, or it may
174174
// have properties to decrypt.
@@ -178,7 +178,7 @@ namespace litecore { namespace repl {
178178
if (!fleeceDoc) {
179179
// Don't have the body of the source revision. This might be because I'm in
180180
// no-conflict mode and the peer is trying to push me a now-obsolete revision.
181-
if (_options.noIncomingConflicts())
181+
if (_options->noIncomingConflicts())
182182
err = {WebSocketDomain, 409};
183183
else
184184
err = C4Error::printf(LiteCoreDomain, kC4ErrorDeltaBaseUnknown,
@@ -208,7 +208,7 @@ namespace litecore { namespace repl {
208208
// no longer accessible (not in any channel the client has access to.)
209209
if (root["_removed"_sl].asBool()) {
210210
_rev->flags |= kRevPurged;
211-
if (!_options.enableAutoPurge()) {
211+
if (!_options->enableAutoPurge()) {
212212
finish();
213213
return;
214214
}
@@ -220,8 +220,8 @@ namespace litecore { namespace repl {
220220
C4Error error;
221221
decryptedRoot = DecryptDocumentProperties(_rev->docID,
222222
root,
223-
_options.propertyDecryptor,
224-
_options.callbackContext,
223+
_options->propertyDecryptor,
224+
_options->callbackContext,
225225
&error);
226226
if (decryptedRoot) {
227227
root = decryptedRoot;
@@ -277,10 +277,10 @@ namespace litecore { namespace repl {
277277

278278
// Calls the custom pull validator if available.
279279
bool IncomingRev::performPullValidation(Dict body) {
280-
if (_options.pullValidator) {
281-
if (!_options.pullValidator(nullslice, // TODO: Collection support
280+
if (_options->pullValidator) {
281+
if (!_options->pullValidator(nullslice, // TODO: Collection support
282282
_rev->docID, _rev->revID, _rev->flags, body,
283-
_options.callbackContext)) {
283+
_options->callbackContext)) {
284284
failWithError(WebSocketDomain, 403, "rejected by validation function"_sl);
285285
return false;
286286
}
@@ -372,12 +372,6 @@ namespace litecore { namespace repl {
372372
}
373373

374374

375-
int IncomingRev::progressNotificationLevel() const {
376-
return _puller ? _puller->progressNotificationLevel() : 0;
377-
}
378-
379-
380-
381375
Worker::ActivityLevel IncomingRev::computeActivityLevel() const {
382376
if (Worker::computeActivityLevel() == kC4Busy || _pendingCallbacks > 0
383377
|| (_blob != _pendingBlobs.end())) {

Replicator/IncomingRev.hh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,13 @@ namespace litecore { namespace repl {
4040
void revisionProvisionallyInserted();
4141
void revisionInserted();
4242

43-
int progressNotificationLevel() const override;
44-
4543
protected:
4644
ActivityLevel computeActivityLevel() const override;
4745

4846
private:
4947
void reinitialize();
5048
void parseAndInsert(alloc_slice jsonBody);
51-
bool nonPassive() const {return _options.pull > kC4Passive;}
49+
bool nonPassive() const {return _options->pull > kC4Passive;}
5250
void _handleRev(Retained<blip::MessageIn>);
5351
void gotDeltaSrc(alloc_slice deltaSrcBody);
5452
fleece::Doc parseBody(alloc_slice jsonBody);

0 commit comments

Comments
 (0)