libcephsqlite: rework architecture and backend

This is a complete rewrite on top of SimpleRADOSStriper as well as the
API. The VFS is now a loadable extension as well.

Fixes: https://tracker.ceph.com/issues/40609
Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
This commit is contained in:
Patrick Donnelly 2021-01-28 15:11:50 -08:00
parent 458c6e7c12
commit f7fa3b50c1
No known key found for this signature in database
GPG Key ID: 3A2A7E25BEA8AADB
9 changed files with 829 additions and 872 deletions

View File

@ -281,12 +281,9 @@ endif(WITH_QATZIP)
# needs mds and? XXX
option(WITH_LIBCEPHFS "libcephfs client library" ON)
find_package(SQLite3)
if(SQLITE3_FOUND)
option(WITH_LIBCEPHSQLITE "libcephsqlite client library" ON)
else()
message(WARNING "disabling WITH_LIBCEPHSQLITE, which depends on SQLite3")
set(WITH_LIBCEPHSQLITE OFF)
option(WITH_LIBCEPHSQLITE "libcephsqlite client library" ON)
if(WITH_LIBCEPHSQLITE)
find_package(SQLite3 REQUIRED)
endif()
# key-value store

View File

@ -1,10 +1,12 @@
find_path(SQLITE3_INCLUDE_DIR NAMES sqlite3.h PATHS /usr/include /usr/local/include)
find_library(SQLITE3_LIBRARY NAMES sqlite3)
find_path(SQLite3_INCLUDE_DIR NAMES sqlite3.h)
find_library(SQLite3_LIBRARY NAMES sqlite3 sqlite)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(SQLITE3 DEFAULT_MSG SQLITE3_LIBRARY SQLITE3_INCLUDE_DIR)
find_package_handle_standard_args(SQLite3 DEFAULT_MSG SQLite3_LIBRARY SQLite3_INCLUDE_DIR)
if(SQLITE3_FOUND)
set(SQLITE3_LIBRARIES ${SQLITE3_LIBRARY})
set(SQLITE3_INCLUDE_DIRS ${SQLITE3_INCLUDE_DIR})
if(NOT TARGET SQLite3::SQLite3)
add_library(SQLite3::SQLite3 UNKNOWN IMPORTED)
set_target_properties(SQLite3::SQLite3 PROPERTIES
IMPORTED_LOCATION "${SQLite3_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${SQLite3_INCLUDE_DIR}")
endif()

View File

