[ovs-dev,v2] ovsdb: Fix database compaction check

Message ID 20180310135014.31551-1-dalvarez@redhat.com
State Accepted
Headers show
Series
  • [ovs-dev,v2] ovsdb: Fix database compaction check
Related show

Commit Message

Daniel Alvarez Sanchez March 10, 2018, 1:50 p.m.
We want to compact database file if it has been over 24 hours since we
last compacted it and there's more than 100 commits regardless of the
size of the database. This patch fixes the previous comparisson which
checked if 24 hours was elapsed since the next scheduled compaction.

Signed-off-by: Daniel Alvarez <dalvarez@redhat.com>
---
 ovsdb/file.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Comments

Ben Pfaff March 14, 2018, 10:21 p.m. | #1
On Sat, Mar 10, 2018 at 02:50:14PM +0100, Daniel Alvarez wrote:
> We want to compact database file if it has been over 24 hours since we
> last compacted it and there's more than 100 commits regardless of the
> size of the database. This patch fixes the previous comparisson which
> checked if 24 hours was elapsed since the next scheduled compaction.
> 
> Signed-off-by: Daniel Alvarez <dalvarez@redhat.com>

OK, v2 is much better.  Applied to master, thanks!
Daniel Alvarez Sanchez March 15, 2018, 9:11 a.m. | #2
Thanks Ben!
Sorry for the confusion with the previous version,  I forgot to commit the changes and sent the wrong version. 

> On 14 Mar 2018, at 23:21, Ben Pfaff <blp@ovn.org> wrote:
> 
>> On Sat, Mar 10, 2018 at 02:50:14PM +0100, Daniel Alvarez wrote:
>> We want to compact database file if it has been over 24 hours since we
>> last compacted it and there's more than 100 commits regardless of the
>> size of the database. This patch fixes the previous comparisson which
>> checked if 24 hours was elapsed since the next scheduled compaction.
>> 
>> Signed-off-by: Daniel Alvarez <dalvarez@redhat.com>
> 
> OK, v2 is much better.  Applied to master, thanks!
Ben Pfaff March 16, 2018, 8:23 p.m. | #3
Happens to everyone sometimes.

On Thu, Mar 15, 2018 at 10:11:09AM +0100, Daniel Alvarez wrote:
> Thanks Ben!
> Sorry for the confusion with the previous version,  I forgot to commit the changes and sent the wrong version. 
> 
> > On 14 Mar 2018, at 23:21, Ben Pfaff <blp@ovn.org> wrote:
> > 
> >> On Sat, Mar 10, 2018 at 02:50:14PM +0100, Daniel Alvarez wrote:
> >> We want to compact database file if it has been over 24 hours since we
> >> last compacted it and there's more than 100 commits regardless of the
> >> size of the database. This patch fixes the previous comparisson which
> >> checked if 24 hours was elapsed since the next scheduled compaction.
> >> 
> >> Signed-off-by: Daniel Alvarez <dalvarez@redhat.com>
> > 
> > OK, v2 is much better.  Applied to master, thanks!

Patch

diff --git a/ovsdb/file.c b/ovsdb/file.c
index 02e0e8b76..40192e30d 100644
--- a/ovsdb/file.c
+++ b/ovsdb/file.c
@@ -590,7 +590,7 @@  ovsdb_file_commit(struct ovsdb_replica *replica,
     struct ovsdb_file *file = ovsdb_file_cast(replica);
     struct ovsdb_file_txn ftxn;
     struct ovsdb_error *error;
-    long long int next_compact_elapsed;
+    long long int current_time;
 
     ovsdb_file_txn_init(&ftxn);
     ovsdb_txn_for_each_change(txn, ovsdb_file_change_cb, &ftxn);
@@ -611,12 +611,12 @@  ovsdb_file_commit(struct ovsdb_replica *replica,
      * tried), and if there are at least 100 transactions in the database, and
      * if the database is at least 10 MB, and the database is at least 2x the
      * size of the previous snapshot, then compact the database. However, if
-     * it has been over COMPACT_MAX_MSEC ms, the database size is not taken
-     * into account. */
-    next_compact_elapsed = time_msec() - file->next_compact;
-    if (next_compact_elapsed >= 0
+     * it has been over COMPACT_MAX_MSEC ms since the last compaction, the
+     * database size is not taken into account. */
+    current_time = time_msec();
+    if (current_time >= file->next_compact
         && file->n_transactions >= 100
-        && (next_compact_elapsed >= COMPACT_MAX_MSEC
+        && (current_time - file->last_compact >= COMPACT_MAX_MSEC
             || ovsdb_log_grew_lots(file->log))) {
         error = ovsdb_file_compact(file);
         if (error) {