github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/c-deps/libroach/env_manager.h (about) 1 // Copyright 2018 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 #pragma once 12 13 #include <rocksdb/env.h> 14 #include "../file_registry.h" 15 #include "rocksdbutils/env_encryption.h" 16 17 namespace cockroach { 18 19 // EnvStatsHandler provides an interface to generate Env-specific stats. 20 class EnvStatsHandler { 21 public: 22 virtual ~EnvStatsHandler() {} 23 24 // Get serialized encryption stats. 25 virtual rocksdb::Status GetEncryptionStats(std::string* stats) = 0; 26 // Get a serialized encryption registry (scrubbed of key contents). 27 virtual rocksdb::Status GetEncryptionRegistry(std::string* registry) = 0; 28 // Get the ID of the active data key, or "plain" if none. 29 virtual std::string GetActiveDataKeyID() = 0; 30 // Get the enum value of the encryption type. 31 virtual int32_t GetActiveStoreKeyType() = 0; 32 // Get the key ID in use by this file, or "plain" if none. 33 virtual rocksdb::Status GetFileEntryKeyID(const enginepb::FileEntry* entry, std::string* id) = 0; 34 }; 35 36 // EnvManager manages all created Envs, as well as the file registry. 37 // Rocksdb owns Env::Default (global static). All other envs are owned by EnvManager. 38 // 39 // Some useful envs are kept: 40 // base_env: the env that all other envs must wrap. Usually a Env::Default or MemEnv. 41 // db_env: the env used by rocksdb. This can be an EncryptedEnv. 42 struct EnvManager { 43 EnvManager(rocksdb::Env* env) : base_env(env), db_env(env) {} 44 ~EnvManager() {} 45 46 // Set the stats handler implementing GetEncryptionStats to fill in env-related stats. 47 // It does not have called, leaving env_stats_handler nil. 48 void SetStatsHandler(EnvStatsHandler* stats_handler) { env_stats_handler.reset(stats_handler); } 49 void TakeEnvOwnership(rocksdb::Env* env) { envs.push_back(std::unique_ptr<rocksdb::Env>(env)); } 50 51 rocksdb::Env* base_env; 52 rocksdb::Env* db_env; 53 std::unique_ptr<EnvStatsHandler> env_stats_handler; 54 std::unique_ptr<FileRegistry> file_registry; 55 std::vector<std::unique_ptr<rocksdb::Env>> envs; 56 }; 57 58 } // namespace cockroach