|
45 | 45 | #include "simap.h" |
46 | 46 | #include "sset.h" |
47 | 47 | #include "svec.h" |
| 48 | +#include "timeval.h" |
48 | 49 | #include "util.h" |
49 | 50 | #include "uuid.h" |
50 | 51 | #include "openvswitch/vlog.h" |
@@ -439,13 +440,14 @@ ovsdb_idl_clear(struct ovsdb_idl *db) |
439 | 440 | /* Processes a batch of messages from the database server on 'idl'. This may |
440 | 441 | * cause the IDL's contents to change. The client may check for that with |
441 | 442 | * ovsdb_idl_get_seqno(). */ |
442 | | -void |
| 443 | +int |
443 | 444 | ovsdb_idl_run(struct ovsdb_idl *idl) |
444 | 445 | { |
445 | 446 | ovs_assert(!idl->txn); |
446 | 447 |
|
447 | 448 | struct ovs_list events; |
448 | | - ovsdb_cs_run(idl->cs, &events); |
| 449 | + int ret; |
| 450 | + ret = ovsdb_cs_run(idl->cs, &events); |
449 | 451 |
|
450 | 452 | struct ovsdb_cs_event *event; |
451 | 453 | LIST_FOR_EACH_POP (event, list_node, &events) { |
@@ -479,6 +481,8 @@ ovsdb_idl_run(struct ovsdb_idl *idl) |
479 | 481 | ovsdb_idl_reparse_refs_to_inserted(idl); |
480 | 482 | ovsdb_idl_reparse_deleted(idl); |
481 | 483 | ovsdb_idl_row_destroy_postprocess(idl); |
| 484 | + |
| 485 | + return ret; |
482 | 486 | } |
483 | 487 |
|
484 | 488 | /* Arranges for poll_block() to wake up when ovsdb_idl_run() has something to |
@@ -4391,6 +4395,44 @@ ovsdb_idl_loop_run(struct ovsdb_idl_loop *loop) |
4391 | 4395 | return loop->open_txn; |
4392 | 4396 | } |
4393 | 4397 |
|
| 4398 | +/* Run the ovsdb_idl_loop until there is no more data to be received. |
| 4399 | + * A timeout in milliseconds can be provided. The actual duration of the |
| 4400 | + * function is returned in the duration parameter. */ |
| 4401 | +struct ovsdb_idl_txn * |
| 4402 | +ovsdb_idl_loop_run_completion(struct ovsdb_idl_loop *idl_loop, |
| 4403 | + unsigned long long timeout, |
| 4404 | + uint64_t *idl_duration) |
| 4405 | +{ |
| 4406 | + unsigned long long duration, start = time_msec(); |
| 4407 | + struct ovsdb_idl_txn *txn; |
| 4408 | + int n = 0; |
| 4409 | + |
| 4410 | + /* Accumulate database changes as long as there are some, |
| 4411 | + * but no longer than the given timeout. */ |
| 4412 | + while (time_msec() - start < timeout) { |
| 4413 | + if (ovsdb_idl_run(idl_loop->idl) == EAGAIN) { |
| 4414 | + break; |
| 4415 | + } |
| 4416 | + n++; |
| 4417 | + } |
| 4418 | + |
| 4419 | + txn = ovsdb_idl_loop_run(idl_loop); |
| 4420 | + |
| 4421 | + duration = time_msec() - start; |
| 4422 | + if (idl_duration) { |
| 4423 | + *idl_duration = duration; |
| 4424 | + } |
| 4425 | + /* ovsdb_idl_run() is called at least 2 times. Once directly and |
| 4426 | + * once in the ovsdb_idl_loop_run(). n > 2 means that we received |
| 4427 | + * data on at least 2 subsequent calls. */ |
| 4428 | + if (n > 2 || duration > 100) { |
| 4429 | + VLOG(duration > timeout ? VLL_INFO : VLL_DBG, |
| 4430 | + "%d iterations in %lld ms", n + 1, duration); |
| 4431 | + } |
| 4432 | + |
| 4433 | + return txn; |
| 4434 | +} |
| 4435 | + |
4394 | 4436 | /* Attempts to commit the current transaction, if one is open. |
4395 | 4437 | * |
4396 | 4438 | * If a transaction was open, in this or a previous iteration of the main loop, |
|
0 commit comments