支持以业务为单位,配置文件不持久化到本地

This commit is contained in:
linuxrc@163.com
2021-09-08 10:45:47 +08:00
parent 6386e5de57
commit 6922e3dd50
15 changed files with 572 additions and 142 deletions

View File

@@ -0,0 +1,97 @@
#include <string.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <string>
#include "leveldb/db.h"
#include "leveldb/comparator.h"
#include "leveldb/cache.h"
#include "doris_server_kvdb.h"
struct doris_kvhandle
{
leveldb::DB *kvdb;
};
struct doris_kvhandle *doris_kvdb_hanlde_new(const char *dir)
{
struct doris_kvhandle *handle;
leveldb::Options options;
handle = (struct doris_kvhandle *)malloc(sizeof(struct doris_kvhandle));
options.create_if_missing = true;
leveldb::Status status = leveldb::DB::Open(options, std::string(dir), &(handle->kvdb));
if(!status.ok())
{
free(handle);
return NULL;
}
return handle;
}
bool doris_kvdb_update_keyint_valint(struct doris_kvhandle *handle, u_int64_t key, int64_t value)
{
leveldb::WriteOptions wop;
leveldb::Slice _key((const char *)&key, sizeof(key));
leveldb::Slice _value((const char *)&value, sizeof(value));
wop.sync = true;
leveldb::Status s = handle->kvdb->Put(wop, _key, _value);
return s.ok();
}
bool doris_kvdb_update_keystr_valint(struct doris_kvhandle *handle, const char *key, int64_t value)
{
leveldb::WriteOptions wop;
leveldb::Slice _key((const char *)key, strlen(key));
leveldb::Slice _value((const char *)&value, sizeof(value));
wop.sync = true;
leveldb::Status s = handle->kvdb->Put(wop, _key, _value);
return s.ok();
}
int doris_kvdb_delete_keyint(struct doris_kvhandle *handle, u_int64_t key)
{
leveldb::Slice _key((char *)&key, sizeof(key));
leveldb::Status s = handle->kvdb->Delete(leveldb::WriteOptions(), _key);
return s.ok();
}
int doris_kvdb_delete_keystr(struct doris_kvhandle *handle, const char *key)
{
leveldb::Slice _key((const char *)key, strlen(key));
leveldb::Status s = handle->kvdb->Delete(leveldb::WriteOptions(), _key);
return s.ok();
}
void doris_kvdb_handle_destroy(struct doris_kvhandle *handle)
{
delete handle->kvdb;
free(handle);
}
int64_t doris_kvdb_get_keyint_valint(struct doris_kvhandle *handle, u_int64_t key)
{
std::string value;
leveldb::Slice off_key((const char *)&key, sizeof(key));
leveldb::Status s = handle->kvdb->Get(leveldb::ReadOptions(), off_key, &value);
if(!s.ok())
{
return 0;
}
return *(int64_t *)value.data();
}
int64_t doris_kvdb_get_keystr_valint(struct doris_kvhandle *handle, const char *key)
{
std::string value;
leveldb::Slice off_key((const char *)key, strlen(key));
leveldb::Status s = handle->kvdb->Get(leveldb::ReadOptions(), off_key, &value);
if(!s.ok())
{
return 0;
}
return *(int64_t *)value.data();
}