Files
ldb/common/config.h

77 lines
1.7 KiB
C

#ifndef __CONFIG_H__
#define __CONFIG_H__
#include <stddef.h>
#include <memory/alloc_dispatch.h>
typedef enum {
LOG_LEVEL_DEBUG,
LOG_LEVEL_INFO,
LOG_LEVEL_ERROR
} LogLevel;
typedef enum {
MODE_MASTER,
MODE_SLAVE
} ServerMode;
typedef enum {
PERSIST_INCREMENTAL,
PERSIST_NONE
} PersistenceType;
typedef enum {
REPLICA_DISABLE,
REPLICA_ENABLE
}ReplicaMode;
// typedef enum {
// ALLOC_JEMALLOC,
// ALLOC_MALLOC,
// ALLOC_MYPOOL,
// ALLOC_OTHER
// } AllocatorType;
// typedef enum {
// MEMLEAK_DETECT_OFF = 0, // 关闭检测
// MEMLEAK_DETECT_ON = 1 // 开启检测
// } MemLeakDetectMode;
typedef struct {
char ip[64];
int port;
ServerMode mode;
char master_ip[64]; // slave 才需要
int master_port; // slave 才需要
LogLevel log_level;
PersistenceType persistence;
char persist_dir[256];
char oplog_file[256];
char array_file[256];
char rbtree_file[256];
char hash_file[256];
AllocatorType allocator;
MemLeakDetectMode leak_mode;
ReplicaMode replica_mode;
} AppConfig;
/**
* 从 XML 文件加载配置
* 返回 0 表示成功;非 0 表示失败
*/
int config_load(const char *filename, AppConfig *out_cfg);
const char *log_level_to_string(LogLevel lvl);
const char *server_mode_to_string(ServerMode mode);
const char *persistence_to_string(PersistenceType p);
const char *allocator_to_string(AllocatorType a);
const char *leakage_to_string(MemLeakDetectMode a);
const char *replica_to_string(ReplicaMode a);
#endif /* CONFIG_H */