-
Notifications
You must be signed in to change notification settings - Fork 861
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KIP-460] Elect leader api implemented (#2320)
- Loading branch information
1 parent
dc5aff2
commit 8212364
Showing
15 changed files
with
680 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2024 Confluent Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// Refer to LICENSE for more information. | ||
|
||
using System.Linq; | ||
|
||
|
||
namespace Confluent.Kafka.Admin | ||
{ | ||
/// <summary> | ||
/// Represents an error that occured during the ElectLeaders operation. | ||
/// </summary> | ||
public class ElectLeadersException : KafkaException | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of ElectLeadersException. | ||
/// </summary> | ||
/// <param name="report"> | ||
/// The result of the ElectLeaders operation. | ||
/// </param> | ||
public ElectLeadersException(ElectLeadersReport report) | ||
: base(new Error(ErrorCode.Local_Partial, | ||
"Some errors occurred electing leaders: [" + | ||
string.Join(", ", report.TopicPartitions.Where(tp => tp.Error.IsError)) + | ||
"]")) | ||
{ | ||
this.Results = report; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the results of the ElectLeaders operation. | ||
/// </summary> | ||
public ElectLeadersReport Results { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2024 Confluent Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// Refer to LICENSE for more information. | ||
|
||
using System; | ||
|
||
|
||
namespace Confluent.Kafka.Admin | ||
{ | ||
/// <summary> | ||
/// Options for the "AdminClient.ElectLeaders" method. | ||
/// </summary> | ||
public class ElectLeadersOptions | ||
{ | ||
/// <summary> | ||
/// The overall request timeout, including broker lookup, request | ||
/// transmission, operation time on broker, and response. If set | ||
/// to null, the default request timeout for the AdminClient will | ||
/// be used. | ||
/// | ||
/// Default: null | ||
/// </summary> | ||
public TimeSpan? RequestTimeout { get; set; } | ||
|
||
/// <summary> | ||
/// The broker's operation timeout - the maximum time to wait for | ||
/// ElectLeaders before returning a result to the application. | ||
/// If set to null, will return immediately upon triggering election. | ||
/// | ||
/// Default: null | ||
/// </summary> | ||
public TimeSpan? OperationTimeout { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2024 Confluent Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// Refer to LICENSE for more information. | ||
|
||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Linq; | ||
|
||
|
||
namespace Confluent.Kafka.Admin | ||
{ | ||
/// <summary> | ||
/// Represents the result of an elect leaders request (including error status). | ||
/// </summary> | ||
public class ElectLeadersReport | ||
{ | ||
/// <summary> | ||
/// First error encountered in TopicPartitions. | ||
/// </summary> | ||
internal Error Error { get; set; } | ||
|
||
/// <summary> | ||
/// Individual partition results. | ||
/// At least one of these will be in error. | ||
/// </summary> | ||
public List<TopicPartitionError> TopicPartitions { get; set; } | ||
|
||
/// <summary> | ||
/// A Json representation of the object. | ||
/// </summary> | ||
/// <returns> | ||
/// A Json representation of the object. | ||
/// </returns> | ||
public override string ToString() | ||
{ | ||
var result = new StringBuilder(); | ||
result.Append($"{{\"TopicPartitions\": ["); | ||
result.Append(string.Join(",", TopicPartitions.Select(b => $" {b.ToString()}"))); | ||
result.Append($"]}}"); | ||
return result.ToString(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2024 Confluent Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// Refer to LICENSE for more information. | ||
|
||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Linq; | ||
|
||
|
||
namespace Confluent.Kafka.Admin | ||
{ | ||
/// <summary> | ||
/// Result information for all Partitions queried | ||
/// in an ElectLeaderRequest. | ||
/// </summary> | ||
public class ElectLeadersResult | ||
{ | ||
/// <summary> | ||
/// Individual partition results. | ||
/// </summary> | ||
public List<TopicPartitionError> TopicPartitions { get; set; } | ||
|
||
/// <summary> | ||
/// A Json representation of the object. | ||
/// </summary> | ||
/// <returns> | ||
/// A Json representation of the object. | ||
/// </returns> | ||
public override string ToString() | ||
{ | ||
var result = new StringBuilder(); | ||
result.Append($"{{ \"TopicPartitions\": ["); | ||
result.Append(string.Join(",", TopicPartitions.Select(b => $" {b.ToString()}"))); | ||
result.Append($"]}}"); | ||
return result.ToString(); | ||
} | ||
} | ||
} |
Oops, something went wrong.