From bbf586735391154d8bd20d3defd40808e7949df3 Mon Sep 17 00:00:00 2001
From: Federico Guerinoni <guerinoni.federico@gmail.com>
Date: Tue, 19 Apr 2022 09:34:02 -0700
Subject: [PATCH] Add C API for setting `strict_capacity_limit` (#9855)

Summary:
This allows to set with true the field `strict_capacity_limit` from C
API and other languages that wrap that.

Signed-off-by: Federico Guerinoni <guerinoni.federico@gmail.com>

Closes: https://github.com/facebook/rocksdb/issues/9707

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

Reviewed By: ajkr

Differential Revision: D35724150

Pulled By: jay-zhuang

fbshipit-source-id: d8514797e9d90b1cd88329018f9ac4776722aa0f
---
 db/c.cc             | 8 ++++++++
 include/rocksdb/c.h | 2 ++
 2 files changed, 10 insertions(+)

diff --git a/db/c.cc b/db/c.cc
index 4ddf6ad80..0a6ae8562 100644
--- a/db/c.cc
+++ b/db/c.cc
@@ -4193,6 +4193,14 @@ rocksdb_cache_t* rocksdb_cache_create_lru(size_t capacity) {
   return c;
 }
 
+rocksdb_cache_t* rocksdb_cache_create_lru_with_strict_capacity_limit(
+    size_t capacity) {
+  rocksdb_cache_t* c = new rocksdb_cache_t;
+  c->rep = NewLRUCache(capacity);
+  c->rep->SetStrictCapacityLimit(true);
+  return c;
+}
+
 rocksdb_cache_t* rocksdb_cache_create_lru_opts(
     rocksdb_lru_cache_options_t* opt) {
   rocksdb_cache_t* c = new rocksdb_cache_t;
diff --git a/include/rocksdb/c.h b/include/rocksdb/c.h
index aae4d3486..1456c15a6 100644
--- a/include/rocksdb/c.h
+++ b/include/rocksdb/c.h
@@ -1766,6 +1766,8 @@ extern ROCKSDB_LIBRARY_API void rocksdb_lru_cache_options_set_memory_allocator(
 
 extern ROCKSDB_LIBRARY_API rocksdb_cache_t* rocksdb_cache_create_lru(
     size_t capacity);
+extern ROCKSDB_LIBRARY_API rocksdb_cache_t*
+rocksdb_cache_create_lru_with_strict_capacity_limit(size_t capacity);
 extern ROCKSDB_LIBRARY_API rocksdb_cache_t* rocksdb_cache_create_lru_opts(
     rocksdb_lru_cache_options_t*);
 extern ROCKSDB_LIBRARY_API void rocksdb_cache_destroy(rocksdb_cache_t* cache);