From 44d5647b4b92089fc90195b41373f6b99dc5c42c Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 24 Oct 2019 08:23:42 +0200 Subject: Close database as soon as possible This becomes important if we trigger a recursive implicit sync that uses the same database (e.g., in a build system module project). --- bdep/build.txx | 14 ++++++++++---- bdep/ci.cxx | 5 ++++- bdep/deinit.cxx | 18 ++++++++++-------- bdep/fetch.cxx | 14 ++++++++++---- bdep/publish.cxx | 5 ++++- 5 files changed, 38 insertions(+), 18 deletions(-) diff --git a/bdep/build.txx b/bdep/build.txx index 1cd5fff..b83aa9c 100644 --- a/bdep/build.txx +++ b/bdep/build.txx @@ -45,11 +45,17 @@ namespace bdep const dir_path& prj (pp.project); - database db (open (prj, trace)); + // Load the configurations without keeping the database open longer + // than necessary. + // + configurations cfgs; + { + database db (open (prj, trace)); - transaction t (db.begin ()); - configurations cfgs (find_configurations (o, prj, t)); - t.commit (); + transaction t (db.begin ()); + cfgs = find_configurations (o, prj, t); + t.commit (); + } // If specified, verify packages are present in each configuration. // diff --git a/bdep/ci.cxx b/bdep/ci.cxx index 08f2578..81db678 100644 --- a/bdep/ci.cxx +++ b/bdep/ci.cxx @@ -200,10 +200,13 @@ namespace bdep false /* load_packages */)); const dir_path& prj (pp.project); - database db (open (prj, trace)); shared_ptr cfg; { + // Don't keep the database open longer than necessary. + // + database db (open (prj, trace)); + transaction t (db.begin ()); configurations cfgs (find_configurations (o, prj, t)); t.commit (); diff --git a/bdep/deinit.cxx b/bdep/deinit.cxx index 735b746..18acf52 100644 --- a/bdep/deinit.cxx +++ b/bdep/deinit.cxx @@ -111,14 +111,16 @@ namespace bdep database db (open (prj, trace)); - transaction t (db.begin ()); - configurations cfgs ( - find_configurations (o, - prj, - t, - true /* fallback_default */, - !force /* validate */)); - t.commit (); + configurations cfgs; + { + transaction t (db.begin ()); + cfgs = find_configurations (o, + prj, + t, + true /* fallback_default */, + !force /* validate */); + t.commit (); + } // If specified, verify packages are present in each configuration. // diff --git a/bdep/fetch.cxx b/bdep/fetch.cxx index 7a88106..3527e51 100644 --- a/bdep/fetch.cxx +++ b/bdep/fetch.cxx @@ -33,11 +33,17 @@ namespace bdep tracer trace ("fetch"); dir_path prj (find_project (o)); - database db (open (prj, trace)); - transaction t (db.begin ()); - configurations cfgs (find_configurations (o, prj, t)); - t.commit (); + configurations cfgs; + { + // Don't keep the database open longer than necessary. + // + database db (open (prj, trace)); + + transaction t (db.begin ()); + cfgs = find_configurations (o, prj, t); + t.commit (); + } bool first (true); for (const shared_ptr& c: cfgs) diff --git a/bdep/publish.cxx b/bdep/publish.cxx index 1fcc942..ab58025 100644 --- a/bdep/publish.cxx +++ b/bdep/publish.cxx @@ -807,12 +807,15 @@ namespace bdep true /* load_packages */)); const dir_path& prj (pp.project); - database db (open (prj, trace)); // We need a single configuration to prepare package distribution. // shared_ptr cfg; { + // Don't keep the database open longer than necessary. + // + database db (open (prj, trace)); + transaction t (db.begin ()); configurations cfgs (find_configurations (o, prj, t)); t.commit (); -- cgit v1.1