Ticket #884: ticket884_handle_new_changes_with_type_modified_v2.diff

File ticket884_handle_new_changes_with_type_modified_v2.diff, 11.4 KB (added by dgollub, 6 years ago)

skip unmodified changes

  • opensync/engine/opensync_mapping_engine.c

     
    4646#include "opensync_mapping_engine_internals.h" 
    4747 
    4848 
    49 OSyncMappingEngine *osync_mapping_engine_new(OSyncObjEngine *parent, OSyncMapping *mapping, OSyncError **error) 
     49OSyncMappingEngine *osync_mapping_engine_new(OSyncObjEngine *parent, OSyncMapping *mapping, OSyncChangeType initial_changetype, OSyncError **error) 
    5050{ 
    51         osync_trace(TRACE_ENTRY, "%s(%p, %p, %p)", __func__, parent, mapping, error); 
     51        osync_trace(TRACE_ENTRY, "%s(%p, %p, %d, %p)", __func__, parent, mapping, initial_changetype, error); 
    5252 
    5353        osync_assert(parent); 
    5454        osync_assert(mapping); 
     
    7676                if (!entry_engine) 
    7777                        goto error_free_engine; 
    7878 
     79                OSyncChange *change = osync_entry_engine_get_change(entry_engine); 
     80                osync_change_set_changetype(change, initial_changetype); 
     81 
    7982                engine->entries = g_list_append(engine->entries, entry_engine); 
    8083        } 
    8184         
     
    357360                if (newChangeType == OSYNC_CHANGE_TYPE_ADDED && (existChangeType != OSYNC_CHANGE_TYPE_DELETED && existChangeType != OSYNC_CHANGE_TYPE_UNKNOWN)) { 
    358361                        osync_trace(TRACE_INTERNAL, "Updating change type to MODIFIED"); 
    359362                        osync_change_set_changetype(existChange, OSYNC_CHANGE_TYPE_MODIFIED); 
    360                 /* Only adapt the change to ADDED if the existing Change got deleted. Don't update it to ADDED if existChangeType is UNKOWN. 
     363                /* Only adapt the change to ADDED if the existing Change got deleted. 
    361364                   The exitChangeType is at least also UNKOWN if the file-sync has only one modified entry. */ 
    362                 } else if (newChangeType == OSYNC_CHANGE_TYPE_MODIFIED && (existChangeType == OSYNC_CHANGE_TYPE_DELETED)) { 
     365                } else if (newChangeType == OSYNC_CHANGE_TYPE_MODIFIED && 
     366                                (existChangeType == OSYNC_CHANGE_TYPE_DELETED || existChangeType == OSYNC_CHANGE_TYPE_UNKNOWN)) { 
    363367                        osync_trace(TRACE_INTERNAL, "Updating change type to ADDED"); 
    364368                        osync_change_set_changetype(existChange, OSYNC_CHANGE_TYPE_ADDED); 
    365369                } 
     
    425429                if (leftchange == NULL) 
    426430                        continue; 
    427431                         
    428                 if (osync_change_get_changetype(leftchange) == OSYNC_CHANGE_TYPE_UNKNOWN) 
     432                if (osync_change_get_changetype(leftchange) == OSYNC_CHANGE_TYPE_UNMODIFIED 
     433                        || osync_change_get_changetype(leftchange) == OSYNC_CHANGE_TYPE_UNKNOWN) 
    429434                        continue; 
    430435                 
    431436                osync_mapping_engine_set_master(engine, leftentry); 
     
    437442                        if (rightchange == NULL) 
    438443                                continue; 
    439444                 
    440                         if (osync_change_get_changetype(rightchange) == OSYNC_CHANGE_TYPE_UNKNOWN) 
     445                        if (osync_change_get_changetype(rightchange) == OSYNC_CHANGE_TYPE_UNMODIFIED 
     446                                        || osync_change_get_changetype(rightchange) == OSYNC_CHANGE_TYPE_UNKNOWN) 
    441447                                continue; 
    442448                         
    443449                        if (osync_change_compare(leftchange, rightchange) != OSYNC_CONV_DATA_SAME) { 
  • opensync/engine/opensync_obj_engine.c

     
    6969                osync_mapping_entry_unref(mapping_entry); 
    7070        } 
    7171         
    72         OSyncMappingEngine *mapping_engine = osync_mapping_engine_new(engine, mapping, error); 
     72        OSyncMappingEngine *mapping_engine = osync_mapping_engine_new(engine, mapping, OSYNC_CHANGE_TYPE_UNKNOWN, error); 
    7373        if (!mapping_engine) 
    7474                goto error_free_mapping; 
    7575        osync_mapping_unref(mapping); 
     
    549549        for (i = 0; i < osync_mapping_table_num_mappings(engine->mapping_table); i++) { 
    550550                OSyncMapping *mapping = osync_mapping_table_nth_mapping(engine->mapping_table, i); 
    551551                 
    552                 OSyncMappingEngine *mapping_engine = osync_mapping_engine_new(engine, mapping, error); 
     552                OSyncMappingEngine *mapping_engine = osync_mapping_engine_new(engine, mapping, OSYNC_CHANGE_TYPE_UNMODIFIED, error); 
    553553                if (!mapping_engine) 
    554554                        goto error; 
    555555                 
     
    865865                                        OSyncMappingEntryEngine *entry = m->data; 
    866866                                        OSyncChange *change = entry->change; 
    867867 
    868                                         if (!change) 
     868                                        osync_assert(change); 
     869 
     870                                        if (osync_change_get_changetype(change) == OSYNC_CHANGE_TYPE_UNMODIFIED) 
    869871                                                continue; 
    870872 
    871873                                        if (!osync_client_proxy_read(sinkengine->proxy, _osync_obj_engine_read_ignored_callback, sinkengine, change, error)) 
     
    940942                                        OSyncMappingEntryEngine *entry_engine = e->data; 
    941943                                        osync_assert(entry_engine); 
    942944 
     945                                        if (osync_change_get_changetype(entry_engine->change) == OSYNC_CHANGE_TYPE_UNMODIFIED) 
     946                                                continue; 
     947 
    943948                                        /* Merger - Save the entire xml and demerge */ 
    944949                                        /* TODO: is here the right place to save the xml???? */ 
    945950                                        if (osync_group_get_merger_enabled(osync_engine_get_group(engine->parent)) && 
  • opensync/engine/opensync_mapping_entry_engine.c

     
    5050        engine->sink_engine = sink_engine; 
    5151         
    5252        engine->objengine = objengine; 
    53          
     53 
     54        engine->change = osync_change_new(error); 
     55        if (!engine->change) 
     56                goto error_free; 
     57  
    5458        engine->mapping_engine = osync_mapping_engine_ref(mapping_engine); 
    5559        engine->entry = osync_mapping_entry_ref(entry); 
    5660         
     
    6064        osync_trace(TRACE_EXIT, "%s: %p", __func__, engine); 
    6165        return engine; 
    6266 
     67error_free: 
     68        osync_entry_engine_unref(engine); 
    6369error: 
    6470        osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); 
    6571        return NULL; 
  • opensync/engine/opensync_mapping_engine_internals.h

     
    3434        osync_bool synced; 
    3535}; 
    3636 
    37 OSyncMappingEngine *osync_mapping_engine_new(OSyncObjEngine *parent, OSyncMapping *mapping, OSyncError **error); 
     37OSyncMappingEngine *osync_mapping_engine_new(OSyncObjEngine *parent, OSyncMapping *mapping, OSyncChangeType initial_changetype, OSyncError **error); 
    3838OSyncMappingEngine *osync_mapping_engine_ref(OSyncMappingEngine *engine); 
    3939void osync_mapping_engine_unref(OSyncMappingEngine *engine); 
    4040 
  • tests/mock-plugin/mock_sync.c

     
    284284 
    285285                        OSyncChangeType type = osync_hashtable_get_changetype(directory->hashtable, change); 
    286286                         
    287                         osync_change_set_changetype(change, type); 
     287                        /* simulate plugins which can't determine if a change is ADDED and need 
     288                           to call always MODIFIED instead. This should be correctly handled by 
     289                           the mapping engine. See #884 
     290                         */ 
     291                        if (mock_get_error(info->memberid, "MOCK_SYNC_ALWAYS_CHANGETYPE_MODIFIED")) 
     292                                osync_change_set_changetype(change, OSYNC_CHANGE_TYPE_MODIFIED); 
     293                        else 
     294                                osync_change_set_changetype(change, type); 
     295 
    288296                        osync_hashtable_update_change(directory->hashtable, change); 
    289297 
    290298                        if (type == OSYNC_CHANGE_TYPE_UNMODIFIED) { 
     
    413421                osync_trace(TRACE_EXIT_ERROR, "COMMIT_TIMEOUT (mock-sync)!"); 
    414422                return; 
    415423        } 
     424 
     425        if (mock_get_error(info->memberid, "MOCK_SYNC_EXPECT_COMMIT_ALWAYS_ADDED")) { 
     426                /* for testcase: engine_getchanges_fixed_chtype_modified */ 
     427                osync_assert(osync_change_get_changetype(change) == OSYNC_CHANGE_TYPE_ADDED); 
     428        } 
    416429         
    417430        if (!mock_write(data, info, ctx, change)) { 
    418431                osync_trace(TRACE_EXIT_ERROR, "%s", __func__); 
  • tests/support.c

     
    2525        unsetenv("MAINSINK_CONNECT"); 
    2626 
    2727        unsetenv("OSYNC_NOMEMORY"); 
     28        unsetenv("MOCK_SYNC_EXPECT_COMMIT_ALWAYS_ADDED"); 
     29        unsetenv("MOCK_SYNC_ALWAYS_CHANGETYPE_MODIFIED"); 
    2830} 
    2931 
    3032 
  • tests/engine-tests/check_engine.c

     
    1111#include "opensync/engine/opensync_engine_internals.h" 
    1212#include "opensync/engine/opensync_engine_private.h" 
    1313 
     14#include "opensync/group/opensync_group_internals.h" 
    1415#include "opensync/group/opensync_member_internals.h" 
    1516#include "opensync/client/opensync_client_internals.h" 
    1617 
     
    19851986} 
    19861987END_TEST 
    19871988 
     1989/* 
     1990 * Testing following secnarios: 
     1991 *  
     1992 * Member A: will _never_ report changes as ADDED, instead those get reported 
     1993 *           as MODIFIED. DELETED is supported as usual. 
     1994 * 
     1995 * Member B: supports reporting of ADDED, MODIFIED and DELETED changetypes. 
     1996 * 
     1997 * 0. Very first sync, no previous mappings are available. 
     1998 * 1. Member A reports _new_ change "testdata" as MODIFIED (not ADDED!) 
     1999 *    Expected result: Member B commit function sees "testdata" change as 
     2000 *                     ADDED changetype. NOT modified. 
     2001 * 2. Member A rerpots _modified_ change "testdata" as MODIFIED (as regular) 
     2002 *    Expected result: Member B commit function sees "testdata" change as 
     2003 *                     MODIFIED changetype (as regular). 
     2004 * 
     2005 * Regression testing: #884 
     2006 */ 
     2007START_TEST (engine_getchanges_fixed_chtype_modified) 
     2008{ 
     2009        char *testbed = setup_testbed("sync"); 
     2010        char *formatdir = g_strdup_printf("%s/formats",  testbed); 
     2011        char *plugindir = g_strdup_printf("%s/plugins", testbed); 
     2012 
     2013        OSyncError *error = NULL; 
     2014        OSyncGroup *group = osync_group_new(&error); 
     2015        osync_group_set_schemadir(group, testbed); 
     2016        osync_group_load(group, "configs/group", &error);  
     2017        fail_unless(error == NULL, NULL); 
     2018 
     2019        /* Engine Init */ 
     2020        OSyncEngine *engine = osync_engine_new(group, &error); 
     2021        fail_unless(engine != NULL, NULL); 
     2022        fail_unless(error == NULL, NULL); 
     2023 
     2024        osync_engine_set_schemadir(engine, testbed); 
     2025        osync_engine_set_plugindir(engine, plugindir); 
     2026        osync_engine_set_formatdir(engine, formatdir); 
     2027 
     2028        fail_unless(osync_engine_initialize(engine, &error), NULL); 
     2029        fail_unless(error == NULL, NULL); 
     2030        /* End of Engine Init */ 
     2031 
     2032        /* Playground */ 
     2033 
     2034 
     2035        /* Step 1: Create new entry which gets reported as MODIFIED, 
     2036                   and retrieved as ADDED */ 
     2037 
     2038        /* Tune Member A (1st) to MODIFIED-only reporting plugin */ 
     2039        setenv("MOCK_SYNC_ALWAYS_CHANGETYPE_MODIFIED", "1", TRUE); 
     2040 
     2041        /* Tune Member B (2nd) to exepcted ADDED reproted change */ 
     2042        setenv("MOCK_SYNC_EXPECT_COMMIT_ALWAYS_ADDED", "2", TRUE); 
     2043        osync_testing_system_abort("cp testdata data1/testdata"); 
     2044         
     2045        fail_unless(synchronize_once(engine, &error), NULL); 
     2046        fail_unless(error == NULL, NULL); 
     2047        fail_unless(osync_testing_diff("data1", "data2"), NULL); 
     2048        /* (mock-sync plugin would fail if unexpected changetype got send */ 
     2049 
     2050        /* Step 2: Modifed change which gets reported as MODIFIED and 
     2051           retrieved as MODIFIED. Don't expected ADDED for Member B (2nd) */ 
     2052        unsetenv("MOCK_SYNC_EXPECT_COMMIT_ALWAYS_ADDED"); 
     2053 
     2054        osync_testing_system_abort("cp new_data1 data1/testdata"); 
     2055         
     2056        fail_unless(synchronize_once(engine, &error), NULL); 
     2057        fail_unless(error == NULL, NULL); 
     2058        fail_unless(osync_testing_diff("data1", "data2"), NULL); 
     2059 
     2060        /* End of playground */ 
     2061 
     2062        /* Finalize */ 
     2063        osync_engine_unref(engine); 
     2064        osync_group_unref(group); 
     2065 
     2066        g_free(formatdir); 
     2067        g_free(plugindir); 
     2068 
     2069        destroy_testbed(testbed); 
     2070} 
     2071END_TEST 
     2072 
     2073 
    19882074Suite *engine_suite(void) 
    19892075{ 
    19902076        Suite *s = suite_create("Engine"); 
     
    20042090         
    20052091        //batch commit 
    20062092        //connect problem 
     2093 
    20072094        //get_changes problem 
     2095        create_case(s, "engine_getchanges_fixed_chtype_modified", engine_getchanges_fixed_chtype_modified); 
    20082096         
    20092097        return s; 
    20102098}