Make vitastor_kv.h header public

Vitaliy Filippov 2024-05-15 01:48:41 +03:00
parent ba52359611
commit 44692d148a
12 changed files with 55 additions and 25 deletions

View File

@ -196,8 +196,8 @@ endif (HAVE_NBD_NETLINK_H AND NL3_LIBRARIES)
# libvitastor_kv.so # libvitastor_kv.so
add_library(vitastor_kv SHARED add_library(vitastor_kv SHARED
kv_db.cpp kv_db.cpp
kv_db.h
) )
set_target_properties(vitastor_kv PROPERTIES PUBLIC_HEADER "vitastor_kv.h")
target_link_libraries(vitastor_kv target_link_libraries(vitastor_kv
vitastor_client vitastor_client
) )

View File

@ -12,16 +12,17 @@
#include <fcntl.h> #include <fcntl.h>
//#include <signal.h> //#include <signal.h>
#include "cluster_client.h"
#include "epoll_manager.h" #include "epoll_manager.h"
#include "str_util.h" #include "str_util.h"
#include "kv_db.h" #include "vitastor_kv.h"
const char *exe_name = NULL; const char *exe_name = NULL;
class kv_cli_t class kv_cli_t
{ {
public: public:
json11::Json::object cfg; std::map<std::string, std::string> cfg;
std::vector<std::string> cli_cmd; std::vector<std::string> cli_cmd;
kv_dbw_t *db = NULL; kv_dbw_t *db = NULL;
@ -156,7 +157,7 @@ void kv_cli_t::run()
if (cfg.find("db") != cfg.end()) if (cfg.find("db") != cfg.end())
{ {
bool done = false; bool done = false;
handle_cmd({ "open", cfg.at("db").string_value() }, [&done](int res) { if (res != 0) exit(1); done = true; }); handle_cmd({ "open", cfg.at("db") }, [&done](int res) { if (res != 0) exit(1); done = true; });
while (!done) while (!done)
{ {
ringloop->loop(); ringloop->loop();

View File

@ -15,7 +15,7 @@
#include "cluster_client.h" #include "cluster_client.h"
#include "str_util.h" #include "str_util.h"
#include "kv_db.h" #include "vitastor_kv.h"
// 0x VITASTOR OPTBTREE // 0x VITASTOR OPTBTREE
#define KV_BLOCK_MAGIC 0x761A5106097B18EE #define KV_BLOCK_MAGIC 0x761A5106097B18EE
@ -1969,12 +1969,12 @@ kv_dbw_t::~kv_dbw_t()
delete db; delete db;
} }
void kv_dbw_t::open(inode_t inode_id, json11::Json cfg, std::function<void(int)> cb) void kv_dbw_t::open(uint64_t inode_id, std::map<std::string, std::string> cfg, std::function<void(int)> cb)
{ {
db->open(inode_id, cfg, cb); db->open(inode_id, cfg, cb);
} }
void kv_dbw_t::set_config(json11::Json cfg) void kv_dbw_t::set_config(std::map<std::string, std::string> cfg)
{ {
db->set_config(cfg); db->set_config(cfg);
} }

View File

@ -12,9 +12,10 @@
#include <fcntl.h> #include <fcntl.h>
//#include <signal.h> //#include <signal.h>
#include "cluster_client.h"
#include "epoll_manager.h" #include "epoll_manager.h"
#include "str_util.h" #include "str_util.h"
#include "kv_db.h" #include "vitastor_kv.h"
const char *exe_name = NULL; const char *exe_name = NULL;
@ -44,7 +45,7 @@ class kv_test_t
{ {
public: public:
// Config // Config
json11::Json::object kv_cfg; std::map<std::string, std::string> kv_cfg;
std::string key_prefix, key_suffix; std::string key_prefix, key_suffix;
uint64_t inode_id = 0; uint64_t inode_id = 0;
uint64_t op_count = 1000000; uint64_t op_count = 1000000;
@ -238,22 +239,22 @@ void kv_test_t::parse_config(json11::Json cfg)
if (!cfg["stop_on_error"].is_null()) if (!cfg["stop_on_error"].is_null())
stop_on_error = cfg["stop_on_error"].bool_value(); stop_on_error = cfg["stop_on_error"].bool_value();
if (!cfg["kv_block_size"].is_null()) if (!cfg["kv_block_size"].is_null())
kv_cfg["kv_block_size"] = cfg["kv_block_size"]; kv_cfg["kv_block_size"] = cfg["kv_block_size"].as_string();
if (!cfg["kv_memory_limit"].is_null()) if (!cfg["kv_memory_limit"].is_null())
kv_cfg["kv_memory_limit"] = cfg["kv_memory_limit"]; kv_cfg["kv_memory_limit"] = cfg["kv_memory_limit"].as_string();
if (!cfg["kv_allocate_blocks"].is_null()) if (!cfg["kv_allocate_blocks"].is_null())
kv_cfg["kv_allocate_blocks"] = cfg["kv_allocate_blocks"]; kv_cfg["kv_allocate_blocks"] = cfg["kv_allocate_blocks"].as_string();
if (!cfg["kv_evict_max_misses"].is_null()) if (!cfg["kv_evict_max_misses"].is_null())
kv_cfg["kv_evict_max_misses"] = cfg["kv_evict_max_misses"]; kv_cfg["kv_evict_max_misses"] = cfg["kv_evict_max_misses"].as_string();
if (!cfg["kv_evict_attempts_per_level"].is_null()) if (!cfg["kv_evict_attempts_per_level"].is_null())
kv_cfg["kv_evict_attempts_per_level"] = cfg["kv_evict_attempts_per_level"]; kv_cfg["kv_evict_attempts_per_level"] = cfg["kv_evict_attempts_per_level"].as_string();
if (!cfg["kv_evict_unused_age"].is_null()) if (!cfg["kv_evict_unused_age"].is_null())
kv_cfg["kv_evict_unused_age"] = cfg["kv_evict_unused_age"]; kv_cfg["kv_evict_unused_age"] = cfg["kv_evict_unused_age"].as_string();
if (!cfg["kv_log_level"].is_null()) if (!cfg["kv_log_level"].is_null())
{ {
log_level = cfg["kv_log_level"].uint64_value(); log_level = cfg["kv_log_level"].uint64_value();
trace = log_level >= 10; trace = log_level >= 10;
kv_cfg["kv_log_level"] = cfg["kv_log_level"]; kv_cfg["kv_log_level"] = std::to_string(log_level);
} }
total_prob = reopen_prob+get_prob+add_prob+update_prob+del_prob+list_prob; total_prob = reopen_prob+get_prob+add_prob+update_prob+del_prob+list_prob;
stat.get.name = "get"; stat.get.name = "get";

View File

@ -2,6 +2,8 @@
// License: VNPL-1.1 (see README.md for details) // License: VNPL-1.1 (see README.md for details)
// //
// NFS proxy over Vitastor block images // NFS proxy over Vitastor block images
// Presents all images as files
// Keeps image/file list in memory and is thus unsuitable for a large number of files
#include <sys/time.h> #include <sys/time.h>

View File

@ -2,6 +2,8 @@
// License: VNPL-1.1 (see README.md for details) // License: VNPL-1.1 (see README.md for details)
// //
// NFS proxy over Vitastor block images - header // NFS proxy over Vitastor block images - header
// Presents all images as files
// Keeps image/file list in memory and is thus unsuitable for a large number of files
#pragma once #pragma once

View File

@ -256,7 +256,12 @@ void kv_fs_state_t::init(nfs_proxy_t *proxy, json11::Json cfg)
int open_res = 0; int open_res = 0;
bool open_done = false; bool open_done = false;
proxy->db = new kv_dbw_t(proxy->cli); proxy->db = new kv_dbw_t(proxy->cli);
proxy->db->open(fs_kv_inode, cfg, [&](int res) std::map<std::string, std::string> kv_cfg;
for (auto & kv: cfg.object_items())
{
kv_cfg[kv.first] = kv.second.as_string();
}
proxy->db->open(fs_kv_inode, kv_cfg, [&](int res)
{ {
open_done = true; open_done = true;
open_res = res; open_res = res;

View File

@ -1,9 +1,7 @@
// Copyright (c) Vitaliy Filippov, 2019+ // Copyright (c) Vitaliy Filippov, 2019+
// License: VNPL-1.1 (see README.md for details) // License: VNPL-1.1 (see README.md for details)
// //
// Simplified NFS proxy // NFS proxy entrypoint, common for both pseudo-FS and Vitastor-KV based FS
// Presents all images as files
// Keeps image/file list in memory and is thus unsuitable for a large number of files
#define _XOPEN_SOURCE #define _XOPEN_SOURCE
#include <limits.h> #include <limits.h>

View File

@ -1,10 +1,15 @@
// Copyright (c) Vitaliy Filippov, 2019+
// License: VNPL-1.1 (see README.md for details)
//
// Simplified NFS proxy - main entrypoint header
#pragma once #pragma once
#include "cluster_client.h" #include "cluster_client.h"
#include "epoll_manager.h" #include "epoll_manager.h"
#include "nfs_portmap.h" #include "nfs_portmap.h"
#include "nfs/xdr_impl.h" #include "nfs/xdr_impl.h"
#include "kv_db.h" #include "vitastor_kv.h"
#define NFS_ROOT_HANDLE "R" #define NFS_ROOT_HANDLE "R"
#define RPC_INIT_BUF_SIZE 32768 #define RPC_INIT_BUF_SIZE 32768

View File

@ -200,6 +200,11 @@ vitastor_c *vitastor_c_create_epoll_json(const char **options, int options_len)
return self; return self;
} }
void* vitastor_c_get_internal_client(vitastor_c *client)
{
return client->cli;
}
void vitastor_c_destroy(vitastor_c *client) void vitastor_c_destroy(vitastor_c *client)
{ {
delete client->cli; delete client->cli;

View File

@ -7,7 +7,7 @@
#define VITASTOR_QEMU_PROXY_H #define VITASTOR_QEMU_PROXY_H
// C API wrapper version // C API wrapper version
#define VITASTOR_C_API_VERSION 3 #define VITASTOR_C_API_VERSION 4
#ifndef POOL_ID_BITS #ifndef POOL_ID_BITS
#define POOL_ID_BITS 16 #define POOL_ID_BITS 16
@ -41,6 +41,7 @@ vitastor_c *vitastor_c_create_uring(const char *config_path, const char *etcd_ho
int use_rdma, const char *rdma_device, int rdma_port_num, int rdma_gid_index, int rdma_mtu, int log_level); int use_rdma, const char *rdma_device, int rdma_port_num, int rdma_gid_index, int rdma_mtu, int log_level);
vitastor_c *vitastor_c_create_uring_json(const char **options, int options_len); vitastor_c *vitastor_c_create_uring_json(const char **options, int options_len);
vitastor_c *vitastor_c_create_epoll_json(const char **options, int options_len); vitastor_c *vitastor_c_create_epoll_json(const char **options, int options_len);
void* vitastor_c_get_internal_client(vitastor_c *client);
void vitastor_c_destroy(vitastor_c *client); void vitastor_c_destroy(vitastor_c *client);
int vitastor_c_is_ready(vitastor_c *client); int vitastor_c_is_ready(vitastor_c *client);
int vitastor_c_uring_register_eventfd(vitastor_c *client); int vitastor_c_uring_register_eventfd(vitastor_c *client);

View File

@ -6,17 +6,27 @@
#pragma once #pragma once
#include "cluster_client.h" #include <stdint.h>
#include <sys/uio.h>
#include <string>
#include <map>
#include <functional>
#define VITASTOR_KV_API_VERSION 1
class cluster_client_t;
struct kv_db_t; struct kv_db_t;
struct kv_dbw_t struct kv_dbw_t
{ {
// cli = vitastor_c_get_internal_client(client)
kv_dbw_t(cluster_client_t *cli); kv_dbw_t(cluster_client_t *cli);
~kv_dbw_t(); ~kv_dbw_t();
void open(inode_t inode_id, json11::Json cfg, std::function<void(int)> cb); void open(uint64_t inode_id, std::map<std::string, std::string> cfg, std::function<void(int)> cb);
void set_config(json11::Json cfg); void set_config(std::map<std::string, std::string> cfg);
void close(std::function<void()> cb); void close(std::function<void()> cb);
uint64_t get_size(); uint64_t get_size();