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 // 6 // Copyright (c) 2011 The LevelDB Authors. All rights reserved. 7 // Use of this source code is governed by a BSD-style license that can be 8 // found in the LICENSE file. See the AUTHORS file for names of contributors. 9 10 #pragma once 11 12 #include "rocksdb/env.h" 13 #include "rocksdb/statistics.h" 14 15 namespace ROCKSDB_NAMESPACE { 16 17 class ConcurrentTaskLimiter { 18 public: ~ConcurrentTaskLimiter()19 virtual ~ConcurrentTaskLimiter() {} 20 21 // Returns a name that identifies this concurrent task limiter. 22 virtual const std::string& GetName() const = 0; 23 24 // Set max concurrent tasks. 25 // limit = 0 means no new task allowed. 26 // limit < 0 means no limitation. 27 virtual void SetMaxOutstandingTask(int32_t limit) = 0; 28 29 // Reset to unlimited max concurrent task. 30 virtual void ResetMaxOutstandingTask() = 0; 31 32 // Returns current outstanding task count. 33 virtual int32_t GetOutstandingTask() const = 0; 34 }; 35 36 // Create a ConcurrentTaskLimiter that can be shared with mulitple CFs 37 // across RocksDB instances to control concurrent tasks. 38 // 39 // @param name: Name of the limiter. 40 // @param limit: max concurrent tasks. 41 // limit = 0 means no new task allowed. 42 // limit < 0 means no limitation. 43 extern ConcurrentTaskLimiter* NewConcurrentTaskLimiter(const std::string& name, 44 int32_t limit); 45 46 } // namespace ROCKSDB_NAMESPACE 47