@@ -1284,10 +1284,7 @@ void ServerFamily::FlushAll(Namespace* ns) {
1284
1284
boost::intrusive_ptr<Transaction> flush_trans (new Transaction{cid});
1285
1285
flush_trans->InitByArgs (ns, 0 , {});
1286
1286
VLOG (1 ) << " Performing flush" ;
1287
- error_code ec = Drakarys (flush_trans.get (), DbSlice::kDbAll );
1288
- if (ec) {
1289
- LOG (ERROR) << " Error flushing db " << ec.message ();
1290
- }
1287
+ Drakarys (flush_trans.get (), DbSlice::kDbAll , false );
1291
1288
}
1292
1289
1293
1290
// Load starts as many fibers as there are files to load each one separately.
@@ -2206,17 +2203,20 @@ bool ServerFamily::TEST_IsSaving() const {
2206
2203
return is_saving.load (std::memory_order_relaxed);
2207
2204
}
2208
2205
2209
- error_code ServerFamily::Drakarys (Transaction* transaction, DbIndex db_ind) {
2206
+ void ServerFamily::Drakarys (Transaction* transaction, DbIndex db_ind, bool wait ) {
2210
2207
VLOG (1 ) << " Drakarys" ;
2211
2208
2209
+ vector<fb2::Fiber> fibers (shard_set->size ());
2212
2210
transaction->Execute (
2213
- [db_ind](Transaction* t, EngineShard* shard) {
2214
- t->GetDbSlice (shard->shard_id ()).FlushDb (db_ind);
2211
+ [db_ind, &fibers ](Transaction* t, EngineShard* shard) {
2212
+ fibers[shard-> shard_id ()] = t->GetDbSlice (shard->shard_id ()).FlushDb (db_ind);
2215
2213
return OpStatus::OK;
2216
2214
},
2217
2215
true );
2218
2216
2219
- return error_code{};
2217
+ auto action = wait ? &fb2::Fiber::JoinIfNeeded : &fb2::Fiber::Detach;
2218
+ for (auto & f : fibers)
2219
+ (f.*action)();
2220
2220
}
2221
2221
2222
2222
SaveInfoData ServerFamily::GetLastSaveInfo () const {
@@ -2286,20 +2286,14 @@ void ServerFamily::SendInvalidationMessages() const {
2286
2286
}
2287
2287
2288
2288
void ServerFamily::FlushDb (CmdArgList args, const CommandContext& cmd_cntx) {
2289
- DCHECK (cmd_cntx.tx );
2290
- Drakarys (cmd_cntx.tx , cmd_cntx.tx ->GetDbIndex ());
2291
- SendInvalidationMessages ();
2292
- cmd_cntx.rb ->SendOk ();
2293
- }
2289
+ if (args.size () > 1 )
2290
+ return cmd_cntx.rb ->SendError (kSyntaxErr );
2294
2291
2295
- void ServerFamily::FlushAll (CmdArgList args, const CommandContext& cmd_cntx) {
2296
- if (args.size () > 1 ) {
2297
- cmd_cntx.rb ->SendError (kSyntaxErr );
2298
- return ;
2299
- }
2292
+ bool sync = CmdArgParser{args}.Check (" SYNC" );
2293
+ string_view cmd_name = cmd_cntx.tx ->GetCId ()->name ();
2294
+ DbIndex index = cmd_name == " FLUSHALL" ? DbSlice::kDbAll : cmd_cntx.tx ->GetDbIndex ();
2300
2295
2301
- DCHECK (cmd_cntx.tx );
2302
- Drakarys (cmd_cntx.tx , DbSlice::kDbAll );
2296
+ Drakarys (cmd_cntx.tx , index, sync);
2303
2297
SendInvalidationMessages ();
2304
2298
cmd_cntx.rb ->SendOk ();
2305
2299
}
@@ -4037,10 +4031,10 @@ void ServerFamily::Register(CommandRegistry* registry) {
4037
4031
<< CI{" CONFIG" , CO::ADMIN | CO::LOADING | CO::DANGEROUS, -2 , 0 , 0 , acl::kConfig }.HFUNC (Config)
4038
4032
<< CI{" DBSIZE" , CO::READONLY | CO::FAST | CO::LOADING, 1 , 0 , 0 , acl::kDbSize }.HFUNC (DbSize)
4039
4033
<< CI{" DEBUG" , CO::ADMIN | CO::LOADING, -2 , 0 , 0 , acl::kDebug }.HFUNC (Debug)
4040
- << CI{" FLUSHDB" , CO::WRITE | CO::GLOBAL_TRANS | CO::DANGEROUS, 1 , 0 , 0 , acl::kFlushDB }.HFUNC (
4034
+ << CI{" FLUSHDB" , CO::WRITE | CO::GLOBAL_TRANS | CO::DANGEROUS, - 1 , 0 , 0 , acl::kFlushDB }.HFUNC (
4041
4035
FlushDb)
4042
4036
<< CI{" FLUSHALL" , CO::WRITE | CO::GLOBAL_TRANS | CO::DANGEROUS, -1 , 0 , 0 , acl::kFlushAll }
4043
- .HFUNC (FlushAll )
4037
+ .HFUNC (FlushDb )
4044
4038
<< CI{" INFO" , CO::LOADING, -1 , 0 , 0 , acl::kInfo }.HFUNC (Info)
4045
4039
<< CI{" HELLO" , CO::LOADING, -1 , 0 , 0 , acl::kHello }.HFUNC (Hello)
4046
4040
<< CI{" LASTSAVE" , CO::LOADING | CO::FAST, 1 , 0 , 0 , acl::kLastSave }.HFUNC (LastSave)
0 commit comments