Skip to content

Commit 17a2226

Browse files
committed
Merge branch 'master' into performance
2 parents 8c4eb71 + 9f690ec commit 17a2226

File tree

5 files changed

+56
-67
lines changed

5 files changed

+56
-67
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@ sst_dump
1919
util/build_version.cc
2020
build_tools/VALGRIND_LOGS/
2121
coverage/COVERAGE_REPORT
22-
util/build_version.cc.tmp
2322
.gdbhistory

build_tools/build_detect_version

+11-31
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,18 @@
55
# is then built as a regular source file as part of the compilation process.
66
# One can run "strings executable_filename | grep _build_" to find the version of
77
# the source that we used to build the executable file.
8-
#
9-
10-
# create git version file
11-
VFILE=$PWD/util/build_version.cc.tmp
12-
trap "rm $VFILE" EXIT
138

14-
# check to see if git is in the path
15-
which git > /dev/null
9+
OUTFILE="$PWD/util/build_version.cc"
1610

17-
if [ "$?" = 0 ]; then
18-
env -i git rev-parse HEAD 2>&1 |
19-
awk '
20-
BEGIN {
21-
print "#include \"build_version.h\"\n"
22-
}
23-
{ print "const char* rocksdb_build_git_sha = \"rocksdb_build_git_sha:" $0"\";" }
24-
' > ${VFILE}
25-
else
26-
echo "git not found" |
27-
awk '
28-
BEGIN {
29-
print "#include \"build_version.h\""
30-
}
31-
{ print "const char* rocksdb_build_git_sha = \"rocksdb_build_git_sha:git not found\";" }
32-
' > ${VFILE}
11+
GIT_SHA=""
12+
if command -v git >/dev/null 2>&1; then
13+
GIT_SHA=$(git rev-parse HEAD 2>/dev/null)
3314
fi
3415

35-
echo "const char* rocksdb_build_git_datetime = \"rocksdb_build_git_datetime:$(date)\";" >> ${VFILE}
36-
echo "const char* rocksdb_build_compile_date = __DATE__;" >> ${VFILE}
37-
echo "const char* rocksdb_build_compile_time = __TIME__;" >> ${VFILE}
38-
39-
OUTFILE=$PWD/util/build_version.cc
40-
if [ ! -e $OUTFILE ] || ! cmp -s $VFILE $OUTFILE; then
41-
cp $VFILE $OUTFILE
42-
fi
16+
cat > "${OUTFILE}" <<EOF
17+
#include "build_version.h"
18+
const char* rocksdb_build_git_sha = "rocksdb_build_git_sha:${GIT_SHA}";
19+
const char* rocksdb_build_git_datetime = "rocksdb_build_git_datetime:$(date)";
20+
const char* rocksdb_build_compile_date = __DATE__;
21+
const char* rocksdb_build_compile_time = __TIME__;
22+
EOF

db/db_impl.cc

