Skip to content

Commit e72aa37

Browse files
committed
Merge branch 'master' into performance
Conflicts: db/table_cache.cc
2 parents 476416c + 463086b commit e72aa37

18 files changed

+169
-29
lines changed

.clang-format

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Complete list of style options can be found at:
2+
# http://clang.llvm.org/docs/ClangFormatStyleOptions.html
3+
---
4+
BasedOnStyle: Google
5+
AccessModifierOffset: -1
6+
ConstructorInitializerIndentWidth: 4
7+
AlignEscapedNewlinesLeft: true
8+
AlignTrailingComments: true
9+
AllowAllParametersOfDeclarationOnNextLine: true
10+
AllowShortIfStatementsOnASingleLine: false
11+
AllowShortLoopsOnASingleLine: false
12+
AlwaysBreakTemplateDeclarations: true
13+
AlwaysBreakBeforeMultilineStrings: true
14+
BreakBeforeBinaryOperators: false
15+
BreakConstructorInitializersBeforeComma: false
16+
BinPackParameters: false
17+
ColumnLimit: 80
18+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
19+
DerivePointerBinding: true
20+
ExperimentalAutoDetectBinPacking: true
21+
IndentCaseLabels: false
22+
MaxEmptyLinesToKeep: 1
23+
NamespaceIndentation: None
24+
ObjCSpaceBeforeProtocolList: false
25+
PenaltyBreakBeforeFirstCallParameter: 10
26+
PenaltyBreakComment: 60
27+
PenaltyBreakString: 1000
28+
PenaltyBreakFirstLessLess: 20
29+
PenaltyExcessCharacter: 1000000
30+
PenaltyReturnTypeOnItsOwnLine: 200
31+
PointerBindsToType: true
32+
SpacesBeforeTrailingComments: 2
33+
Cpp11BracedListStyle: true
34+
Standard: Cpp11
35+
IndentWidth: 2
36+
TabWidth: 8
37+
UseTab: Never
38+
BreakBeforeBraces: Attach
39+
IndentFunctionDeclarationAfterType: false
40+
SpacesInParentheses: false
41+
SpacesInAngles: false
42+
SpaceInEmptyParentheses: false
43+
SpacesInCStyleCastParentheses: false
44+
SpaceAfterControlStatementKeyword: true
45+
SpaceBeforeAssignmentOperators: true
46+
ContinuationIndentWidth: 4
47+
...

INSTALL.md

+2
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,7 @@ libraries. You are on your own.
4444
`make clean; make` will compile librocksdb.a (RocskDB static library) and all
4545
the unit tests. You can run all unit tests with `make check`.
4646

47+
For shared library builds, exec `make librocksdb.so` instead.
48+
4749
If you followed the above steps and your compile or unit tests fail,
4850
please submit an issue: (https://github.com/facebook/rocksdb/issues)

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ VALGRIND_VER := $(join $(VALGRIND_VER),valgrind)
4545
VALGRIND_OPTS = --error-exitcode=$(VALGRIND_ERROR) --leak-check=full
4646

4747
TESTS = \
48-
autovector_test \
4948
db_test \
49+
autovector_test \
5050
table_properties_collector_test \
5151
arena_test \
5252
auto_roll_logger_test \

README.fb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
* Detailed instructions on how to compile using fbcode and jemalloc
22

3-
* Latest release is 2.5.fb
3+
* Latest release is 2.7.fb

build_tools/build_detect_platform

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ EOF
198198
}
199199
EOF
200200
if [ "$?" = 0 ]; then
201-
COMMON_FLAGS="$PLATFORM_LDFLAGS -DROCKSDB_FALLOCATE_PRESENT"
201+
COMMON_FLAGS="$COMMON_FLAGS -DROCKSDB_FALLOCATE_PRESENT"
202202
fi
203203

204204
# Test whether Snappy library is installed

build_tools/build_detect_version

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#
99

1010
# create git version file
11-
VFILE=$ROCKSDB_ROOT/util/build_version.cc.tmp
11+
VFILE=$PWD/util/build_version.cc.tmp
1212
trap "rm $VFILE" EXIT
1313

1414
# check to see if git is in the path
@@ -36,7 +36,7 @@ echo "const char* rocksdb_build_git_datetime = \"rocksdb_build_git_datetime:$(da
3636
echo "const char* rocksdb_build_compile_date = __DATE__;" >> ${VFILE}
3737
echo "const char* rocksdb_build_compile_time = __TIME__;" >> ${VFILE}
3838

