db_stress_compaction_service.cc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
  2. // This source code is licensed under both the GPLv2 (found in the
  3. // COPYING file in the root directory) and Apache 2.0 License
  4. // (found in the LICENSE.Apache file in the root directory).
  5. #ifdef GFLAGS
  6. #include "db_stress_tool/db_stress_compaction_service.h"
  7. #include <string>
  8. #include "db_stress_tool/db_stress_test_base.h"
  9. #include "rocksdb/env.h"
  10. namespace ROCKSDB_NAMESPACE {
  11. CompactionServiceJobStatus DbStressCompactionService::Wait(
  12. const std::string& scheduled_job_id, std::string* result) {
  13. while (true) {
  14. if (aborted_.load()) {
  15. return CompactionServiceJobStatus::kAborted;
  16. }
  17. const auto& maybeResultStatus =
  18. shared_->GetRemoteCompactionResult(scheduled_job_id, result);
  19. if (maybeResultStatus.has_value()) {
  20. auto s = maybeResultStatus.value();
  21. if (s.ok()) {
  22. assert(result);
  23. assert(!result->empty());
  24. return CompactionServiceJobStatus::kSuccess;
  25. } else {
  26. // Remote Compaction failed
  27. if (failure_should_fall_back_to_local_) {
  28. return CompactionServiceJobStatus::kUseLocal;
  29. }
  30. if (StressTest::IsErrorInjectedAndRetryable(s)) {
  31. return CompactionServiceJobStatus::kUseLocal;
  32. }
  33. if (result && result->empty()) {
  34. // If result is empty, set the compaction status in the result so
  35. // that it can be bubbled up to main thread
  36. CompactionServiceResult compaction_result;
  37. compaction_result.status = s;
  38. if (compaction_result.Write(result).ok()) {
  39. assert(result);
  40. assert(!result->empty());
  41. }
  42. }
  43. return CompactionServiceJobStatus::kFailure;
  44. }
  45. } else {
  46. // Remote Compaction is still running
  47. Env::Default()->SleepForMicroseconds(kWaitIntervalInMicros);
  48. }
  49. }
  50. return CompactionServiceJobStatus::kFailure;
  51. }
  52. } // namespace ROCKSDB_NAMESPACE
  53. #endif // GFLAGS