* chore: remove unreachable dead code across the codebase Remove ~50,000 lines of unreachable code identified by static analysis. Major removals: - weed/filer/redis_lua: entire unused Redis Lua filer store implementation - weed/wdclient/net2, resource_pool: unused connection/resource pool packages - weed/plugin/worker/lifecycle: unused lifecycle plugin worker - weed/s3api: unused S3 policy templates, presigned URL IAM, streaming copy, multipart IAM, key rotation, and various SSE helper functions - weed/mq/kafka: unused partition mapping, compression, schema, and protocol functions - weed/mq/offset: unused SQL storage and migration code - weed/worker: unused registry, task, and monitoring functions - weed/query: unused SQL engine, parquet scanner, and type functions - weed/shell: unused EC proportional rebalance functions - weed/storage/erasure_coding/distribution: unused distribution analysis functions - Individual unreachable functions removed from 150+ files across admin, credential, filer, iam, kms, mount, mq, operation, pb, s3api, server, shell, storage, topology, and util packages * fix(s3): reset shared memory store in IAM test to prevent flaky failure TestLoadIAMManagerFromConfig_EmptyConfigWithFallbackKey was flaky because the MemoryStore credential backend is a singleton registered via init(). Earlier tests that create anonymous identities pollute the shared store, causing LookupAnonymous() to unexpectedly return true. Fix by calling Reset() on the memory store before the test runs. * style: run gofmt on changed files * fix: restore KMS functions used by integration tests * fix(plugin): prevent panic on send to closed worker session channel The Plugin.sendToWorker method could panic with "send on closed channel" when a worker disconnected while a message was being sent. The race was between streamSession.close() closing the outgoing channel and sendToWorker writing to it concurrently. Add a done channel to streamSession that is closed before the outgoing channel, and check it in sendToWorker's select to safely detect closed sessions without panicking.
128 lines
4.6 KiB
Go
128 lines
4.6 KiB
Go
package broker
|
|
|
|
// Broker Error Codes
|
|
// These codes are used internally by the broker and can be mapped to Kafka protocol error codes
|
|
const (
|
|
// Success
|
|
BrokerErrorNone int32 = 0
|
|
|
|
// General broker errors
|
|
BrokerErrorUnknownServerError int32 = 1
|
|
BrokerErrorTopicNotFound int32 = 2
|
|
BrokerErrorPartitionNotFound int32 = 3
|
|
BrokerErrorNotLeaderOrFollower int32 = 6 // Maps to Kafka ErrorCodeNotLeaderOrFollower
|
|
BrokerErrorRequestTimedOut int32 = 7
|
|
BrokerErrorBrokerNotAvailable int32 = 8
|
|
BrokerErrorMessageTooLarge int32 = 10
|
|
BrokerErrorNetworkException int32 = 13
|
|
BrokerErrorOffsetLoadInProgress int32 = 14
|
|
BrokerErrorInvalidRecord int32 = 42
|
|
BrokerErrorTopicAlreadyExists int32 = 36
|
|
BrokerErrorInvalidPartitions int32 = 37
|
|
BrokerErrorInvalidConfig int32 = 40
|
|
|
|
// Publisher/connection errors
|
|
BrokerErrorPublisherNotFound int32 = 100
|
|
BrokerErrorConnectionFailed int32 = 101
|
|
BrokerErrorFollowerConnectionFailed int32 = 102
|
|
)
|
|
|
|
// BrokerErrorInfo contains metadata about a broker error
|
|
type BrokerErrorInfo struct {
|
|
Code int32
|
|
Name string
|
|
Description string
|
|
KafkaCode int16 // Corresponding Kafka protocol error code
|
|
}
|
|
|
|
// BrokerErrors maps broker error codes to their metadata and Kafka equivalents
|
|
var BrokerErrors = map[int32]BrokerErrorInfo{
|
|
BrokerErrorNone: {
|
|
Code: BrokerErrorNone, Name: "NONE",
|
|
Description: "No error", KafkaCode: 0,
|
|
},
|
|
BrokerErrorUnknownServerError: {
|
|
Code: BrokerErrorUnknownServerError, Name: "UNKNOWN_SERVER_ERROR",
|
|
Description: "Unknown server error", KafkaCode: 1,
|
|
},
|
|
BrokerErrorTopicNotFound: {
|
|
Code: BrokerErrorTopicNotFound, Name: "TOPIC_NOT_FOUND",
|
|
Description: "Topic not found", KafkaCode: 3, // UNKNOWN_TOPIC_OR_PARTITION
|
|
},
|
|
BrokerErrorPartitionNotFound: {
|
|
Code: BrokerErrorPartitionNotFound, Name: "PARTITION_NOT_FOUND",
|
|
Description: "Partition not found", KafkaCode: 3, // UNKNOWN_TOPIC_OR_PARTITION
|
|
},
|
|
BrokerErrorNotLeaderOrFollower: {
|
|
Code: BrokerErrorNotLeaderOrFollower, Name: "NOT_LEADER_OR_FOLLOWER",
|
|
Description: "Not leader or follower for this partition", KafkaCode: 6,
|
|
},
|
|
BrokerErrorRequestTimedOut: {
|
|
Code: BrokerErrorRequestTimedOut, Name: "REQUEST_TIMED_OUT",
|
|
Description: "Request timed out", KafkaCode: 7,
|
|
},
|
|
BrokerErrorBrokerNotAvailable: {
|
|
Code: BrokerErrorBrokerNotAvailable, Name: "BROKER_NOT_AVAILABLE",
|
|
Description: "Broker not available", KafkaCode: 8,
|
|
},
|
|
BrokerErrorMessageTooLarge: {
|
|
Code: BrokerErrorMessageTooLarge, Name: "MESSAGE_TOO_LARGE",
|
|
Description: "Message size exceeds limit", KafkaCode: 10,
|
|
},
|
|
BrokerErrorNetworkException: {
|
|
Code: BrokerErrorNetworkException, Name: "NETWORK_EXCEPTION",
|
|
Description: "Network error", KafkaCode: 13,
|
|
},
|
|
BrokerErrorOffsetLoadInProgress: {
|
|
Code: BrokerErrorOffsetLoadInProgress, Name: "OFFSET_LOAD_IN_PROGRESS",
|
|
Description: "Offset loading in progress", KafkaCode: 14,
|
|
},
|
|
BrokerErrorInvalidRecord: {
|
|
Code: BrokerErrorInvalidRecord, Name: "INVALID_RECORD",
|
|
Description: "Invalid record", KafkaCode: 42,
|
|
},
|
|
BrokerErrorTopicAlreadyExists: {
|
|
Code: BrokerErrorTopicAlreadyExists, Name: "TOPIC_ALREADY_EXISTS",
|
|
Description: "Topic already exists", KafkaCode: 36,
|
|
},
|
|
BrokerErrorInvalidPartitions: {
|
|
Code: BrokerErrorInvalidPartitions, Name: "INVALID_PARTITIONS",
|
|
Description: "Invalid partition count", KafkaCode: 37,
|
|
},
|
|
BrokerErrorInvalidConfig: {
|
|
Code: BrokerErrorInvalidConfig, Name: "INVALID_CONFIG",
|
|
Description: "Invalid configuration", KafkaCode: 40,
|
|
},
|
|
BrokerErrorPublisherNotFound: {
|
|
Code: BrokerErrorPublisherNotFound, Name: "PUBLISHER_NOT_FOUND",
|
|
Description: "Publisher not found", KafkaCode: 1, // UNKNOWN_SERVER_ERROR
|
|
},
|
|
BrokerErrorConnectionFailed: {
|
|
Code: BrokerErrorConnectionFailed, Name: "CONNECTION_FAILED",
|
|
Description: "Connection failed", KafkaCode: 13, // NETWORK_EXCEPTION
|
|
},
|
|
BrokerErrorFollowerConnectionFailed: {
|
|
Code: BrokerErrorFollowerConnectionFailed, Name: "FOLLOWER_CONNECTION_FAILED",
|
|
Description: "Failed to connect to follower brokers", KafkaCode: 13, // NETWORK_EXCEPTION
|
|
},
|
|
}
|
|
|
|
// GetBrokerErrorInfo returns error information for the given broker error code
|
|
func GetBrokerErrorInfo(code int32) BrokerErrorInfo {
|
|
if info, exists := BrokerErrors[code]; exists {
|
|
return info
|
|
}
|
|
return BrokerErrorInfo{
|
|
Code: code, Name: "UNKNOWN", Description: "Unknown broker error code", KafkaCode: 1,
|
|
}
|
|
}
|
|
|
|
// CreateBrokerError creates a structured broker error with both error code and message
|
|
func CreateBrokerError(code int32, message string) (int32, string) {
|
|
info := GetBrokerErrorInfo(code)
|
|
if message == "" {
|
|
message = info.Description
|
|
}
|
|
return code, message
|
|
}
|