engine: change tracking optional for caching mode and item modification

Recording the revision of items during a caching sync is unnecessary
because the next sync will not use the information. For item
modifications, the information was not even recorded.

Now a "don't need changes" mode can be set in SyncSource, which is
done for caching and command line item operations. This is better than
second-guessing the mode in which a source is used.

SyncSourceRevision checks that flag and skips updating the
luid->revision mapping if set.

Individual backends can also check the flag and skip calculating the
revision to begin with.
This commit is contained in:
Patrick Ohly 2013-06-11 15:25:37 +02:00
parent b7ea49ea8d
commit 6c551167c4
4 changed files with 45 additions and 3 deletions

View File

@ -1328,6 +1328,7 @@ bool Cmdline::run() {
checkSyncPasswords(*context);
checkSourcePasswords(*context, source->getName(), sourceNodes);
source->setNeedChanges(false);
source->open();
const SyncSource::Operations &ops = source->getOperations();
if (m_printItems) {

View File

@ -2198,6 +2198,14 @@ void SyncContext::startSourceAccess(SyncSource *source)
m_firstSourceAccess = false;
}
if (m_serverMode) {
// When using the source as cache, change tracking
// is not required. Disabling it can make item
// changes faster.
SyncMode mode = StringToSyncMode(source->getSync());
if (mode == SYNC_LOCAL_CACHE_SLOW ||
mode == SYNC_LOCAL_CACHE_INCREMENTAL) {
source->setNeedChanges(false);
}
// source is active in sync, now open it
source->open();
}

View File

@ -196,7 +196,8 @@ SyncSource::SyncSource(const SyncSourceParams &params) :
m_numDeleted(0),
m_forceSlowSync(false),
m_database("", ""),
m_name(params.getDisplayName())
m_name(params.getDisplayName()),
m_needChanges(true)
{
}
@ -1174,13 +1175,22 @@ bool SyncSourceRevisions::detectChanges(ConfigNode &trackingNode, ChangeMode mod
initRevisions();
// Check whether we have valid revision information. If not, then
// we need to do a slow sync. The assumption here is
if (!m_revisions.empty() &&
// we need to do a slow sync. The assumption here is that an empty
// revision string marks missing information. When we don't need
// change information, not having a revision string is okay.
if (needChanges() &&
!m_revisions.empty() &&
m_revisions.begin()->second.empty()) {
forceSlowSync = true;
mode = CHANGES_SLOW;
}
// If we don't need changes, then override the mode so that
// we don't compute them below.
if (!needChanges()) {
mode = CHANGES_SLOW;
}
// Delay setProperty calls until after checking all uids.
// Necessary for MapSyncSource, which shares the revision among
// several uids. Another advantage is that we can do the "find
@ -1246,6 +1256,10 @@ void SyncSourceRevisions::updateRevision(ConfigNode &trackingNode,
const std::string &new_luid,
const std::string &revision)
{
if (!needChanges()) {
return;
}
databaseModified();
if (old_luid != new_luid) {
trackingNode.removeProperty(old_luid);
@ -1259,6 +1273,9 @@ void SyncSourceRevisions::updateRevision(ConfigNode &trackingNode,
void SyncSourceRevisions::deleteRevision(ConfigNode &trackingNode,
const std::string &luid)
{
if (!needChanges()) {
return;
}
databaseModified();
trackingNode.removeProperty(luid);
}

View File

@ -1642,6 +1642,16 @@ class SyncSourceBase {
*/
virtual void finishItemChanges() {}
/**
* In some usage scenarios, change tracking is not necessary.
* This includes local caching (where local data is not expected
* to changed outside of sync) or item manipulation.
*
* The user of a source must explicitly disable change tracking,
* see SyncSource.
*/
virtual bool needChanges() { return true; }
protected:
struct SynthesisInfo {
/**
@ -1986,6 +1996,9 @@ class SyncSource : virtual public SyncSourceBase, public SyncSourceConfig, publi
virtual long getNumDeleted() const { return m_numDeleted; }
virtual void setNumDeleted(long num) { m_numDeleted = num; }
virtual void incrementNumDeleted() { m_numDeleted++; }
virtual bool needChanges() { return m_needChanges; }
void setNeedChanges(bool needChanges) { m_needChanges = needChanges; }
/**
* Set to true in SyncContext::initSAN() when a SyncML server has
@ -2026,6 +2039,9 @@ class SyncSource : virtual public SyncSourceBase, public SyncSourceConfig, publi
/** actual name of the source */
std::string m_name;
/** change tracking enabled? */
bool m_needChanges;
};
/**