From b9f83d0d666037b7f7728b674362d365470a244a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 21 Nov 2014 08:16:49 +0200 Subject: Add support for stopping after a failed batch --- common/bulk/driver.cxx | 62 ++++++++++++++++++++++++++++++++++++++------------ common/bulk/test.std | 9 ++++++++ 2 files changed, 56 insertions(+), 15 deletions(-) (limited to 'common/bulk') diff --git a/common/bulk/driver.cxx b/common/bulk/driver.cxx index c043931..4b3b9f8 100644 --- a/common/bulk/driver.cxx +++ b/common/bulk/driver.cxx @@ -81,7 +81,7 @@ struct element_traits> template void -persist (const auto_ptr& db, I b, I e) +persist (const auto_ptr& db, I b, I e, bool cont = true) { typedef element_traits traits; typedef typename traits::type type; @@ -89,7 +89,7 @@ persist (const auto_ptr& db, I b, I e) { transaction t (db->begin ()); - db->persist (b, e); + db->persist (b, e, cont); t.commit (); } @@ -111,11 +111,11 @@ persist (const auto_ptr& db, I b, I e) template void -try_persist (const auto_ptr& db, I b, I e) +try_persist (const auto_ptr& db, I b, I e, bool cont = true) { try { - persist (db, b, e); + persist (db, b, e, cont); assert (false); } catch (const multiple_exceptions& e) @@ -126,7 +126,8 @@ try_persist (const auto_ptr& db, I b, I e) template void -update (const auto_ptr& db, I b, I e, bool modify = true) +update (const auto_ptr& db, I b, I e, + bool modify = true, bool cont = true) { typedef element_traits traits; typedef typename traits::type type; @@ -144,7 +145,7 @@ update (const auto_ptr& db, I b, I e, bool modify = true) { transaction t (db->begin ()); - db->update (b, e); + db->update (b, e, cont); t.commit (); } @@ -166,11 +167,11 @@ update (const auto_ptr& db, I b, I e, bool modify = true) template void -try_update (const auto_ptr& db, I b, I e) +try_update (const auto_ptr& db, I b, I e, bool cont = true) { try { - update (db, b, e, false); + update (db, b, e, false, cont); assert (false); } catch (const multiple_exceptions& e) @@ -209,14 +210,14 @@ erase (const auto_ptr& db, I b, I e) template void -erase_id (const auto_ptr& db, I b, I e) +erase_id (const auto_ptr& db, I b, I e, bool cont = true) { typedef element_traits traits; typedef T type; { transaction t (db->begin ()); - db->erase (b, e); + db->erase (b, e, cont); t.commit (); } @@ -234,11 +235,11 @@ erase_id (const auto_ptr& db, I b, I e) template void -try_erase (const auto_ptr& db, const A& a) +try_erase (const auto_ptr& db, const A& a, bool cont = true) { try { - erase_id (db, a, a + sizeof (a) / sizeof (a[0])); + erase_id (db, a, a + sizeof (a) / sizeof (a[0]), cont); assert (false); } catch (const multiple_exceptions& e) @@ -589,13 +590,25 @@ main (int argc, char* argv[]) vector v; // mixture v.push_back (object (0, 0)); v.push_back (object (6, 6)); - v.push_back (object (2, 2)); + v.push_back (object (1, 1)); v.push_back (object (7, 7)); - v.push_back (object (3, 3)); + v.push_back (object (2, 2)); v.push_back (object (8, 8)); - v.push_back (object (4, 4)); + v.push_back (object (3, 3)); try_persist (db, v.begin (), v.end ()); } + + // Test stopping after failure. + // + { + vector v; // batch + v.push_back (object (0, 0)); + v.push_back (object (1, 1)); + v.push_back (object (6, 6)); + v.push_back (object (2, 2)); + v.push_back (object (3, 3)); + try_persist (db, v.begin (), v.end (), false); + } } // update @@ -735,6 +748,18 @@ main (int argc, char* argv[]) try_update (db, v.begin (), v.end ()); } + // Test stopping after failure. + // + { + vector v; // batch + v.push_back (object (6, 6)); + v.push_back (object (7, 7)); + v.push_back (object (0, 0)); + v.push_back (object (8, 8)); + v.push_back (object (9, 9)); + try_update (db, v.begin (), v.end (), false); + } + // Test a database exception (unique constraint violation) // try @@ -842,6 +867,13 @@ main (int argc, char* argv[]) unsigned long a[] = {0, 1, 2, 6, 7, 8, 3, 4, 5, 9}; // mixture try_erase (db, a); } + + // Test stopping after failure. + // + { + unsigned long a[] = {6, 7, 0, 8, 9}; + try_erase (db, a, false); + } } erase (db, v.begin (), v.end ()); diff --git a/common/bulk/test.std b/common/bulk/test.std index 354ad62..6c4bdf9 100644 --- a/common/bulk/test.std +++ b/common/bulk/test.std @@ -64,6 +64,9 @@ multiple exceptions, 7 elements attempted, 3 failed: [3] object already persistent [5] object already persistent +multiple exceptions, 3 elements attempted, 1 failed: +[2] object already persistent + multiple exceptions, 1 element attempted, 1 failed: [0] object not persistent @@ -131,6 +134,9 @@ multiple exceptions, 7 elements attempted, 4 failed: [2] object not persistent [6] object not persistent +multiple exceptions, 3 elements attempted, 3 failed: +[0-2] (some) object not persistent + multiple exceptions, 1 element attempted, 1 failed: [0] object not persistent @@ -207,3 +213,6 @@ multiple exceptions, 10 elements attempted, 6 failed: [7] object not persistent [8] object not persistent +multiple exceptions, 3 elements attempted, 3 failed: +[0-2] (some) object not persistent + -- cgit v1.1