39-
OUTFILE=$ROCKSDB_ROOT/util/build_version.cc
39+
OUTFILE=$PWD/util/build_version.cc
4040
if [ ! -e $OUTFILE ] || ! cmp -s $VFILE $OUTFILE; then
4141
cp $VFILE $OUTFILE
4242
fi

build_tools/fbcode.gcc471.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ RANLIB=$TOOLCHAIN_EXECUTABLES/binutils/binutils-2.21.1/da39a3e/bin/ranlib
5454
CFLAGS="-B$TOOLCHAIN_EXECUTABLES/binutils/binutils-2.21.1/da39a3e/bin/gold -m64 -mtune=generic"
5555
CFLAGS+=" -I $TOOLCHAIN_LIB_BASE/jemalloc/$TOOL_JEMALLOC/include -DHAVE_JEMALLOC"
5656
CFLAGS+=" $LIBGCC_INCLUDE $GLIBC_INCLUDE"
57-
CFLAGS+=" -DROCKSDB_PLATFORM_POSIX -DROCKSDB_ATOMIC_PRESENT"
57+
CFLAGS+=" -DROCKSDB_PLATFORM_POSIX -DROCKSDB_ATOMIC_PRESENT -DROCKSDB_FALLOCATE_PRESENT"
5858
CFLAGS+=" -DSNAPPY -DGFLAGS -DZLIB -DBZIP2"
5959

6060
EXEC_LDFLAGS=" -Wl,--whole-archive $TOOLCHAIN_LIB_BASE/jemalloc/$TOOL_JEMALLOC/lib/libjemalloc.a"

build_tools/fbcode.gcc481.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ RANLIB=$TOOLCHAIN_EXECUTABLES/binutils/binutils-2.21.1/da39a3e/bin/ranlib
6161

6262
CFLAGS="-B$TOOLCHAIN_EXECUTABLES/binutils/binutils-2.21.1/da39a3e/bin/gold -m64 -mtune=generic"
6363
CFLAGS+=" -nostdlib $LIBGCC_INCLUDE $GLIBC_INCLUDE"
64-
CFLAGS+=" -DROCKSDB_PLATFORM_POSIX -DROCKSDB_ATOMIC_PRESENT"
64+
CFLAGS+=" -DROCKSDB_PLATFORM_POSIX -DROCKSDB_ATOMIC_PRESENT -DROCKSDB_FALLOCATE_PRESENT"
6565
CFLAGS+=" -DSNAPPY -DGFLAGS -DZLIB -DBZIP2"
6666

6767
EXEC_LDFLAGS="-Wl,--dynamic-linker,/usr/local/fbcode/gcc-4.8.1-glibc-2.17/lib/ld.so"

