|
View:
New views
17 Messages
—
Rating Filter:
Alert me
|
|
|
[patch 00/13] [RFC] Hashtable improvements and API changesHi,
while playing around with "osyncplugin", I experienced how slow the osync_hashtable really is. I created a little patch series which consists of some list handling improvements in osync_db and kind of rewrite of osync_hashtable. The main difference which brings the performance increase with the new hashtable is the use of an internal hashtable for temporary store. This safes tons of single SQL queries which would require the database to perform a fsync. Since this isn't async this slows everything down for a bit. For persistent store we insert/update all osync_hashtable information on the end of a sync with the function osync_hashltable_committedall(). This function should get called in the "committed_all" plugin function. This will perform a SQL transaction of several SQL queries which are required by the osync_hashtable at once, which makes everything really fast. This is a proof of concept implementation and needs some further testing. There are some downsides and known issues: * one of the (new!) hashtable stress tests shows dataloss when committing 10K or 100k of hashtable entries. * osync_hashtable API changed again, and plugins have to be adapted. (I'll prepare patch for plugins in advance before committing this.) If there are no objections, I would commit this into trunk and touch again the hashtable API. I guess similar profiling could be done for the archive, which makes also heavy use of osync_db. best regards, Daniel ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone _______________________________________________ Opensync-devel mailing list Opensync-devel@... https://lists.sourceforge.net/lists/listinfo/opensync-devel |
|
|
[patch 01/13] Speed up osync_db database queriesg_list_append calls g_list_last() internally, which is traverse the entire list
every time. Calling g_list_prepend() and later reverse the entire list, is more efficient. good: O(2N) bad: O(N²) --- opensync/db/opensync_db.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) Index: opensync/opensync/db/opensync_db.c =================================================================== --- opensync.orig/opensync/db/opensync_db.c +++ opensync/opensync/db/opensync_db.c @@ -189,11 +189,19 @@ GList *osync_db_query_table(OSyncDB *db, for (j=0; j < numrows; j++) { GList *row = NULL; for (i=0; i < numcolumns; i++) - row = g_list_append(row, g_strdup(result[column_count++])); + /* speed up - prepend instead of append */ + row = g_list_prepend(row, g_strdup(result[column_count++])); - table = g_list_append(table, row); + /* items got prepended, reverse the list again */ + row = g_list_reverse(row); + + /* speed up - prepend instead of append. */ + table = g_list_prepend(table, row); } + /* items got prepended, reverse the list again */ + table = g_list_reverse(table); + sqlite3_free_table(result); osync_trace(TRACE_EXIT, "%s: %p", __func__, table); ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone _______________________________________________ Opensync-devel mailing list Opensync-devel@... https://lists.sourceforge.net/lists/listinfo/opensync-devel |
|
|
[patch 02/13] Make useof OSyncList in osync_dbMake use of OSyncList instead of GList, to provide a clean API without
requiring any direct includes of glib. --- opensync/db/opensync_db.c | 30 +++++++++++++++--------------- opensync/db/opensync_db.h | 4 ++-- 2 files changed, 17 insertions(+), 17 deletions(-) Index: opensync/opensync/db/opensync_db.c =================================================================== --- opensync.orig/opensync/db/opensync_db.c +++ opensync/opensync/db/opensync_db.c @@ -154,22 +154,22 @@ osync_bool osync_db_query(OSyncDB *db, c } /** - * @brief Exectues a SQL query and fill all requested data in a GList. + * @brief Exectues a SQL query and fill all requested data in a OSyncList. * Check error with osync_error_is_set(). * * @param db Pointer to database struct * @param query SQL database query * @param error Pointer to a error struct - * @return Returns pointer to GList which contains the each result as another GList ptr. Freeing is recommend with osync_db_free_list() + * @return Returns pointer to OSyncList which contains the each result as another OSyncList ptr. Freeing is recommend with osync_db_free_list() */ -GList *osync_db_query_table(OSyncDB *db, const char *query, OSyncError **error) +OSyncList *osync_db_query_table(OSyncDB *db, const char *query, OSyncError **error) { osync_trace(TRACE_ENTRY, "%s(%p, %s, %p)", __func__, db, query, error); osync_assert(db); osync_assert(query); - GList *table = NULL; + OSyncList *table = NULL; int i, j, column_count = 0; int numrows = 0, numcolumns = 0; char **result = NULL; @@ -187,20 +187,20 @@ GList *osync_db_query_table(OSyncDB *db, column_count = numcolumns; for (j=0; j < numrows; j++) { - GList *row = NULL; + OSyncList *row = NULL; for (i=0; i < numcolumns; i++) /* speed up - prepend instead of append */ - row = g_list_prepend(row, g_strdup(result[column_count++])); + row = osync_list_prepend(row, g_strdup(result[column_count++])); /* items got prepended, reverse the list again */ - row = g_list_reverse(row); + row = osync_list_reverse(row); /* speed up - prepend instead of append. */ - table = g_list_prepend(table, row); + table = osync_list_prepend(table, row); } /* items got prepended, reverse the list again */ - table = g_list_reverse(table); + table = osync_list_reverse(table); sqlite3_free_table(result); @@ -211,18 +211,18 @@ GList *osync_db_query_table(OSyncDB *db, /** * @brief Frees the full result of osync_db_query_table(). * - * @param list Result GList pointer of osync_db_query_table() + * @param list Result OSyncList pointer of osync_db_query_table() */ -void osync_db_free_list(GList *list) { +void osync_db_free_list(OSyncList *list) { osync_trace(TRACE_ENTRY, "%s(%p)", __func__, list); - GList *row; + OSyncList *row; for (row = list; row; row = row->next) { - g_list_foreach((GList *) row->data, (GFunc) g_free, NULL); - g_list_free((GList *) row->data); + osync_list_foreach((OSyncList *) row->data, (GFunc) g_free, NULL); + osync_list_free((OSyncList *) row->data); } - g_list_free(list); + osync_list_free(list); osync_trace(TRACE_EXIT, "%s", __func__); } Index: opensync/opensync/db/opensync_db.h =================================================================== --- opensync.orig/opensync/db/opensync_db.h +++ opensync/opensync/db/opensync_db.h @@ -37,8 +37,8 @@ OSYNC_EXPORT int osync_db_count(OSyncDB OSYNC_EXPORT char *osync_db_query_single_string(OSyncDB *db, const char *query, OSyncError **error); OSYNC_EXPORT int osync_db_query_single_int(OSyncDB *db, const char *query, OSyncError **error); OSYNC_EXPORT osync_bool osync_db_query(OSyncDB *db, const char *query, OSyncError **error); -OSYNC_EXPORT GList *osync_db_query_table(OSyncDB *db, const char *query, OSyncError **error); -OSYNC_EXPORT void osync_db_free_list(GList *list); +OSYNC_EXPORT OSyncList *osync_db_query_table(OSyncDB *db, const char *query, OSyncError **error); +OSYNC_EXPORT void osync_db_free_list(OSyncList *list); OSYNC_EXPORT osync_bool osync_db_bind_blob(OSyncDB *db, const char *query, const char *data, unsigned int size, OSyncError **error); OSYNC_EXPORT int osync_db_get_blob(OSyncDB *db, const char *query, char **data, unsigned int *size, OSyncError **error); ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone _______________________________________________ Opensync-devel mailing list Opensync-devel@... https://lists.sourceforge.net/lists/listinfo/opensync-devel |
|
|
[patch 03/13] Improved function woring in osync_dbImprove function wording - renamed osync_db_reset to osync_db_reset_table,
since a table gets rested, not an entire database! --- opensync/db/opensync_db.c | 4 ++-- opensync/db/opensync_db.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) Index: opensync/opensync/db/opensync_db.c =================================================================== --- opensync.orig/opensync/db/opensync_db.c +++ opensync/opensync/db/opensync_db.c @@ -334,7 +334,7 @@ error: * @param error Pointer to a error struct * @return TRUE on success otherwise FALSE */ -osync_bool osync_db_reset(OSyncDB *db, const char *tablename, OSyncError **error) +osync_bool osync_db_reset_table(OSyncDB *db, const char *tablename, OSyncError **error) { osync_trace(TRACE_ENTRY, "%s(%p, %s, %p)", __func__, db, tablename, error); @@ -372,7 +372,7 @@ osync_bool osync_db_reset_full(OSyncDB * while (sqlite3_step(ppStmt) == SQLITE_ROW) { const char *table = (const char *) sqlite3_column_text(ppStmt, 0); - if (!osync_db_reset(db, table, error)) + if (!osync_db_reset_table(db, table, error)) goto error; } @@ -417,7 +417,7 @@ error: * @param error Pointer to a error struct * @return If the table exist 1 else 0. On error -1. */ -int osync_db_exists(OSyncDB *db, const char *tablename, OSyncError **error) +int osync_db_table_exists(OSyncDB *db, const char *tablename, OSyncError **error) { osync_trace(TRACE_ENTRY, "%s(%p, %s, %p)", __func__, db, tablename, error); Index: opensync/opensync/db/opensync_db.h =================================================================== --- opensync.orig/opensync/db/opensync_db.h +++ opensync/opensync/db/opensync_db.h @@ -27,9 +27,9 @@ OSYNC_EXPORT OSyncDB *osync_db_new(OSync OSYNC_EXPORT osync_bool osync_db_open(OSyncDB *db, const char *dbfile, OSyncError **error); OSYNC_EXPORT osync_bool osync_db_close(OSyncDB *db, OSyncError **error); -OSYNC_EXPORT int osync_db_exists(OSyncDB *db, const char *tablename, OSyncError **error); +OSYNC_EXPORT int osync_db_table_exists(OSyncDB *db, const char *tablename, OSyncError **error); -OSYNC_EXPORT osync_bool osync_db_reset(OSyncDB *db, const char *tablename, OSyncError **error); +OSYNC_EXPORT osync_bool osync_db_reset_table(OSyncDB *db, const char *tablename, OSyncError **error); OSYNC_EXPORT osync_bool osync_db_reset_full(OSyncDB *db, OSyncError **error); OSYNC_EXPORT int osync_db_count(OSyncDB *db, const char *query, OSyncError **error); ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone _______________________________________________ Opensync-devel mailing list Opensync-devel@... https://lists.sourceforge.net/lists/listinfo/opensync-devel |
|
|
[patch 04/13] assert when set function get called with NULL---
opensync/plugin/opensync_plugin_info.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) Index: opensync/opensync/plugin/opensync_plugin_info.c =================================================================== --- opensync.orig/opensync/plugin/opensync_plugin_info.c +++ opensync/opensync/plugin/opensync_plugin_info.c @@ -114,6 +114,8 @@ void osync_plugin_info_unref(OSyncPlugin void osync_plugin_info_set_loop(OSyncPluginInfo *info, void *loop) { osync_assert(info); + osync_assert(loop); + info->loop = loop; } @@ -136,6 +138,8 @@ void *osync_plugin_info_get_loop(OSyncPl void osync_plugin_info_set_config(OSyncPluginInfo *info, const char *config) { osync_assert(info); + osync_assert(config); + if (info->config) g_free(info->config); info->config = g_strdup(config); @@ -162,6 +166,8 @@ const char *osync_plugin_info_get_config void osync_plugin_info_set_configdir(OSyncPluginInfo *info, const char *configdir) { osync_assert(info); + osync_assert(configdir); + if (info->configdir) g_free(info->configdir); info->configdir = g_strdup(configdir); @@ -188,6 +194,8 @@ const char *osync_plugin_info_get_config void osync_plugin_info_set_groupname(OSyncPluginInfo *info, const char *groupname) { osync_assert(info); + osync_assert(groupname); + if (info->groupname) g_free(info->groupname); info->groupname = g_strdup(groupname); @@ -214,9 +222,11 @@ const char *osync_plugin_info_get_groupn */ OSyncObjTypeSink *osync_plugin_info_find_objtype(OSyncPluginInfo *info, const char *name) { + osync_assert(info); + osync_assert(name); + osync_trace(TRACE_ENTRY, "%s(%p, %s)", __func__, info, name); GList *p; - osync_assert(info); OSyncObjTypeSink *sink = NULL; for (p = info->objtypes; p; p = p->next) { ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone _______________________________________________ Opensync-devel mailing list Opensync-devel@... https://lists.sourceforge.net/lists/listinfo/opensync-devel |
|
|
[patch 05/13] osync_db_exists got renamed to osync_db_table_exists---
opensync/helper/opensync_anchor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) Index: opensync/opensync/helper/opensync_anchor.c =================================================================== --- opensync.orig/opensync/helper/opensync_anchor.c +++ opensync/opensync/helper/opensync_anchor.c @@ -69,7 +69,7 @@ static OSyncDB *_osync_anchor_db_new(con goto error_free_db; } - int ret = osync_db_exists(db, "tbl_anchor", error); + int ret = osync_db_table_exists(db, "tbl_anchor", error); if (ret > 0) { osync_trace(TRACE_EXIT, "%s: %p", __func__, db); return db; ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone _______________________________________________ Opensync-devel mailing list Opensync-devel@... https://lists.sourceforge.net/lists/listinfo/opensync-devel |
|
|
[patch 06/13] Make use of OSyncList in ArchiveMake use of OSyncList instead of GList, since osync_db_query makes also use of
OSyncList. osync_db_exists got renamed t osync_db_table_exists. --- opensync/archive/opensync_archive.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) Index: opensync/opensync/archive/opensync_archive.c =================================================================== --- opensync.orig/opensync/archive/opensync_archive.c +++ opensync/opensync/archive/opensync_archive.c @@ -57,7 +57,7 @@ static osync_bool osync_archive_create_c osync_assert(objtype); char *tbl_changes = g_strdup_printf("tbl_changes_%s", objtype); - int ret = osync_db_exists(db, tbl_changes, error); + int ret = osync_db_table_exists(db, tbl_changes, error); g_free(tbl_changes); /* error if ret -1 */ @@ -94,7 +94,7 @@ static osync_bool osync_archive_create_c osync_assert(objtype); char *tbl_changelog = g_strdup_printf("tbl_changelog_%s", objtype); - int ret = osync_db_exists(db, tbl_changelog, error); + int ret = osync_db_table_exists(db, tbl_changelog, error); g_free(tbl_changelog); /* error if ret -1 */ @@ -130,7 +130,7 @@ static osync_bool osync_archive_create(O osync_assert(objtype); char *tbl_archive = g_strdup_printf("tbl_archive_%s", objtype); - int ret = osync_db_exists(db, tbl_archive, error); + int ret = osync_db_table_exists(db, tbl_archive, error); g_free(tbl_archive); /* error if ret -1 */ @@ -425,7 +425,7 @@ osync_bool osync_archive_load_changes(OS osync_assert(mappingids); osync_assert(memberids); - GList *result = NULL, *row = NULL; + OSyncList *result = NULL, *row = NULL; if (!osync_archive_create_changes(archive->db, objtype, error)) goto error; @@ -440,12 +440,12 @@ osync_bool osync_archive_load_changes(OS goto error; for (row = result; row; row = row->next) { - GList *column = row->data; + OSyncList *column = row->data; - long long int id = g_ascii_strtoull(g_list_nth_data(column, 0), NULL, 0); - const char *uid = g_list_nth_data(column, 1); - long long int mappingid = g_ascii_strtoull(g_list_nth_data(column, 2), NULL, 0); - long long int memberid = g_ascii_strtoull(g_list_nth_data(column, 3), NULL, 0); + long long int id = g_ascii_strtoull(osync_list_nth_data(column, 0), NULL, 0); + const char *uid = osync_list_nth_data(column, 1); + long long int mappingid = g_ascii_strtoull(osync_list_nth_data(column, 2), NULL, 0); + long long int memberid = g_ascii_strtoull(osync_list_nth_data(column, 3), NULL, 0); *ids = osync_list_append((*ids), GINT_TO_POINTER((int)id)); *uids = osync_list_append((*uids), g_strdup(uid)); @@ -518,8 +518,8 @@ osync_bool osync_archive_load_ignored_co osync_assert(ids); osync_assert(changetypes); - GList *result = NULL; - GList *row = NULL; + OSyncList *result = NULL; + OSyncList *row = NULL; if (!osync_archive_create_changelog(archive->db, objtype, error)) goto error; @@ -534,10 +534,10 @@ osync_bool osync_archive_load_ignored_co goto error; for (row = result; row; row = row->next) { - GList *column = row->data; + OSyncList *column = row->data; - long long int id = g_ascii_strtoull(g_list_nth_data(column, 0), NULL, 0); - int changetype = atoi(g_list_nth_data(column, 1)); + long long int id = g_ascii_strtoull(osync_list_nth_data(column, 0), NULL, 0); + int changetype = atoi(osync_list_nth_data(column, 1)); *ids = osync_list_append((*ids), GINT_TO_POINTER((int)id)); *changetypes = osync_list_append((*changetypes), GINT_TO_POINTER((int)changetype)); ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone _______________________________________________ Opensync-devel mailing list Opensync-devel@... https://lists.sourceforge.net/lists/listinfo/opensync-devel |
|
|
[patch 07/13] Fix gcc warning in tests/support.cIndex: opensync/tests/support.c
=================================================================== --- opensync.orig/tests/support.c +++ opensync/tests/support.c @@ -37,7 +37,7 @@ void check_env(void) { "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n"); } -char *setup_testbed(char *fkt_name) +char *setup_testbed(const char *fkt_name) { setuid(65534); Index: opensync/tests/support.h =================================================================== --- opensync.orig/tests/support.h +++ opensync/tests/support.h @@ -48,7 +48,7 @@ int num_mapping_conflicts; void check_env(void); -char *setup_testbed(char *fkt_name); +char *setup_testbed(const char *fkt_name); void destroy_testbed(char *path); // create_case() with timeout of 30seconds (default) void create_case(Suite *s, const char *name, TFun function); ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone _______________________________________________ Opensync-devel mailing list Opensync-devel@... https://lists.sourceforge.net/lists/listinfo/opensync-devel |
|
|
[patch 08/13] Introduce new osync_hashltable API* The hashtable is now restricted to one object type/table.
* Instead of performing single SQL queries an internal hashtable data structure is used for temporary store. * The persistent store of the hashtable is done by the function osync_hashtable_committedall(), which is using SQL transaction. Call this function in your committedall() plugin sink function. * Hashtable needs to be loaded with function osync_hashtable_load() * Added reference counting for hashtable object * osync_hashtable_num_entries() return value changed from int to unsigned int * osync_hashtable_nth_entry() got replaced by osync_hashtable_foreach(), which is more performant to iterate through the hashtable * osync_hashtable_get_deleted() return value changed from char* Array to OSyncList * osync_hashtable_update_hash() got by replaced osync_hashtable_update_change() which allows to use the OSyncChange object, since this contains changetype and UID. Depending on the changetype more specific SQL query get prepared. * osync_hashtable_write()/osync_hashtable_delete() got dropped. No need - right? * It's FAST now (seriously)! --- opensync/helper/opensync_hashtable.c | 452 +++++++++++-------------- opensync/helper/opensync_hashtable.h | 26 - opensync/helper/opensync_hashtable_internals.h | 14 3 files changed, 239 insertions(+), 253 deletions(-) Index: opensync/opensync/helper/opensync_hashtable.c =================================================================== --- opensync.orig/opensync/helper/opensync_hashtable.c +++ opensync/opensync/helper/opensync_hashtable.c @@ -38,17 +38,18 @@ /*! @brief Creates the database table for the hashtable * * @param table The hashtable - * @param objtype the object type of the hashtable + * @param ame The name of the hastable inside the database * @param error An error struct * @returns TRUE on success, or FALSE if an error occurred. * */ -static osync_bool osync_hashtable_create(OSyncHashTable *table, const char *objtype, OSyncError **error) +static osync_bool osync_hashtable_create(OSyncHashTable *table, OSyncError **error) { - osync_trace(TRACE_ENTRY, "%s(%p, %s, %p)", __func__, table, objtype, error); + osync_assert(table); + osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, table, error); - char *query = g_strdup_printf("CREATE TABLE tbl_hash_%s (id INTEGER PRIMARY KEY, uid VARCHAR UNIQUE, hash VARCHAR)", objtype); + char *query = g_strdup_printf("CREATE TABLE %s (id INTEGER PRIMARY KEY, uid VARCHAR UNIQUE, hash VARCHAR)", table->name); if (!osync_db_query(table->dbhandle, query, error)) { osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); g_free(query); @@ -116,42 +117,44 @@ static osync_bool osync_hashtable_create */ OSyncHashTable *osync_hashtable_new(const char *path, const char *objtype, OSyncError **error) { - osync_trace(TRACE_ENTRY, "%s(%s, %s, %p)", __func__, path, objtype, error); + osync_trace(TRACE_ENTRY, "%s(%s, %p)", __func__, path, error); OSyncHashTable *table = osync_try_malloc0(sizeof(OSyncHashTable), error); - if (!table) { - osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); - return NULL; - } + if (!table) + goto error; + + table->ref_count = 1; - table->used_entries = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); + + table->reported_entries = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); + table->db_entries = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); table->dbhandle = osync_db_new(error); if (!table->dbhandle) - goto error; + goto error_and_free_db; if (!osync_db_open(table->dbhandle, path, error)) goto error_and_free; - table->tablename = g_strdup_printf("tbl_hash_%s", objtype); + table->name = g_strdup_printf(OSYNC_HASHTABLE_DB_PREFIX"%s", objtype); - int ret = osync_db_exists(table->dbhandle, table->tablename, error); - if (ret > 0) { - goto end; - } else if (ret < 0) { - goto error_and_free; - } - /* if ret == 0 then table does not exist yet. contiune and create one. */ + int ret = osync_db_table_exists(table->dbhandle, table->name, error); + /* greater then 0 means evrything is O.k. */ + + if (ret < 0) + goto error; + else if (ret == 0) + /* if ret == 0 then table does not exist yet. contiune and create one. */ + if (!osync_hashtable_create(table, error)) + goto error; - if (!osync_hashtable_create(table, objtype, error)) - goto error_and_free; -end: osync_trace(TRACE_EXIT, "%s: %p", __func__, table); return table; -error_and_free: +error_and_free_db: g_free(table->dbhandle); +error_and_free: g_free(table); error: osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); @@ -159,29 +162,132 @@ error: } -/*! @brief Frees a hashtable +/*! @brief Increase the refernece count of the hashtable. + * + * @param table The hashtable to increase the reference count + * @returns Pointer to increased hashtable object + */ +OSyncHashTable *osync_hashtable_ref(OSyncHashTable *table) +{ + osync_assert(table); + + g_atomic_int_inc(&(table->ref_count)); + + return table; +} + +/*! @brief Decrease the reference count of the hastable. Hashtable + * gets freed if the reference count get less then one. * - * @param table The hashtable to free + * @param table The hashtable to decrease the reference count * */ -void osync_hashtable_free(OSyncHashTable *table) +void osync_hashtable_unref(OSyncHashTable *table) { - osync_trace(TRACE_ENTRY, "%s(%p)", __func__, table); osync_assert(table); - - if (!osync_db_close(table->dbhandle, NULL)) - osync_trace(TRACE_INTERNAL, "Can't close database"); + if (g_atomic_int_dec_and_test(&(table->ref_count))) { + osync_trace(TRACE_ENTRY, "%s(%p)", __func__, table); + + OSyncError *error = NULL; - g_hash_table_destroy(table->used_entries); + if (!osync_db_close(table->dbhandle, &error)) { + osync_trace(TRACE_ERROR, "Couldn't close database: %s", osync_error_print(&error)); + osync_error_unref(&error); + } + + g_hash_table_destroy(table->reported_entries); + g_hash_table_destroy(table->db_entries); + + g_free(table->name); + g_free(table->dbhandle); + g_free(table); - g_free(table->tablename); - g_free(table->dbhandle); - g_free(table); + osync_trace(TRACE_EXIT, "%s", __func__); + } +} + +osync_bool osync_hashtable_load(OSyncHashTable *table, OSyncError **error) +{ + osync_trace(TRACE_ENTRY, "%s(%p, %p)", __func__, table, error); + + char *query; + OSyncList *row, *result; + + query = g_strdup_printf("SELECT uid, hash FROM %s", table->name); + result = osync_db_query_table(table->dbhandle, query, error); + g_free(query); + + /* If result is NULL, this means no entries - just check for error. */ + if (osync_error_is_set(error)) + goto error; + + for (row = result; row; row = row->next) { + OSyncList *column = row->data; + + char *uid = g_strdup(osync_list_nth_data(column, 0)); + char *hash = g_strdup(osync_list_nth_data(column, 1)); + + g_hash_table_insert(table->db_entries, uid, hash); + } + osync_trace(TRACE_EXIT, "%s", __func__); + return TRUE; + +error: + osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); + return FALSE; } +static void _osync_hashtable_prepare_insert_query(const char *uid, const char *hash, void *user_data) +{ + OSyncHashTable *table = user_data; + + char *escaped_uid = osync_db_sql_escape(uid); + char *escaped_hash = osync_db_sql_escape(hash); + + g_string_append_printf(table->query, + "REPLACE INTO %s ('uid', 'hash') VALUES('%s', '%s');", + table->name, escaped_uid, escaped_hash); + + g_free(escaped_uid); + g_free(escaped_hash); +} + +osync_bool osync_hashtable_committedall(OSyncHashTable *table, OSyncError **error) +{ + osync_trace(TRACE_ENTRY, "%s(%p, %s, %p)", __func__, table, error); + + osync_bool ret; + + /* Should only be used by this function */ + osync_assert(!table->query); + + table->query = g_string_new("BEGIN TRANSACTION;"); + + osync_hashtable_foreach(table, _osync_hashtable_prepare_insert_query, table); + + table->query = g_string_append(table->query, "COMMIT TRANSACTION;"); + + char *query = g_string_free(table->query, FALSE); + ret = osync_db_query(table->dbhandle, query, error); + g_free(query); + + table->query = NULL; + + if (!ret) + goto error; + + osync_trace(TRACE_EXIT, "%s", __func__); + return TRUE; + +error: + osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); + return FALSE; +} + + /*! @brief Prepares the hashtable for a slowsync and flush the entire hashtable * * This function should be called to prepare the hashtable for a slowsync. @@ -199,13 +305,21 @@ osync_bool osync_hashtable_slowsync(OSyn osync_assert(table); osync_assert(table->dbhandle); - if (!osync_db_reset(table->dbhandle, table->tablename, error)) { - osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); - return FALSE; - } + osync_bool ret = FALSE; + + /* Reset hashtable in database */ + ret = osync_db_reset_table(table->dbhandle, table->name, error); + + if (!ret) + goto error; osync_trace(TRACE_EXIT, "%s", __func__); return TRUE; + +error: + osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error)); + return FALSE; + } #if !GLIB_CHECK_VERSION(2,12,0) @@ -237,199 +351,46 @@ void osync_hashtable_reset_reports(OSync /* Only free the internal hashtable of reported entries. Don't flush the real database. */ #if GLIB_CHECK_VERSION(2,12,0) - g_hash_table_remove_all(table->used_entries); + g_hash_table_remove_all(table->reported_entries); #else - g_hash_table_foreach_remove(table->used_entries, remove_entry, NULL); + g_hash_table_foreach_remove(table->reported_entries, remove_entry, NULL); #endif osync_trace(TRACE_EXIT, "%s", __func__); } -/*! @brief Returns the number of entries in this hashtable - * - * @param table The hashtable - * @returns The number of entries, or -1 if an error occurred - * - */ -int osync_hashtable_num_entries(OSyncHashTable *table) -{ - osync_trace(TRACE_ENTRY, "%s(%p)", __func__, table); - osync_assert(table); - osync_assert(table->dbhandle); - - char *query = g_strdup_printf("SELECT * FROM %s", table->tablename); - int ret = osync_db_count(table->dbhandle, query, NULL); - g_free(query); - - if (ret < 0) { - osync_trace(TRACE_EXIT_ERROR, "%s: Cannot count number of hashtable entries!", __func__); - return -1; - } - - osync_trace(TRACE_EXIT, "%s: %i", __func__, ret); - return ret; -} - -/*! @brief Gets the nth entry from the table - * - * This is mainly useful for debugging or special purposes +/*! @brief Update the an entry * - * @param table The hashtable - * @param nth The number of the entry to return - * @param uid A pointer to a char * that will hold the uid. The caller is responsible for freeing this. - * @param hash A pointer to a char * that will hold the hash. The caller is responsible for freeing this. - * @returns TRUE if successful, FALSE otherwise - * - */ -osync_bool osync_hashtable_nth_entry(OSyncHashTable *table, int nth, char **uid, char **hash) -{ - osync_assert(table); - osync_assert(table->dbhandle); - - GList *list = NULL; - OSyncError *error = NULL; - - - char *query = g_strdup_printf("SELECT uid, hash FROM %s LIMIT 1 OFFSET %i", table->tablename, nth); - list = osync_db_query_table(table->dbhandle, query, &error); - g_free(query); - - if (osync_error_is_set(&error)) { - osync_trace(TRACE_EXIT_ERROR, "%s: Cannot get #%i entry from hashtable: %s", __func__, nth, osync_error_print(&error)); - osync_error_unref(&error); - return FALSE; - } - - GList *column = list->data; - - *uid = g_strdup((char*)g_list_nth_data(column, 0)); - *hash = g_strdup((char*)g_list_nth_data(column, 1)); - - osync_db_free_list(list); - - return TRUE; -} - -/*! @brief Gets the hash value for given uid - * - * @param table The hashtable - * @param uid The uid to lookup - * @returns The hash. Has to be freed by the caller. - */ -char *osync_hashtable_get_hash(OSyncHashTable *table, const char *uid) -{ - osync_assert(uid); - osync_assert(table); - osync_assert(table->dbhandle); - - char *hash = NULL; - GList *list = NULL; - OSyncError *error = NULL; - char *escaped_uid = osync_db_sql_escape(uid); - - char *query = g_strdup_printf("SELECT hash FROM %s WHERE uid= '%s' LIMIT 1", - table->tablename, escaped_uid); - list = osync_db_query_table(table->dbhandle, query, &error); - g_free(query); - g_free(escaped_uid); - - if (osync_error_is_set(&error)) { - osync_trace(TRACE_EXIT_ERROR, "%s: Cannot get hash for '%s': %s", - __func__, uid, osync_error_print(&error)); - osync_error_unref(&error); - return NULL; - } - - if (list && list->data) { - GList *column = list->data; - hash = g_strdup((char *)g_list_nth_data(column, 0)); - } - - osync_db_free_list(list); - - return hash; -} - -/*! @brief Write the hash value for given uid - * - * @param table The hashtable - * @param uid The uid - * @param hash The hash - */ -void osync_hashtable_write(OSyncHashTable *table, const char *uid, const char *hash) -{ - osync_trace(TRACE_ENTRY, "%s(%p, %s, %s)", __func__, table, uid, hash); - osync_assert(table); - osync_assert(table->dbhandle); - - char *escaped_uid = osync_db_sql_escape(uid); - char *escaped_hash = osync_db_sql_escape(hash); - char *query = g_strdup_printf("REPLACE INTO %s ('uid', 'hash') VALUES('%s', '%s')", table->tablename, escaped_uid, escaped_hash); - g_free(escaped_uid); - g_free(escaped_hash); - - if (!osync_db_query(table->dbhandle, query, NULL)) { - g_free(query); - osync_trace(TRACE_EXIT, "%s: Cannot write hashtable entry.", __func__); - return; - } - g_free(query); - - osync_trace(TRACE_EXIT, "%s", __func__); -} - -/*! @brief Delete hashtable entries for given uid - * - * @param table The hashtable - * @param uid The uid of the entry to delete - */ -void osync_hashtable_delete(OSyncHashTable *table, const char *uid) -{ - osync_trace(TRACE_ENTRY, "%s(%p, %s)", __func__, table, uid); - osync_assert(table); - osync_assert(table->dbhandle); - - char *escaped_uid = osync_db_sql_escape(uid); - char *query = g_strdup_printf("DELETE FROM %s WHERE uid='%s'", table->tablename, escaped_uid); - g_free(escaped_uid); - - if (!osync_db_query(table->dbhandle, query, NULL)) { - g_free(query); - osync_trace(TRACE_EXIT_ERROR, "%s: Cannot delete hashtable entry.", __func__); - return; - /* TODO: Error handling */ - } - g_free(query); - - osync_trace(TRACE_EXIT, "%s", __func__); -} - -/*! @brief Update the hash for a entry - * - * Updates the hash for a entry in the hashtable. Do this after you see that a hash + * Updates the entry in the hashtable. Do this after you see that a hash * has changed, for example after reading it during get_changes or after you - * wrote it + * wrote it. * * @param table The hashtable * @param type The type of change (added, modified, etc.) * @param uid the uid of the changed entry * @param hash the new hash of the changed entry */ -void osync_hashtable_update_hash(OSyncHashTable *table, OSyncChangeType type, const char *uid, const char *hash) +void osync_hashtable_update_change(OSyncHashTable *table, OSyncChange *change, const char *hash) { - osync_trace(TRACE_ENTRY, "%s(%p, %i, %s, %s)", __func__, table, type, uid, hash); osync_assert(table); osync_assert(table->dbhandle); + osync_assert(change); - switch (type) { + osync_trace(TRACE_ENTRY, "%s(%p, %p, %s)", __func__, table, change, __NULLSTR(hash)); + + const char *uid = osync_change_get_uid(change); + + switch (osync_change_get_changetype(change)) { case OSYNC_CHANGE_TYPE_DELETED: - osync_hashtable_delete(table, uid); + g_hash_table_remove(table->db_entries, uid); break; case OSYNC_CHANGE_TYPE_UNMODIFIED: case OSYNC_CHANGE_TYPE_UNKNOWN: case OSYNC_CHANGE_TYPE_MODIFIED: + g_hash_table_replace(table->db_entries, g_strdup(uid), g_strdup(hash)); + break; case OSYNC_CHANGE_TYPE_ADDED: - osync_hashtable_write(table, uid, hash); + g_hash_table_insert(table->db_entries, g_strdup(uid), g_strdup(hash)); break; } @@ -448,51 +409,44 @@ void osync_hashtable_update_hash(OSyncHa */ void osync_hashtable_report(OSyncHashTable *table, const char *uid) { - osync_trace(TRACE_ENTRY, "%s(%p, %s)", __func__, table, uid); osync_assert(table); osync_assert(table->dbhandle); + osync_assert(uid); + + osync_trace(TRACE_ENTRY, "%s(%p, %s)", __func__, table, uid); - g_hash_table_insert(table->used_entries, g_strdup(uid), GINT_TO_POINTER(1)); + g_hash_table_insert(table->reported_entries, g_strdup(uid), GINT_TO_POINTER(1)); osync_trace(TRACE_EXIT, "%s", __func__); } -/*! @brief Get the uid of all deleted items +/*! @brief Get a list of uids which deleted * * @param table The hashtable - * @returns A null-terminated array of uids. The uids and this array have to be freed by the caller. + * @returns OSyncList containing UIDs of deleted entries. Caller is responsible for freeing the list, not the content. * */ -char **osync_hashtable_get_deleted(OSyncHashTable *table) +OSyncList *osync_hashtable_get_deleted(OSyncHashTable *table) { - osync_trace(TRACE_ENTRY, "%s(%p)", __func__, table); - osync_assert(table); osync_assert(table->dbhandle); - GList *row = NULL, *result = NULL; + osync_trace(TRACE_ENTRY, "%s(%p)", __func__, table); - char *query = g_strdup_printf("SELECT uid FROM %s", table->tablename); - result = osync_db_query_table(table->dbhandle, query, NULL); - g_free(query); + GList *e, *db_entries; + OSyncList *deleted_entries = NULL; - int numrows = g_list_length(result); - char **ret = g_malloc0((numrows + 1) * sizeof(char *)); - - int num = 0; - for (row = result; row; row = row->next) { - GList *column = row->data; + db_entries = g_hash_table_get_keys(table->db_entries); - const char *uid = (const char *) g_list_nth_data(column, 0); + for (e = db_entries; e; e = e->next) { + const char *uid = e->data; - if (!g_hash_table_lookup(table->used_entries, uid)) - ret[num++] = g_strdup(uid); + if (!g_hash_table_lookup(table->reported_entries, uid)) + deleted_entries = osync_list_prepend(deleted_entries, (char *) uid); } - osync_db_free_list(result); - - osync_trace(TRACE_EXIT, "%s: %p(%i)", __func__, ret, num); - return ret; + osync_trace(TRACE_EXIT, "%s: %p", __func__, deleted_entries); + return deleted_entries; } /*! @brief Gets the changetype for a given uid and hash @@ -509,21 +463,16 @@ char **osync_hashtable_get_deleted(OSync */ OSyncChangeType osync_hashtable_get_changetype(OSyncHashTable *table, const char *uid, const char *hash) { - osync_trace(TRACE_ENTRY, "%s(%p, %s, %s)", __func__, table, uid, hash); osync_assert(table); osync_assert(table->dbhandle); + osync_assert(uid); + osync_assert(hash); - char *orighash = NULL; - - OSyncChangeType retval = OSYNC_CHANGE_TYPE_UNMODIFIED; + osync_trace(TRACE_ENTRY, "%s(%p, %s, %s)", __func__, table, uid, hash); - char *escaped_uid = osync_db_sql_escape(uid); - char *query = g_strdup_printf("SELECT hash FROM %s WHERE uid='%s'", table->tablename, escaped_uid); - orighash = osync_db_query_single_string(table->dbhandle, query, NULL); - g_free(query); - g_free(escaped_uid); - - osync_trace(TRACE_INTERNAL, "Comparing %s with %s", hash, orighash); + OSyncChangeType retval = OSYNC_CHANGE_TYPE_UNKNOWN; + + const char *orighash = osync_hashtable_get_hash(table, uid); if (orighash) { if (!strcmp(hash, orighash)) @@ -533,10 +482,27 @@ OSyncChangeType osync_hashtable_get_chan } else retval = OSYNC_CHANGE_TYPE_ADDED; - g_free(orighash); osync_trace(TRACE_EXIT, "%s: %i", __func__, retval); return retval; } +unsigned int osync_hashtable_num_entries(OSyncHashTable *table) +{ + osync_assert(table); + return g_hash_table_size(table->db_entries); +} + +void osync_hashtable_foreach(OSyncHashTable *table, OSyncHashtableForEach func, void *user_data) +{ + osync_assert(table); + g_hash_table_foreach(table->db_entries, (GHFunc) func, user_data); +} + +const char *osync_hashtable_get_hash(OSyncHashTable *table, const char *uid) +{ + osync_assert(table); + return (const char *) g_hash_table_lookup(table->db_entries, uid); +} + /*@}*/ Index: opensync/opensync/helper/opensync_hashtable.h =================================================================== --- opensync.orig/opensync/helper/opensync_hashtable.h +++ opensync/opensync/helper/opensync_hashtable.h @@ -1,6 +1,7 @@ /* * libopensync - A synchronization framework * Copyright (C) 2004-2005 Armin Bauer <armin.bauer@...> + * Copyright (C) 2008 Daniel Gollub <dgollub@...> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -21,22 +22,28 @@ #ifndef OPENSYNC_HASHTABLE_H_ #define OPENSYNC_HASHTABLE_H_ +typedef void (*OSyncHashtableForEach) (const char *uid, const char *hash, void *user_data); + OSYNC_EXPORT OSyncHashTable *osync_hashtable_new(const char *path, const char *objtype, OSyncError **error); -OSYNC_EXPORT void osync_hashtable_free(OSyncHashTable *table); + +OSYNC_EXPORT OSyncHashTable *osync_hashtable_ref(OSyncHashTable *table); +OSYNC_EXPORT void osync_hashtable_unref(OSyncHashTable *table); + +OSYNC_EXPORT osync_bool osync_hashtable_load(OSyncHashTable *table, OSyncError **error); +OSYNC_EXPORT osync_bool osync_hashtable_committedall(OSyncHashTable *table, OSyncError **error); OSYNC_EXPORT osync_bool osync_hashtable_slowsync(OSyncHashTable *table, OSyncError **error); -OSYNC_EXPORT int osync_hashtable_num_entries(OSyncHashTable *table); -OSYNC_EXPORT osync_bool osync_hashtable_nth_entry(OSyncHashTable *table, int i, char **uid, char **hash); -OSYNC_EXPORT void osync_hashtable_write(OSyncHashTable *table, const char *uid, const char *hash); -OSYNC_EXPORT void osync_hashtable_delete(OSyncHashTable *table, const char *uid); -OSYNC_EXPORT void osync_hashtable_update_hash(OSyncHashTable *table, OSyncChangeType type, const char *uid, const char *hash); +OSYNC_EXPORT unsigned int osync_hashtable_num_entries(OSyncHashTable *table); +OSYNC_EXPORT void osync_hashtable_foreach(OSyncHashTable *table, OSyncHashtableForEach func, void *user_data); + +OSYNC_EXPORT void osync_hashtable_update_change(OSyncHashTable *table, OSyncChange *change, const char *hash); OSYNC_EXPORT void osync_hashtable_report(OSyncHashTable *table, const char *uid); OSYNC_EXPORT void osync_hashtable_reset_reports(OSyncHashTable *table); -OSYNC_EXPORT char **osync_hashtable_get_deleted(OSyncHashTable *table); +OSYNC_EXPORT OSyncList *osync_hashtable_get_deleted(OSyncHashTable *table); OSYNC_EXPORT OSyncChangeType osync_hashtable_get_changetype(OSyncHashTable *table, const char *uid, const char *hash); -OSYNC_EXPORT char *osync_hashtable_get_hash(OSyncHashTable *table, const char *uid); +OSYNC_EXPORT const char *osync_hashtable_get_hash(OSyncHashTable *table, const char *uid); #endif /* OPENSYNC_HASHTABLE_H_ */ Index: opensync/opensync/helper/opensync_hashtable_internals.h =================================================================== --- opensync.orig/opensync/helper/opensync_hashtable_internals.h +++ opensync/opensync/helper/opensync_hashtable_internals.h @@ -22,11 +22,21 @@ #ifndef _OPENSYNC_HASHTABLE_INTERNALS_H_ #define _OPENSYNC_HASHTABLE_INTERNALS_H_ +#define OSYNC_HASHTABLE_DB_PREFIX "tbl_hash_" + /*! @brief Represent a hashtable which can be used to check if changes have been modifed or deleted */ struct OSyncHashTable { + int ref_count; OSyncDB *dbhandle; - GHashTable *used_entries; - char *tablename; + + GHashTable *reported_entries; + + GHashTable *db_entries; + + char *name; + + /* Only to build transaction queries */ + GString *query; }; #endif /*_OPENSYNC_HASHTABLE_INTERNALS_H_*/ ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone _______________________________________________ Opensync-devel mailing list Opensync-devel@... https://lists.sourceforge.net/lists/listinfo/opensync-devel |
|
|
[patch 09/13] Port osyncdump to new osync_hashtable APIIndex: tools/osyncdump.c
=================================================================== --- tools/osyncdump.c.orig +++ tools/osyncdump.c @@ -102,6 +102,11 @@ static void dump_map(OSyncGroupEnv *env, } +static void print_hashtable(const char *uid, const char *hash, void *user_data) +{ + printf("UID: %s\tHASH:%s\n", uid, hash); +} + static void dump_hash(OSyncGroupEnv *env, const char *objtype, const char *groupname, char *memberid) { OSyncError *error = NULL; @@ -125,17 +130,9 @@ static void dump_hash(OSyncGroupEnv *env goto error; g_free(path); - int i; - char *uid; - char *hash; - for (i = 0; i < osync_hashtable_num_entries(table); i++) { - osync_hashtable_nth_entry(table, i, &uid, &hash); - printf("UID: %s HASH: %s\n", uid, hash); - g_free(hash); - g_free(uid); - } - - osync_hashtable_free(table); + osync_hashtable_foreach(table, print_hashtable, NULL); + + osync_hashtable_unref(table); return; ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone _______________________________________________ Opensync-devel mailing list Opensync-devel@... https://lists.sourceforge.net/lists/listinfo/opensync-devel |
|
|
[patch 10/13] Adapt to latest hashtable api changesUse reference counting of hashtable.
--- tests/sync-tests/check_sync.c | 116 +++++++++++++++++++++--------------------- 1 file changed, 58 insertions(+), 58 deletions(-) Index: tests/sync-tests/check_sync.c =================================================================== --- tests/sync-tests/check_sync.c.orig +++ tests/sync-tests/check_sync.c @@ -137,13 +137,13 @@ START_TEST (sync_easy_new) OSyncHashTable *table = hashtable_load(path, "mockobjtype1", 1); g_free(path); check_hash(table, "testdata"); - osync_hashtable_free(table); + osync_hashtable_unref(table); path = g_strdup_printf("%s/configs/group/2/hashtable.db", testbed); table = hashtable_load(path, "mockobjtype1", 1); g_free(path); check_hash(table, "testdata"); - osync_hashtable_free(table); + osync_hashtable_unref(table); destroy_testbed(testbed); } @@ -197,13 +197,13 @@ START_TEST (sync_easy_new_del) OSyncHashTable *table = hashtable_load(path, "mockobjtype1", 1); g_free(path); check_hash(table, "testdata"); - osync_hashtable_free(table); + osync_hashtable_unref(table); path = g_strdup_printf("%s/configs/group/2/hashtable.db", testbed); table = hashtable_load(path, "mockobjtype1", 1); g_free(path); check_hash(table, "testdata"); - osync_hashtable_free(table); + osync_hashtable_unref(table); reset_counters(); system("rm data1/testdata"); @@ -262,12 +262,12 @@ START_TEST (sync_easy_new_del) path = g_strdup_printf("%s/configs/group/1/hashtable.db", testbed); table = hashtable_load(path, "mockobjtype1", 0); g_free(path); - osync_hashtable_free(table); + osync_hashtable_unref(table); path = g_strdup_printf("%s/configs/group/2/hashtable.db", testbed); table = hashtable_load(path, "mockobjtype1", 0); g_free(path); - osync_hashtable_free(table); + osync_hashtable_unref(table); destroy_testbed(testbed); } @@ -365,13 +365,13 @@ START_TEST (sync_easy_conflict) OSyncHashTable *table = hashtable_load(path, "mockobjtype1", 1); g_free(path); check_hash(table, "testdata"); - osync_hashtable_free(table); + osync_hashtable_unref(table); path = g_strdup_printf("%s/configs/group/2/hashtable.db", testbed); table = hashtable_load(path, "mockobjtype1", 1); g_free(path); check_hash(table, "testdata"); - osync_hashtable_free(table); + osync_hashtable_unref(table); destroy_testbed(testbed); } @@ -461,13 +461,13 @@ START_TEST (sync_easy_new_mapping) OSyncHashTable *table = hashtable_load(path, "mockobjtype1", 1); g_free(path); check_hash(table, "testdata"); - osync_hashtable_free(table); + osync_hashtable_unref(table); path = g_strdup_printf("%s/configs/group/2/hashtable.db", testbed); table = hashtable_load(path, "mockobjtype1", 1); g_free(path); check_hash(table, "testdata"); - osync_hashtable_free(table); + osync_hashtable_unref(table); reset_counters(); system("rm data1/testdata"); @@ -526,12 +526,12 @@ START_TEST (sync_easy_new_mapping) path = g_strdup_printf("%s/configs/group/1/hashtable.db", testbed); table = hashtable_load(path, "mockobjtype1", 0); g_free(path); - osync_hashtable_free(table); + osync_hashtable_unref(table); path = g_strdup_printf("%s/configs/group/2/hashtable.db", testbed); table = hashtable_load(path, "mockobjtype1", 0); g_free(path); - osync_hashtable_free(table); + osync_hashtable_unref(table); destroy_testbed(testbed); } @@ -624,14 +624,14 @@ START_TEST (sync_easy_conflict_duplicate g_free(path); check_hash(table, "testdata"); check_hash(table, "testdata-dupe"); - osync_hashtable_free(table); + osync_hashtable_unref(table); path = g_strdup_printf("%s/configs/group/2/hashtable.db", testbed); table = hashtable_load(path, "mockobjtype1", 2); g_free(path); check_hash(table, "testdata"); check_hash(table, "testdata-dupe"); - osync_hashtable_free(table); + osync_hashtable_unref(table); fail_unless(!system("test \"x$(diff -x \".*\" data1 data2)\" = \"x\""), NULL); system("rm -f data1/testdata-dupe"); @@ -695,13 +695,13 @@ START_TEST (sync_easy_conflict_duplicate table = hashtable_load(path, "mockobjtype1", 1); g_free(path); check_hash(table, "testdata"); - osync_hashtable_free(table); + osync_hashtable_unref(table); path = g_strdup_printf("%s/configs/group/2/hashtable.db", testbed); table = hashtable_load(path, "mockobjtype1", 1); g_free(path); check_hash(table, "testdata"); - osync_hashtable_free(table); + osync_hashtable_unref(table); destroy_testbed(testbed); } @@ -797,14 +797,14 @@ START_TEST (sync_easy_conflict_abort) g_free(path); check_hash(table, "testdata"); // check_hash(table, "testdata-dupe"); - osync_hashtable_free(table); + osync_hashtable_unref(table); path = g_strdup_printf("%s/configs/group/2/hashtable.db", testbed); table = hashtable_load(path, "mockobjtype1", 1); g_free(path); check_hash(table, "testdata"); // check_hash(table, "testdata-dupe"); - osync_hashtable_free(table); + osync_hashtable_unref(table); fail_unless(!system("test \"x$(diff -x \".*\" data1 data2)\" != \"x\""), NULL); // system("rm -f data1/testdata-dupe"); @@ -870,13 +870,13 @@ START_TEST (sync_easy_conflict_abort) table = hashtable_load(path, "mockobjtype1", 1); g_free(path); check_hash(table, "testdata"); - osync_hashtable_free(table); + osync_hashtable_unref(table); path = g_strdup_printf("%s/configs/group/2/hashtable.db", testbed); table = hashtable_load(path, "mockobjtype1", 1); g_free(path); check_hash(table, "testdata"); - osync_hashtable_free(table); + osync_hash |