Skip to content

Commit

Permalink
Document bullshit
Browse files Browse the repository at this point in the history
  • Loading branch information
aurelienpierre committed Feb 6, 2025
1 parent 086d62b commit 7eed30c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/common/database.c
Original file line number Diff line number Diff line change
Expand Up @@ -4614,7 +4614,7 @@ gchar *dt_database_get_most_recent_snap(const char* db_filename)
// transaction routines. And it has been done to help further implementation for
// proper threading and nested transaction support.
//
void dt_database_start_transaction(const struct dt_database_t *db)
void dt_database_start_transaction_debug(const struct dt_database_t *db)
{
const int trxid = dt_atomic_add_int(&_trxid, 1);

Expand All @@ -4625,6 +4625,8 @@ void dt_database_start_transaction(const struct dt_database_t *db)
{
// In theads application it may be safer to use an IMMEDIATE transaction:
// "BEGIN IMMEDIATE TRANSACTION"
// This implies "BEGIN DEFERRED TRANSACTION", which means
// no write event is dispatched to DB until the first "COMMIT"
DT_DEBUG_SQLITE3_EXEC(dt_database_get(db), "BEGIN TRANSACTION", NULL, NULL, NULL);
}
#ifdef USE_NESTED_TRANSACTIONS
Expand All @@ -4640,7 +4642,7 @@ void dt_database_start_transaction(const struct dt_database_t *db)
fprintf(stderr, "[dt_database_start_transaction] more than %d nested transaction\n", MAX_NESTED_TRANSACTIONS);
}

void dt_database_release_transaction(const struct dt_database_t *db)
void dt_database_release_transaction_debug(const struct dt_database_t *db)
{
const int trxid = dt_atomic_sub_int(&_trxid, 1);

Expand Down
10 changes: 6 additions & 4 deletions src/common/database.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ gchar *dt_database_get_most_recent_snap(const char* db_filename);


// nested transactions support

void dt_database_start_transaction(const struct dt_database_t *db);
void dt_database_release_transaction(const struct dt_database_t *db);
void dt_database_start_transaction_debug(const struct dt_database_t *db);
void dt_database_release_transaction_debug(const struct dt_database_t *db);
void dt_database_rollback_transaction(const struct dt_database_t *db);

#define dt_database_start_transaction(db) DT_DEBUG_TRACE_WRAPPER(DT_DEBUG_SQL, dt_database_start_transaction_debug, (db))
#define dt_database_release_transaction(db) DT_DEBUG_TRACE_WRAPPER(DT_DEBUG_SQL, dt_database_release_transaction_debug, (db))


// clang-format off
// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
// vim: shiftwidth=2 expandtab tabstop=2 cindent
// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
// clang-format on

29 changes: 29 additions & 0 deletions src/develop/dev_history.c
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,35 @@ static inline void _dt_dev_load_pipeline_defaults(dt_develop_t *dev)
}


/**
* TODO: this is a big pile of bullshit
*
* We insert modules into a temporary history SQL table in memory.history
* Then perform all kinds of silly SQL operations.
* Then merge into where we keep the real histories, aka main.history in dev_merge_history function.
*
* First of all, that merge_history function needs to re-index all entries sequentially through C
* because SQLite doesn't do it.
*
* Then, when loading large numbers of small files (PNG, JPEG) for the first time in lighttable,
* sooner or later, we get the error:
* `function dt_database_start_transaction_debug(), query "BEGIN": cannot start a transaction within a transaction`,
* coming from _merge_history. When using a DEBUG build, which checks asserts, that makes the app crash.
* Otherwise, the app doesn't crash and there is no telling what's going on in histories.
*
* But then, I couldn't find where we nest transactions here.
*
* Or perhaps, due to DEBUG builds being slow due to -O0 optimization, the race condition shows, and doesn't otherwise.
*
* So, anyway… history init should be done in C, so modules are inserted with defaults params inited
* and sanitized directly with a pipe order. Then, we save to history or keep building the pipeline,
* because anyway, read_history_ext() init defaults only if it's the first time we open the image,
* and then reloads everything from main.history table from database.
*
* None of that is thread-safe.
*
**/

static void _init_default_history(dt_develop_t *dev, const int imgid, gboolean *first_run, gboolean *auto_apply_modules)
{
// cleanup DB
Expand Down

0 comments on commit 7eed30c

Please sign in to comment.