Commit f3954335 authored by Yi Wu's avatar Yi Wu

remove titan_c.h

Signed-off-by: 's avatarYi Wu <yiwu@pingcap.com>
parent 0d9b1f79
......@@ -70,7 +70,6 @@ set(SOURCES
src/options.cc
src/table_builder.cc
src/table_factory.cc
src/titan_c.cc
src/util.cc
src/version.cc
src/version_edit.cc
......
/*
C bindings for TitanDB. May be useful as a stable ABI that can be
used by programs that keep rocksdb in a shared library, or for
a JNI api.
Does not support:
. getters for the option types
. custom comparators that implement key shortening
. capturing post-write-snapshot
. custom iter, db, env, cache implementations using just the C bindings
Some conventions:
(1) We expose just opaque struct pointers and functions to clients.
This allows us to change internal representations without having to
recompile clients.
(2) For simplicity, there is no equivalent to the Slice type. Instead,
the caller has to pass the pointer and length as separate
arguments.
(3) Errors are represented by a null-terminated c string. NULL
means no error. All operations that can raise an error are passed
a "char** errptr" as the last argument. One of the following must
be true on entry:
*errptr == NULL
*errptr points to a malloc()ed null-terminated error message
On success, a leveldb routine leaves *errptr unchanged.
On failure, leveldb frees the old value of *errptr and
set *errptr to a malloc()ed error message.
(4) Bools have the type unsigned char (0 == false; rest == true)
(5) All of the pointer arguments must be non-NULL.
*/
#ifndef ROCKSDB_TITAN_C_H
#define ROCKSDB_TITAN_C_H
#pragma once
#ifdef _WIN32
#ifdef ROCKSDB_DLL
#ifdef ROCKSDB_LIBRARY_EXPORTS
#define ROCKSDB_LIBRARY_API __declspec(dllexport)
#else
#define ROCKSDB_LIBRARY_API __declspec(dllimport)
#endif
#else
#define ROCKSDB_LIBRARY_API
#endif
#else
#define ROCKSDB_LIBRARY_API
#endif
#ifdef __cplusplus
extern "C" {
#endif
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include "rocksdb/c.h"
/* Exported types */
// TitanDB
typedef struct titandb_options_t titandb_options_t;
extern ROCKSDB_LIBRARY_API rocksdb_t* titandb_open(
const titandb_options_t* options, const char* name, char** errptr);
extern ROCKSDB_LIBRARY_API titandb_options_t* titandb_options_create();
extern ROCKSDB_LIBRARY_API void titandb_options_destroy(titandb_options_t*);
extern ROCKSDB_LIBRARY_API void titandb_options_set_rocksdb(
titandb_options_t* options, rocksdb_options_t* rocksdb);
extern ROCKSDB_LIBRARY_API void titandb_options_set_dirname(
titandb_options_t* options, const char* name);
extern ROCKSDB_LIBRARY_API void titandb_options_set_min_blob_size(
titandb_options_t* options, uint64_t size);
extern ROCKSDB_LIBRARY_API void titandb_options_set_blob_file_compression(
titandb_options_t* options, int compression);
extern ROCKSDB_LIBRARY_API void titandb_options_set_blob_cache(
titandb_options_t* options, rocksdb_cache_t* blob_cache);
extern ROCKSDB_LIBRARY_API void titandb_options_set_disable_background_gc(
titandb_options_t* options, unsigned char disable);
extern ROCKSDB_LIBRARY_API void titandb_options_set_max_gc_batch_size(
titandb_options_t* options, uint64_t size);
extern ROCKSDB_LIBRARY_API void titandb_options_set_min_gc_batch_size(
titandb_options_t* options, uint64_t size);
extern ROCKSDB_LIBRARY_API void titandb_options_set_blob_file_discardable_ratio(
titandb_options_t* options, float ratio);
extern ROCKSDB_LIBRARY_API void titandb_options_set_sample_file_size_ratio(
titandb_options_t* options, float ratio);
extern ROCKSDB_LIBRARY_API void titandb_options_set_merge_small_file_threshold(
titandb_options_t* options, uint64_t size);
#ifdef __cplusplus
} /* end extern "C" */
#endif
#endif // ROCKSDB_TITAN_C_H
#include "rocksdb/utilities/titan_c.h"
#include "rocksdb/db.h"
#include "titan/db.h"
using rocksdb::Cache;
using rocksdb::CompressionType;
using rocksdb::DB;
using rocksdb::Options;
using rocksdb::Status;
using rocksdb::titandb::TitanDB;
using rocksdb::titandb::TitanOptions;
extern "C" {
struct rocksdb_t {
DB* rep;
};
struct rocksdb_options_t {
Options rep;
};
struct rocksdb_cache_t {
std::shared_ptr<Cache> rep;
};
struct titandb_options_t {
TitanOptions rep;
};
static bool SaveError(char** errptr, const Status& s) {
assert(errptr != nullptr);
if (s.ok()) {
return false;
} else if (*errptr == nullptr) {
*errptr = strdup(s.ToString().c_str());
} else {
// TODO(sanjay): Merge with existing error?
// This is a bug if *errptr is not created by malloc()
free(*errptr);
*errptr = strdup(s.ToString().c_str());
}
return true;
}
rocksdb_t* titandb_open(const titandb_options_t* options, const char* name,
char** errptr) {
TitanDB* db;
if (SaveError(errptr, TitanDB::Open(options->rep, name, &db))) {
return nullptr;
}
rocksdb_t* result = new rocksdb_t;
result->rep = db;
return result;
}
titandb_options_t* titandb_options_create() { return new titandb_options_t; }
void titandb_options_destroy(titandb_options_t* options) { delete options; }
void titandb_options_set_rocksdb(titandb_options_t* options,
rocksdb_options_t* rocksdb) {
options->rep = TitanOptions(rocksdb->rep);
}
void titandb_options_set_dirname(titandb_options_t* options, const char* name) {
options->rep.dirname = name;
}
void titandb_options_set_min_blob_size(titandb_options_t* options,
uint64_t size) {
options->rep.min_blob_size = size;
}
void titandb_options_set_blob_file_compression(titandb_options_t* options,
int compression) {
options->rep.blob_file_compression =
static_cast<CompressionType>(compression);
}
void titandb_options_set_blob_cache(titandb_options_t* options,
rocksdb_cache_t* blob_cache) {
if (blob_cache) {
options->rep.blob_cache = blob_cache->rep;
} else {
options->rep.blob_cache.reset();
}
}
void titandb_options_set_disable_background_gc(titandb_options_t* options,
unsigned char disable) {
options->rep.disable_background_gc = disable;
}
void titandb_options_set_max_gc_batch_size(titandb_options_t* options,
uint64_t size) {
options->rep.max_gc_batch_size = size;
}
void titandb_options_set_min_gc_batch_size(titandb_options_t* options,
uint64_t size) {
options->rep.min_gc_batch_size = size;
}
void titandb_options_set_blob_file_discardable_ratio(titandb_options_t* options,
float ratio) {
options->rep.blob_file_discardable_ratio = ratio;
}
void titandb_options_set_sample_file_size_ratio(titandb_options_t* options,
float ratio) {
options->rep.sample_file_size_ratio = ratio;
}
void titandb_options_set_merge_small_file_threshold(titandb_options_t* options,
uint64_t size) {
options->rep.merge_small_file_threshold = size;
}
} // end extern "C"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment