@@ -551,53 +551,49 @@ string_view GetRedisMode() {
551
551
}
552
552
553
553
struct ReplicaOfArgs {
554
- bool no_one = false ;
555
554
string_view host;
556
555
string_view port_sv;
557
- uint32_t port;
556
+ uint16_t port;
558
557
std::optional<SlotRange> slot_range;
559
558
static OpResult<ReplicaOfArgs> FromParams (string_view host, string_view port,
560
559
std::optional<string_view> slot_start,
561
560
std::optional<string_view> slot_end);
561
+ bool IsReplicaOfNoOne ();
562
562
};
563
563
564
- OpResult<ReplicaOfArgs> ReplicaOfArgs::FromParams (string_view host, string_view port,
564
+ bool ReplicaOfArgs::IsReplicaOfNoOne () {
565
+ if (absl::EqualsIgnoreCase (host, " no" ) && absl::EqualsIgnoreCase (port_sv, " one" )) {
566
+ return true ;
567
+ }
568
+ return false ;
569
+ }
570
+
571
+ OpResult<ReplicaOfArgs> ReplicaOfArgs::FromParams (string_view host, string_view port_sv,
565
572
std::optional<string_view> slot_start,
566
573
std::optional<string_view> slot_end) {
567
574
ReplicaOfArgs replicaof_args;
568
575
replicaof_args.host = host;
569
- replicaof_args.port_sv = port;
570
- if (absl::EqualsIgnoreCase (replicaof_args.host , " no" ) &&
571
- absl::EqualsIgnoreCase (replicaof_args.port_sv , " one" )) {
572
- replicaof_args.no_one = true ;
576
+ replicaof_args.port_sv = port_sv;
577
+ if (replicaof_args.IsReplicaOfNoOne ()) {
573
578
return replicaof_args;
574
579
}
575
580
576
- if (! absl::SimpleAtoi (replicaof_args. port_sv , &replicaof_args. port ) || replicaof_args. port < 1 ||
577
- replicaof_args. port > 65535 ) {
581
+ uint32_t port;
582
+ if (! absl::SimpleAtoi (port_sv, &port) || port < 1 || port > 65535 ) {
578
583
return facade::OpStatus::INVALID_INT;
579
584
}
585
+ replicaof_args.port = static_cast <uint16_t >(port);
580
586
581
587
if (slot_start.has_value ()) {
582
588
if (!slot_end.has_value ()) {
583
589
return facade::OpStatus::SYNTAX_ERR;
584
590
}
585
591
586
- uint32_t slot_id_start, slot_id_end;
587
- if (!absl::SimpleAtoi (*slot_start, &slot_id_start)) {
588
- return facade::OpStatus::INVALID_INT;
589
- }
590
- if (slot_id_start > ClusterConfig::kMaxSlotNum ) {
591
- return facade::OpStatus::INVALID_VALUE;
592
+ OpResult<SlotRange> slot_range = ClusterConfig::SlotRangeFromStr (*slot_start, *slot_end);
593
+ if (!slot_range) {
594
+ return slot_range.status ();
592
595
}
593
- if (!absl::SimpleAtoi (*slot_end, &slot_id_end)) {
594
- return facade::OpStatus::INVALID_INT;
595
- }
596
- if (slot_id_end > ClusterConfig::kMaxSlotNum ) {
597
- return facade::OpStatus::INVALID_VALUE;
598
- }
599
- replicaof_args.slot_range = SlotRange{.start = static_cast <uint16_t >(slot_id_start),
600
- .end = static_cast <uint16_t >(slot_id_end)};
596
+ replicaof_args.slot_range = slot_range.value ();
601
597
}
602
598
return replicaof_args;
603
599
}
@@ -846,9 +842,9 @@ void ServerFamily::Shutdown() {
846
842
unique_lock lk (replicaof_mu_);
847
843
if (replica_) {
848
844
replica_->Stop ();
849
- for ( auto & replica : cluster_replicas_) {
850
- replica-> Stop ();
851
- }
845
+ }
846
+ for ( auto & replica : cluster_replicas_) {
847
+ replica-> Stop ();
852
848
}
853
849
854
850
dfly_cmd_->Shutdown ();
@@ -2344,7 +2340,7 @@ void ServerFamily::AddReplicaOf(CmdArgList args, ConnectionContext* cntx) {
2344
2340
if (!replicaof_args) {
2345
2341
return cntx->SendError (replicaof_args.status ());
2346
2342
}
2347
- if (replicaof_args->no_one ) {
2343
+ if (replicaof_args->IsReplicaOfNoOne () ) {
2348
2344
return cntx->SendError (" ADDREPLICAOF does not supprot no one" );
2349
2345
}
2350
2346
LOG (INFO) << " Add Replica " << replicaof_args->host << " :" << replicaof_args->port_sv ;
@@ -2377,7 +2373,7 @@ void ServerFamily::ReplicaOfInternal(std::string_view host, std::string_view por
2377
2373
}
2378
2374
2379
2375
// If NO ONE was supplied, just stop the current replica (if it exists)
2380
- if (replicaof_args->no_one ) {
2376
+ if (replicaof_args->IsReplicaOfNoOne () ) {
2381
2377
if (!ServerState::tlocal ()->is_master ) {
2382
2378
CHECK (replica_);
2383
2379
@@ -2618,9 +2614,7 @@ void ServerFamily::Role(CmdArgList args, ConnectionContext* cntx) {
2618
2614
2619
2615
} else {
2620
2616
unique_lock lk{replicaof_mu_};
2621
-
2622
- size_t additional_replication = cluster_replicas_.size ();
2623
- rb->StartArray (4 + additional_replication * 3 );
2617
+ rb->StartArray (4 + cluster_replicas_.size () * 3 );
2624
2618
rb->SendBulkString (" replica" );
2625
2619
2626
2620
auto send_replica_info = [rb](Replica::Info rinfo) {
0 commit comments