Skip to content

Commit 2303d5a

Browse files
jjuliamolinmeta-codesync[bot]
authored andcommitted
add disk limit in rocksdb (disk/mem ratio)
Summary: Introducting a disk size limit (relative memory) ```db_rocksdb_disk_mem_capacity_ratio_limit``` and changing the RocksDB impl of ```getTotalCapacity``` * ratio is optional, if not provided we use full host (as today) * ratio defined in server_config, defined per-tier. So possible to deploy to ```glean.query``` tiers only If we go for this solution: * No more load balancing work needed for a mix of T3/T10 * we can set a ratio (e.g., 30 to start with) which is higher than possible ratio for a T10, so effectively a T10 will use the actual full disk space, and a T3 will be capped at 30 * RAM_capacity * will also allow to easily change cache size programmatically with a similar config value: ```db_rocks_cache_mem_capacity_ratio``` _______ **OSS compat** see MemoryReader in D87988951 ______ **How SM loadbalancing works** We define a resource where formula is shard_size = counter / thresholdCounter ==> shard_size = glean.shard.[SHARDID.LSB].disk_used_bytes / glean.db.disk.capacity_bytes defined here https://www.internalfb.com/code/configerator/[3227e8542f281d93b3a2b529c501e76e92463167]/source/glean/server/glean.query.cinc?lines=201-207 We log to fb303 counters here, using the **getTotalCapacity** so we'll report a limited capacity here if ratio is set https://www.internalfb.com/code/fbsource/[6137dfc20518d1c567e635052c344e6fd14e9c81]/fbcode/glean/db/Glean/Database/Env.hs?lines=222%2C225-226 Reviewed By: iamirzhan Differential Revision: D88269912 fbshipit-source-id: a7acccf33f74b0eecf59645e90aba3c82dd5b19e
1 parent 5df2a83 commit 2303d5a

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

glean.cabal.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ library util
416416
Glean.Impl.ThriftService
417417
Glean.Impl.ConfigProvider
418418
Glean.Impl.TestConfigProvider
419+
Glean.Impl.MemoryReader
419420
Glean.Util.Bisect
420421
Glean.Util.ConfigProvider
421422
Glean.Util.Disk

glean/db/Glean/Database/Storage/RocksDB.hs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import Glean.RTS.Types (Fid(..), invalidFid, Pid(..))
4747
import qualified Glean.ServerConfig.Types as ServerConfig
4848
import Glean.Types (Repo)
4949
import Glean.Util.Disk
50+
import Glean.Impl.MemoryReader
5051
import System.IO.Extra (withTempFile)
5152

5253
newtype Cache = Cache (ForeignPtr Cache)
@@ -68,6 +69,11 @@ data RocksDB = RocksDB
6869
{ rocksRoot :: FilePath
6970
, rocksCache :: Maybe Cache
7071
, rocksCacheIndexAndFilterBlocks :: Bool
72+
, rocksMaxDiskSize :: Maybe Int
73+
-- ^ virtual limit to report capped disk capacities. The limit is
74+
-- not enforced. It's up to each io usage to check diskspace before writing.
75+
-- We're using this to avoid serving too many dbs on query servers,
76+
-- and smarter sharding.
7177
}
7278

7379
newStorage :: FilePath -> ServerConfig.Config -> IO RocksDB
@@ -76,11 +82,16 @@ newStorage root ServerConfig.Config{..} = do
7682
then
7783
Just <$> newCache (fromIntegral config_db_rocksdb_cache_mb * 1024 * 1024)
7884
else return Nothing
85+
mem_capacity <- totalMemCapacity
7986
return RocksDB
8087
{ rocksRoot = root
8188
, rocksCache = cache
8289
, rocksCacheIndexAndFilterBlocks =
8390
config_db_rocksdb_cache_index_and_filter_blocks
91+
, rocksMaxDiskSize = case mem_capacity of
92+
Just mem -> (* mem) . fromIntegral <$>
93+
config_db_rocksdb_disk_mem_capacity_ratio_limit
94+
Nothing -> Nothing
8495
}
8596

8697
newtype Container = Container (Ptr Container)
@@ -236,7 +247,11 @@ instance Storage RocksDB where
236247
getTotalCapacity rocksdb = do
237248
exists <- doesDirectoryExist (rocksRoot rocksdb)
238249
if exists
239-
then Just <$> getDiskSize (rocksRoot rocksdb)
250+
then do
251+
fullDiskCapacity <- getDiskSize (rocksRoot rocksdb)
252+
return $ Just $ case rocksMaxDiskSize rocksdb of
253+
Just maxDiskSize -> min maxDiskSize fullDiskCapacity
254+
Nothing -> fullDiskCapacity
240255
else return Nothing
241256

242257
getUsedCapacity rocksdb = do
@@ -245,7 +260,12 @@ instance Storage RocksDB where
245260
then Just <$> getUsedDiskSpace (rocksRoot rocksdb)
246261
else return Nothing
247262

248-
getFreeCapacity = getFreeDiskSpace . rocksRoot
263+
getFreeCapacity rocksdb = do
264+
used <- getUsedCapacity rocksdb
265+
total <- getTotalCapacity rocksdb
266+
case (used,total) of
267+
(Just used, Just total) -> return $ total - used
268+
_ -> getFreeDiskSpace (rocksRoot rocksdb) -- not aware of disk limit
249269

250270
withScratchRoot rocks f = f $ rocksRoot rocks </> ".scratch"
251271

0 commit comments

Comments
 (0)