@@ -155,21 +155,36 @@ Status DBImpl::Write(const WriteOptions& write_options, WriteBatch* my_batch) {
155
155
}
156
156
if (s.ok ()) {
157
157
s = WriteImpl (write_options, my_batch, /* callback=*/ nullptr ,
158
+ /* user_write_cb=*/ nullptr ,
158
159
/* log_used=*/ nullptr );
159
160
}
160
161
return s;
161
162
}
162
163
164
+ Status DBImpl::WriteWithCallback (const WriteOptions& write_options,
165
+ WriteBatch* my_batch, WriteCallback* callback,
166
+ UserWriteCallback* user_write_cb) {
167
+ Status s;
168
+ if (write_options.protection_bytes_per_key > 0 ) {
169
+ s = WriteBatchInternal::UpdateProtectionInfo (
170
+ my_batch, write_options.protection_bytes_per_key );
171
+ }
172
+ if (s.ok ()) {
173
+ s = WriteImpl (write_options, my_batch, callback, user_write_cb);
174
+ }
175
+ return s;
176
+ }
177
+
163
178
Status DBImpl::WriteWithCallback (const WriteOptions& write_options,
164
179
WriteBatch* my_batch,
165
- WriteCallback* callback ) {
180
+ UserWriteCallback* user_write_cb ) {
166
181
Status s;
167
182
if (write_options.protection_bytes_per_key > 0 ) {
168
183
s = WriteBatchInternal::UpdateProtectionInfo (
169
184
my_batch, write_options.protection_bytes_per_key );
170
185
}
171
186
if (s.ok ()) {
172
- s = WriteImpl (write_options, my_batch, callback, nullptr );
187
+ s = WriteImpl (write_options, my_batch, /* callback= */ nullptr , user_write_cb );
173
188
}
174
189
return s;
175
190
}
@@ -179,9 +194,9 @@ Status DBImpl::WriteWithCallback(const WriteOptions& write_options,
179
194
// published sequence.
180
195
Status DBImpl::WriteImpl (const WriteOptions& write_options,
181
196
WriteBatch* my_batch, WriteCallback* callback,
182
- uint64_t * log_used , uint64_t log_ref ,
183
- bool disable_memtable, uint64_t * seq_used ,
184
- size_t batch_cnt,
197
+ UserWriteCallback* user_write_cb , uint64_t * log_used ,
198
+ uint64_t log_ref, bool disable_memtable ,
199
+ uint64_t * seq_used, size_t batch_cnt,
185
200
PreReleaseCallback* pre_release_callback,
186
201
PostMemTableCallback* post_memtable_callback) {
187
202
assert (!seq_per_batch_ || batch_cnt != 0 );
@@ -288,10 +303,10 @@ Status DBImpl::WriteImpl(const WriteOptions& write_options,
288
303
seq_per_batch_ ? kDoAssignOrder : kDontAssignOrder ;
289
304
// Otherwise it is WAL-only Prepare batches in WriteCommitted policy and
290
305
// they don't consume sequence.
291
- return WriteImplWALOnly (&nonmem_write_thread_, write_options, my_batch,
292
- callback, log_used, log_ref, seq_used, batch_cnt ,
293
- pre_release_callback, assign_order ,
294
- kDontPublishLastSeq , disable_memtable);
306
+ return WriteImplWALOnly (
307
+ &nonmem_write_thread_, write_options, my_batch, callback, user_write_cb ,
308
+ log_used, log_ref, seq_used, batch_cnt, pre_release_callback ,
309
+ assign_order, kDontPublishLastSeq , disable_memtable);
295
310
}
296
311
297
312
if (immutable_db_options_.unordered_write ) {
@@ -303,9 +318,9 @@ Status DBImpl::WriteImpl(const WriteOptions& write_options,
303
318
// Use a write thread to i) optimize for WAL write, ii) publish last
304
319
// sequence in in increasing order, iii) call pre_release_callback serially
305
320
Status status = WriteImplWALOnly (
306
- &write_thread_, write_options, my_batch, callback, log_used, log_ref ,
307
- &seq, sub_batch_cnt, pre_release_callback, kDoAssignOrder ,
308
- kDoPublishLastSeq , disable_memtable);
321
+ &write_thread_, write_options, my_batch, callback, user_write_cb ,
322
+ log_used, log_ref, &seq, sub_batch_cnt, pre_release_callback,
323
+ kDoAssignOrder , kDoPublishLastSeq , disable_memtable);
309
324
TEST_SYNC_POINT (" DBImpl::WriteImpl:UnorderedWriteAfterWriteWAL" );
310
325
if (!status.ok ()) {
311
326
return status;
@@ -322,14 +337,14 @@ Status DBImpl::WriteImpl(const WriteOptions& write_options,
322
337
}
323
338
324
339
if (immutable_db_options_.enable_pipelined_write ) {
325
- return PipelinedWriteImpl (write_options, my_batch, callback, log_used ,
326
- log_ref, disable_memtable, seq_used);
340
+ return PipelinedWriteImpl (write_options, my_batch, callback, user_write_cb ,
341
+ log_used, log_ref, disable_memtable, seq_used);
327
342
}
328
343
329
344
PERF_TIMER_GUARD (write_pre_and_post_process_time);
330
- WriteThread::Writer w (write_options, my_batch, callback, log_ref ,
331
- disable_memtable, batch_cnt, pre_release_callback ,
332
- post_memtable_callback);
345
+ WriteThread::Writer w (write_options, my_batch, callback, user_write_cb ,
346
+ log_ref, disable_memtable, batch_cnt ,
347
+ pre_release_callback, post_memtable_callback);
333
348
StopWatch write_sw (immutable_db_options_.clock , stats_, DB_WRITE);
334
349
335
350
write_thread_.JoinBatchGroup (&w);
@@ -686,15 +701,16 @@ Status DBImpl::WriteImpl(const WriteOptions& write_options,
686
701
687
702
Status DBImpl::PipelinedWriteImpl (const WriteOptions& write_options,
688
703
WriteBatch* my_batch, WriteCallback* callback,
704
+ UserWriteCallback* user_write_cb,
689
705
uint64_t * log_used, uint64_t log_ref,
690
706
bool disable_memtable, uint64_t * seq_used) {
691
707
PERF_TIMER_GUARD (write_pre_and_post_process_time);
692
708
StopWatch write_sw (immutable_db_options_.clock , stats_, DB_WRITE);
693
709
694
710
WriteContext write_context;
695
711
696
- WriteThread::Writer w (write_options, my_batch, callback, log_ref ,
697
- disable_memtable, /* _batch_cnt=*/ 0 ,
712
+ WriteThread::Writer w (write_options, my_batch, callback, user_write_cb ,
713
+ log_ref, disable_memtable, /* _batch_cnt=*/ 0 ,
698
714
/* _pre_release_callback=*/ nullptr );
699
715
write_thread_.JoinBatchGroup (&w);
700
716
TEST_SYNC_POINT (" DBImplWrite::PipelinedWriteImpl:AfterJoinBatchGroup" );
@@ -875,7 +891,8 @@ Status DBImpl::UnorderedWriteMemtable(const WriteOptions& write_options,
875
891
PERF_TIMER_GUARD (write_pre_and_post_process_time);
876
892
StopWatch write_sw (immutable_db_options_.clock , stats_, DB_WRITE);
877
893
878
- WriteThread::Writer w (write_options, my_batch, callback, log_ref,
894
+ WriteThread::Writer w (write_options, my_batch, callback,
895
+ /* user_write_cb=*/ nullptr , log_ref,
879
896
false /* disable_memtable*/ );
880
897
881
898
if (w.CheckCallback (this ) && w.ShouldWriteToMemtable ()) {
@@ -925,13 +942,15 @@ Status DBImpl::UnorderedWriteMemtable(const WriteOptions& write_options,
925
942
// applicable in a two-queue setting.
926
943
Status DBImpl::WriteImplWALOnly (
927
944
WriteThread* write_thread, const WriteOptions& write_options,
928
- WriteBatch* my_batch, WriteCallback* callback, uint64_t * log_used,
945
+ WriteBatch* my_batch, WriteCallback* callback,
946
+ UserWriteCallback* user_write_cb, uint64_t * log_used,
929
947
const uint64_t log_ref, uint64_t * seq_used, const size_t sub_batch_cnt,
930
948
PreReleaseCallback* pre_release_callback, const AssignOrder assign_order,
931
949
const PublishLastSeq publish_last_seq, const bool disable_memtable) {
932
950
PERF_TIMER_GUARD (write_pre_and_post_process_time);
933
- WriteThread::Writer w (write_options, my_batch, callback, log_ref,
934
- disable_memtable, sub_batch_cnt, pre_release_callback);
951
+ WriteThread::Writer w (write_options, my_batch, callback, user_write_cb,
952
+ log_ref, disable_memtable, sub_batch_cnt,
953
+ pre_release_callback);
935
954
StopWatch write_sw (immutable_db_options_.clock , stats_, DB_WRITE);
936
955
937
956
write_thread->JoinBatchGroup (&w);
@@ -1498,6 +1517,11 @@ IOStatus DBImpl::WriteToWAL(const WriteThread::WriteGroup& write_group,
1498
1517
RecordTick (stats_, WAL_FILE_BYTES, log_size);
1499
1518
stats->AddDBStats (InternalStats::kIntStatsWriteWithWal , write_with_wal);
1500
1519
RecordTick (stats_, WRITE_WITH_WAL, write_with_wal);
1520
+ for (auto * writer : write_group) {
1521
+ if (!writer->CallbackFailed ()) {
1522
+ writer->CheckPostWalWriteCallback ();
1523
+ }
1524
+ }
1501
1525
}
1502
1526
return io_s;
1503
1527
}
@@ -1562,6 +1586,11 @@ IOStatus DBImpl::ConcurrentWriteToWAL(
1562
1586
stats->AddDBStats (InternalStats::kIntStatsWriteWithWal , write_with_wal,
1563
1587
concurrent);
1564
1588
RecordTick (stats_, WRITE_WITH_WAL, write_with_wal);
1589
+ for (auto * writer : write_group) {
1590
+ if (!writer->CallbackFailed ()) {
1591
+ writer->CheckPostWalWriteCallback ();
1592
+ }
1593
+ }
1565
1594
}
1566
1595
return io_s;
1567
1596
}
0 commit comments