Fix record_size in log_write_bench, swap args to std::string::assign. (#1373)
Fix record_size in log_write_bench, swap args to std::string::assign. (#1373)

Hello and thank you for RocksDB,
 
I noticed when using log_write_bench that writes were always 88 bytes:
 
> strace -e trace=write ./log_write_bench -num_records 2 2>&1 | head -n 2
write(3, "\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371"..., 88) = 88
write(3, "\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371\371"..., 88) = 88

> strace -e trace=write ./log_write_bench -record_size 4096 -num_records 2 2>&1 | head -n 2
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 88) = 88
write(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 88) = 88
 
I think this should be:

<<    record.assign('X', FLAGS_record_size);
>>    record.assign(FLAGS_record_size, 'X');

So fill and not buffer. Otherwise I always see writes of size 88 (the decimal value for chr "X").

string& assign (const char* s, size_t n);
buffer - Copies the first n characters from the array of characters pointed by s.

string& assign (size_t n, char c);
fill   - Replaces the current value by n consecutive copies of character c.

perl -le 'print ord "X"'
88
 
With the change:
 
> strace -e trace=write ./log_write_bench -record_size 4096 -num_records 2 2>&1 | head -n 2
write(3, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"..., 4096) = 4096
write(3, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"..., 4096) = 4096
 
> strace -e trace=write ./log_write_bench -num_records 2 2>&1 | head -n 2
write(3, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"..., 249) = 249
write(3, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"..., 249) = 249

Thanks.

https://github.com/facebook/rocksdb/commit/01c27be5fb42524c5052b4b4a23e05501e1d1421
https://reviews.facebook.net/D16239
bbiao/rocksdb,wat-ze-hex/rocksdb,vmx/rocksdb,wenduo/rocksdb,SunguckLee/RocksDB,facebook/rocksdb,vmx/rocksdb,tsheasha/rocksdb,facebook/rocksdb,Andymic/rocksdb,facebook/rocksdb,Andymic/rocksdb,facebook/rocksdb,vmx/rocksdb,Andymic/rocksdb,wat-ze-hex/rocksdb,wenduo/rocksdb,vmx/rocksdb,vmx/rocksdb,SunguckLee/RocksDB,Andymic/rocksdb,tsheasha/rocksdb,Andymic/rocksdb,Andymic/rocksdb,vmx/rocksdb,wat-ze-hex/rocksdb,bbiao/rocksdb,wat-ze-hex/rocksdb,vmx/rocksdb,bbiao/rocksdb,wenduo/rocksdb,wat-ze-hex/rocksdb,bbiao/rocksdb,SunguckLee/RocksDB,bbiao/rocksdb,Andymic/rocksdb,facebook/rocksdb,Andymic/rocksdb,vmx/rocksdb,wenduo/rocksdb,facebook/rocksdb,wat-ze-hex/rocksdb,wenduo/rocksdb,tsheasha/rocksdb,wat-ze-hex/rocksdb,tsheasha/rocksdb,tsheasha/rocksdb,facebook/rocksdb,tsheasha/rocksdb,bbiao/rocksdb,tsheasha/rocksdb,SunguckLee/RocksDB,wenduo/rocksdb,SunguckLee/RocksDB,bbiao/rocksdb,tsheasha/rocksdb,wenduo/rocksdb,SunguckLee/RocksDB,SunguckLee/RocksDB,facebook/rocksdb,bbiao/rocksdb,wat-ze-hex/rocksdb,SunguckLee/RocksDB,wenduo/rocksdb