@@ -8,6 +8,8 @@ typedef struct {
8
8
int max_open_files ;
9
9
int sync ;
10
10
int bits_per_key ;
11
+ long write_buffer_size ;
12
+ long max_file_size ;
11
13
12
14
char * db_name ;
13
15
char * compression ;
@@ -87,6 +89,20 @@ static command_t cmds[] = {
87
89
offsetof(ldb_options_t , range_end ),
88
90
""
89
91
},
92
+ {
93
+ "" ,
94
+ "write_buffer_size" ,
95
+ cmd_set_size ,
96
+ offsetof(ldb_options_t , write_buffer_size ),
97
+ "16m"
98
+ },
99
+ {
100
+ "" ,
101
+ "max_file_size" ,
102
+ cmd_set_size ,
103
+ offsetof(ldb_options_t , max_file_size ),
104
+ "16m"
105
+ },
90
106
{
91
107
"" ,
92
108
"propname" ,
@@ -140,7 +156,7 @@ static void ldb_get(leveldb_t *ldb, const char *db_name, const char *line, level
140
156
141
157
char * value = leveldb_get (ldb , ropt , line , strlen (line ), & vallen , & errstr );
142
158
143
- printf ("leveldb_get key <%s> %s, vallen = %lu, errstr = %s, taken %.2fms\n " , line , value ? "HIT" : "MISS" , vallen , errstr ? errstr : "errstr is empty" , tv_sub_msec_double (tv_now (), tv ));
159
+ log_info ("leveldb_get key <%s> %s, vallen = %lu, errstr = %s, taken %.2fms" , line , value ? "HIT" : "MISS" , vallen , errstr ? errstr : "errstr is empty" , tv_sub_msec_double (tv_now (), tv ));
144
160
145
161
leveldb_free (errstr );
146
162
leveldb_free (value );
@@ -161,9 +177,7 @@ static void process_ldb_get(leveldb_t *ldb, ldb_options_t *opt) {
161
177
* enter = '\0' ;
162
178
}
163
179
164
- for (int i = 0 ; i < 1000 ; i ++ ) {
165
- ldb_get (ldb , opt -> db_name , line , ropt );
166
- }
180
+ ldb_get (ldb , opt -> db_name , line , ropt );
167
181
}
168
182
169
183
leveldb_readoptions_destroy (ropt );
@@ -176,10 +190,10 @@ static void ldb_put(leveldb_t *ldb, const char *db_name, const char *line, level
176
190
leveldb_put (ldb , wopt , line , strlen (line ), line , strlen (line ), & errstr );
177
191
178
192
if (errstr ) {
179
- printf ("leveldb_put key <%s> to db %s error: %s\n " , line , db_name , errstr );
193
+ log_info ("leveldb_put key <%s> to db %s error: %s" , line , db_name , errstr );
180
194
leveldb_free (errstr );
181
195
} else {
182
- printf ("leveldb_put key <%s> to db %s taken %.2fms\n " , line , db_name , tv_sub_msec_double (tv_now (), tv ));
196
+ // log_info ("leveldb_put key <%s> to db %s taken %.2fms", line, db_name, tv_sub_msec_double(tv_now(), tv));
183
197
}
184
198
}
185
199
@@ -218,7 +232,7 @@ static void process_ldb_keys(leveldb_t *ldb, ldb_options_t *opt) {
218
232
tv = tv_end ;
219
233
220
234
if (key ) {
221
- printf ("process key <%.*s> klen = %lu, taken %.2fms\n " , (int )klen , key , klen , ms_taken );
235
+ log_info ("process key <%.*s> klen = %lu, taken %.2fms" , (int )klen , key , klen , ms_taken );
222
236
}
223
237
224
238
leveldb_iter_next (iter );
@@ -229,20 +243,20 @@ static void process_ldb_keys(leveldb_t *ldb, ldb_options_t *opt) {
229
243
}
230
244
231
245
static void process_ldb_compact_range (leveldb_t * ldb , ldb_options_t * opt ) {
232
- printf ("start to compact_range start <%s> end <%s>\n " , opt -> range_start , opt -> range_end );
246
+ log_info ("start to compact_range start <%s> end <%s>" , opt -> range_start , opt -> range_end );
233
247
234
248
struct timeval tv_start = tv_now ();
235
249
leveldb_compact_range (ldb , opt -> range_start , strlen (opt -> range_start ), opt -> range_end , strlen (opt -> range_end ));
236
- printf ("compact finished! taken %.2fms\n " , tv_sub_msec_double (tv_now (), tv_start ));
250
+ log_info ("compact finished! taken %.2fms" , tv_sub_msec_double (tv_now (), tv_start ));
237
251
}
238
252
239
253
static void process_ldb_property (leveldb_t * ldb , ldb_options_t * opt ) {
240
254
char * value = leveldb_property_value (ldb , opt -> propname );
241
255
242
256
if (value == NULL ) {
243
- printf ("get property <%s> but return NULL\n " , opt -> propname );
257
+ log_info ("get property <%s> but return NULL" , opt -> propname );
244
258
} else {
245
- printf ("%s\n " , value );
259
+ log_info ("%s" , value );
246
260
leveldb_free (value );
247
261
}
248
262
}
@@ -253,7 +267,7 @@ static void process_ldb_repair(ldb_options_t *ldb_opt, leveldb_options_t *opt) {
253
267
struct timeval tv_start = tv_now ();
254
268
leveldb_repair_db (opt , ldb_opt -> db_name , & errstr );
255
269
256
- printf ("repair db <%s> %s! taken %.2fms" , ldb_opt -> db_name , errstr == NULL ? "successful!" : errstr , tv_sub_msec_double (tv_now (), tv_start ));
270
+ log_info ("repair db <%s> %s! taken %.2fms" , ldb_opt -> db_name , errstr == NULL ? "successful!" : errstr , tv_sub_msec_double (tv_now (), tv_start ));
257
271
leveldb_free (errstr );
258
272
}
259
273
@@ -262,12 +276,12 @@ static void process_ldb(leveldb_t *ldb, const char *typ, const char *errstr, ldb
262
276
if (errstr == NULL ) {
263
277
errstr = "no error str" ;
264
278
}
265
- printf ("open %s error: %s\n " , opt -> db_name , errstr );
279
+ log_info ("open %s error: %s" , opt -> db_name , errstr );
266
280
return ;
267
281
}
268
282
269
283
if (typ == NULL ) {
270
- printf ("type is NULL, impossible!\n " );
284
+ log_info ("type is NULL, impossible!" );
271
285
} else if (!strcasecmp (typ , "get" )) {
272
286
process_ldb_get (ldb , opt );
273
287
} else if (!strcasecmp (typ , "put" )) {
@@ -279,7 +293,7 @@ static void process_ldb(leveldb_t *ldb, const char *typ, const char *errstr, ldb
279
293
} else if (!strcasecmp (typ , "property" )) {
280
294
process_ldb_property (ldb , opt );
281
295
} else {
282
- printf ("invalid type %s\n " , typ );
296
+ log_info ("invalid type %s" , typ );
283
297
}
284
298
}
285
299
@@ -306,6 +320,9 @@ int main(int argc, const char *argv[]) {
306
320
leveldb_options_t * opt = leveldb_options_create ();
307
321
leveldb_options_set_create_if_missing (opt , 1 );
308
322
leveldb_options_set_max_open_files (opt , ldb_opt -> max_open_files );
323
+ leveldb_options_set_write_buffer_size (opt , ldb_opt -> write_buffer_size );
324
+ // leveldb_options_set_max_file_size(opt, ldb_opt->max_file_size);
325
+ log_info ("write_buffer_size is %ld" , ldb_opt -> write_buffer_size );
309
326
if (!strcasecmp (ldb_opt -> compression , "snappy" )) {
310
327
leveldb_options_set_compression (opt , leveldb_snappy_compression );
311
328
}
@@ -321,8 +338,6 @@ int main(int argc, const char *argv[]) {
321
338
leveldb_options_set_cache (opt , cache );
322
339
}
323
340
324
- // leveldb_options_set_max_file_size(opt, 1024 * 1024 * 8);
325
-
326
341
if (!strcasecmp (type , "repair" )) {
327
342
process_ldb_repair (ldb_opt , opt );
328
343
} else {
0 commit comments