Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
indiff7643
Terarkdb
提交
fbd60f9b
T
Terarkdb
项目概览
indiff7643
/
Terarkdb
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Terarkdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fbd60f9b
编写于
10月 29, 2019
作者:
Z
ZhaoMing
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix variable naming for LazyBuffer
上级
5a647c99
变更
32
展开全部
显示空白变更内容
内联
并排
Showing
32 changed file
with
425 addition
and
429 deletion
+425
-429
db/compaction_dispatcher.cc
db/compaction_dispatcher.cc
+9
-9
db/compaction_job.cc
db/compaction_job.cc
+2
-2
db/compaction_picker.cc
db/compaction_picker.cc
+1
-1
db/compaction_picker_universal.cc
db/compaction_picker_universal.cc
+1
-1
db/db_iter.cc
db/db_iter.cc
+1
-1
db/db_test_util.h
db/db_test_util.h
+2
-2
db/map_builder.cc
db/map_builder.cc
+1
-1
db/memtable.cc
db/memtable.cc
+3
-3
db/memtablerep.cc
db/memtablerep.cc
+3
-3
db/merge_operator.cc
db/merge_operator.cc
+4
-4
db/table_cache.cc
db/table_cache.cc
+1
-1
db/version_set.cc
db/version_set.cc
+6
-5
db/version_set.h
db/version_set.h
+1
-1
db/write_batch.cc
db/write_batch.cc
+1
-1
include/rocksdb/compaction_filter.h
include/rocksdb/compaction_filter.h
+2
-2
include/rocksdb/lazy_buffer.h
include/rocksdb/lazy_buffer.h
+93
-91
memtable/terark_zip_memtable.cc
memtable/terark_zip_memtable.cc
+1
-1
memtable/terark_zip_memtable.h
memtable/terark_zip_memtable.h
+4
-4
table/block_based_table_builder.cc
table/block_based_table_builder.cc
+1
-1
table/block_based_table_reader.h
table/block_based_table_reader.h
+1
-1
table/cuckoo_table_builder.cc
table/cuckoo_table_builder.cc
+1
-1
table/plain_table_builder.cc
table/plain_table_builder.cc
+1
-1
table/terark_zip_table_builder.cc
table/terark_zip_table_builder.cc
+3
-3
table/terark_zip_table_reader.cc
table/terark_zip_table_reader.cc
+1
-1
table/two_level_iterator.cc
table/two_level_iterator.cc
+1
-1
util/lazy_buffer.cc
util/lazy_buffer.cc
+239
-239
util/lazy_buffer_test.cc
util/lazy_buffer_test.cc
+30
-37
utilities/merge_operators/max.cc
utilities/merge_operators/max.cc
+4
-4
utilities/transactions/write_prepared_txn.cc
utilities/transactions/write_prepared_txn.cc
+1
-1
utilities/transactions/write_unprepared_txn.cc
utilities/transactions/write_unprepared_txn.cc
+1
-1
utilities/transactions/write_unprepared_txn_db.cc
utilities/transactions/write_unprepared_txn_db.cc
+1
-1
utilities/ttl/db_ttl_impl.cc
utilities/ttl/db_ttl_impl.cc
+4
-4
未找到文件。
db/compaction_dispatcher.cc
浏览文件 @
fbd60f9b
...
...
@@ -140,7 +140,7 @@ using TMap = std::unordered_map<std::string, T>;
template
<
class
T
>
using
STMap
=
std
::
unordered_map
<
std
::
string
,
std
::
shared_ptr
<
T
>>
;
class
WorkerSeparateHelper
:
public
SeparateHelper
,
public
LazyBuffer
Controller
{
class
WorkerSeparateHelper
:
public
SeparateHelper
,
public
LazyBuffer
State
{
public:
void
destroy
(
LazyBuffer
*
/*buffer*/
)
const
override
{}
...
...
@@ -148,7 +148,7 @@ class WorkerSeparateHelper : public SeparateHelper, public LazyBufferController
Status
fetch_buffer
(
LazyBuffer
*
buffer
)
const
override
{
return
inplace_decode_callback_
(
inplace_decode_arg_
,
buffer
,
get_
rep
(
buffer
));
get_
context
(
buffer
));
}
void
TransToCombined
(
const
Slice
&
user_key
,
uint64_t
sequence
,
...
...
@@ -156,7 +156,7 @@ class WorkerSeparateHelper : public SeparateHelper, public LazyBufferController
auto
s
=
value
.
fetch
();
if
(
s
.
ok
())
{
uint64_t
file_number
=
SeparateHelper
::
DecodeFileNumber
(
value
.
get_
slice
());
SeparateHelper
::
DecodeFileNumber
(
value
.
slice
());
value
.
reset
(
this
,
{
reinterpret_cast
<
uint64_t
>
(
user_key
.
data
()),
user_key
.
size
(),
sequence
,
0
},
Slice
::
Invalid
(),
file_number
);
...
...
@@ -165,10 +165,10 @@ class WorkerSeparateHelper : public SeparateHelper, public LazyBufferController
}
}
WorkerSeparateHelper
(
DependenceMap
*
dependence_map
,
void
*
inplace_decode_arg
,
Status
(
*
inplace_decode_callback
)(
void
*
arg
,
LazyBuffer
*
buffer
,
LazyBufferRep
*
rep
))
WorkerSeparateHelper
(
DependenceMap
*
dependence_map
,
void
*
inplace_decode_
arg
,
Status
(
*
inplace_decode_callback
)(
void
*
arg
,
LazyBuffer
*
buffer
,
LazyBufferContext
*
rep
))
:
dependence_map_
(
dependence_map
),
inplace_decode_arg_
(
inplace_decode_arg
),
inplace_decode_callback_
(
inplace_decode_callback
)
{}
...
...
@@ -176,7 +176,7 @@ class WorkerSeparateHelper : public SeparateHelper, public LazyBufferController
DependenceMap
*
dependence_map_
;
void
*
inplace_decode_arg_
;
Status
(
*
inplace_decode_callback_
)(
void
*
arg
,
LazyBuffer
*
buffer
,
LazyBuffer
Rep
*
rep
);
LazyBuffer
Context
*
rep
);
};
std
::
function
<
CompactionWorkerResult
()
>
...
...
@@ -526,7 +526,7 @@ std::string RemoteCompactionDispatcher::Worker::DoCompaction(
c_style_new_iterator
.
arg
=
&
new_iterator
;
c_style_new_iterator
.
callback
=
c_style_callback
(
new_iterator
);
auto
separate_inplace_decode
=
[
&
](
LazyBuffer
*
buffer
,
LazyBuffer
Rep
*
rep
)
{
auto
separate_inplace_decode
=
[
&
](
LazyBuffer
*
buffer
,
LazyBuffer
Context
*
rep
)
{
Slice
user_key
(
reinterpret_cast
<
const
char
*>
(
rep
->
data
[
0
]),
rep
->
data
[
1
]);
uint64_t
sequence
=
rep
->
data
[
2
];
uint64_t
file_number
=
buffer
->
file_number
();
...
...
db/compaction_job.cc
浏览文件 @
fbd60f9b
...
...
@@ -1350,7 +1350,7 @@ void CompactionJob::ProcessKeyValueCompaction(SubcompactionState* sub_compact) {
if
(
!
status
.
ok
())
{
break
;
}
for
(
const
auto
&
data_elmt
:
{
key
,
value
.
get_
slice
()})
{
for
(
const
auto
&
data_elmt
:
{
key
,
value
.
slice
()})
{
size_t
data_end_offset
=
data_begin_offset
+
data_elmt
.
size
();
while
(
sample_begin_offset_iter
!=
sample_begin_offsets
.
cend
()
&&
*
sample_begin_offset_iter
<
data_end_offset
)
{
...
...
@@ -1646,7 +1646,7 @@ void CompactionJob::ProcessGarbageCollection(SubcompactionState* sub_compact) {
break
;
}
uint64_t
file_number
=
SeparateHelper
::
DecodeFileNumber
(
value
.
get_
slice
());
SeparateHelper
::
DecodeFileNumber
(
value
.
slice
());
auto
find
=
dependence_map
.
find
(
file_number
);
if
(
find
==
dependence_map
.
end
())
{
status
=
Status
::
Corruption
(
"Separate value dependence missing"
);
...
...
db/compaction_picker.cc
浏览文件 @
fbd60f9b
...
...
@@ -749,7 +749,7 @@ void CompactionPicker::InitFilesBeingCompact(
iter
->
Valid
();
iter
->
Next
())
{
LazyBuffer
value
=
iter
->
value
();
if
(
!
value
.
fetch
().
ok
()
||
!
element
.
Decode
(
iter
->
key
(),
value
.
get_
slice
()))
{
!
element
.
Decode
(
iter
->
key
(),
value
.
slice
()))
{
// TODO: log error ?
break
;
}
...
...
db/compaction_picker_universal.cc
浏览文件 @
fbd60f9b
...
...
@@ -128,7 +128,7 @@ bool ReadMapElement(MapSstElement& map_element, InternalIterator* iter,
cf_name
.
c_str
(),
s
.
ToString
().
c_str
());
return
false
;
}
if
(
!
map_element
.
Decode
(
iter
->
key
(),
value
.
get_
slice
()))
{
if
(
!
map_element
.
Decode
(
iter
->
key
(),
value
.
slice
()))
{
ROCKS_LOG_BUFFER
(
log_buffer
,
"[%s] UniversalCompactionPicker MapSstElement Decode fail
\n
"
,
...
...
db/db_iter.cc
浏览文件 @
fbd60f9b
...
...
@@ -183,7 +183,7 @@ class DBIter final: public Iterator {
status_
=
s
;
return
Slice
::
Invalid
();
}
return
value_
.
get_
slice
();
return
value_
.
slice
();
}
virtual
Status
status
()
const
override
{
if
(
status_
.
ok
())
{
...
...
db/db_test_util.h
浏览文件 @
fbd60f9b
...
...
@@ -626,7 +626,7 @@ class TestPutOperator : public MergeOperator {
if
(
!
Fetch
(
*
merge_in
.
existing_value
,
&
merge_out
->
new_value
))
{
return
true
;
}
if
(
merge_in
.
existing_value
->
get_
slice
()
==
"corrupted"
)
{
if
(
merge_in
.
existing_value
->
slice
()
==
"corrupted"
)
{
return
false
;
}
}
...
...
@@ -634,7 +634,7 @@ class TestPutOperator : public MergeOperator {
if
(
!
Fetch
(
value
,
&
merge_out
->
new_value
))
{
return
true
;
}
if
(
value
.
get_
slice
()
==
"corrupted"
)
{
if
(
value
.
slice
()
==
"corrupted"
)
{
return
false
;
}
}
...
...
db/map_builder.cc
浏览文件 @
fbd60f9b
...
...
@@ -356,7 +356,7 @@ Status LoadRangeWithDepend(std::vector<RangeWithDepend>& ranges,
if
(
!
s
.
ok
())
{
return
s
;
}
if
(
!
map_element
.
Decode
(
iter
->
key
(),
value
.
get_
slice
()))
{
if
(
!
map_element
.
Decode
(
iter
->
key
(),
value
.
slice
()))
{
return
Status
::
Corruption
(
"Map sst invalid key or value"
);
}
ranges
.
emplace_back
(
map_element
);
...
...
db/memtable.cc
浏览文件 @
fbd60f9b
...
...
@@ -393,12 +393,12 @@ class MemTableTombstoneIterator : public MemTableIteratorBase<Slice> {
assert
(
valid_
);
LazyBuffer
v
=
iter_
->
value
();
assert
(
v
.
fetch
().
ok
());
return
v
.
fetch
().
ok
()
?
v
.
get_
slice
()
:
Slice
::
Invalid
();
return
v
.
fetch
().
ok
()
?
v
.
slice
()
:
Slice
::
Invalid
();
}
};
class
MemTableIterator
:
public
MemTableIteratorBase
<
LazyBuffer
>
,
public
LazyBuffer
Controller
{
:
public
MemTableIteratorBase
<
LazyBuffer
>
,
public
LazyBuffer
State
{
using
Base
=
MemTableIteratorBase
<
LazyBuffer
>
;
using
Base
::
iter_
;
using
Base
::
valid_
;
...
...
@@ -411,7 +411,7 @@ class MemTableIterator
void
pin_buffer
(
LazyBuffer
*
buffer
)
const
override
{
if
(
!
value_pinned_
||
!
iter_
->
IsValuePinned
())
{
LazyBuffer
Controller
::
pin_buffer
(
buffer
);
LazyBuffer
State
::
pin_buffer
(
buffer
);
}
else
{
*
buffer
=
iter_
->
value
();
buffer
->
pin
();
...
...
db/memtablerep.cc
浏览文件 @
fbd60f9b
...
...
@@ -39,15 +39,15 @@ void MemTableRep::EncodeKeyValue(const Slice& key, const Slice& value,
LazyBuffer
MemTableRep
::
DecodeToLazyValue
(
const
char
*
key
)
{
struct
SliceControllerImpl
:
public
LazyBuffer
Controller
{
struct
SliceControllerImpl
:
public
LazyBuffer
State
{
void
destroy
(
LazyBuffer
*
/*buffer*/
)
const
override
{}
void
pin_buffer
(
LazyBuffer
*
/*buffer*/
)
const
override
{}
Status
fetch_buffer
(
LazyBuffer
*
buffer
)
const
override
{
auto
rep
=
get_rep
(
buffer
);
const
char
*
k
=
reinterpret_cast
<
const
char
*>
(
rep
->
data
[
0
]);
auto
context
=
get_context
(
buffer
);
const
char
*
k
=
reinterpret_cast
<
const
char
*>
(
context
->
data
[
0
]);
Slice
key_slice
=
GetLengthPrefixedSlice
(
k
);
set_slice
(
buffer
,
GetLengthPrefixedSlice
(
key_slice
.
data
()
+
key_slice
.
size
()));
...
...
db/merge_operator.cc
浏览文件 @
fbd60f9b
...
...
@@ -28,7 +28,7 @@ bool MergeOperator::FullMergeV2(const MergeOperationInput& merge_in,
if
(
!
Fetch
(
*
merge_in
.
existing_value
,
&
merge_out
->
new_value
))
{
return
true
;
}
existing_value
=
&
merge_in
.
existing_value
->
get_
slice
();
existing_value
=
&
merge_in
.
existing_value
->
slice
();
}
return
FullMerge
(
merge_in
.
key
,
existing_value
,
operand_list_str
,
merge_out
->
new_value
.
trans_to_string
(),
merge_in
.
logger
);
...
...
@@ -75,8 +75,8 @@ bool AssociativeMergeOperator::FullMergeV2(
}
temp_value
.
clear
();
const
Slice
*
existing_value_slice
=
existing_value
==
nullptr
?
nullptr
:
&
existing_value
->
get_
slice
();
if
(
!
Merge
(
merge_in
.
key
,
existing_value_slice
,
operand
.
get_
slice
(),
existing_value
==
nullptr
?
nullptr
:
&
existing_value
->
slice
();
if
(
!
Merge
(
merge_in
.
key
,
existing_value_slice
,
operand
.
slice
(),
temp_value
.
trans_to_string
(),
merge_in
.
logger
))
{
return
false
;
}
...
...
@@ -98,7 +98,7 @@ bool AssociativeMergeOperator::PartialMerge(const Slice& key,
if
(
!
Fetch
(
left_operand
,
new_value
)
||
!
Fetch
(
right_operand
,
new_value
))
{
return
true
;
}
return
Merge
(
key
,
&
left_operand
.
get_slice
(),
right_operand
.
get_
slice
(),
return
Merge
(
key
,
&
left_operand
.
slice
(),
right_operand
.
slice
(),
new_value
->
trans_to_string
(),
logger
);
}
...
...
db/table_cache.cc
浏览文件 @
fbd60f9b
...
...
@@ -391,7 +391,7 @@ Status TableCache::Get(const ReadOptions& options,
}
// Manual inline MapSstElement::Decode
const
char
*
err_msg
=
"Map sst invalid link_value"
;
Slice
map_input
=
map_value
.
get_
slice
();
Slice
map_input
=
map_value
.
slice
();
Slice
smallest_key
;
uint64_t
link_count
;
uint64_t
flags
;
...
...
db/version_set.cc
浏览文件 @
fbd60f9b
...
...
@@ -1203,11 +1203,12 @@ Version::Version(ColumnFamilyData* column_family_data, VersionSet* vset,
version_number_
(
version_number
)
{}
Status
Version
::
fetch_buffer
(
LazyBuffer
*
buffer
)
const
{
auto
rep
=
get_rep
(
buffer
);
Slice
user_key
(
reinterpret_cast
<
const
char
*>
(
rep
->
data
[
0
]),
rep
->
data
[
1
]);
uint64_t
sequence
=
rep
->
data
[
2
];
auto
context
=
get_context
(
buffer
);
Slice
user_key
(
reinterpret_cast
<
const
char
*>
(
context
->
data
[
0
]),
context
->
data
[
1
]);
uint64_t
sequence
=
context
->
data
[
2
];
const
FileMetaData
*
file_metadata
=
reinterpret_cast
<
FileMetaData
*>
(
rep
->
data
[
3
]);
reinterpret_cast
<
FileMetaData
*>
(
context
->
data
[
3
]);
bool
value_found
=
false
;
SequenceNumber
context_seq
;
GetContext
get_context
(
cfd_
->
internal_comparator
().
user_comparator
(),
nullptr
,
...
...
@@ -1246,7 +1247,7 @@ void Version::TransToCombined(const Slice& user_key, uint64_t sequence,
value
.
reset
(
std
::
move
(
s
));
return
;
}
uint64_t
file_number
=
SeparateHelper
::
DecodeFileNumber
(
value
.
get_
slice
());
uint64_t
file_number
=
SeparateHelper
::
DecodeFileNumber
(
value
.
slice
());
auto
&
dependence_map
=
storage_info_
.
dependence_map
();
auto
find
=
dependence_map
.
find
(
file_number
);
if
(
find
==
dependence_map
.
end
())
{
...
...
db/version_set.h
浏览文件 @
fbd60f9b
...
...
@@ -572,7 +572,7 @@ class VersionStorageInfo {
void
operator
=
(
const
VersionStorageInfo
&
)
=
delete
;
};
class
Version
:
public
SeparateHelper
,
private
LazyBuffer
Controller
{
class
Version
:
public
SeparateHelper
,
private
LazyBuffer
State
{
public:
// Append to *iters a sequence of iterators that will
// yield the contents of this Version when merged together.
...
...
db/write_batch.cc
浏览文件 @
fbd60f9b
...
...
@@ -1524,7 +1524,7 @@ class MemTableInserter : public WriteBatch::Handler {
auto
s
=
new_value
.
fetch
();
if
(
s
.
ok
())
{
bool
mem_res
=
mem
->
Add
(
sequence_
,
kTypeValue
,
key
,
new_value
.
get_
slice
());
mem
->
Add
(
sequence_
,
kTypeValue
,
key
,
new_value
.
slice
());
if
(
UNLIKELY
(
!
mem_res
))
{
assert
(
seq_per_batch_
);
ret_status
=
Status
::
TryAgain
(
"key+seq exists"
);
...
...
include/rocksdb/compaction_filter.h
浏览文件 @
fbd60f9b
...
...
@@ -167,7 +167,7 @@ class CompactionFilter {
switch
(
value_type
)
{
case
ValueType
::
kValue
:
{
bool
value_changed
=
false
;
bool
rv
=
Filter
(
level
,
key
,
existing_value
.
get_
slice
(),
bool
rv
=
Filter
(
level
,
key
,
existing_value
.
slice
(),
new_value
->
trans_to_string
(),
&
value_changed
);
if
(
rv
)
{
return
Decision
::
kRemove
;
...
...
@@ -175,7 +175,7 @@ class CompactionFilter {
return
value_changed
?
Decision
::
kChangeValue
:
Decision
::
kKeep
;
}
case
ValueType
::
kMergeOperand
:
{
bool
rv
=
FilterMergeOperand
(
level
,
key
,
existing_value
.
get_
slice
());
bool
rv
=
FilterMergeOperand
(
level
,
key
,
existing_value
.
slice
());
return
rv
?
Decision
::
kRemove
:
Decision
::
kKeep
;
}
}
...
...
include/rocksdb/lazy_buffer.h
浏览文件 @
fbd60f9b
...
...
@@ -18,10 +18,12 @@
namespace
rocksdb
{
// State pattern
class
LazyBuffer
;
class
LazyBuffer
Edito
r
;
class
LazyBuffer
Builde
r
;
struct
LazyBuffer
Rep
{
struct
LazyBuffer
Context
{
uint64_t
data
[
4
];
};
...
...
@@ -30,9 +32,9 @@ struct LazyBufferCustomizeBuffer {
void
*
(
*
uninitialized_resize
)(
void
*
handle
,
size_t
size
);
};
class
LazyBuffer
Controller
{
class
LazyBuffer
State
{
public:
virtual
~
LazyBuffer
Controller
()
=
default
;
virtual
~
LazyBuffer
State
()
=
default
;
// Release resource
virtual
void
destroy
(
LazyBuffer
*
buffer
)
const
=
0
;
...
...
@@ -46,7 +48,7 @@ class LazyBufferController {
// Save error into buffer
virtual
void
assign_error
(
LazyBuffer
*
buffer
,
Status
&&
status
)
const
;
// Pin the buffer, turn the
controller
into editable
// Pin the buffer, turn the
state
into editable
virtual
void
pin_buffer
(
LazyBuffer
*
buffer
)
const
;
// Fetch buffer and dump to target, the buffer may be destroyed
...
...
@@ -55,39 +57,39 @@ class LazyBufferController {
// Fetch buffer
virtual
Status
fetch_buffer
(
LazyBuffer
*
buffer
)
const
=
0
;
// Use LazyBuffer
Rep
as local storage
// Use LazyBuffer
Context
as local storage
// data -> 32 bytes
static
const
LazyBuffer
Controller
*
light_controller
();
static
const
LazyBuffer
State
*
light_state
();
// Use LazyBuffer
Rep
as buffer
// Use LazyBuffer
Context
as buffer
// data[0] -> handle
// data[1] -> uninitialized_resize call
// data[2 - 3] -> Status
static
const
LazyBuffer
Controller
*
buffer_controller
();
static
const
LazyBuffer
State
*
buffer_state
();
// Use LazyBuffer
Rep
as string holder
// Use LazyBuffer
Context
as string holder
// data[0] -> string ptr
// data[1] -> is owner
// data[2 - 3] -> Status
static
const
LazyBuffer
Controller
*
string_controller
();
static
const
LazyBuffer
State
*
string_state
();
// Use LazyBuffer
Rep
as LazuBuffer reference
// Use LazyBuffer
Context
as LazuBuffer reference
// data[0] -> ptr to LazyBuffer
static
const
LazyBuffer
Controller
*
reference_controller
();
static
const
LazyBuffer
State
*
reference_state
();
// Use LazyBuffer
Rep
as Cleanable
//
rep
-> Cleanable
static
const
LazyBuffer
Controller
*
cleanable_controller
();
// Use LazyBuffer
Context
as Cleanable
//
context
-> Cleanable
static
const
LazyBuffer
State
*
cleanable_state
();
// Set buffer->slice_ = slice
static
void
set_slice
(
LazyBuffer
*
buffer
,
const
Slice
&
slice
);
// Get &buffer->
rep
_
static
LazyBuffer
Rep
*
get_rep
(
LazyBuffer
*
buffer
);
// Get &buffer->
context
_
static
LazyBuffer
Context
*
get_context
(
LazyBuffer
*
buffer
);
};
class
LazyBuffer
{
friend
LazyBuffer
Controller
;
friend
LazyBuffer
State
;
protected:
union
{
struct
{
...
...
@@ -96,18 +98,18 @@ class LazyBuffer {
};
Slice
slice_
=
Slice
();
};
const
LazyBuffer
Controller
*
controller
_
;
LazyBuffer
Rep
rep
_
;
const
LazyBuffer
State
*
state
_
;
LazyBuffer
Context
context
_
;
uint64_t
file_number_
;
// Call LazyBuffer
Controller::destroy if controller
_ not nullptr
// Call LazyBuffer
State::destroy if state
_ not nullptr
void
destroy
();
// Call LazyBuffer
Controller
::assign_error if _status not ok
// Call LazyBuffer
State
::assign_error if _status not ok
void
assign_error
(
Status
&&
_status
);
// Fix light_
controller
local storage
void
fix_light_
controller
(
const
LazyBuffer
&
other
);
// Fix light_
state
local storage
void
fix_light_
state
(
const
LazyBuffer
&
other
);
public:
...
...
@@ -142,9 +144,9 @@ public:
LazyBuffer
(
const
Slice
&
_slice
,
Cleanable
&&
_cleanable
,
uint64_t
_file_number
=
uint64_t
(
-
1
))
noexcept
;
// Init from customize
controller
LazyBuffer
(
const
LazyBuffer
Controller
*
_controller
,
const
LazyBufferRep
&
_rep
,
const
Slice
&
_slice
=
Slice
::
Invalid
(),
// Init from customize
state
LazyBuffer
(
const
LazyBuffer
State
*
_state
,
const
LazyBufferContext
&
_context
,
const
Slice
&
_slice
=
Slice
::
Invalid
(),
uint64_t
_file_number
=
uint64_t
(
-
1
))
noexcept
;
~
LazyBuffer
()
{
...
...
@@ -162,7 +164,7 @@ public:
// Get inner slice
// REQUIRES: valid()
const
Slice
&
get_
slice
()
const
{
assert
(
valid
());
return
slice_
;
}
const
Slice
&
slice
()
const
{
assert
(
valid
());
return
slice_
;
}
// Return a pointer to the beginning of the referenced data
// REQUIRES: valid()
...
...
@@ -249,16 +251,16 @@ public:
void
reset
(
const
Slice
&
_slice
,
Cleanable
&&
_cleanable
,
uint64_t
_file_number
=
uint64_t
(
-
1
));
// Reset to customize
controller
void
reset
(
const
LazyBuffer
Controller
*
_controller
,
const
LazyBufferRep
&
_rep
,
// Reset to customize
state
void
reset
(
const
LazyBuffer
State
*
_state
,
const
LazyBufferContext
&
_context
,
const
Slice
&
_slice
=
Slice
::
Invalid
(),
uint64_t
_file_number
=
uint64_t
(
-
1
));
// Fetch source and copy it
void
assign
(
const
LazyBuffer
&
_source
);
// Trans to editable buffer and get
edito
r
LazyBuffer
Editor
*
get_edito
r
();
// Trans to editable buffer and get
builde
r
LazyBuffer
Builder
*
get_builde
r
();
// Trans buffer to string for modification
std
::
string
*
trans_to_string
();
...
...
@@ -266,7 +268,7 @@ public:
// Return the certain file number of SST, -1 for unknown
uint64_t
file_number
()
const
{
return
file_number_
;
}
// Pin this buffer, turn the
controller
into editable
// Pin this buffer, turn the
state
into editable
void
pin
();
// Dump buffer to customize buffer
...
...
@@ -282,13 +284,13 @@ public:
Status
fetch
()
const
;
// For test
const
LazyBuffer
Controller
*
TEST_controller
()
const
{
return
controller
_
;
}
const
LazyBuffer
State
*
TEST_state
()
const
{
return
state
_
;
}
// For test
const
LazyBuffer
Rep
*
TEST_rep
()
const
{
return
&
rep
_
;
}
const
LazyBuffer
Context
*
TEST_context
()
const
{
return
&
context
_
;
}
};
class
LazyBuffer
Edito
r
:
private
LazyBuffer
{
class
LazyBuffer
Builde
r
:
private
LazyBuffer
{
public:
char
*
data
()
const
{
return
data_
;
}
using
LazyBuffer
::
size
;
...
...
@@ -303,85 +305,85 @@ class LazyBufferEditor : private LazyBuffer {
bool
uninitialized_resize
(
size_t
_size
);
};
inline
void
LazyBufferController
::
set_slice
(
LazyBuffer
*
buffer
,
const
Slice
&
slice
)
{
inline
void
LazyBufferState
::
set_slice
(
LazyBuffer
*
buffer
,
const
Slice
&
slice
)
{
buffer
->
slice_
=
slice
;
}
inline
LazyBuffer
Rep
*
LazyBufferController
::
get_rep
(
LazyBuffer
*
buffer
)
{
return
&
buffer
->
rep
_
;
inline
LazyBuffer
Context
*
LazyBufferState
::
get_context
(
LazyBuffer
*
buffer
)
{
return
&
buffer
->
context
_
;
}
inline
LazyBuffer
::
LazyBuffer
()
noexcept
:
controller_
(
LazyBufferController
::
light_controller
()),
rep
_
{},
:
state_
(
LazyBufferState
::
light_state
()),
context
_
{},
file_number_
(
uint64_t
(
-
1
))
{}
inline
LazyBuffer
::
LazyBuffer
(
LazyBuffer
&&
_buffer
)
noexcept
:
slice_
(
_buffer
.
slice_
),
controller_
(
_buffer
.
controller
_
),
rep_
(
_buffer
.
rep
_
),
state_
(
_buffer
.
state
_
),
context_
(
_buffer
.
context
_
),
file_number_
(
_buffer
.
file_number_
)
{
if
(
controller_
==
LazyBufferController
::
light_controller
()
&&
_buffer
.
size_
<=
sizeof
(
LazyBuffer
Rep
))
{
fix_light_
controller
(
_buffer
);
if
(
state_
==
LazyBufferState
::
light_state
()
&&
_buffer
.
size_
<=
sizeof
(
LazyBuffer
Context
))
{
fix_light_
state
(
_buffer
);
}
_buffer
.
slice_
=
Slice
::
Invalid
();
_buffer
.
controller
_
=
nullptr
;
_buffer
.
state
_
=
nullptr
;
}
inline
LazyBuffer
::
LazyBuffer
(
const
Slice
&
_slice
,
bool
_copy
,
uint64_t
_file_number
)
:
slice_
(
_slice
),
controller_
(
LazyBufferController
::
light_controller
()),
rep
_
{},
state_
(
LazyBufferState
::
light_state
()),
context
_
{},
file_number_
(
_file_number
)
{
assert
(
_slice
.
valid
());
if
(
_copy
)
{
controller
_
->
assign_slice
(
this
,
_slice
);
state
_
->
assign_slice
(
this
,
_slice
);
}
}
inline
LazyBuffer
::
LazyBuffer
(
const
Slice
&
_slice
,
Cleanable
&&
_cleanable
,
uint64_t
_file_number
)
noexcept
:
slice_
(
_slice
),
controller_
(
LazyBufferController
::
cleanable_controller
()),
rep
_
{},
state_
(
LazyBufferState
::
cleanable_state
()),
context
_
{},
file_number_
(
_file_number
)
{
assert
(
_slice
.
valid
());
static_assert
(
sizeof
_cleanable
==
sizeof
rep
_
,
""
);
static_assert
(
alignof
(
Cleanable
)
==
alignof
(
LazyBuffer
Rep
),
""
);
::
new
(
&
rep
_
)
Cleanable
(
std
::
move
(
_cleanable
));
static_assert
(
sizeof
_cleanable
==
sizeof
context
_
,
""
);
static_assert
(
alignof
(
Cleanable
)
==
alignof
(
LazyBuffer
Context
),
""
);
::
new
(
&
context
_
)
Cleanable
(
std
::
move
(
_cleanable
));
}
inline
LazyBuffer
::
LazyBuffer
(
const
LazyBufferController
*
_controller
,
const
LazyBufferRep
&
_rep
,
const
Slice
&
_slice
,
inline
LazyBuffer
::
LazyBuffer
(
const
LazyBufferState
*
_state
,
const
LazyBufferContext
&
_context
,
const
Slice
&
_slice
,
uint64_t
_file_number
)
noexcept
:
slice_
(
_slice
),
controller_
(
_controller
),
rep_
(
_rep
),
state_
(
_state
),
context_
(
_context
),
file_number_
(
_file_number
)
{
assert
(
_
controller
!=
nullptr
);
assert
(
_
state
!=
nullptr
);
}
inline
void
LazyBuffer
::
destroy
()
{
if
(
controller
_
!=
nullptr
)
{
controller
_
->
destroy
(
this
);
if
(
state
_
!=
nullptr
)
{
state
_
->
destroy
(
this
);
}
}
inline
void
LazyBuffer
::
assign_error
(
Status
&&
_status
)
{
if
(
_status
.
ok
())
{
controller
_
->
assign_slice
(
this
,
Slice
());
state
_
->
assign_slice
(
this
,
Slice
());
}
else
{
controller
_
->
assign_error
(
this
,
std
::
move
(
_status
));
state
_
->
assign_error
(
this
,
std
::
move
(
_status
));
assert
(
!
slice_
.
valid
());
}
file_number_
=
uint64_t
(
-
1
);
}
inline
void
LazyBuffer
::
clear
()
{
controller
_
->
assign_slice
(
this
,
Slice
());
state
_
->
assign_slice
(
this
,
Slice
());
assert
(
size_
==
0
);
file_number_
=
uint64_t
(
-
1
);
}
...
...
@@ -390,15 +392,15 @@ inline void LazyBuffer::reset(LazyBuffer&& _buffer) {
if
(
this
!=
&
_buffer
)
{
destroy
();
slice_
=
_buffer
.
slice_
;
controller_
=
_buffer
.
controller
_
;
rep_
=
_buffer
.
rep
_
;
state_
=
_buffer
.
state
_
;
context_
=
_buffer
.
context
_
;
file_number_
=
_buffer
.
file_number_
;
if
(
controller_
==
LazyBufferController
::
light_controller
()
&&
_buffer
.
size_
<=
sizeof
(
LazyBuffer
Rep
))
{
fix_light_
controller
(
_buffer
);
if
(
state_
==
LazyBufferState
::
light_state
()
&&
_buffer
.
size_
<=
sizeof
(
LazyBuffer
Context
))
{
fix_light_
state
(
_buffer
);
}
_buffer
.
slice_
=
Slice
::
Invalid
();
_buffer
.
controller
_
=
nullptr
;
_buffer
.
state
_
=
nullptr
;
}
}
...
...
@@ -406,13 +408,13 @@ inline void LazyBuffer::reset(const Slice& _slice, bool _copy,
uint64_t
_file_number
)
{
assert
(
_slice
.
valid
());
if
(
_copy
)
{
controller
_
->
assign_slice
(
this
,
_slice
);
state
_
->
assign_slice
(
this
,
_slice
);
assert
(
slice_
==
_slice
);
}
else
{
destroy
();
slice_
=
_slice
;
controller_
=
LazyBufferController
::
light_controller
();
rep
_
=
{};
state_
=
LazyBufferState
::
light_state
();
context
_
=
{};
}
file_number_
=
_file_number
;
}
...
...
@@ -421,40 +423,40 @@ inline void LazyBuffer::reset(const Slice& _slice, Cleanable&& _cleanable,
uint64_t
_file_number
)
{
assert
(
_slice
.
valid
());
destroy
();
controller_
=
LazyBufferController
::
cleanable_controller
();
state_
=
LazyBufferState
::
cleanable_state
();
slice_
=
_slice
;
new
(
&
rep
_
)
Cleanable
(
std
::
move
(
_cleanable
));
new
(
&
context
_
)
Cleanable
(
std
::
move
(
_cleanable
));
file_number_
=
_file_number
;
}
inline
void
LazyBuffer
::
reset
(
const
LazyBuffer
Controller
*
_controller
,
const
LazyBuffer
Rep
&
_rep
,
const
Slice
&
_slice
,
uint64_t
_file_number
)
{
assert
(
_
controller
!=
nullptr
);
inline
void
LazyBuffer
::
reset
(
const
LazyBuffer
State
*
_state
,
const
LazyBuffer
Context
&
_context
,
const
Slice
&
_slice
,
uint64_t
_file_number
)
{
assert
(
_
state
!=
nullptr
);
destroy
();
slice_
=
_slice
;
controller_
=
_controller
;
rep_
=
_rep
;
state_
=
_state
;
context_
=
_context
;
file_number_
=
_file_number
;
}
inline
void
LazyBuffer
::
pin
()
{
assert
(
controller
_
!=
nullptr
);
return
controller
_
->
pin_buffer
(
this
);
assert
(
state
_
!=
nullptr
);
return
state
_
->
pin_buffer
(
this
);
}
inline
Status
LazyBuffer
::
dump
(
LazyBuffer
&
_target
)
&&
{
assert
(
controller
_
!=
nullptr
);
inline
Status
LazyBuffer
::
dump
(
LazyBuffer
&
_target
)
&&
{
assert
(
state
_
!=
nullptr
);
assert
(
this
!=
&
_target
);
return
controller
_
->
dump_buffer
(
this
,
&
_target
);
return
state
_
->
dump_buffer
(
this
,
&
_target
);
}
inline
Status
LazyBuffer
::
fetch
()
const
{
assert
(
controller
_
!=
nullptr
);
assert
(
state
_
!=
nullptr
);
if
(
slice_
.
valid
())
{
return
Status
::
OK
();
}
return
controller
_
->
fetch_buffer
(
const_cast
<
LazyBuffer
*>
(
this
));
return
state
_
->
fetch_buffer
(
const_cast
<
LazyBuffer
*>
(
this
));
}
// make a slice reference
...
...
memtable/terark_zip_memtable.cc
浏览文件 @
fbd60f9b
...
...
@@ -124,7 +124,7 @@ void PatriciaTrieRep::Get(
valvec
<
char
>
buffer
;
};
class
Controller
:
public
LazyBuffer
Controller
{
class
Controller
:
public
LazyBuffer
State
{
public:
virtual
void
destroy
(
LazyBuffer
*
/*buffer*/
)
const
override
{}
...
...
memtable/terark_zip_memtable.h
浏览文件 @
fbd60f9b
...
...
@@ -140,7 +140,7 @@ public:
template
<
bool
heap_mode
>
class
PatriciaRepIterator
:
public
MemTableRep
::
Iterator
,
public
LazyBuffer
Controller
,
public
LazyBuffer
State
,
boost
::
noncopyable
{
typedef
terark
::
Patricia
::
ReaderToken
token_t
;
...
...
@@ -228,17 +228,17 @@ public:
virtual
~
PatriciaRepIterator
();
// LazyBuffer
Controller
override
// LazyBuffer
State
override
virtual
void
destroy
(
LazyBuffer
*
/*buffer*/
)
const
override
{}
// LazyBuffer
Controller
override
// LazyBuffer
State
override
virtual
void
pin_buffer
(
LazyBuffer
*
buffer
)
const
override
{
if
(
!
buffer
->
valid
())
{
buffer
->
reset
(
GetValue
());
}
}
// LazyBuffer
Controller
override
// LazyBuffer
State
override
Status
fetch_buffer
(
LazyBuffer
*
buffer
)
const
override
{
set_slice
(
buffer
,
GetValue
());
return
Status
::
OK
();
...
...
table/block_based_table_builder.cc
浏览文件 @
fbd60f9b
...
...
@@ -425,7 +425,7 @@ void BlockBasedTableBuilder::Add(const Slice& key,
r
->
status
=
s
;
return
;
}
const
Slice
&
value
=
lazy_value
.
get_
slice
();
const
Slice
&
value
=
lazy_value
.
slice
();
ValueType
value_type
=
ExtractValueType
(
key
);
if
(
r
->
ignore_key_type
||
IsValueType
(
value_type
))
{
if
(
r
->
props
.
num_entries
>
0
)
{
...
...
table/block_based_table_reader.h
浏览文件 @
fbd60f9b
...
...
@@ -680,7 +680,7 @@ class BlockBasedTableIterator
template
<
>
class
BlockBasedTableIterator
<
DataBlockIter
,
LazyBuffer
>
:
public
BlockBasedTableIteratorBase
<
DataBlockIter
,
LazyBuffer
>
,
public
LazyBuffer
Controller
{
public
LazyBuffer
State
{
using
Base
=
BlockBasedTableIteratorBase
<
DataBlockIter
,
LazyBuffer
>
;
using
Base
::
block_iter_
;
using
Base
::
icomp_
;
...
...
table/cuckoo_table_builder.cc
浏览文件 @
fbd60f9b
...
...
@@ -88,7 +88,7 @@ void CuckooTableBuilder::Add(const Slice& key, const LazyBuffer& lazy_value) {
status_
=
s
;
return
;
}
const
Slice
&
value
=
lazy_value
.
get_
slice
();
const
Slice
&
value
=
lazy_value
.
slice
();
if
(
num_entries_
>=
kMaxVectorIdx
-
1
)
{
status_
=
Status
::
NotSupported
(
"Number of keys in a file must be < 2^32-1"
);
return
;
...
...
table/plain_table_builder.cc
浏览文件 @
fbd60f9b
...
...
@@ -122,7 +122,7 @@ void PlainTableBuilder::Add(const Slice& key, const LazyBuffer& lazy_value) {
status_
=
s
;
return
;
}
const
Slice
&
value
=
lazy_value
.
get_
slice
();
const
Slice
&
value
=
lazy_value
.
slice
();
// temp buffer for metadata bytes between key and value.
char
meta_bytes_buf
[
6
];
size_t
meta_bytes_buf_size
=
0
;
...
...
table/terark_zip_table_builder.cc
浏览文件 @
fbd60f9b
...
...
@@ -382,7 +382,7 @@ void TerarkZipTableBuilder::Add(const Slice& key,
status_
=
s
;
return
;
}
const
Slice
&
value
=
lazy_value
.
get_
slice
();
const
Slice
&
value
=
lazy_value
.
slice
();
if
(
table_options_
.
debugLevel
==
3
)
{
rocksdb
::
ParsedInternalKey
ikey
;
rocksdb
::
ParseInternalKey
(
key
,
&
ikey
);
...
...
@@ -1495,7 +1495,7 @@ TerarkZipTableBuilder::BuilderWriteValues(KeyValueStatus& kvs, std::function<voi
return
s
;
}
curKey
=
second_pass_iter_
->
key
();
curVal
=
lazy_value
.
get_
slice
();
curVal
=
lazy_value
.
slice
();
TERARK_RT_assert
(
ParseInternalKey
(
curKey
,
&
pIKey
),
std
::
logic_error
);
if
(
debugDumpKeyValue
)
{
dumpKeyValueFunc
(
pIKey
,
curVal
);
...
...
@@ -1553,7 +1553,7 @@ TerarkZipTableBuilder::BuilderWriteValues(KeyValueStatus& kvs, std::function<voi
return
false
;
}
curKey
=
second_pass_iter_
->
key
();
curVal
=
lazy_value
.
get_
slice
();
curVal
=
lazy_value
.
slice
();
TERARK_RT_assert
(
ParseInternalKey
(
curKey
,
&
pIKey
),
std
::
logic_error
);
if
(
debugDumpKeyValue
)
{
dumpKeyValueFunc
(
pIKey
,
curVal
);
...
...
table/terark_zip_table_reader.cc
浏览文件 @
fbd60f9b
...
...
@@ -238,7 +238,7 @@ public:
template
<
bool
reverse
>
class
TerarkZipTableIterator
:
public
TerarkZipTableIndexIterator
,
public
LazyBuffer
Controller
{
public
LazyBuffer
State
{
protected:
const
TableReaderOptions
*
table_reader_options_
;
SequenceNumber
global_seqno_
;
...
...
table/two_level_iterator.cc
浏览文件 @
fbd60f9b
...
...
@@ -255,7 +255,7 @@ class MapSstIterator final : public InternalIterator {
if
(
!
status_
.
ok
())
{
return
kInitFirstIterInvalid
;
}
Slice
map_input
=
first_level_value_
.
get_
slice
();
Slice
map_input
=
first_level_value_
.
slice
();
link_
.
clear
();
largest_key_
=
first_level_iter_
->
key
();
uint64_t
flags
;
...
...
util/lazy_buffer.cc
浏览文件 @
fbd60f9b
此差异已折叠。
点击以展开。
util/lazy_buffer_test.cc
浏览文件 @
fbd60f9b
...
...
@@ -20,55 +20,51 @@ TEST_F(LazyBufferTest, Basic) {
LazyBuffer
empty
;
ASSERT_OK
(
empty
.
fetch
());
ASSERT_EQ
(
empty
.
get_
slice
(),
""
);
ASSERT_EQ
(
empty
.
slice
(),
""
);
LazyBuffer
abc
(
"abc"
);
ASSERT_OK
(
abc
.
fetch
());
ASSERT_EQ
(
abc
.
get_
slice
(),
"abc"
);
ASSERT_EQ
(
abc
.
slice
(),
"abc"
);
LazyBuffer
abc2
(
std
::
move
(
abc
));
ASSERT_OK
(
abc2
.
fetch
());
ASSERT_EQ
(
abc2
.
get_
slice
(),
"abc"
);
ASSERT_EQ
(
abc2
.
slice
(),
"abc"
);
LazyBuffer
abc3
=
std
::
move
(
abc2
);
ASSERT_OK
(
abc3
.
fetch
());
ASSERT_EQ
(
abc3
.
get_
slice
(),
"abc"
);
ASSERT_EQ
(
abc3
.
slice
(),
"abc"
);
}
TEST_F
(
LazyBufferTest
,
LightColtroller
)
{
LazyBuffer
buffer
;
ASSERT_EQ
(
buffer
.
TEST_controller
(),
LazyBufferController
::
light_controller
());
ASSERT_EQ
(
buffer
.
TEST_state
(),
LazyBufferState
::
light_state
());
std
::
string
string
(
'a'
,
33
);
buffer
.
reset
(
string
,
false
);
ASSERT_EQ
(
buffer
.
TEST_controller
(),
LazyBufferController
::
light_controller
());
ASSERT_EQ
(
buffer
.
TEST_state
(),
LazyBufferState
::
light_state
());
for
(
auto
&
c
:
string
)
{
c
=
'b'
;
};
ASSERT_OK
(
buffer
.
fetch
());
ASSERT_EQ
(
buffer
.
get_
slice
(),
string
);
ASSERT_EQ
(
buffer
.
slice
(),
string
);
buffer
.
reset
(
Slice
(
string
.
data
(),
32
),
true
);
ASSERT_EQ
(
buffer
.
TEST_controller
(),
LazyBufferController
::
light_controller
());
ASSERT_EQ
(
buffer
.
TEST_state
(),
LazyBufferState
::
light_state
());
buffer
.
reset
(
string
,
true
);
ASSERT_EQ
(
buffer
.
TEST_controller
(),
LazyBufferController
::
buffer_controller
());
ASSERT_EQ
(
buffer
.
TEST_state
(),
LazyBufferState
::
buffer_state
());
string
=
"abc"
;
buffer
.
reset
(
string
);
for
(
auto
&
c
:
string
)
{
c
=
'a'
;
};
ASSERT_OK
(
buffer
.
fetch
());
ASSERT_EQ
(
buffer
.
get_
slice
(),
"aaa"
);
ASSERT_EQ
(
buffer
.
slice
(),
"aaa"
);
buffer
.
reset
(
string
,
true
);
for
(
auto
&
c
:
string
)
{
c
=
'b'
;
};
ASSERT_OK
(
buffer
.
fetch
());
ASSERT_EQ
(
buffer
.
get_
slice
(),
"aaa"
);
ASSERT_EQ
(
buffer
.
slice
(),
"aaa"
);
}
...
...
@@ -76,24 +72,23 @@ TEST_F(LazyBufferTest, LightColtroller) {
TEST_F
(
LazyBufferTest
,
BufferColtroller
)
{
auto
test
=
[](
LazyBuffer
&
b
)
{
auto
editor
=
b
.
get_edito
r
();
ASSERT_FALSE
(
edito
r
->
resize
(
size_t
(
-
1
)));
ASSERT_NOK
(
edito
r
->
fetch
());
ASSERT_TRUE
(
edito
r
->
resize
(
4
));
ASSERT_EQ
(
b
.
get_
slice
(),
Slice
(
"
\0\0\0\0
"
,
4
));
::
memcpy
(
edito
r
->
data
(),
"abcd"
,
4
);
ASSERT_TRUE
(
edito
r
->
resize
(
3
));
ASSERT_EQ
(
b
.
get_
slice
(),
"abc"
);
auto
builder
=
b
.
get_builde
r
();
ASSERT_FALSE
(
builde
r
->
resize
(
size_t
(
-
1
)));
ASSERT_NOK
(
builde
r
->
fetch
());
ASSERT_TRUE
(
builde
r
->
resize
(
4
));
ASSERT_EQ
(
b
.
slice
(),
Slice
(
"
\0\0\0\0
"
,
4
));
::
memcpy
(
builde
r
->
data
(),
"abcd"
,
4
);
ASSERT_TRUE
(
builde
r
->
resize
(
3
));
ASSERT_EQ
(
b
.
slice
(),
"abc"
);
};
LazyBuffer
buffer
(
size_t
(
-
1
));
ASSERT_EQ
(
buffer
.
TEST_controller
(),
LazyBufferController
::
buffer_controller
());
ASSERT_EQ
(
buffer
.
TEST_state
(),
LazyBufferState
::
buffer_state
());
ASSERT_NOK
(
buffer
.
fetch
());
test
(
buffer
);
buffer
.
clear
();
ASSERT_EQ
(
buffer
.
TEST_
controller
(),
LazyBuffer
Controller
::
buffer_controller
());
ASSERT_EQ
(
buffer
.
TEST_
state
(),
LazyBuffer
State
::
buffer_state
());
test
(
buffer
);
buffer
=
LazyBuffer
(
"123"
);
...
...
@@ -121,30 +116,28 @@ TEST_F(LazyBufferTest, StringColtroller) {
std
::
string
string
=
"abc"
;
LazyBuffer
buffer
(
&
string
);
ASSERT_EQ
(
buffer
.
TEST_controller
(),
LazyBufferController
::
string_controller
());
ASSERT_EQ
(
buffer
.
get_slice
(),
"abc"
);
ASSERT_EQ
(
buffer
.
TEST_state
(),
LazyBufferState
::
string_state
());
ASSERT_EQ
(
buffer
.
slice
(),
"abc"
);
buffer
.
reset
(
"aaa"
,
true
);
buffer
.
trans_to_string
()
->
append
(
"bbb"
);
ASSERT_OK
(
buffer
.
fetch
());
ASSERT_EQ
(
buffer
.
get_
slice
(),
"aaabbb"
);
ASSERT_EQ
(
buffer
.
TEST_
rep
()
->
data
[
1
],
0
);
ASSERT_EQ
(
buffer
.
slice
(),
"aaabbb"
);
ASSERT_EQ
(
buffer
.
TEST_
context
()
->
data
[
1
],
0
);
buffer
.
get_editor
()
->
resize
(
buffer
.
size
()
-
1
);
ASSERT_EQ
(
buffer
.
TEST_controller
(),
LazyBufferController
::
string_controller
());
buffer
.
get_builder
()
->
resize
(
buffer
.
size
()
-
1
);
ASSERT_EQ
(
buffer
.
TEST_state
(),
LazyBufferState
::
string_state
());
ASSERT_OK
(
std
::
move
(
buffer
).
dump
(
&
string
));
ASSERT_EQ
(
string
,
"aaabb"
);
buffer
.
reset
(
string
);
buffer
.
trans_to_string
()
->
resize
(
string
.
size
()
-
1
);
ASSERT_OK
(
std
::
move
(
buffer
).
dump
(
&
string
));
ASSERT_EQ
(
buffer
.
TEST_
rep
()
->
data
[
1
],
1
);
ASSERT_EQ
(
buffer
.
TEST_
context
()
->
data
[
1
],
1
);
ASSERT_EQ
(
string
,
"aaab"
);
buffer
.
reset
(
string
);
buffer
.
get_
edito
r
()
->
resize
(
string
.
size
()
-
1
);
buffer
.
get_
builde
r
()
->
resize
(
string
.
size
()
-
1
);
ASSERT_OK
(
std
::
move
(
buffer
).
dump
(
&
string
));
ASSERT_EQ
(
string
,
"aaa"
);
...
...
utilities/merge_operators/max.cc
浏览文件 @
fbd60f9b
...
...
@@ -36,7 +36,7 @@ class MaxOperator : public MergeOperator {
max
=
nullptr
;
return
true
;
}
if
(
max
==
nullptr
||
max
->
get_slice
().
compare
(
op
.
get_
slice
())
<
0
)
{
if
(
max
==
nullptr
||
max
->
slice
().
compare
(
op
.
slice
())
<
0
)
{
max
=
&
op
;
}
}
...
...
@@ -52,7 +52,7 @@ class MaxOperator : public MergeOperator {
if
(
!
Fetch
(
left_operand
,
new_value
)
||
!
Fetch
(
right_operand
,
new_value
))
{
return
true
;
}
if
(
left_operand
.
get_slice
().
compare
(
right_operand
.
get_
slice
())
>=
0
)
{
if
(
left_operand
.
slice
().
compare
(
right_operand
.
slice
())
>=
0
)
{
new_value
->
assign
(
left_operand
);
}
else
{
new_value
->
assign
(
right_operand
);
...
...
@@ -70,8 +70,8 @@ class MaxOperator : public MergeOperator {
if
(
!
Fetch
(
operand
,
new_value
))
{
return
true
;
}
if
(
max
.
get_slice
().
compare
(
operand
.
get_
slice
())
<
0
)
{
max
.
reset
(
operand
.
get_
slice
());
if
(
max
.
slice
().
compare
(
operand
.
slice
())
<
0
)
{
max
.
reset
(
operand
.
slice
());
}
}
...
...
utilities/transactions/write_prepared_txn.cc
浏览文件 @
fbd60f9b
...
...
@@ -263,7 +263,7 @@ Status WritePreparedTxn::RollbackInternal() {
&
callback
);
assert
(
s
.
ok
()
?
lazy_val
.
valid
()
:
s
.
IsNotFound
());
if
(
s
.
ok
())
{
s
=
rollback_batch_
->
Put
(
cf_handle
,
key
,
lazy_val
.
get_
slice
());
s
=
rollback_batch_
->
Put
(
cf_handle
,
key
,
lazy_val
.
slice
());
assert
(
s
.
ok
());
}
else
if
(
s
.
IsNotFound
())
{
// There has been no readable value before txn. By adding a delete we
...
...
utilities/transactions/write_unprepared_txn.cc
浏览文件 @
fbd60f9b
...
...
@@ -386,7 +386,7 @@ Status WriteUnpreparedTxn::RollbackInternal() {
&
callback
);
if
(
s
.
ok
())
{
assert
(
lazy_val
.
valid
());
s
=
rollback_batch
.
Put
(
cf_handle
,
key
,
lazy_val
.
get_
slice
());
s
=
rollback_batch
.
Put
(
cf_handle
,
key
,
lazy_val
.
slice
());
assert
(
s
.
ok
());
}
else
if
(
s
.
IsNotFound
())
{
s
=
rollback_batch
.
Delete
(
cf_handle
,
key
);
...
...
utilities/transactions/write_unprepared_txn_db.cc
浏览文件 @
fbd60f9b
...
...
@@ -78,7 +78,7 @@ Status WriteUnpreparedTxnDB::RollbackRecoveredTransaction(
&
callback
);
assert
(
s
.
ok
()
?
lazy_val
.
valid
()
:
s
.
IsNotFound
());
if
(
s
.
ok
())
{
s
=
rollback_batch_
->
Put
(
cf_handle
,
key
,
lazy_val
.
get_
slice
());
s
=
rollback_batch_
->
Put
(
cf_handle
,
key
,
lazy_val
.
slice
());
assert
(
s
.
ok
());
}
else
if
(
s
.
IsNotFound
())
{
// There has been no readable value before txn. By adding a delete we
...
...
utilities/ttl/db_ttl_impl.cc
浏览文件 @
fbd60f9b
...
...
@@ -181,9 +181,9 @@ Status DBWithTTLImpl::StripTS(LazyBuffer* lazy_val) {
return
Status
::
Corruption
(
"Bad timestamp in key-value"
);
}
// Erasing characters which hold the TS
auto
editor
=
lazy_val
->
get_edito
r
();
if
(
!
edito
r
->
resize
(
size
-
kTSLength
))
{
return
edito
r
->
fetch
();
auto
builder
=
lazy_val
->
get_builde
r
();
if
(
!
builde
r
->
resize
(
size
-
kTSLength
))
{
return
builde
r
->
fetch
();
}
return
st
;
}
...
...
@@ -214,7 +214,7 @@ Status DBWithTTLImpl::Get(const ReadOptions& options,
if
(
!
st
.
ok
())
{
return
st
;
}
st
=
SanityCheckTimestamp
(
value
->
get_
slice
());
st
=
SanityCheckTimestamp
(
value
->
slice
());
if
(
!
st
.
ok
())
{
return
st
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录