diff --git a/qa/standalone/osd/repro_long_log.sh b/qa/standalone/osd/repro_long_log.sh index 9fadc50609b..1f4ba29bdfb 100755 --- a/qa/standalone/osd/repro_long_log.sh +++ b/qa/standalone/osd/repro_long_log.sh @@ -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 "$@" diff --git a/src/osd/PrimaryLogPG.cc b/src/osd/PrimaryLogPG.cc index d60a9824a46..a805eedc792 100644 --- a/src/osd/PrimaryLogPG.cc +++ b/src/osd/PrimaryLogPG.cc @@ -1540,8 +1540,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::const_iterator it = pg_log.get_log().log.begin();