From 75910a187a3eaacedbb5b9a0ccb9236a2ac651f9 Mon Sep 17 00:00:00 2001 From: Chris Frey Date: Tue, 31 Aug 2010 18:32:35 -0400 Subject: [PATCH] os4x: optimized dirty flag clearing Clearing the dirty flags on newly updated records requires a reconnect, but it only requires one reconnect, and no reconnect it needed if nothing is written to the device, so skip the reconnect whenever possible, which makes syncing much faster. --- ChangeLog | 7 +++++++ opensync-plugin-0.4x/src/barry_sync.cc | 31 ++++++++++--------------------- opensync-plugin-0.4x/src/environment.cc | 18 +++++++++++++++++- opensync-plugin-0.4x/src/environment.h | 5 +++++ 4 files changed, 39 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index fcbd3684..369a2e9c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ Release: version 0.17 - 2010/01/?? ------------------------------------------------------------------------------ +2010/08/31 + - os4x: optimized dirty flag clearing + Clearing the dirty flags on newly updated records requires + a reconnect, but it only requires one reconnect, and no + reconnect it needed if nothing is written to the device, + so skip the reconnect whenever possible, which makes syncing + much faster 2010/08/30 - lib: use thread-safe getpwuid_r() in config file code 2010/08/18 diff --git a/opensync-plugin-0.4x/src/barry_sync.cc b/opensync-plugin-0.4x/src/barry_sync.cc index d1434bdb..91c593b9 100644 --- a/opensync-plugin-0.4x/src/barry_sync.cc +++ b/opensync-plugin-0.4x/src/barry_sync.cc @@ -316,10 +316,14 @@ bool FinishSync(OSyncContext *ctx, BarryEnvironment *env, DatabaseSyncState *pSy return true; } - Barry::Mode::Desktop &desktop = *env->m_pDesktop; + // we reconnect to the device here, since dirty flags + // for records we've just touched do not show up until + // a disconnect... as far as I can tell. + env->ReconnectForDirtyFlags(); // get the state table again, so we can update // the cache properly + Barry::Mode::Desktop &desktop = *env->m_pDesktop; desktop.GetRecordStateTable(pSync->m_dbId, pSync->m_Table); // clear all dirty flags in device @@ -896,6 +900,11 @@ static void commit_change(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncCo } } + // if we get here, we are about to update the device, + // and dirty flags will change in such a way that a + // reconnect will be required later... so flag this state + env->RequireDirtyReconnect(); + std::string errmsg; bool status; @@ -968,11 +977,6 @@ static void contact_sync_done(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSy BarryEnvironment *env = (BarryEnvironment *) userdata; - // we reconnect to the device here, since dirty flags - // for records we've just touched do not show up until - // a disconnect... as far as I can tell. - env->Reconnect(); - // do cleanup for each database if( FinishSync(ctx, env, &env->m_ContactsSync) ) { @@ -999,11 +1003,6 @@ static void event_sync_done(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSync BarryEnvironment *env = (BarryEnvironment *) userdata; - // we reconnect to the device here, since dirty flags - // for records we've just touched do not show up until - // a disconnect... as far as I can tell. - env->Reconnect(); - // do cleanup for each database if( FinishSync(ctx, env, &env->m_CalendarSync) ) { @@ -1030,11 +1029,6 @@ static void journal_sync_done(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSy BarryEnvironment *env = (BarryEnvironment *) userdata; - // we reconnect to the device here, since dirty flags - // for records we've just touched do not show up until - // a disconnect... as far as I can tell. - env->Reconnect(); - // do cleanup for each database if( FinishSync(ctx, env, &env->m_JournalSync) ) { @@ -1061,11 +1055,6 @@ static void todo_sync_done(OSyncObjTypeSink *sink, OSyncPluginInfo *info, OSyncC BarryEnvironment *env = (BarryEnvironment *) userdata; - // we reconnect to the device here, since dirty flags - // for records we've just touched do not show up until - // a disconnect... as far as I can tell. - env->Reconnect(); - // do cleanup for each database if( FinishSync(ctx, env, &env->m_TodoSync) ) { diff --git a/opensync-plugin-0.4x/src/environment.cc b/opensync-plugin-0.4x/src/environment.cc index 7a9dba91..0cde48a5 100644 --- a/opensync-plugin-0.4x/src/environment.cc +++ b/opensync-plugin-0.4x/src/environment.cc @@ -80,7 +80,8 @@ BarryEnvironment::BarryEnvironment(OSyncPluginInfo *info): m_CalendarSync(info, "calendar"), m_ContactsSync(info, "contacts"), m_JournalSync(info, "note"), - m_TodoSync(info, "todo") + m_TodoSync(info, "todo"), + m_NeedsReconnect(false) { } @@ -185,6 +186,8 @@ void BarryEnvironment::Disconnect() delete m_pCon; m_pCon = 0; + + m_NeedsReconnect = false; } bool BarryEnvironment::isConnected() @@ -195,6 +198,19 @@ bool BarryEnvironment::isConnected() return false; } +void BarryEnvironment::ReconnectForDirtyFlags() +{ + if( m_NeedsReconnect ) { + // Reconnect resets the m_NeedsReconnect via Disconnect + Reconnect(); + } +} + +void BarryEnvironment::RequireDirtyReconnect() +{ + m_NeedsReconnect = true; +} + void BarryEnvironment::ClearDirtyFlags(Barry::RecordStateTable &table, const std::string &dbname) { diff --git a/opensync-plugin-0.4x/src/environment.h b/opensync-plugin-0.4x/src/environment.h index 56d7550e..31c96bfa 100644 --- a/opensync-plugin-0.4x/src/environment.h +++ b/opensync-plugin-0.4x/src/environment.h @@ -73,6 +73,9 @@ public: // sync data DatabaseSyncState m_CalendarSync, m_ContactsSync, m_JournalSync, m_TodoSync; + // optimization state + bool m_NeedsReconnect; + protected: void DoConnect(); @@ -84,6 +87,8 @@ public: void Reconnect(); void Disconnect(); bool isConnected(); + void ReconnectForDirtyFlags(); + void RequireDirtyReconnect(); DatabaseSyncState* GetSyncObject(OSyncChange *change); -- 2.11.4.GIT