diff --git a/examples/c_simple_example.c b/examples/c_simple_example.c index 5564361d1e69c6abca4a2aa7350b0f95d219f6fb..fe2f917b43f8f44d3540517242126f50efb80d6a 100644 --- a/examples/c_simple_example.c +++ b/examples/c_simple_example.c @@ -10,18 +10,35 @@ #include "rocksdb/c.h" +#if defined(OS_WIN) +#include +#else #include // sysconf() - get CPU count +#endif -const char DBPath[] = "/tmp/rocksdb_simple_example"; -const char DBBackupPath[] = "/tmp/rocksdb_simple_example_backup"; +#if defined(OS_WIN) +const char DBPath[] = "C:\\Windows\\TEMP\\rocksdb_c_simple_example"; +const char DBBackupPath[] = + "C:\\Windows\\TEMP\\rocksdb_c_simple_example_backup"; +#else +const char DBPath[] = "/tmp/rocksdb_c_simple_example"; +const char DBBackupPath[] = "/tmp/rocksdb_c_simple_example_backup"; +#endif int main(int argc, char **argv) { rocksdb_t *db; rocksdb_backup_engine_t *be; rocksdb_options_t *options = rocksdb_options_create(); // Optimize RocksDB. This is the easiest way to - // get RocksDB to perform well - long cpus = sysconf(_SC_NPROCESSORS_ONLN); // get # of online cores + // get RocksDB to perform well. +#if defined(OS_WIN) + SYSTEM_INFO system_info; + GetSystemInfo(&system_info); + long cpus = system_info.dwNumberOfProcessors; +#else + long cpus = sysconf(_SC_NPROCESSORS_ONLN); +#endif + // Set # of online cores rocksdb_options_increase_parallelism(options, (int)(cpus)); rocksdb_options_optimize_level_style_compaction(options, 0); // create the DB if it's not already present diff --git a/examples/column_families_example.cc b/examples/column_families_example.cc index 0012e9dc183fa8130561337207c1ec44d7a39b5e..12c9cf47e0b89dab00f04d90e0b69f76e1debcad 100644 --- a/examples/column_families_example.cc +++ b/examples/column_families_example.cc @@ -12,7 +12,11 @@ using namespace ROCKSDB_NAMESPACE; +#if defined(OS_WIN) +std::string kDBPath = "C:\\Windows\\TEMP\\rocksdb_column_families_example"; +#else std::string kDBPath = "/tmp/rocksdb_column_families_example"; +#endif int main() { // open DB diff --git a/examples/compact_files_example.cc b/examples/compact_files_example.cc index a0a9fa90aae3ad2425550073876eafbffad9c801..01e7d94d5072f6a87b458d0adea3dc587ee358be 100644 --- a/examples/compact_files_example.cc +++ b/examples/compact_files_example.cc @@ -13,7 +13,13 @@ #include "rocksdb/options.h" using namespace ROCKSDB_NAMESPACE; + +#if defined(OS_WIN) +std::string kDBPath = "C:\\Windows\\TEMP\\rocksdb_compact_files_example"; +#else std::string kDBPath = "/tmp/rocksdb_compact_files_example"; +#endif + struct CompactionTask; // This is an example interface of external-compaction algorithm. diff --git a/examples/compaction_filter_example.cc b/examples/compaction_filter_example.cc index cee763195ed3c52e179f37905f4e9d28466192fd..bc960e01645b91e35b354633778d4af6838993e5 100644 --- a/examples/compaction_filter_example.cc +++ b/examples/compaction_filter_example.cc @@ -54,22 +54,30 @@ class MyFilter : public ROCKSDB_NAMESPACE::CompactionFilter { mutable int merge_count_ = 0; }; +#if defined(OS_WIN) +std::string kDBPath = "C:\\Windows\\TEMP\\rocksmergetest"; +std::string kRemoveDirCommand = "rmdir /Q /S "; +#else +std::string kDBPath = "/tmp/rocksmergetest"; +std::string kRemoveDirCommand = "rm -rf "; +#endif + int main() { ROCKSDB_NAMESPACE::DB* raw_db; ROCKSDB_NAMESPACE::Status status; MyFilter filter; - int ret = system("rm -rf /tmp/rocksmergetest"); + std::string rm_cmd = kRemoveDirCommand + kDBPath; + int ret = system(rm_cmd.c_str()); if (ret != 0) { - fprintf(stderr, "Error deleting /tmp/rocksmergetest, code: %d\n", ret); - return ret; + fprintf(stderr, "Error deleting %s, code: %d\n", kDBPath.c_str(), ret); } ROCKSDB_NAMESPACE::Options options; options.create_if_missing = true; options.merge_operator.reset(new MyMerge); options.compaction_filter = &filter; - status = ROCKSDB_NAMESPACE::DB::Open(options, "/tmp/rocksmergetest", &raw_db); + status = ROCKSDB_NAMESPACE::DB::Open(options, kDBPath, &raw_db); assert(status.ok()); std::unique_ptr db(raw_db); diff --git a/examples/multi_processes_example.cc b/examples/multi_processes_example.cc index 21d422cf2fd05b95606ef0eff8334ab10a89edf8..93c54d7556999f58d2e71c5a01f98709c85a30e3 100644 --- a/examples/multi_processes_example.cc +++ b/examples/multi_processes_example.cc @@ -23,6 +23,8 @@ #include #include +// TODO: port this example to other systems. It should be straightforward for +// POSIX-compliant systems. #if defined(OS_LINUX) #include #include @@ -30,7 +32,6 @@ #include #include #include -#endif // !OS_LINUX #include "rocksdb/db.h" #include "rocksdb/options.h" @@ -136,9 +137,6 @@ static Slice GenerateRandomValue(const size_t max_length, char scratch[]) { static bool ShouldCloseDB() { return true; } -// TODO: port this example to other systems. It should be straightforward for -// POSIX-compliant systems. -#if defined(OS_LINUX) void CreateDB() { long my_pid = static_cast(getpid()); Options options; @@ -389,7 +387,7 @@ int main(int argc, char** argv) { } #else // OS_LINUX int main() { - fpritnf(stderr, "Not implemented.\n"); + fprintf(stderr, "Not implemented.\n"); return 0; } #endif // !OS_LINUX diff --git a/examples/optimistic_transaction_example.cc b/examples/optimistic_transaction_example.cc index fd6dbad63185834faa6b8be3e9843c3d287853ea..e398ad05e622fea455dc0394ae41a52e4bf75bb5 100644 --- a/examples/optimistic_transaction_example.cc +++ b/examples/optimistic_transaction_example.cc @@ -13,7 +13,11 @@ using namespace ROCKSDB_NAMESPACE; +#if defined(OS_WIN) +std::string kDBPath = "C:\\Windows\\TEMP\\rocksdb_transaction_example"; +#else std::string kDBPath = "/tmp/rocksdb_transaction_example"; +#endif int main() { // open DB diff --git a/examples/options_file_example.cc b/examples/options_file_example.cc index 30051d8d5edc06c8ba253a3aff243724a0ba6369..11ec642a4023b6f1ad15f880c35d052a8bb9de2e 100644 --- a/examples/options_file_example.cc +++ b/examples/options_file_example.cc @@ -20,7 +20,11 @@ using namespace ROCKSDB_NAMESPACE; +#if defined(OS_WIN) +std::string kDBPath = "C:\\Windows\\TEMP\\rocksdb_options_file_example"; +#else std::string kDBPath = "/tmp/rocksdb_options_file_example"; +#endif namespace { // A dummy compaction filter diff --git a/examples/simple_example.cc b/examples/simple_example.cc index 98102c073b19680b95f363ffef8c34c9f6837ddb..c821a5c66f0b05e48ffe28b70646e895448637d1 100644 --- a/examples/simple_example.cc +++ b/examples/simple_example.cc @@ -12,7 +12,11 @@ using namespace ROCKSDB_NAMESPACE; +#if defined(OS_WIN) +std::string kDBPath = "C:\\Windows\\TEMP\\rocksdb_simple_example"; +#else std::string kDBPath = "/tmp/rocksdb_simple_example"; +#endif int main() { DB* db; diff --git a/examples/transaction_example.cc b/examples/transaction_example.cc index 41b233544b86261c62e9f3d7b333abba7a6b80a3..051b968de227ae89dfc25ca447668c8cc76f2e70 100644 --- a/examples/transaction_example.cc +++ b/examples/transaction_example.cc @@ -13,7 +13,11 @@ using namespace ROCKSDB_NAMESPACE; +#if defined(OS_WIN) +std::string kDBPath = "C:\\Windows\\TEMP\\rocksdb_transaction_example"; +#else std::string kDBPath = "/tmp/rocksdb_transaction_example"; +#endif int main() { // open DB