PrimaryLogPG: only trim up to osd_pg_log_trim_max entries at once

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>
This commit is contained in:
Josh Durgin 2018-03-07 22:31:59 -05:00
parent b50186bfe6
commit 1c15458a00
2 changed files with 54 additions and 22 deletions

View File

@ -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 "$@"

View File

@ -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<pg_log_entry_t>::const_iterator it = pg_log.get_log().log.begin();