Skip to content

Commit a1068c9

Browse files
committed
Make RocksDB work with newer gflags
Summary: Newer gflags switched from `google` namespace to `gflags` namespace. See: facebook/rocksdb#139 and facebook/rocksdb#102 Unfortunately, they don't define any macro with their namespace, so we need to actually try to compile gflags with two different namespace to figure out which one is the correct one. Test Plan: works in fbcode environemnt. I'll also try in ubutnu with newer gflags Reviewers: dhruba Reviewed By: dhruba CC: leveldb Differential Revision: https://reviews.facebook.net/D18537
1 parent ddd4114 commit a1068c9

7 files changed

+108
-50
lines changed

build_tools/build_detect_platform

+14-1
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,25 @@ EOF
219219

220220
# Test whether gflags library is installed
221221
# http://code.google.com/p/gflags/
222+
# check if the namespace is gflags
222223
$CXX $CFLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF
223224
#include <gflags/gflags.h>
225+
using namespace gflags;
224226
int main() {}
225227
EOF
226228
if [ "$?" = 0 ]; then
227-
COMMON_FLAGS="$COMMON_FLAGS -DGFLAGS"
229+
COMMON_FLAGS="$COMMON_FLAGS -DGFLAGS=gflags"
230+
PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -lgflags"
231+
fi
232+
233+
# check if namespace is google
234+
$CXX $CFLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF
235+
#include <gflags/gflags.h>
236+
using namespace google;
237+
int main() {}
238+
EOF
239+
if [ "$?" = 0 ]; then
240+
COMMON_FLAGS="$COMMON_FLAGS -DGFLAGS=google"
228241
PLATFORM_LDFLAGS="$PLATFORM_LDFLAGS -lgflags"
229242
fi
230243

build_tools/fbcode.gcc471.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ CFLAGS="-B$TOOLCHAIN_EXECUTABLES/binutils/binutils-2.21.1/da39a3e/bin/gold -m64
5555
CFLAGS+=" -I $TOOLCHAIN_LIB_BASE/jemalloc/$TOOL_JEMALLOC/include -DHAVE_JEMALLOC"
5656
CFLAGS+=" $LIBGCC_INCLUDE $GLIBC_INCLUDE"
5757
CFLAGS+=" -DROCKSDB_PLATFORM_POSIX -DROCKSDB_ATOMIC_PRESENT -DROCKSDB_FALLOCATE_PRESENT"
58-
CFLAGS+=" -DSNAPPY -DGFLAGS -DZLIB -DBZIP2"
58+
CFLAGS+=" -DSNAPPY -DGFLAGS=google -DZLIB -DBZIP2"
5959

6060
EXEC_LDFLAGS=" -Wl,--whole-archive $TOOLCHAIN_LIB_BASE/jemalloc/$TOOL_JEMALLOC/lib/libjemalloc.a"
6161
EXEC_LDFLAGS+=" -Wl,--no-whole-archive $TOOLCHAIN_LIB_BASE/libunwind/libunwind-1.0.1/350336c/lib/libunwind.a"

build_tools/fbcode.gcc481.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ RANLIB=$TOOLCHAIN_EXECUTABLES/binutils/binutils-2.21.1/da39a3e/bin/ranlib
6666
CFLAGS="-B$TOOLCHAIN_EXECUTABLES/binutils/binutils-2.21.1/da39a3e/bin/gold -m64 -mtune=generic"
6767
CFLAGS+=" $LIBGCC_INCLUDE $GLIBC_INCLUDE"
6868
CFLAGS+=" -DROCKSDB_PLATFORM_POSIX -DROCKSDB_ATOMIC_PRESENT -DROCKSDB_FALLOCATE_PRESENT"
69-
CFLAGS+=" -DSNAPPY -DGFLAGS -DZLIB -DBZIP2 -DLZ4"
69+
CFLAGS+=" -DSNAPPY -DGFLAGS=google -DZLIB -DBZIP2 -DLZ4"
7070

7171
EXEC_LDFLAGS="-Wl,--dynamic-linker,/usr/local/fbcode/gcc-4.8.1-glibc-2.17/lib/ld.so"
7272
EXEC_LDFLAGS+=" -Wl,--no-whole-archive $TOOLCHAIN_LIB_BASE/libunwind/libunwind-1.0.1/675d945/lib/libunwind.a"

db/db_bench.cc

+29-20
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
// found in the LICENSE file. See the AUTHORS file for names of contributors.
99

