]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
PrimaryLogPG: only trim up to osd_pg_log_trim_max entries at once 20851/head
authorJosh Durgin <jdurgin@redhat.com>
Thu, 8 Mar 2018 03:31:59 +0000 (22:31 -0500)
committerJosh Durgin <jdurgin@redhat.com>
Sat, 10 Mar 2018 01:02:26 +0000 (20:02 -0500)
This prevents the fix for http://tracker.ceph.com/issues/22050 or
potential future bugs from causing too much latency by trimming too
many log entries at once.

Signed-off-by: Josh Durgin <jdurgin@redhat.com>
(cherry picked from commit 1c15458a00e64d1fd0127ae171305b8f8afa6619)

qa/standalone/osd/repro_long_log.sh
src/osd/PrimaryLogPG.cc

index 9fadc50609be623106bf3a0982c1b7556d637627..1f4ba29bdfbc444d0880c68c70fcf7884825bf43 100755 (executable)
@@ -36,17 +36,19 @@ function run() {
     done
 }
 
+PGID=
+
 function test_log_size()
 {
-    PGID=$1
-    EXPECTED=$2
+    local PGID=$1
+    local EXPECTED=$2
     ceph tell osd.\* flush_pg_stats
     sleep 3
     ceph pg $PGID query | jq .info.stats.log_size
     ceph pg $PGID query | jq .info.stats.log_size | grep "${EXPECTED}"
 }
 
-function do_repro_long_log() {
+function setup_log_test() {
     local dir=$1
     local which=$2
 
@@ -83,35 +85,63 @@ function do_repro_long_log() {
 
     # log should have been trimmed down to min_entries with one extra
     test_log_size $PGID 21 || return 1
-
-    if [ "$which" = "test1" ];
-    then
-        # regular write should trim the log
-        rados -p test put foo foo || return 1
-        test_log_size $PGID 22 || return 1
-    else
-        PRIMARY=$(ceph pg $PGID query  | jq '.info.stats.up_primary')
-        kill_daemons $dir TERM osd.$PRIMARY || return 1
-
-        CEPH_ARGS="--osd-max-pg-log-entries=2" ceph-objectstore-tool --data-path $dir/$PRIMARY --pgid $PGID --op trim-pg-log || return 1
-        run_osd $dir $PRIMARY || return 1
-        wait_for_clean || return 1
-        test_log_size $PGID 2 || return 1
-    fi
 }
 
 function TEST_repro_long_log1()
 {
     local dir=$1
 
-    do_repro_long_log $dir test1
+    setup_log_test $dir || return 1
+    # regular write should trim the log
+    rados -p test put foo foo || return 1
+    test_log_size $PGID 22 || return 1
 }
 
 function TEST_repro_long_log2()
 {
     local dir=$1
 
-    do_repro_long_log $dir test2
+    setup_log_test $dir || return 1
+    local PRIMARY=$(ceph pg $PGID query  | jq '.info.stats.up_primary')
+    kill_daemons $dir TERM osd.$PRIMARY || return 1
+    CEPH_ARGS="--osd-max-pg-log-entries=2 --no-mon-config" ceph-objectstore-tool --data-path $dir/$PRIMARY --pgid $PGID --op trim-pg-log || return 1
+    run_osd $dir $PRIMARY || return 1
+    wait_for_clean || return 1
+    test_log_size $PGID 2 || return 1
+}
+
+function TEST_trim_max_entries()
+{
+    local dir=$1
+
+    setup_log_test $dir || return 1
+
+    ceph tell osd.\* injectargs -- --osd-min-pg-log-entries 1
+    ceph tell osd.\* injectargs -- --osd-pg-log-trim-min 2
+    ceph tell osd.\* injectargs -- --osd-pg-log-trim-max 4
+
+    # adding log entries, should only trim 4 and add one each time
+    rados -p test rm foo
+    test_log_size $PGID 17
+    rados -p test rm foo
+    test_log_size $PGID 14
+    rados -p test rm foo
+    test_log_size $PGID 11
+    rados -p test rm foo
+    test_log_size $PGID 8
+    rados -p test rm foo
+    test_log_size $PGID 5
+    rados -p test rm foo
+    test_log_size $PGID 2
+
+    # below trim_min
+    rados -p test rm foo
+    test_log_size $PGID 3
+    rados -p test rm foo
+    test_log_size $PGID 4
+
+    rados -p test rm foo
+    test_log_size $PGID 2
 }
 
 main repro-long-log "$@"
index 59fa969485ad34272ee703aeaadbddbd2a60664e..f7f9fdabc88e1c2aacc47e4f8df869c6540c5ea1 100644 (file)
@@ -1574,8 +1574,10 @@ void PrimaryLogPG::calc_trim_to()
   if (limit != eversion_t() &&
       limit != pg_trim_to &&
       pg_log.get_log().approx_size() > target) {
-    size_t num_to_trim = pg_log.get_log().approx_size() - target;
-    if (num_to_trim < cct->_conf->osd_pg_log_trim_min) {
+    size_t num_to_trim = MIN(pg_log.get_log().approx_size() - target,
+                            cct->_conf->osd_pg_log_trim_max);
+    if (num_to_trim < cct->_conf->osd_pg_log_trim_min &&
+       cct->_conf->osd_pg_log_trim_max >= cct->_conf->osd_pg_log_trim_min) {
       return;
     }
     list<pg_log_entry_t>::const_iterator it = pg_log.get_log().log.begin();