build_tools/make_new_version.sh

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
# Copyright (c) 2013, Facebook, Inc. All rights reserved.
3+
# This source code is licensed under the BSD-style license found in the
4+
# LICENSE file in the root directory of this source tree. An additional grant
5+
# of patent rights can be found in the PATENTS file in the same directory.
6+
7+
set -e
8+
# Print out the colored progress info so that it can be brainlessly
9+
# distinguished by users.
10+
function title() {
11+
echo -e "\033[1;32m$*\033[0m"
12+
}
13+
14+
usage="Create new rocksdb version and prepare it for the release process\n"
15+
usage+="USAGE: ./make_new_version.sh <version>"
16+
17+
# -- Pre-check
18+
if [[ $# < 1 ]]; then
19+
echo -e $usage
20+
exit 1
21+
fi
22+
23+
ROCKSDB_VERSION=$1
24+
25+
GIT_BRANCH=`git rev-parse --abbrev-ref HEAD`
26+
if [ $GIT_BRANCH != "master" ]; then
27+
echo "Error: Current branch is '$GIT_BRANCH', Please switch to master branch."
28+
fi
29+
30+
# --Step 1: cutting new tag
31+
title "Adding new tag for this release ..."
32+
git tag -a "$ROCKSDB_VERSION.fb" -m "Rocksdb $ROCKSDB_VERSION"
33+
34+
# Setting up the proxy for remote repo access
35+
export http_proxy=http://172.31.255.99:8080
36+
export https_proxy="$http_proxy";
37+
38+
title "Pushing new tag to remote repo ..."
39+
proxycmd.sh git push origin --tags
40+
41+
# --Step 2: Update README.fb
42+
title "Updating the latest version info in README.fb ..."
43+
sed -i "s/Latest release is [0-9]\+.[0-9]\+.fb/Latest release is $ROCKSDB_VERSION.fb/" README.fb
44+
git commit README.fb -m "update the latest version in README.fb to $ROCKSDB_VERSION"
45+
proxycmd.sh git push
46+
47+
# --Step 3: Prepare this repo for 3rd release
48+
title "Cleaning up repo ..."
49+
make clean
50+
git clean -fxd
51+
52+
title "Generating the build info ..."
53+
# Comment out the call of `build_detection_version` so that the SHA number and build date of this
54+
# release will remain constant. Otherwise everytime we run "make" util/build_version.cc will be
55+
# overridden.
56+
sed -i 's/^\$PWD\/build_tools\/build_detect_version$//' build_tools/build_detect_platform
57+
58+
# Generate util/build_version.cc
59+
build_tools/build_detect_version
60+
61+
title "Done!"

db/db_filesnapshot.cc

+21-7
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,34 @@ namespace rocksdb {
2222

2323
Status DBImpl::DisableFileDeletions() {
2424
MutexLock l(&mutex_);
25-
disable_delete_obsolete_files_ = true;
26-
Log(options_.info_log, "File Deletions Disabled");
25+
++disable_delete_obsolete_files_;
26+
if (disable_delete_obsolete_files_ == 1) {
27+
// if not, it has already been disabled, so don't log anything
28+
Log(options_.info_log, "File Deletions Disabled");
29+
}
2730
return Status::OK();
2831
}
2932

30-
Status DBImpl::EnableFileDeletions() {
33+
Status DBImpl::EnableFileDeletions(bool force) {
3134
DeletionState deletion_state;
35+
bool should_purge_files = false;
3236
{
3337
MutexLock l(&mutex_);
34-
disable_delete_obsolete_files_ = false;
35-
Log(options_.info_log, "File Deletions Enabled");
36-
FindObsoleteFiles(deletion_state, true);
38+
if (force) {
39+
// if force, we need to enable file deletions right away
40+
disable_delete_obsolete_files_ = 0;
41+
} else if (disable_delete_obsolete_files_ > 0) {
42+
--disable_delete_obsolete_files_;
43+
}
44+
if (disable_delete_obsolete_files_ == 0) {
45+
Log(options_.info_log, "File Deletions Enabled");
46+
should_purge_files = true;
47+
FindObsoleteFiles(deletion_state, true);
48+
}
49+
}
50+
if (should_purge_files) {
51+
PurgeObsoleteFiles(deletion_state);
3752
}
38-
PurgeObsoleteFiles(deletion_state);
3953
LogFlush(options_.info_log);
4054
return Status::OK();
4155
}

db/db_impl.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ DBImpl::DBImpl(const Options& options, const std::string& dbname)
247247
bg_logstats_scheduled_(false),
248248
manual_compaction_(nullptr),
249249
logger_(nullptr),
250-
disable_delete_obsolete_files_(false),
250+
disable_delete_obsolete_files_(0),
251251
delete_obsolete_files_last_run_(options.env->NowMicros()),
252252
purge_wal_files_last_run_(0),
253253
last_stats_dump_time_microsec_(0),
@@ -509,7 +509,7 @@ void DBImpl::FindObsoleteFiles(DeletionState& deletion_state,
509509
mutex_.AssertHeld();
510510

511511
// if deletion is disabled, do nothing
512-
if (disable_delete_obsolete_files_) {
512+
if (disable_delete_obsolete_files_ > 0) {
513513
return;
514514
}
515515

@@ -1262,7 +1262,7 @@ Status DBImpl::FlushMemTableToOutputFile(bool* madeProgress,
12621262

12631263
MaybeScheduleLogDBDeployStats();
12641264

1265-
if (!disable_delete_obsolete_files_) {
1265+
if (disable_delete_obsolete_files_ == 0) {
12661266
// add to deletion state
12671267
deletion_state.log_delete_files.insert(
12681268
deletion_state.log_delete_files.end(),

db/db_impl.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class DBImpl : public DB {
7373
virtual const Options& GetOptions() const;
7474
virtual Status Flush(const FlushOptions& options);
7575
virtual Status DisableFileDeletions();
76-
virtual Status EnableFileDeletions();
76+
virtual Status EnableFileDeletions(bool force);
7777
// All the returned filenames start with "/"
7878
virtual Status GetLiveFiles(std::vector<std::string>&,
7979
uint64_t* manifest_file_size,
@@ -417,7 +417,12 @@ class DBImpl : public DB {
417417
int64_t volatile last_log_ts;
418418

419419
// shall we disable deletion of obsolete files
420-
bool disable_delete_obsolete_files_;
420+
// if 0 the deletion is enabled.
421+
// if non-zero, files will not be getting deleted
422+
// This enables two different threads to call
423+
// EnableFileDeletions() and DisableFileDeletions()
424+
// without any synchronization
425+
int disable_delete_obsolete_files_;
421426

422427
// last time when DeleteObsoleteFiles was invoked
423428
uint64_t delete_obsolete_files_last_run_;

db/db_impl_readonly.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class DBImplReadOnly : public DBImpl {
5555
virtual Status DisableFileDeletions() {
5656
return Status::NotSupported("Not supported operation in read only mode.");
5757
}
58-
virtual Status EnableFileDeletions() {
58+
virtual Status EnableFileDeletions(bool force) {
5959
return Status::NotSupported("Not supported operation in read only mode.");
6060
}
6161
virtual Status GetLiveFiles(std::vector<std::string>&,

db/db_test.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -4381,7 +4381,7 @@ class ModelDB: public DB {
43814381
virtual Status DisableFileDeletions() {
43824382
return Status::OK();
43834383
}
4384-
virtual Status EnableFileDeletions() {
4384+
virtual Status EnableFileDeletions(bool force) {
43854385
return Status::OK();
43864386
}
43874387
virtual Status GetLiveFiles(std::vector<std::string>&, uint64_t* size,

db/table_cache.cc

+7-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ static void UnrefEntry(void* arg1, void* arg2) {
2929
cache->Release(h);
3030
}
3131

32+
static Slice GetSliceForFileNumber(uint64_t* file_number) {
33+
return Slice(reinterpret_cast<const char*>(file_number),
34+
sizeof(*file_number));
35+
}
36+
3237
TableCache::TableCache(const std::string& dbname,
3338
const Options* options,
3439
const EnvOptions& storage_options,
@@ -50,8 +55,7 @@ Status TableCache::FindTable(const EnvOptions& toptions,
5055
Cache::Handle** handle, bool* table_io,
5156
const bool no_io) {
5257
Status s;
53-
Slice key(reinterpret_cast<const char*>(&file_number), sizeof(file_number));
54-
58+
Slice key = GetSliceForFileNumber(&file_number);
5559
*handle = cache_->Lookup(key);
5660
if (*handle == nullptr) {
5761
if (no_io) { // Dont do IO and return a not-found status
@@ -164,8 +168,7 @@ bool TableCache::PrefixMayMatch(const ReadOptions& options,
164168
}
165169

166170
void TableCache::Evict(uint64_t file_number) {
167-
Slice key(reinterpret_cast<const char*>(&file_number), sizeof(file_number));
168-
cache_->Erase(key);
171+
cache_->Erase(GetSliceForFileNumber(&file_number));
169172
}
170173

171174
} // namespace rocksdb

include/rocksdb/db.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,15 @@ class DB {
247247
virtual Status DisableFileDeletions() = 0;
248248

249249
// Allow compactions to delete obselete files.
250-
virtual Status EnableFileDeletions() = 0;
250+
// If force == true, the call to EnableFileDeletions() will guarantee that
251+
// file deletions are enabled after the call, even if DisableFileDeletions()
252+
// was called multiple times before.
253+
// If force == false, EnableFileDeletions will only enable file deletion
254+
// after it's been called at least as many times as DisableFileDeletions(),
255+
// enabling the two methods to be called by two threads concurrently without
256+
// synchronization -- i.e., file deletions will be enabled only after both
257+
// threads call EnableFileDeletions()
258+
virtual Status EnableFileDeletions(bool force = true) = 0;
251259

252260
// GetLiveFiles followed by GetSortedWalFiles can generate a lossless backup
253261

include/utilities/stackable_db.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ class StackableDB : public DB {
123123
return db_->DisableFileDeletions();
124124
}
125125

126-
virtual Status EnableFileDeletions() override {
127-
return db_->EnableFileDeletions();
126+
virtual Status EnableFileDeletions(bool force) override {
127+
return db_->EnableFileDeletions(force);
128128
}
129129

130130
virtual Status GetLiveFiles(std::vector<std::string>& vec, uint64_t* mfs,

utilities/backupable/backupable_db_test.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class DummyDB : public StackableDB {
4848
return options_;
4949
}
5050

51-
virtual Status EnableFileDeletions() override {
51+
virtual Status EnableFileDeletions(bool force) override {
5252
ASSERT_TRUE(!deletions_enabled_);
5353
deletions_enabled_ = true;
5454
return Status::OK();

0 commit comments

Comments
 (0)