1010
#define __STDC_FORMAT_MACROS
11+
12+
#ifndef GFLAGS
13+
#include <cstdio>
14+
int main() {
15+
fprintf(stderr, "Please install gflags to run rocksdb tools\n");
16+
return 1;
17+
}
18+
#else
19+
1120
#include <inttypes.h>
1221
#include <cstddef>
1322
#include <sys/types.h>
@@ -40,6 +49,9 @@
4049
#include "hdfs/env_hdfs.h"
4150
#include "utilities/merge_operators.h"
4251

52+
using GFLAGS::ParseCommandLineFlags;
53+
using GFLAGS::RegisterFlagValidator;
54+
using GFLAGS::SetUsageMessage;
4355

4456
DEFINE_string(benchmarks,
4557
"fillseq,"
@@ -376,8 +388,7 @@ static bool ValidateCompressionLevel(const char* flagname, int32_t value) {
376388
}
377389

378390
static const bool FLAGS_compression_level_dummy __attribute__((unused)) =
379-
google::RegisterFlagValidator(&FLAGS_compression_level,
380-
&ValidateCompressionLevel);
391+
RegisterFlagValidator(&FLAGS_compression_level, &ValidateCompressionLevel);
381392

382393
DEFINE_int32(min_level_to_compress, -1, "If non-negative, compression starts"
383394
" from this level. Levels with number < min_level_to_compress are"
@@ -529,33 +540,29 @@ DEFINE_string(merge_operator, "", "The merge operator to use with the database."
529540
" utilities/merge_operators.h");
530541

531542
static const bool FLAGS_soft_rate_limit_dummy __attribute__((unused)) =
532-
google::RegisterFlagValidator(&FLAGS_soft_rate_limit,
533-
&ValidateRateLimit);
543+
RegisterFlagValidator(&FLAGS_soft_rate_limit, &ValidateRateLimit);
534544

535545
static const bool FLAGS_hard_rate_limit_dummy __attribute__((unused)) =
536-
google::RegisterFlagValidator(&FLAGS_hard_rate_limit, &ValidateRateLimit);
546+
RegisterFlagValidator(&FLAGS_hard_rate_limit, &ValidateRateLimit);
537547

538548
static const bool FLAGS_prefix_size_dummy __attribute__((unused)) =
539-
google::RegisterFlagValidator(&FLAGS_prefix_size, &ValidatePrefixSize);
549+
RegisterFlagValidator(&FLAGS_prefix_size, &ValidatePrefixSize);
540550

541551
static const bool FLAGS_key_size_dummy __attribute__((unused)) =
542-
google::RegisterFlagValidator(&FLAGS_key_size, &ValidateKeySize);
552+
RegisterFlagValidator(&FLAGS_key_size, &ValidateKeySize);
543553

544554
static const bool FLAGS_cache_numshardbits_dummy __attribute__((unused)) =
545-
google::RegisterFlagValidator(&FLAGS_cache_numshardbits,
546-
&ValidateCacheNumshardbits);
555+
RegisterFlagValidator(&FLAGS_cache_numshardbits,
556+
&ValidateCacheNumshardbits);
547557

548558
static const bool FLAGS_readwritepercent_dummy __attribute__((unused)) =
549-
google::RegisterFlagValidator(&FLAGS_readwritepercent,
550-
&ValidateInt32Percent);
559+
RegisterFlagValidator(&FLAGS_readwritepercent, &ValidateInt32Percent);
551560

552561
static const bool FLAGS_deletepercent_dummy __attribute__((unused)) =
553-
google::RegisterFlagValidator(&FLAGS_deletepercent,
554-
&ValidateInt32Percent);
555-
static const bool
556-
FLAGS_table_cache_numshardbits_dummy __attribute__((unused)) =
557-
google::RegisterFlagValidator(&FLAGS_table_cache_numshardbits,
558-
&ValidateTableCacheNumshardbits);
562+
RegisterFlagValidator(&FLAGS_deletepercent, &ValidateInt32Percent);
563+
static const bool FLAGS_table_cache_numshardbits_dummy __attribute__((unused)) =
564+
RegisterFlagValidator(&FLAGS_table_cache_numshardbits,
565+
&ValidateTableCacheNumshardbits);
559566

560567
namespace rocksdb {
561568

@@ -2561,9 +2568,9 @@ class Benchmark {
25612568

25622569
int main(int argc, char** argv) {
25632570
rocksdb::port::InstallStackTraceHandler();
2564-
google::SetUsageMessage(std::string("\nUSAGE:\n") + std::string(argv[0]) +
2565-
" [OPTIONS]...");
2566-
google::ParseCommandLineFlags(&argc, &argv, true);
2571+
SetUsageMessage(std::string("\nUSAGE:\n") + std::string(argv[0]) +
2572+
" [OPTIONS]...");
2573+
ParseCommandLineFlags(&argc, &argv, true);
25672574

25682575
FLAGS_compaction_style_e = (rocksdb::CompactionStyle) FLAGS_compaction_style;
25692576
if (FLAGS_statistics) {
@@ -2614,3 +2621,5 @@ int main(int argc, char** argv) {
26142621
benchmark.Run();
26152622
return 0;
26162623
}
2624+
2625+
#endif // GFLAGS

db/prefix_test.cc

+13-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
// LICENSE file in the root directory of this source tree. An additional grant
44
// of patent rights can be found in the PATENTS file in the same directory.
55

6+
#ifndef GFLAGS
7+
#include <cstdio>
8+
int main() {
9+
fprintf(stderr, "Please install gflags to run rocksdb tools\n");
10+
return 1;
11+
}
12+
#else
13+
614
#include <algorithm>
715
#include <iostream>
816
#include <vector>
@@ -17,6 +25,8 @@
1725
#include "util/stop_watch.h"
1826
#include "util/testharness.h"
1927

28+
using GFLAGS::ParseCommandLineFlags;
29+
2030
DEFINE_bool(trigger_deadlock, false,
2131
"issue delete in range scan to trigger PrefixHashMap deadlock");
2232
DEFINE_uint64(bucket_count, 100000, "number of buckets");
@@ -479,9 +489,11 @@ TEST(PrefixTest, DynamicPrefixIterator) {
479489
}
480490

481491
int main(int argc, char** argv) {
482-
google::ParseCommandLineFlags(&argc, &argv, true);
492+
ParseCommandLineFlags(&argc, &argv, true);
483493
std::cout << kDbName << "\n";
484494

485495
rocksdb::test::RunAllTests();
486496
return 0;
487497
}
498+
499+
#endif // GFLAGS

tools/db_repl_stress.cc

+19-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22
// This source code is licensed under the BSD-style license found in the
33
// LICENSE file in the root directory of this source tree. An additional grant
44
// of patent rights can be found in the PATENTS file in the same directory.
5-
//
5+
6+
#ifndef GFLAGS
7+
#include <cstdio>
8+
int main() {
9+
fprintf(stderr, "Please install gflags to run rocksdb tools\n");
10+
return 1;
11+
}
12+
#else
13+
614
#include <cstdio>
715

816
#include <gflags/gflags.h>
@@ -13,7 +21,6 @@
1321
#include "port/atomic_pointer.h"
1422
#include "util/testutil.h"
1523

16-
1724
// Run a thread to perform Put's.
1825
// Another thread uses GetUpdatesSince API to keep getting the updates.
1926
// options :
@@ -22,6 +29,9 @@
2229

2330
using namespace rocksdb;
2431

32+
using GFLAGS::ParseCommandLineFlags;
33+
using GFLAGS::SetUsageMessage;
34+
2535
struct DataPumpThread {
2636
size_t no_records;
2737
DB* db; // Assumption DB is Open'ed already.
@@ -87,10 +97,11 @@ DEFINE_uint64(wal_size_limit_MB, 10, "the wal size limit for the run"
8797
"(in MB)");
8898

8999
int main(int argc, const char** argv) {
90-
google::SetUsageMessage(std::string("\nUSAGE:\n") + std::string(argv[0]) +
91-
" --num_inserts=<num_inserts> --wal_ttl_seconds=<WAL_ttl_seconds>" +
92-
" --wal_size_limit_MB=<WAL_size_limit_MB>");
93-
google::ParseCommandLineFlags(&argc, const_cast<char***>(&argv), true);
100+
SetUsageMessage(
101+
std::string("\nUSAGE:\n") + std::string(argv[0]) +
102+
" --num_inserts=<num_inserts> --wal_ttl_seconds=<WAL_ttl_seconds>" +
103+
" --wal_size_limit_MB=<WAL_size_limit_MB>");
104+
ParseCommandLineFlags(&argc, const_cast<char***>(&argv), true);
94105

95106
Env* env = Env::Default();
96107
std::string default_db_path;
@@ -132,3 +143,5 @@ int main(int argc, const char** argv) {
132143
fprintf(stderr, "Successful!\n");
133144
exit(0);
134145
}
146+
147+
#endif // GFLAGS

tools/db_stress.cc

+31-20
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@
2020
// NOTE that if FLAGS_test_batches_snapshots is set, the test will have
2121
// different behavior. See comment of the flag for details.
2222

23+
#ifndef GFLAGS
24+
#include <cstdio>
25+
int main() {
26+
fprintf(stderr, "Please install gflags to run rocksdb tools\n");
27+
return 1;
28+
}
29+
#else
30+
2331
#include <sys/types.h>
2432
#include <stdio.h>
2533
#include <stdlib.h>
@@ -45,8 +53,11 @@
4553
#include "hdfs/env_hdfs.h"
4654
#include "utilities/merge_operators.h"
4755

48-
static const long KB = 1024;
56+
using GFLAGS::ParseCommandLineFlags;
57+
using GFLAGS::RegisterFlagValidator;
58+
using GFLAGS::SetUsageMessage;
4959

60+
static const long KB = 1024;
5061

5162
static bool ValidateUint32Range(const char* flagname, uint64_t value) {
5263
if (value > std::numeric_limits<uint32_t>::max()) {
@@ -61,7 +72,7 @@ static bool ValidateUint32Range(const char* flagname, uint64_t value) {
6172

6273
DEFINE_uint64(seed, 2341234, "Seed for PRNG");
6374
static const bool FLAGS_seed_dummy __attribute__((unused)) =
64-
google::RegisterFlagValidator(&FLAGS_seed, &ValidateUint32Range);
75+
RegisterFlagValidator(&FLAGS_seed, &ValidateUint32Range);
6576

6677
DEFINE_int64(max_key, 1 * KB* KB,
6778
"Max number of key/values to place in database");
@@ -185,7 +196,7 @@ static bool ValidateInt32Positive(const char* flagname, int32_t value) {
185196
}
186197
DEFINE_int32(reopen, 10, "Number of times database reopens");
187198
static const bool FLAGS_reopen_dummy __attribute__((unused)) =
188-
google::RegisterFlagValidator(&FLAGS_reopen, &ValidateInt32Positive);
199+
RegisterFlagValidator(&FLAGS_reopen, &ValidateInt32Positive);
189200

190201
DEFINE_int32(bloom_bits, 10, "Bloom filter bits per key. "
191202
"Negative means use default settings.");
@@ -213,8 +224,7 @@ DEFINE_int32(kill_random_test, 0,
213224
"If non-zero, kill at various points in source code with "
214225
"probability 1/this");
215226
static const bool FLAGS_kill_random_test_dummy __attribute__((unused)) =
216-
google::RegisterFlagValidator(&FLAGS_kill_random_test,
217-
&ValidateInt32Positive);
227+
RegisterFlagValidator(&FLAGS_kill_random_test, &ValidateInt32Positive);
218228
extern int rocksdb_kill_odds;
219229

220230
DEFINE_bool(disable_wal, false, "If true, do not write WAL for write.");
@@ -241,32 +251,32 @@ static bool ValidateInt32Percent(const char* flagname, int32_t value) {
241251
DEFINE_int32(readpercent, 10,
242252
"Ratio of reads to total workload (expressed as a percentage)");
243253
static const bool FLAGS_readpercent_dummy __attribute__((unused)) =
244-
google::RegisterFlagValidator(&FLAGS_readpercent, &ValidateInt32Percent);
254+
RegisterFlagValidator(&FLAGS_readpercent, &ValidateInt32Percent);
245255

246256
DEFINE_int32(prefixpercent, 20,
247257
"Ratio of prefix iterators to total workload (expressed as a"
248258
" percentage)");
249259
static const bool FLAGS_prefixpercent_dummy __attribute__((unused)) =
250-
google::RegisterFlagValidator(&FLAGS_prefixpercent, &ValidateInt32Percent);
260+
RegisterFlagValidator(&FLAGS_prefixpercent, &ValidateInt32Percent);
251261

252262
DEFINE_int32(writepercent, 45,
253263
" Ratio of deletes to total workload (expressed as a percentage)");
254264
static const bool FLAGS_writepercent_dummy __attribute__((unused)) =
255-
google::RegisterFlagValidator(&FLAGS_writepercent, &ValidateInt32Percent);
265+
RegisterFlagValidator(&FLAGS_writepercent, &ValidateInt32Percent);
256266

257267
DEFINE_int32(delpercent, 15,
258268
"Ratio of deletes to total workload (expressed as a percentage)");
259269
static const bool FLAGS_delpercent_dummy __attribute__((unused)) =
260-
google::RegisterFlagValidator(&FLAGS_delpercent, &ValidateInt32Percent);
270+
RegisterFlagValidator(&FLAGS_delpercent, &ValidateInt32Percent);
261271

262272
DEFINE_int32(iterpercent, 10, "Ratio of iterations to total workload"
263273
" (expressed as a percentage)");
264274
static const bool FLAGS_iterpercent_dummy __attribute__((unused)) =
265-
google::RegisterFlagValidator(&FLAGS_iterpercent, &ValidateInt32Percent);
275+
RegisterFlagValidator(&FLAGS_iterpercent, &ValidateInt32Percent);
266276

267277
DEFINE_uint64(num_iterations, 10, "Number of iterations per MultiIterate run");
268278
static const bool FLAGS_num_iterations_dummy __attribute__((unused)) =
269-
google::RegisterFlagValidator(&FLAGS_num_iterations, &ValidateUint32Range);
279+
RegisterFlagValidator(&FLAGS_num_iterations, &ValidateUint32Range);
270280

271281
DEFINE_bool(disable_seek_compaction, false,
272282
"Option to disable compation triggered by read.");
@@ -304,19 +314,18 @@ static rocksdb::Env* FLAGS_env = rocksdb::Env::Default();
304314

305315
DEFINE_uint64(ops_per_thread, 1200000, "Number of operations per thread.");
306316
static const bool FLAGS_ops_per_thread_dummy __attribute__((unused)) =
307-
google::RegisterFlagValidator(&FLAGS_ops_per_thread, &ValidateUint32Range);
317+
RegisterFlagValidator(&FLAGS_ops_per_thread, &ValidateUint32Range);
308318

309319
DEFINE_uint64(log2_keys_per_lock, 2, "Log2 of number of keys per lock");
310320
static const bool FLAGS_log2_keys_per_lock_dummy __attribute__((unused)) =
311-
google::RegisterFlagValidator(&FLAGS_log2_keys_per_lock,
312-
&ValidateUint32Range);
321+
RegisterFlagValidator(&FLAGS_log2_keys_per_lock, &ValidateUint32Range);
313322

314323
DEFINE_int32(purge_redundant_percent, 50,
315324
"Percentage of times we want to purge redundant keys in memory "
316325
"before flushing");
317326
static const bool FLAGS_purge_redundant_percent_dummy __attribute__((unused)) =
318-
google::RegisterFlagValidator(&FLAGS_purge_redundant_percent,
319-
&ValidateInt32Percent);
327+
RegisterFlagValidator(&FLAGS_purge_redundant_percent,
328+
&ValidateInt32Percent);
320329

321330
DEFINE_bool(filter_deletes, false, "On true, deletes use KeyMayExist to drop"
322331
" the delete if key not present");
@@ -356,7 +365,7 @@ static bool ValidatePrefixSize(const char* flagname, int32_t value) {
356365
}
357366
DEFINE_int32(prefix_size, 7, "Control the prefix size for HashSkipListRep");
358367
static const bool FLAGS_prefix_size_dummy =
359-
google::RegisterFlagValidator(&FLAGS_prefix_size, &ValidatePrefixSize);
368+
RegisterFlagValidator(&FLAGS_prefix_size, &ValidatePrefixSize);
360369

361370
DEFINE_bool(use_merge, false, "On true, replaces all writes with a Merge "
362371
"that behaves like a Put");
@@ -1666,9 +1675,9 @@ class StressTest {
16661675
} // namespace rocksdb
16671676

16681677
int main(int argc, char** argv) {
1669-
google::SetUsageMessage(std::string("\nUSAGE:\n") + std::string(argv[0]) +
1670-
" [OPTIONS]...");
1671-
google::ParseCommandLineFlags(&argc, &argv, true);
1678+
SetUsageMessage(std::string("\nUSAGE:\n") + std::string(argv[0]) +
1679+
" [OPTIONS]...");
1680+
ParseCommandLineFlags(&argc, &argv, true);
16721681

16731682
if (FLAGS_statistics) {
16741683
dbstats = rocksdb::CreateDBStatistics();
@@ -1730,3 +1739,5 @@ int main(int argc, char** argv) {
17301739
return 1;
17311740
}
17321741
}
1742+
1743+
#endif // GFLAGS

0 commit comments

Comments
 (0)