dee

Merge lp:~mhr3/dee/discard-invalid-transactions into lp:dee

Proposed by Michal Hruby
Status: Merged
Approved by: Didier Roche-Tolomelli
Approved revision: 360
Merged at revision: 360
Proposed branch: lp:~mhr3/dee/discard-invalid-transactions
Merge into: lp:dee
Diff against target: 85 lines (+26/-17)
1 file modified
src/dee-shared-model.c (+26/-17)
To merge this branch: bzr merge lp:~mhr3/dee/discard-invalid-transactions
Reviewer Review Type Date Requested Status
Mikkel Kamstrup Erlandsen (community) Approve
Review via email: mp+99267@code.launchpad.net

Commit message

Discard invalid transactions

Description of the change

When we receive a commit on a model that is not valid (wrong seqnum etc), we only emit a warning and apply the transaction. This is wrong as it may leave the model in a weird state, the transaction needs to be discarded.

Discard invalid transactions.

To post a comment you must log in.
Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Code looks correct. Nice to get rid of the FIXMEs :-)

Testing wise it would be quite a lot of work for little gain. These code paths are quite heavily tested already, and getting into all the nooks and crannies of the ways this can fail is a big undertaking. Very worthwhile, but let's not block this branch on it.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/dee-shared-model.c'
--- src/dee-shared-model.c 2012-02-28 10:56:27 +0000
+++ src/dee-shared-model.c 2012-03-26 08:47:25 +0000
@@ -1183,6 +1183,7 @@
1183 guint32 pos;1183 guint32 pos;
1184 guchar change_type;1184 guchar change_type;
1185 gint i, j;1185 gint i, j;
1186 gboolean transaction_error;
11861187
1187 g_return_if_fail (DEE_IS_SHARED_MODEL (self));1188 g_return_if_fail (DEE_IS_SHARED_MODEL (self));
1188 g_return_if_fail (transaction != NULL);1189 g_return_if_fail (transaction != NULL);
@@ -1249,48 +1250,56 @@
1249 g_variant_get (tt, "(tt)", &seqnum_before, &seqnum_after);1250 g_variant_get (tt, "(tt)", &seqnum_before, &seqnum_after);
1250 g_variant_unref (tt);1251 g_variant_unref (tt);
12511252
1253 transaction_error = FALSE;
1252 /* If this is our first transaction we accept anything, if not the1254 /* If this is our first transaction we accept anything, if not the
1253 * incoming seqnums must align with our own records */1255 * incoming seqnums must align with our own records */
1254 current_seqnum = dee_serializable_model_get_seqnum (DEE_MODEL (self));1256 current_seqnum = dee_serializable_model_get_seqnum (DEE_MODEL (self));
1255 if (current_seqnum != 0 &&1257
1256 current_seqnum != seqnum_before)1258 if (current_seqnum != 0 && current_seqnum != seqnum_before)
1257 {1259 {
1258 g_warning ("Transaction from %s is in the %s. Expected seqnum %"G_GUINT64_FORMAT1260 g_warning ("Transaction from %s is in the %s. Expected seqnum %"G_GUINT64_FORMAT
1259 ", but got %"G_GUINT64_FORMAT". Ignoring transaction.",1261 ", but got %"G_GUINT64_FORMAT". Ignoring transaction.",
1260 sender_name,1262 sender_name,
1261 current_seqnum < seqnum_before ? "future" : "past",1263 current_seqnum < seqnum_before ? "future" : "past",
1262 current_seqnum, seqnum_before);1264 current_seqnum, seqnum_before);
1263 if (dee_shared_model_is_leader (self))1265 transaction_error = TRUE;
1264 {1266 }
1265 g_warning ("Invalidating %s", sender_name);
1266 invalidate_peer (self, sender_name, NULL);
1267 }
1268
1269 g_variant_unref (transaction);
1270 g_variant_unref (aav);
1271 g_variant_unref (au);
1272 g_variant_unref (ay);
1273 return;
1274 }
12751267
1276 /* Check that the lengths of all the arrays match up */1268 /* Check that the lengths of all the arrays match up */
1277 n_rows = g_variant_n_children (aav);1269 n_rows = g_variant_n_children (aav);
1270
1278 if (n_rows != g_variant_n_children (au))1271 if (n_rows != g_variant_n_children (au))
1279 {1272 {
1280 g_warning ("Commit from %s has illegal position vector",1273 g_warning ("Commit from %s has illegal position vector",
1281 sender_name);1274 sender_name);
1282 // FIXME cleanup1275 transaction_error = TRUE;
1283 }1276 }
1284 if (n_rows != g_variant_n_children (ay))1277 if (n_rows != g_variant_n_children (ay))
1285 {1278 {
1286 g_warning ("Commit from %s has illegal change type vector",1279 g_warning ("Commit from %s has illegal change type vector",
1287 sender_name);1280 sender_name);
1288 // FIXME cleanup1281 transaction_error = TRUE;
1289 }1282 }
1290 if (n_rows > (seqnum_after - seqnum_before))1283 if (n_rows > (seqnum_after - seqnum_before))
1291 {1284 {
1292 g_warning ("Commit from %s has illegal seqnum count.",1285 g_warning ("Commit from %s has illegal seqnum count.",
1293 sender_name);1286 sender_name);
1287 transaction_error = TRUE;
1288 }
1289
1290 if (transaction_error)
1291 {
1292 if (dee_shared_model_is_leader (self))
1293 {
1294 g_warning ("Invalidating %s", sender_name);
1295 invalidate_peer (self, sender_name, NULL);
1296 }
1297
1298 g_variant_unref (transaction);
1299 g_variant_unref (aav);
1300 g_variant_unref (au);
1301 g_variant_unref (ay);
1302 return;
1294 }1303 }
1295 1304
1296 /* Allocate an array on the stack as a temporary row data buffer */1305 /* Allocate an array on the stack as a temporary row data buffer */

Subscribers

People subscribed via source and target branches

to all changes: