Skip to content

Commit cfb43d4

Browse files
committed
Expand writebatch methods in C api
Added: - rocksdb_writebatch_get_data_size - rocksdb_writebatch_has_put - rocksdb_writebatch_has_delete - rocksdb_writebatch_has_single_delete - rocksdb_writebatch_has_delete_range - rocksdb_writebatch_has_merge - rocksdb_writebatch_has_begin_prepare - rocksdb_writebatch_has_end_prepare - rocksdb_writebatch_has_commit - rocksdb_writebatch_has_rollback - rocksdb_writebatch_set_max_bytes - rocksdb_writebatch_mark_wal_termination_point - rocksdb_writebatch_get_wal_termination_point - rocksdb_writebatch_wi_get_data_size - rocksdb_save_point_get_size - rocksdb_save_point_get_count - rocksdb_save_point_get_content_flags - rocksdb_save_point_clear - rocksdb_save_point_is_cleared - rocksdb_save_point_destroy And tests
1 parent 0e469c7 commit cfb43d4

File tree

3 files changed

+157
-0
lines changed

3 files changed

+157
-0
lines changed

db/c.cc

+84
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ using ROCKSDB_NAMESPACE::Range;
108108
using ROCKSDB_NAMESPACE::RateLimiter;
109109
using ROCKSDB_NAMESPACE::ReadOptions;
110110
using ROCKSDB_NAMESPACE::RestoreOptions;
111+
using ROCKSDB_NAMESPACE::SavePoint;
111112
using ROCKSDB_NAMESPACE::SequentialFile;
112113
using ROCKSDB_NAMESPACE::Slice;
113114
using ROCKSDB_NAMESPACE::SliceParts;
@@ -154,6 +155,9 @@ struct rocksdb_iterator_t {
154155
struct rocksdb_writebatch_t {
155156
WriteBatch rep;
156157
};
158+
struct rocksdb_save_point_t {
159+
SavePoint rep;
160+
};
157161
struct rocksdb_writebatch_wi_t {
158162
WriteBatchWithIndex* rep;
159163
};
@@ -2344,6 +2348,10 @@ const char* rocksdb_writebatch_data(rocksdb_writebatch_t* b, size_t* size) {
23442348
return b->rep.Data().c_str();
23452349
}
23462350

2351+
size_t rocksdb_writebatch_get_data_size(rocksdb_writebatch_t* b) {
2352+
return b->rep.GetDataSize();
2353+
}
2354+
23472355
void rocksdb_writebatch_set_save_point(rocksdb_writebatch_t* b) {
23482356
b->rep.SetSavePoint();
23492357
}
@@ -2385,6 +2393,58 @@ void rocksdb_writebatch_update_timestamps(
23852393
}));
23862394
}
23872395

2396+
unsigned char rocksdb_writebatch_has_put(rocksdb_writebatch_t* b) {
2397+
return b->rep.HasPut();
2398+
}
2399+
2400+
unsigned char rocksdb_writebatch_has_delete(rocksdb_writebatch_t* b) {
2401+
return b->rep.HasDelete();
2402+
}
2403+
2404+
unsigned char rocksdb_writebatch_has_single_delete(rocksdb_writebatch_t* b) {
2405+
return b->rep.HasSingleDelete();
2406+
}
2407+
2408+
unsigned char rocksdb_writebatch_has_delete_range(rocksdb_writebatch_t* b) {
2409+
return b->rep.HasDeleteRange();
2410+
}
2411+
2412+
unsigned char rocksdb_writebatch_has_merge(rocksdb_writebatch_t* b) {
2413+
return b->rep.HasMerge();
2414+
}
2415+
2416+
unsigned char rocksdb_writebatch_has_begin_prepare(rocksdb_writebatch_t* b) {
2417+
return b->rep.HasBeginPrepare();
2418+
}
2419+
2420+
unsigned char rocksdb_writebatch_has_end_prepare(rocksdb_writebatch_t* b) {
2421+
return b->rep.HasEndPrepare();
2422+
}
2423+
2424+
unsigned char rocksdb_writebatch_has_commit(rocksdb_writebatch_t* b) {
2425+
return b->rep.HasCommit();
2426+
}
2427+
2428+
unsigned char rocksdb_writebatch_has_rollback(rocksdb_writebatch_t* b) {
2429+
return b->rep.HasRollback();
2430+
}
2431+
2432+
void rocksdb_writebatch_set_max_bytes(rocksdb_writebatch_t* b,
2433+
size_t max_bytes) {
2434+
b->rep.SetMaxBytes(max_bytes);
2435+
}
2436+
2437+
void rocksdb_writebatch_mark_wal_termination_point(rocksdb_writebatch_t* b) {
2438+
b->rep.MarkWalTerminationPoint();
2439+
}
2440+
2441+
rocksdb_save_point_t* rocksdb_writebatch_get_wal_termination_point(
2442+
rocksdb_writebatch_t* b) {
2443+
rocksdb_save_point_t* sp = new rocksdb_save_point_t;
2444+
sp->rep = b->rep.GetWalTerminationPoint();
2445+
return sp;
2446+
}
2447+
23882448
void rocksdb_writebatch_wi_update_timestamps(
23892449
rocksdb_writebatch_wi_t* wb, const char* ts, size_t tslen, void* state,
23902450
size_t (*get_ts_size)(void*, uint32_t), char** errptr) {
@@ -2614,6 +2674,10 @@ const char* rocksdb_writebatch_wi_data(rocksdb_writebatch_wi_t* b,
26142674
return wb->Data().c_str();
26152675
}
26162676

2677+
size_t rocksdb_writebatch_wi_get_data_size(rocksdb_writebatch_wi_t* b) {
2678+
return b->rep->GetDataSize();
2679+
}
2680+
26172681
void rocksdb_writebatch_wi_set_save_point(rocksdb_writebatch_wi_t* b) {
26182682
b->rep->SetSavePoint();
26192683
}
@@ -2728,6 +2792,26 @@ void rocksdb_write_writebatch_wi(rocksdb_t* db,
27282792
SaveError(errptr, db->rep->Write(options->rep, wb));
27292793
}
27302794

2795+
size_t rocksdb_save_point_get_size(rocksdb_save_point_t* sp) {
2796+
return sp->rep.size;
2797+
}
2798+
2799+
uint32_t rocksdb_save_point_get_count(rocksdb_save_point_t* sp) {
2800+
return sp->rep.count;
2801+
}
2802+
2803+
uint32_t rocksdb_save_point_get_content_flags(rocksdb_save_point_t* sp) {
2804+
return sp->rep.content_flags;
2805+
}
2806+
2807+
void rocksdb_save_point_clear(rocksdb_save_point_t* sp) { sp->rep.clear(); }
2808+
2809+
bool rocksdb_save_point_is_cleared(rocksdb_save_point_t* sp) {
2810+
return sp->rep.is_cleared();
2811+
}
2812+
2813+
void rocksdb_save_point_destroy(rocksdb_save_point_t* sp) { delete sp; }
2814+
27312815
void rocksdb_load_latest_options(
27322816
const char* db_path, rocksdb_env_t* env, bool ignore_unknown_options,
27332817
rocksdb_cache_t* cache, rocksdb_options_t** db_options,

db/c_test.c

+26
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,10 @@ int main(int argc, char** argv) {
12431243
rocksdb_writebatch_wi_delete(wbi, "bar", 3);
12441244
int count = rocksdb_writebatch_wi_count(wbi);
12451245
CheckCondition(count == 3);
1246+
1247+
size_t data_size = rocksdb_writebatch_wi_get_data_size(wbi);
1248+
CheckCondition(data_size > 0);
1249+
12461250
size_t size;
12471251
char* value;
12481252
value = rocksdb_writebatch_wi_get_from_batch(wbi, options, "box", 3, &size,
@@ -3268,6 +3272,28 @@ int main(int argc, char** argv) {
32683272
rocksdb_writebatch_put(wb, "bar", 3, "b", 1);
32693273
rocksdb_writebatch_put(wb, "box", 3, "c", 1);
32703274
rocksdb_writebatch_delete(wb, "bar", 3);
3275+
3276+
CheckCondition(rocksdb_writebatch_has_put(wb));
3277+
CheckCondition(rocksdb_writebatch_has_delete(wb));
3278+
CheckCondition(0 == rocksdb_writebatch_has_single_delete(wb));
3279+
CheckCondition(0 == rocksdb_writebatch_has_delete_range(wb));
3280+
CheckCondition(0 == rocksdb_writebatch_has_merge(wb));
3281+
CheckCondition(0 == rocksdb_writebatch_has_rollback(wb));
3282+
CheckCondition(0 == rocksdb_writebatch_has_commit(wb));
3283+
CheckCondition(0 == rocksdb_writebatch_has_begin_prepare(wb));
3284+
CheckCondition(0 == rocksdb_writebatch_has_end_prepare(wb));
3285+
3286+
// CheckCondition(rocksdb_writebatch_get_data_size(wb) > 0);
3287+
3288+
rocksdb_writebatch_mark_wal_termination_point(wb);
3289+
rocksdb_save_point_t* sp = rocksdb_writebatch_get_wal_termination_point(wb);
3290+
3291+
CheckCondition(rocksdb_save_point_get_size(sp) > 0);
3292+
CheckCondition(rocksdb_save_point_get_count(sp) > 0);
3293+
CheckCondition(rocksdb_save_point_get_content_flags(sp) > 0);
3294+
CheckCondition(!rocksdb_save_point_is_cleared(sp));
3295+
rocksdb_save_point_destroy(sp);
3296+
32713297
rocksdb_transactiondb_write(txn_db, woptions, wb, &err);
32723298
rocksdb_writebatch_destroy(wb);
32733299
CheckTxnDBGet(txn_db, roptions, "box", "c");

include/rocksdb/c.h

+47
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ typedef struct rocksdb_slicetransform_t rocksdb_slicetransform_t;
107107
typedef struct rocksdb_snapshot_t rocksdb_snapshot_t;
108108
typedef struct rocksdb_writablefile_t rocksdb_writablefile_t;
109109
typedef struct rocksdb_writebatch_t rocksdb_writebatch_t;
110+
typedef struct rocksdb_save_point_t rocksdb_save_point_t;
110111
typedef struct rocksdb_writebatch_wi_t rocksdb_writebatch_wi_t;
111112
typedef struct rocksdb_writeoptions_t rocksdb_writeoptions_t;
112113
typedef struct rocksdb_universal_compaction_options_t
@@ -872,6 +873,8 @@ extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_iterate_cf(
872873
const char* v, size_t vlen));
873874
extern ROCKSDB_LIBRARY_API const char* rocksdb_writebatch_data(
874875
rocksdb_writebatch_t*, size_t* size);
876+
extern ROCKSDB_LIBRARY_API size_t
877+
rocksdb_writebatch_get_data_size(rocksdb_writebatch_t*);
875878
extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_set_save_point(
876879
rocksdb_writebatch_t*);
877880
extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_rollback_to_save_point(
@@ -882,6 +885,33 @@ extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_update_timestamps(
882885
rocksdb_writebatch_t* wb, const char* ts, size_t tslen, void* state,
883886
size_t (*get_ts_size)(void*, uint32_t), char** errptr);
884887

888+
extern ROCKSDB_LIBRARY_API unsigned char rocksdb_writebatch_has_put(
889+
rocksdb_writebatch_t*);
890+
extern ROCKSDB_LIBRARY_API unsigned char rocksdb_writebatch_has_delete(
891+
rocksdb_writebatch_t*);
892+
extern ROCKSDB_LIBRARY_API unsigned char rocksdb_writebatch_has_single_delete(
893+
rocksdb_writebatch_t*);
894+
extern ROCKSDB_LIBRARY_API unsigned char rocksdb_writebatch_has_delete_range(
895+
rocksdb_writebatch_t*);
896+
extern ROCKSDB_LIBRARY_API unsigned char rocksdb_writebatch_has_merge(
897+
rocksdb_writebatch_t*);
898+
extern ROCKSDB_LIBRARY_API unsigned char rocksdb_writebatch_has_begin_prepare(
899+
rocksdb_writebatch_t*);
900+
extern ROCKSDB_LIBRARY_API unsigned char rocksdb_writebatch_has_end_prepare(
901+
rocksdb_writebatch_t*);
902+
extern ROCKSDB_LIBRARY_API unsigned char rocksdb_writebatch_has_commit(
903+
rocksdb_writebatch_t*);
904+
extern ROCKSDB_LIBRARY_API unsigned char rocksdb_writebatch_has_rollback(
905+
rocksdb_writebatch_t*);
906+
907+
extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_set_max_bytes(
908+
rocksdb_writebatch_t* b, size_t max_bytes);
909+
910+
extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_mark_wal_termination_point(
911+
rocksdb_writebatch_t* b);
912+
extern ROCKSDB_LIBRARY_API rocksdb_save_point_t*
913+
rocksdb_writebatch_get_wal_termination_point(rocksdb_writebatch_t* b);
914+
885915
/* Write batch with index */
886916

887917
extern ROCKSDB_LIBRARY_API rocksdb_writebatch_wi_t*
@@ -974,6 +1004,8 @@ extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_wi_iterate(
9741004
void (*deleted)(void*, const char* k, size_t klen));
9751005
extern ROCKSDB_LIBRARY_API const char* rocksdb_writebatch_wi_data(
9761006
rocksdb_writebatch_wi_t* b, size_t* size);
1007+
extern ROCKSDB_LIBRARY_API size_t
1008+
rocksdb_writebatch_wi_get_data_size(rocksdb_writebatch_wi_t* b);
9771009
extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_wi_set_save_point(
9781010
rocksdb_writebatch_wi_t*);
9791011
extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_wi_rollback_to_save_point(
@@ -1008,6 +1040,21 @@ extern ROCKSDB_LIBRARY_API void rocksdb_writebatch_wi_update_timestamps(
10081040
rocksdb_writebatch_wi_t* wbwi, const char* ts, size_t tslen, void* state,
10091041
size_t (*get_ts_size)(void*, uint32_t), char** errptr);
10101042

1043+
/* Save point */
1044+
1045+
extern ROCKSDB_LIBRARY_API size_t
1046+
rocksdb_save_point_get_size(rocksdb_save_point_t* sp);
1047+
extern ROCKSDB_LIBRARY_API uint32_t
1048+
rocksdb_save_point_get_count(rocksdb_save_point_t* sp);
1049+
extern ROCKSDB_LIBRARY_API uint32_t
1050+
rocksdb_save_point_get_content_flags(rocksdb_save_point_t* sp);
1051+
extern ROCKSDB_LIBRARY_API void rocksdb_save_point_clear(
1052+
rocksdb_save_point_t* sp);
1053+
extern ROCKSDB_LIBRARY_API bool rocksdb_save_point_is_cleared(
1054+
rocksdb_save_point_t* sp);
1055+
extern ROCKSDB_LIBRARY_API void rocksdb_save_point_destroy(
1056+
rocksdb_save_point_t* sp);
1057+
10111058
/* Options utils */
10121059

10131060
// Load the latest rocksdb options from the specified db_path.

0 commit comments

Comments
 (0)