]> git-server-git.apps.pok.os.sepia.ceph.com Git - rocksdb.git/commitdiff
Add (& fix) some simple source code checks (#8821)
authorPeter Dillinger <peterd@fb.com>
Wed, 8 Sep 2021 04:18:21 +0000 (21:18 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Wed, 8 Sep 2021 04:19:27 +0000 (21:19 -0700)
Summary:
* Don't hardcode namespace rocksdb (use ROCKSDB_NAMESPACE)
* Don't #include <rocksdb/...> (use double quotes)
* Support putting NOCOMMIT (any case) in source code that should not be
committed/pushed in current state.

These will be run with `make check` and in GitHub actions

Pull Request resolved: https://github.com/facebook/rocksdb/pull/8821

Test Plan: existing tests, manually try out new checks

Reviewed By: zhichao-cao

Differential Revision: D30791726

Pulled By: pdillinger

fbshipit-source-id: 399c883f312be24d9e55c58951d4013e18429d92

16 files changed:
.github/workflows/sanity_check.yml
Makefile
build_tools/check-sources.sh [new file with mode: 0755]
cache/cache_bench.cc
db_stress_tool/db_stress.cc
examples/compaction_filter_example.cc
include/rocksdb/memtablerep.h
include/rocksdb/system_clock.h
java/rocksjni/event_listener_jnicallback.cc
java/rocksjni/event_listener_jnicallback.h
memory/memkind_kmem_allocator.cc
memory/memkind_kmem_allocator.h
memory/memkind_kmem_allocator_test.cc
table/block_based/index_builder.cc
test_util/testharness.h
tools/db_bench.cc

index 276851155844675cd21ab549beb43ad892b77155..e6a5f1591c8aad7cfd6a404df119bd6fe250e98f 100644 (file)
@@ -39,3 +39,6 @@ jobs:
 
     - name: Compare buckify output
       run: make check-buck-targets
+
+    - name: Simple source code checks
+      run: make check-sources
index e2790a2cc33ce1f9911fa80218e584b671f0a94c..b37e43e54db88e99190dbeedf1853fe74b0c5bc2 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -943,6 +943,7 @@ endif
 ifndef SKIP_FORMAT_BUCK_CHECKS
        $(MAKE) check-format
        $(MAKE) check-buck-targets
+       $(MAKE) check-sources
 endif
 
 # TODO add ldb_tests
@@ -1220,6 +1221,9 @@ check-format:
 check-buck-targets:
        buckifier/check_buck_targets.sh
 
+check-sources:
+       build_tools/check-sources.sh
+
 package:
        bash build_tools/make_package.sh $(SHARED_MAJOR).$(SHARED_MINOR)
 
@@ -1897,7 +1901,7 @@ clipping_iterator_test: $(OBJ_DIR)/db/compaction/clipping_iterator_test.o $(TEST
 
 ribbon_bench: $(OBJ_DIR)/microbench/ribbon_bench.o $(LIBRARY)
        $(AM_LINK)
-       
+
 cache_reservation_manager_test: $(OBJ_DIR)/cache/cache_reservation_manager_test.o $(TEST_LIBRARY) $(LIBRARY)
        $(AM_LINK)
 #-------------------------------------------------
@@ -2364,7 +2368,7 @@ build_subset_tests: $(ROCKSDBTESTS_SUBSET)
 
 # Remove the rules for which dependencies should not be generated and see if any are left.
 #If so, include the dependencies; if not, do not include the dependency files
-ROCKS_DEP_RULES=$(filter-out clean format check-format check-buck-targets jclean jtest package analyze tags rocksdbjavastatic% unity.% unity_test, $(MAKECMDGOALS))
+ROCKS_DEP_RULES=$(filter-out clean format check-format check-buck-targets check-sources jclean jtest package analyze tags rocksdbjavastatic% unity.% unity_test, $(MAKECMDGOALS))
 ifneq ("$(ROCKS_DEP_RULES)", "")
 -include $(DEPFILES)
 endif
diff --git a/build_tools/check-sources.sh b/build_tools/check-sources.sh
new file mode 100755 (executable)
index 0000000..7e481ff
--- /dev/null
@@ -0,0 +1,28 @@
+#!/usr/bin/env bash
+# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
+#
+# Check for some simple mistakes that should prevent commit or push
+
+BAD=""
+
+git grep 'namespace rocksdb' -- '*.[ch]*'
+if [ "$?" != "1" ]; then
+  echo "^^^^^ Do not hardcode namespace rocksdb. Use ROCKSDB_NAMESPACE"
+  BAD=1
+fi
+
+git grep -i 'nocommit' -- ':!build_tools/check-sources.sh'
+if [ "$?" != "1" ]; then
+  echo "^^^^^ Code was not intended to be committed"
+  BAD=1
+fi
+
+git grep '<rocksdb/' -- ':!build_tools/check-sources.sh'
+if [ "$?" != "1" ]; then
+  echo '^^^^^ Use double-quotes as in #include "rocksdb/something.h"'
+  BAD=1
+fi
+
+if [ "$BAD" ]; then
+  exit 1
+fi
index 0669354ae1977958ba0dc3052dcbbbb201dab0f8..f836939a325bfcfc9e67c3c62fffcb4a96b201ab 100644 (file)
@@ -13,7 +13,7 @@ int main() {
   return 1;
 }
 #else
-#include <rocksdb/cache_bench_tool.h>
+#include "rocksdb/cache_bench_tool.h"
 int main(int argc, char** argv) {
   return ROCKSDB_NAMESPACE::cache_bench_tool(argc, argv);
 }
index e03e967878dc0c87dff3cc97db869fa442eea8cc..f62268d4cb12cc19e6450862662231f8babe3048 100644 (file)
@@ -15,7 +15,7 @@ int main() {
   return 1;
 }
 #else
-#include <rocksdb/db_stress_tool.h>
+#include "rocksdb/db_stress_tool.h"
 
 int main(int argc, char** argv) {
   return ROCKSDB_NAMESPACE::db_stress_tool(argc, argv);
index bc960e01645b91e35b354633778d4af6838993e5..ed1ada823f0a64c41d3c02c2001495f55c2c6499 100644 (file)
@@ -3,10 +3,10 @@
 //  COPYING file in the root directory) and Apache 2.0 License
 //  (found in the LICENSE.Apache file in the root directory).
 
-#include <rocksdb/compaction_filter.h>
-#include <rocksdb/db.h>
-#include <rocksdb/merge_operator.h>
-#include <rocksdb/options.h>
+#include "rocksdb/compaction_filter.h"
+#include "rocksdb/db.h"
+#include "rocksdb/merge_operator.h"
+#include "rocksdb/options.h"
 
 class MyMerge : public ROCKSDB_NAMESPACE::MergeOperator {
  public:
index a2eeba0413e6b5b57a6686aeb57e35488141c323..3e4a786168d1f725acb8621551a2249354b15f71 100644 (file)
@@ -35,7 +35,6 @@
 
 #pragma once
 
-#include <rocksdb/slice.h>
 #include <stdint.h>
 #include <stdlib.h>
 
@@ -43,6 +42,8 @@
 #include <stdexcept>
 #include <unordered_set>
 
+#include "rocksdb/slice.h"
+
 namespace ROCKSDB_NAMESPACE {
 
 class Arena;
index e03d195ee2494c2155dd3f1c789b8e30a93616eb..3a52b42e26e10ad66bc3ab988ea0b2a7d451ba6d 100644 (file)
@@ -7,12 +7,13 @@
 // found in the LICENSE file. See the AUTHORS file for names of contributors.
 
 #pragma once
-#include <rocksdb/rocksdb_namespace.h>
-#include <rocksdb/status.h>
 #include <stdint.h>
 
 #include <memory>
 
+#include "rocksdb/rocksdb_namespace.h"
+#include "rocksdb/status.h"
+
 #ifdef _WIN32
 // Windows API macro interference
 #undef GetCurrentTime
index cfb5d8c23cc3b4e7678510e34bc9904d02f51faf..342d938b460e68e08e412931b32c309c6d4ad3cf 100644 (file)
@@ -10,7 +10,7 @@
 
 #include "rocksjni/portal.h"
 
-namespace rocksdb {
+namespace ROCKSDB_NAMESPACE {
 EventListenerJniCallback::EventListenerJniCallback(
     JNIEnv* env, jobject jevent_listener,
     const std::set<EnabledEventCallback>& enabled_event_callbacks)
@@ -499,4 +499,4 @@ void EventListenerJniCallback::OnFileOperation(const jmethodID& mid,
 
   CleanupCallbackInvocation(env, attached_thread, {&jop_info});
 }
-}  // namespace rocksdb
+}  // namespace ROCKSDB_NAMESPACE
index b1802b341fbcc6e12459a3cabe1d243de4ef2b8b..f4a235a2329284ef347558748f56393227efca07 100644 (file)
@@ -17,7 +17,7 @@
 #include "rocksdb/listener.h"
 #include "rocksjni/jnicallback.h"
 
-namespace rocksdb {
+namespace ROCKSDB_NAMESPACE {
 
 enum EnabledEventCallback {
   ON_FLUSH_COMPLETED = 0x0,
@@ -117,6 +117,6 @@ class EventListenerJniCallback : public JniCallback, public EventListener {
   jmethodID m_on_error_recovery_completed_mid;
 };
 
-}  // namespace rocksdb
+}  // namespace ROCKSDB_NAMESPACE
 
 #endif  // JAVA_ROCKSJNI_EVENT_LISTENER_JNICALLBACK_H_
index 0ce985f7e12e146f4a2c35f0e92e2d37d7c03d6b..0349c34f91ab8c0e0f1f48ddb7dfb9f59df43a24 100644 (file)
@@ -8,7 +8,7 @@
 
 #include "memkind_kmem_allocator.h"
 
-namespace rocksdb {
+namespace ROCKSDB_NAMESPACE {
 
 void* MemkindKmemAllocator::Allocate(size_t size) {
   void* p = memkind_malloc(MEMKIND_DAX_KMEM, size);
@@ -29,5 +29,5 @@ size_t MemkindKmemAllocator::UsableSize(void* p,
 }
 #endif  // ROCKSDB_MALLOC_USABLE_SIZE
 
-}  // namespace rocksdb
+}  // namespace ROCKSDB_NAMESPACE
 #endif  // MEMKIND
index 8bf3c6c72375d856b7d605e05fa504bee53b1dbb..32ad603ff1d09c3cd939df32f63e9fb5b3c4adff 100644 (file)
@@ -11,7 +11,7 @@
 #include <memkind.h>
 #include "rocksdb/memory_allocator.h"
 
-namespace rocksdb {
+namespace ROCKSDB_NAMESPACE {
 
 class MemkindKmemAllocator : public MemoryAllocator {
  public:
@@ -23,5 +23,5 @@ class MemkindKmemAllocator : public MemoryAllocator {
 #endif
 };
 
-}  // namespace rocksdb
+}  // namespace ROCKSDB_NAMESPACE
 #endif  // MEMKIND
index 4153f0c23313c1845d29d557231bc3e28357b728..ea6de188b055f64171c2110ad3781b2157cb903c 100644 (file)
@@ -14,7 +14,7 @@
 #include "table/block_based/block_based_table_factory.h"
 #include "test_util/testharness.h"
 
-namespace rocksdb {
+namespace ROCKSDB_NAMESPACE {
 TEST(MemkindKmemAllocatorTest, Allocate) {
   MemkindKmemAllocator allocator;
   void* p;
@@ -84,7 +84,7 @@ TEST(MemkindKmemAllocatorTest, DatabaseBlockCache) {
   ASSERT_OK(s);
   ASSERT_OK(DestroyDB(dbname, options));
 }
-}  // namespace rocksdb
+}  // namespace ROCKSDB_NAMESPACE
 
 int main(int argc, char** argv) {
   ::testing::InitGoogleTest(&argc, argv);
index 87585562d841689e17e8d998e307ad9ff45a3ab9..f1c5d8582e31ece48e4624d3424930d834611736 100644 (file)
@@ -20,9 +20,8 @@
 #include "table/block_based/partitioned_filter_block.h"
 #include "table/format.h"
 
-// Without anonymous namespace here, we fail the warning -Wmissing-prototypes
 namespace ROCKSDB_NAMESPACE {
-// using namespace rocksdb;
+
 // Create a index builder based on its type.
 IndexBuilder* IndexBuilder::CreateIndexBuilder(
     BlockBasedTableOptions::IndexType index_type,
index eb104b326eb162dae582c68a408fc4ed39056c7d..e5db00dc6e05e1ebac3b98de8e5e99a05d4e92b5 100644 (file)
@@ -14,7 +14,7 @@
 #else
 #include <gtest/gtest.h>
 #endif
-#include <rocksdb/utilities/regex.h>
+#include "rocksdb/utilities/regex.h"
 
 // A "skipped" test has a specific meaning in Facebook infrastructure: the
 // test is in good shape and should be run, but something about the
index d4fb50c1432ca961364fa5bb81280eda4ed17b68..f13de83fe37c3013eb1072ece8391c0194cf4d48 100644 (file)
@@ -14,7 +14,7 @@ int main() {
   return 1;
 }
 #else
-#include <rocksdb/db_bench_tool.h>
+#include "rocksdb/db_bench_tool.h"
 int main(int argc, char** argv) {
   return ROCKSDB_NAMESPACE::db_bench_tool(argc, argv);
 }