+38-33
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ DBImpl::DBImpl(const Options& options, const std::string& dbname)
244244
super_version_(nullptr),
245245
tmp_batch_(),
246246
bg_compaction_scheduled_(0),
247+
bg_manual_only_(0),
247248
bg_flush_scheduled_(0),
248249
bg_logstats_scheduled_(false),
249250
manual_compaction_(nullptr),
@@ -1608,45 +1609,44 @@ void DBImpl::TEST_CompactRange(int level, const Slice* begin,const Slice* end) {
16081609

16091610
MutexLock l(&mutex_);
16101611

1611-
// When a manual compaction arrives, temporarily throttle down
1612-
// the number of background compaction threads to 1. This is
1613-
// needed to ensure that this manual compaction can compact
1614-
// any range of keys/files. We artificialy increase
1615-
// bg_compaction_scheduled_ by a large number, this causes
1616-
// the system to have a single background thread. Now,
1617-
// this manual compaction can progress without stomping
1618-
// on any other concurrent compactions.
1619-
const int LargeNumber = 10000000;
1620-
const int newvalue = options_.max_background_compactions-1;
1621-
bg_compaction_scheduled_ += LargeNumber;
1622-
while (bg_compaction_scheduled_ > LargeNumber) {
1623-
Log(options_.info_log, "Manual compaction request waiting for background threads to fall below 1");
1612+
// When a manual compaction arrives, temporarily disable scheduling of
1613+
// non-manual compactions and wait until the number of scheduled compaction
1614+
// jobs drops to zero. This is needed to ensure that this manual compaction
1615+
// can compact any range of keys/files.
1616+
//
1617+
// bg_manual_only_ is non-zero when at least one thread is inside
1618+
// TEST_CompactRange(), i.e. during that time no other compaction will
1619+
// get scheduled (see MaybeScheduleFlushOrCompaction).
1620+
//
1621+
// Note that the following loop doesn't stop more that one thread calling
1622+
// TEST_CompactRange() from getting to the second while loop below.
1623+
// However, only one of them will actually schedule compaction, while
1624+
// others will wait on a condition variable until it completes.
1625+
1626+
++bg_manual_only_;
1627+
while (bg_compaction_scheduled_ > 0) {
1628+
Log(options_.info_log,
1629+
"Manual compaction waiting for all other scheduled background "
1630+
"compactions to finish");
16241631
bg_cv_.Wait();
16251632
}
1633+
16261634
Log(options_.info_log, "Manual compaction starting");
16271635

1628-
while (!manual.done) {
1629-
while (manual_compaction_ != nullptr) {
1630-
bg_cv_.Wait();
1631-
}
1632-
manual_compaction_ = &manual;
1633-
if (bg_compaction_scheduled_ == LargeNumber) {
1634-
bg_compaction_scheduled_ = newvalue;
1635-
}
1636-
MaybeScheduleFlushOrCompaction();
1637-
while (manual_compaction_ == &manual) {
1636+
while (!manual.done && !shutting_down_.Acquire_Load() && bg_error_.ok()) {
1637+
assert(bg_manual_only_ > 0);
1638+
if (manual_compaction_ != nullptr) {
1639+
// Running either this or some other manual compaction
16381640
bg_cv_.Wait();
1641+
} else {
1642+
manual_compaction_ = &manual;
1643+
MaybeScheduleFlushOrCompaction();
16391644
}
16401645
}
1641-
assert(!manual.in_progress);
16421646

1643-
// wait till there are no background threads scheduled
1644-
bg_compaction_scheduled_ += LargeNumber;
1645-
while (bg_compaction_scheduled_ > LargeNumber + newvalue) {
1646-
Log(options_.info_log, "Manual compaction resetting background threads");
1647-
bg_cv_.Wait();
1648-
}
1649-
bg_compaction_scheduled_ = 0;
1647+
assert(!manual.in_progress);
1648+
assert(bg_manual_only_ > 0);
1649+
--bg_manual_only_;
16501650
}
16511651

16521652
Status DBImpl::FlushMemTable(const FlushOptions& options) {
@@ -1711,11 +1711,16 @@ void DBImpl::MaybeScheduleFlushOrCompaction() {
17111711
env_->Schedule(&DBImpl::BGWorkFlush, this, Env::Priority::HIGH);
17121712
}
17131713

1714+
// Schedule BGWorkCompaction if there's a compaction pending (or a memtable
1715+
// flush, but the HIGH pool is not enabled). Do it only if
1716+
// max_background_compactions hasn't been reached and, in case
1717+
// bg_manual_only_ > 0, if it's a manual compaction.
17141718
if ((manual_compaction_ ||
17151719
versions_->NeedsCompaction() ||
17161720
(is_flush_pending && (options_.max_background_flushes <= 0))) &&
1717-
bg_compaction_scheduled_ < options_.max_background_compactions) {
1718-
// compaction needed, or memtable flush needed but HIGH pool not enabled.
1721+
bg_compaction_scheduled_ < options_.max_background_compactions &&
1722+
(!bg_manual_only_ || manual_compaction_)) {
1723+
17191724
bg_compaction_scheduled_++;
17201725
env_->Schedule(&DBImpl::BGWorkCompaction, this, Env::Priority::LOW);
17211726
}

db/db_impl.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,14 @@ class DBImpl : public DB {
389389
// part of ongoing compactions.
390390
std::set<uint64_t> pending_outputs_;
391391

392-
// count how many background compaction been scheduled or is running?
392+
// count how many background compactions are running or have been scheduled
393393
int bg_compaction_scheduled_;
394394

395+
// If non-zero, MaybeScheduleFlushOrCompaction() will only schedule manual
396+
// compactions (if manual_compaction_ is not null). This mechanism enables
397+
// manual compactions to wait until all other compactions are finished.
398+
int bg_manual_only_;
399+
395400
// number of background memtable flush jobs, submitted to the HIGH pool
396401
int bg_flush_scheduled_;
397402

util/autovector_test.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ using namespace std;
1717

1818
class AutoVectorTest { };
1919

20-
const size_t kSize = 8;
20+
const unsigned long kSize = 8;
2121
TEST(AutoVectorTest, PushBackAndPopBack) {
2222
autovector<size_t, kSize> vec;
2323
ASSERT_TRUE(vec.empty());

0 commit comments

Comments
 (0)