@ -804,16 +804,9 @@ if(WITH_LIBCEPHFS)
endif(WITH_LIBCEPHFS)
if(WITH_LIBCEPHSQLITE)
set(libcephsqlite_srcs libcephsqlite.cc)
add_library(cephsqlite ${CEPH_SHARED} ${libcephsqlite_srcs})
set_target_properties(cephsqlite PROPERTIES COMPILE_FLAGS "-I${SQLITE3_INCLUDE_DIRS}")
target_link_libraries(cephsqlite radosstriper librados ${SQLITE3_LIBRARIES} ${EXTRALIBS})
if(ENABLE_SHARED)
set_target_properties(cephsqlite PROPERTIES
OUTPUT_NAME cephsqlite
VERSION 1.0.0
SOVERSION 1)
endif(ENABLE_SHARED)
set(cephsqlite_srcs libcephsqlite.cc SimpleRADOSStriper.cc)
add_library(cephsqlite ${CEPH_SHARED} ${cephsqlite_srcs})
target_link_libraries(cephsqlite PRIVATE cls_lock_client librados ceph-common SQLite3::SQLite3 ${EXTRALIBS})
install(TARGETS cephsqlite DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif(WITH_LIBCEPHSQLITE)

View File

@ -5594,6 +5594,28 @@ std::vector<Option> get_global_options() {
.set_description("Size of thread pool for ASIO completions")
.add_tag("osd"),
Option("cephsqlite_lock_renewal_interval", Option::TYPE_MILLISECS, Option::LEVEL_ADVANCED)
.add_see_also("cephsqlite_lock_renewal_timeout")
.add_tag("client")
.set_default(2000)
.set_description("number of milliseconds before lock is renewed")
.set_min(100)
,
Option("cephsqlite_lock_renewal_timeout", Option::TYPE_MILLISECS, Option::LEVEL_ADVANCED)
.add_see_also("cephsqlite_lock_renewal_interval")
.add_tag("client")
.set_default(30000)
.set_description("number of milliseconds before transaction lock times out")
.set_long_description("The amount of time before a running libcephsqlite VFS connection has to renew a lock on the database before the lock is automatically lost. If the lock is lost, the VFS will abort the process to prevent database corruption.")
.set_min(100),
Option("cephsqlite_blocklist_dead_locker", Option::TYPE_BOOL, Option::LEVEL_ADVANCED)
.add_tag("client")
.set_default(true)
.set_description("blocklist the last dead owner of the database lock")
.set_long_description("Require that the Ceph SQLite VFS blocklist the last dead owner of the database when cleanup was incomplete. DO NOT CHANGE THIS UNLESS YOU UNDERSTAND THE RAMIFICATIONS. CORRUPTION MAY RESULT."),
// ----------------------------
// Crimson specific options

View File

@ -81,3 +81,4 @@ SUBSYS(eventtrace, 1, 5)
SUBSYS(prioritycache, 1, 5)
SUBSYS(test, 0, 5)
SUBSYS(cephfs_mirror, 0, 5)
SUBSYS(cephsqlite, 0, 5)

View File

@ -1,3 +1,7 @@
install(FILES
libcephsqlite.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES
rados/librados.h
rados/rados_types.h

View File

@ -0,0 +1,67 @@
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
* Ceph - scalable distributed file system
*
* Copyright (C) 2021 Red Hat, Inc.
*
* This is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License version 2.1, as published by
* the Free Software Foundation. See file COPYING.
*
*/
#ifndef LIBCEPHSQLITE_H
#define LIBCEPHSQLITE_H
/* This loadable extension does not generally require using this header. It is
* here to allow controlling which version of the library is linked in. See
* also sqlite3_cephsqlite_init below. Additionally, you may specify which
* CephContext to use rather than the library instantiating its own and using
* whatever the default credential is.
*/
#include <sqlite3.h>
#ifdef _WIN32
# define LIBCEPHSQLITE_API __declspec(dllexport)
#else
# define LIBCEPHSQLITE_API extern "C"
#endif
/* This is the SQLite entry point when loaded as a dynamic library. You also
* need to ensure SQLite calls this method when using libcephsqlite as a static
* library or a dynamic library linked at compile time. For the latter case,
* you can do this by:
*
* sqlite3_auto_extension((void (*)())sqlite3_cephsqlite_init);
* sqlite3* db = nullptr;
* int rc = sqlite3_open_v2(":memory:", &db, SQLITE_OPEN_READWRITE, nullptr);
* if (rc == SQLITE_DONE) {
* sqlite3_close(db);
* } else {
* // failure
* }
*
* The throwaway database created (name == "") is a memory database opened so
* that SQLite runs the libcephsqlite initialization routine to register the
* VFS. AFter that's done, the VFS is available for a future database open with
* the VFS set to "ceph":
*
* sqlite3_open_v2("foo:bar/baz.db", &db, SQLITE_OPEN_READWRITE, "ceph");
*
* You MUST do this before calling any other libcephsqlite routine so that
* sqlite3 can pass its API routines to the libcephsqlite extension.
*/
LIBCEPHSQLITE_API int sqlite3_cephsqlite_init(sqlite3* db, char** err, const sqlite3_api_routines* api);
/* If you prefer to have libcephsqlite use a CephContext managed by your
* application, use this routine to set that. libcephsqlite can only have one
* context globally.
*/
LIBCEPHSQLITE_API int cephsqlite_setcct(class CephContext* cct, char** ident);
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,24 +0,0 @@
#ifndef LIBCEPHSQLITE_H
#define LIBCEPHSQLITE_H
#include "rados/librados.hpp"
struct sqlite3;
extern "C"
sqlite3 *ceph_sqlite3_open(
librados::Rados &cluster,
const char *dbname, /* eg. "sql" instead of "sql.db" */
const char *rados_namespace,
int ceph_pool_id,
bool must_create
);
extern "C"
void ceph_sqlite3_set_db_params(
const char *dbname, /* eg. "sql" instead of "sql.db" */
int stripe_count,
int obj_size
);
#endif