直接从GitHub上clone下来RocksDB的源码。
RocksDB的put
操作的声明代码在头文件include/rocksdb/db.h
中:
// Set the database entry for "key" to "value".
// If "key" already exists, it will be overwritten.
// Returns OK on success, and a non-OK status on error.
// Note: consider setting options.sync = true.
virtual Status Put(const WriteOptions& options,
ColumnFamilyHandle* column_family, const Slice& key,
const Slice& value) = 0;
virtual Status Put(const WriteOptions& options, const Slice& key,
const Slice& value) {
return Put(options, DefaultColumnFamily(), key, value);
}
注释说明如果put已经存在的key,那么会对value进行覆盖。
如果不指定column_family,那么会用默认的column_family。
put
函数的实现代码在db/db_impl_write.cc
文件中:
// Default implementations of convenience methods that subclasses of DB
// can call if they wish
Status DB::Put(const WriteOptions& opt, ColumnFamilyHandle* column_family,
const Slice& key, const Slice& value) {
// Pre-allocate size of write batch conservatively.