Skip to content

Commit 72aacf6

Browse files
committed
A few more C API functions.
1 parent 6ed450a commit 72aacf6

File tree

2 files changed

+119
-1
lines changed

2 files changed

+119
-1
lines changed

db/c.cc

+81-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ using rocksdb::Status;
5151
using rocksdb::WritableFile;
5252
using rocksdb::WriteBatch;
5353
using rocksdb::WriteOptions;
54+
using rocksdb::LiveFileMetaData;
5455

5556
using std::shared_ptr;
5657

@@ -70,6 +71,7 @@ struct rocksdb_writablefile_t { WritableFile* rep; };
7071
struct rocksdb_filelock_t { FileLock* rep; };
7172
struct rocksdb_logger_t { shared_ptr<Logger> rep; };
7273
struct rocksdb_cache_t { shared_ptr<Cache> rep; };
74+
struct rocksdb_livefiles_t { std::vector<LiveFileMetaData> rep; };
7375

7476
struct rocksdb_comparator_t : public Comparator {
7577
void* state_;
@@ -435,6 +437,19 @@ void rocksdb_approximate_sizes(
435437
delete[] ranges;
436438
}
437439

440+
void rocksdb_delete_file(
441+
rocksdb_t* db,
442+
const char* name) {
443+
db->rep->DeleteFile(name);
444+
}
445+
446+
const rocksdb_livefiles_t* rocksdb_livefiles(
447+
rocksdb_t* db) {
448+
rocksdb_livefiles_t* result = new rocksdb_livefiles_t;
449+
db->rep->GetLiveFilesMetaData(&result->rep);
450+
return result;
451+
}
452+
438453
void rocksdb_compact_range(
439454
rocksdb_t* db,
440455
const char* start_key, size_t start_key_len,
@@ -537,6 +552,10 @@ void rocksdb_writebatch_clear(rocksdb_writebatch_t* b) {
537552
b->rep.Clear();
538553
}
539554

555+
int rocksdb_writebatch_count(rocksdb_writebatch_t* b) {
556+
return b->rep.Count();
557+
}
558+
540559
void rocksdb_writebatch_put(
541560
rocksdb_writebatch_t* b,
542561
const char* key, size_t klen,
@@ -581,6 +600,11 @@ void rocksdb_writebatch_iterate(
581600
b->rep.Iterate(&handler);
582601
}
583602

603+
const char* rocksdb_writebatch_data(rocksdb_writebatch_t* b, size_t* size) {
604+
*size = b->rep.GetDataSize();
605+
return b->rep.Data().c_str();
606+
}
607+
584608
rocksdb_options_t* rocksdb_options_create() {
585609
return new rocksdb_options_t;
586610
}
@@ -983,7 +1007,6 @@ DB::GetSortedWalFiles
9831007
DB::GetLatestSequenceNumber
9841008
DB::GetUpdatesSince
9851009
DB::DeleteFile
986-
DB::GetLiveFilesMetaData
9871010
DB::GetDbIdentity
9881011
DB::RunManualCompaction
9891012
custom cache
@@ -1304,4 +1327,61 @@ void rocksdb_universal_compaction_options_destroy(
13041327
delete uco;
13051328
}
13061329

1330+
void rocksdb_options_set_min_level_to_compress(rocksdb_options_t* opt, int level) {
1331+
if (level >= 0) {
1332+
assert(level <= opt->rep.num_levels);
1333+
opt->rep.compression_per_level.resize(opt->rep.num_levels);
1334+
for (int i = 0; i < level; i++) {
1335+
opt->rep.compression_per_level[i] = rocksdb::kNoCompression;
1336+
}
1337+
for (int i = level; i < opt->rep.num_levels; i++) {
1338+
opt->rep.compression_per_level[i] = opt->rep.compression;
1339+
}
1340+
}
1341+
}
1342+
1343+
int rocksdb_livefiles_count(
1344+
const rocksdb_livefiles_t* lf) {
1345+
return lf->rep.size();
1346+
}
1347+
1348+
const char* rocksdb_livefiles_name(
1349+
const rocksdb_livefiles_t* lf,
1350+
int index) {
1351+
return lf->rep[index].name.c_str();
1352+
}
1353+
1354+
int rocksdb_livefiles_level(
1355+
const rocksdb_livefiles_t* lf,
1356+
int index) {
1357+
return lf->rep[index].level;
1358+
}
1359+
1360+
size_t rocksdb_livefiles_size(
1361+
const rocksdb_livefiles_t* lf,
1362+
int index) {
1363+
return lf->rep[index].size;
1364+
}
1365+
1366+
const char* rocksdb_livefiles_smallestkey(
1367+
const rocksdb_livefiles_t* lf,
1368+
int index,
1369+
size_t* size) {
1370+
*size = lf->rep[index].smallestkey.size();
1371+
return lf->rep[index].smallestkey.data();
1372+
}
1373+
1374+
const char* rocksdb_livefiles_largestkey(
1375+
const rocksdb_livefiles_t* lf,
1376+
int index,
1377+
size_t* size) {
1378+
*size = lf->rep[index].largestkey.size();
1379+
return lf->rep[index].largestkey.data();
1380+
}
1381+
1382+
extern void rocksdb_livefiles_destroy(
1383+
const rocksdb_livefiles_t* lf) {
1384+
delete lf;
1385+
}
1386+
13071387
} // end extern "C"

include/rocksdb/c.h

+38
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ typedef struct rocksdb_writablefile_t rocksdb_writablefile_t;
7474
typedef struct rocksdb_writebatch_t rocksdb_writebatch_t;
7575
typedef struct rocksdb_writeoptions_t rocksdb_writeoptions_t;
7676
typedef struct rocksdb_universal_compaction_options_t rocksdb_universal_compaction_options_t;
77+
typedef struct rocksdb_livefiles_t rocksdb_livefiles_t;
7778

7879
/* DB operations */
7980

@@ -148,6 +149,13 @@ extern void rocksdb_compact_range(
148149
const char* start_key, size_t start_key_len,
149150
const char* limit_key, size_t limit_key_len);
150151

152+
extern void rocksdb_delete_file(
153+
rocksdb_t* db,
154+
const char* name);
155+
156+
extern const rocksdb_livefiles_t* rocksdb_livefiles(
157+
rocksdb_t* db);
158+
151159
extern void rocksdb_flush(
152160
rocksdb_t* db,
153161
const rocksdb_flushoptions_t* options,
@@ -192,6 +200,7 @@ extern void rocksdb_iter_get_error(const rocksdb_iterator_t*, char** errptr);
192200
extern rocksdb_writebatch_t* rocksdb_writebatch_create();
193201
extern void rocksdb_writebatch_destroy(rocksdb_writebatch_t*);
194202
extern void rocksdb_writebatch_clear(rocksdb_writebatch_t*);
203+
extern int rocksdb_writebatch_count(rocksdb_writebatch_t*);
195204
extern void rocksdb_writebatch_put(
196205
rocksdb_writebatch_t*,
197206
const char* key, size_t klen,
@@ -208,6 +217,7 @@ extern void rocksdb_writebatch_iterate(
208217
void* state,
209218
void (*put)(void*, const char* k, size_t klen, const char* v, size_t vlen),
210219
void (*deleted)(void*, const char* k, size_t klen));
220+
extern const char* rocksdb_writebatch_data(rocksdb_writebatch_t*, size_t *size);
211221

212222
/* Options */
213223

@@ -336,6 +346,12 @@ extern void rocksdb_options_set_delete_obsolete_files_period_micros(
336346
extern void rocksdb_options_set_source_compaction_factor(rocksdb_options_t*, int);
337347
extern void rocksdb_options_prepare_for_bulk_load(rocksdb_options_t*);
338348
extern void rocksdb_options_set_memtable_vector_rep(rocksdb_options_t*);
349+
350+
extern void rocksdb_options_set_max_bytes_for_level_base(rocksdb_options_t* opt, uint64_t n);
351+
extern void rocksdb_options_set_stats_dump_period_sec(rocksdb_options_t* opt, unsigned int sec);
352+
353+
extern void rocksdb_options_set_min_level_to_compress(rocksdb_options_t* opt, int level);
354+
339355
extern void rocksdb_options_set_memtable_prefix_bloom_bits(
340356
rocksdb_options_t*, uint32_t);
341357
extern void rocksdb_options_set_memtable_prefix_bloom_probes(
@@ -508,6 +524,28 @@ extern void rocksdb_universal_compaction_options_set_stop_style(
508524
extern void rocksdb_universal_compaction_options_destroy(
509525
rocksdb_universal_compaction_options_t*);
510526

527+
extern int rocksdb_livefiles_count(
528+
const rocksdb_livefiles_t*);
529+
extern const char* rocksdb_livefiles_name(
530+
const rocksdb_livefiles_t*,
531+
int index);
532+
extern int rocksdb_livefiles_level(
533+
const rocksdb_livefiles_t*,
534+
int index);
535+
extern size_t rocksdb_livefiles_size(
536+
const rocksdb_livefiles_t*,
537+
int index);
538+
extern const char* rocksdb_livefiles_smallestkey(
539+
const rocksdb_livefiles_t*,
540+
int index,
541+
size_t* size);
542+
extern const char* rocksdb_livefiles_largestkey(
543+
const rocksdb_livefiles_t*,
544+
int index,
545+
size_t* size);
546+
extern void rocksdb_livefiles_destroy(
547+
const rocksdb_livefiles_t*);
548+
511549
#ifdef __cplusplus
512550
} /* end extern "C" */
513551
#endif

0 commit comments

Comments
 (0)