chore: remove ~50k lines of unreachable dead code (#8913)
* 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.
This commit is contained in:
@@ -56,11 +56,6 @@ func IsBinary(t Type) bool {
|
||||
return int(t)&flagIsBinary == flagIsBinary
|
||||
}
|
||||
|
||||
// isNumber returns true if the type is any type of number.
|
||||
func isNumber(t Type) bool {
|
||||
return IsIntegral(t) || IsFloat(t) || t == Decimal
|
||||
}
|
||||
|
||||
// IsTemporal returns true if Value is time type.
|
||||
func IsTemporal(t Type) bool {
|
||||
switch t {
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package sqltypes
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -19,32 +17,6 @@ type Value struct {
|
||||
val []byte
|
||||
}
|
||||
|
||||
// NewValue builds a Value using typ and val. If the value and typ
|
||||
// don't match, it returns an error.
|
||||
func NewValue(typ Type, val []byte) (v Value, err error) {
|
||||
switch {
|
||||
case IsSigned(typ):
|
||||
if _, err := strconv.ParseInt(string(val), 0, 64); err != nil {
|
||||
return NULL, err
|
||||
}
|
||||
return MakeTrusted(typ, val), nil
|
||||
case IsUnsigned(typ):
|
||||
if _, err := strconv.ParseUint(string(val), 0, 64); err != nil {
|
||||
return NULL, err
|
||||
}
|
||||
return MakeTrusted(typ, val), nil
|
||||
case IsFloat(typ) || typ == Decimal:
|
||||
if _, err := strconv.ParseFloat(string(val), 64); err != nil {
|
||||
return NULL, err
|
||||
}
|
||||
return MakeTrusted(typ, val), nil
|
||||
case IsQuoted(typ) || typ == Bit || typ == Null:
|
||||
return MakeTrusted(typ, val), nil
|
||||
}
|
||||
// All other types are unsafe or invalid.
|
||||
return NULL, fmt.Errorf("invalid type specified for MakeValue: %v", typ)
|
||||
}
|
||||
|
||||
// MakeTrusted makes a new Value based on the type.
|
||||
// This function should only be used if you know the value
|
||||
// and type conform to the rules. Every place this function is
|
||||
@@ -71,11 +43,6 @@ func NewInt32(v int32) Value {
|
||||
return MakeTrusted(Int32, strconv.AppendInt(nil, int64(v), 10))
|
||||
}
|
||||
|
||||
// NewUint64 builds an Uint64 Value.
|
||||
func NewUint64(v uint64) Value {
|
||||
return MakeTrusted(Uint64, strconv.AppendUint(nil, v, 10))
|
||||
}
|
||||
|
||||
// NewFloat32 builds an Float64 Value.
|
||||
func NewFloat32(v float32) Value {
|
||||
return MakeTrusted(Float32, strconv.AppendFloat(nil, float64(v), 'f', -1, 64))
|
||||
@@ -97,136 +64,11 @@ func NewVarBinary(v string) Value {
|
||||
return MakeTrusted(VarBinary, []byte(v))
|
||||
}
|
||||
|
||||
// NewIntegral builds an integral type from a string representation.
|
||||
// The type will be Int64 or Uint64. Int64 will be preferred where possible.
|
||||
func NewIntegral(val string) (n Value, err error) {
|
||||
signed, err := strconv.ParseInt(val, 0, 64)
|
||||
if err == nil {
|
||||
return MakeTrusted(Int64, strconv.AppendInt(nil, signed, 10)), nil
|
||||
}
|
||||
unsigned, err := strconv.ParseUint(val, 0, 64)
|
||||
if err != nil {
|
||||
return Value{}, err
|
||||
}
|
||||
return MakeTrusted(Uint64, strconv.AppendUint(nil, unsigned, 10)), nil
|
||||
}
|
||||
|
||||
// MakeString makes a VarBinary Value.
|
||||
func MakeString(val []byte) Value {
|
||||
return MakeTrusted(VarBinary, val)
|
||||
}
|
||||
|
||||
// BuildValue builds a value from any go type. sqltype.Value is
|
||||
// also allowed.
|
||||
func BuildValue(goval interface{}) (v Value, err error) {
|
||||
// Look for the most common types first.
|
||||
switch goval := goval.(type) {
|
||||
case nil:
|
||||
// no op
|
||||
case []byte:
|
||||
v = MakeTrusted(VarBinary, goval)
|
||||
case int64:
|
||||
v = MakeTrusted(Int64, strconv.AppendInt(nil, int64(goval), 10))
|
||||
case uint64:
|
||||
v = MakeTrusted(Uint64, strconv.AppendUint(nil, uint64(goval), 10))
|
||||
case float64:
|
||||
v = MakeTrusted(Float64, strconv.AppendFloat(nil, goval, 'f', -1, 64))
|
||||
case int:
|
||||
v = MakeTrusted(Int64, strconv.AppendInt(nil, int64(goval), 10))
|
||||
case int8:
|
||||
v = MakeTrusted(Int8, strconv.AppendInt(nil, int64(goval), 10))
|
||||
case int16:
|
||||
v = MakeTrusted(Int16, strconv.AppendInt(nil, int64(goval), 10))
|
||||
case int32:
|
||||
v = MakeTrusted(Int32, strconv.AppendInt(nil, int64(goval), 10))
|
||||
case uint:
|
||||
v = MakeTrusted(Uint64, strconv.AppendUint(nil, uint64(goval), 10))
|
||||
case uint8:
|
||||
v = MakeTrusted(Uint8, strconv.AppendUint(nil, uint64(goval), 10))
|
||||
case uint16:
|
||||
v = MakeTrusted(Uint16, strconv.AppendUint(nil, uint64(goval), 10))
|
||||
case uint32:
|
||||
v = MakeTrusted(Uint32, strconv.AppendUint(nil, uint64(goval), 10))
|
||||
case float32:
|
||||
v = MakeTrusted(Float32, strconv.AppendFloat(nil, float64(goval), 'f', -1, 64))
|
||||
case string:
|
||||
v = MakeTrusted(VarBinary, []byte(goval))
|
||||
case time.Time:
|
||||
v = MakeTrusted(Datetime, []byte(goval.Format("2006-01-02 15:04:05")))
|
||||
case Value:
|
||||
v = goval
|
||||
case *BindVariable:
|
||||
return ValueFromBytes(goval.Type, goval.Value)
|
||||
default:
|
||||
return v, fmt.Errorf("unexpected type %T: %v", goval, goval)
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// BuildConverted is like BuildValue except that it tries to
|
||||
// convert a string or []byte to an integral if the target type
|
||||
// is an integral. We don't perform other implicit conversions
|
||||
// because they're unsafe.
|
||||
func BuildConverted(typ Type, goval interface{}) (v Value, err error) {
|
||||
if IsIntegral(typ) {
|
||||
switch goval := goval.(type) {
|
||||
case []byte:
|
||||
return ValueFromBytes(typ, goval)
|
||||
case string:
|
||||
return ValueFromBytes(typ, []byte(goval))
|
||||
case Value:
|
||||
if goval.IsQuoted() {
|
||||
return ValueFromBytes(typ, goval.Raw())
|
||||
}
|
||||
}
|
||||
}
|
||||
return BuildValue(goval)
|
||||
}
|
||||
|
||||
// ValueFromBytes builds a Value using typ and val. It ensures that val
|
||||
// matches the requested type. If type is an integral it's converted to
|
||||
// a canonical form. Otherwise, the original representation is preserved.
|
||||
func ValueFromBytes(typ Type, val []byte) (v Value, err error) {
|
||||
switch {
|
||||
case IsSigned(typ):
|
||||
signed, err := strconv.ParseInt(string(val), 0, 64)
|
||||
if err != nil {
|
||||
return NULL, err
|
||||
}
|
||||
v = MakeTrusted(typ, strconv.AppendInt(nil, signed, 10))
|
||||
case IsUnsigned(typ):
|
||||
unsigned, err := strconv.ParseUint(string(val), 0, 64)
|
||||
if err != nil {
|
||||
return NULL, err
|
||||
}
|
||||
v = MakeTrusted(typ, strconv.AppendUint(nil, unsigned, 10))
|
||||
case IsFloat(typ) || typ == Decimal:
|
||||
_, err := strconv.ParseFloat(string(val), 64)
|
||||
if err != nil {
|
||||
return NULL, err
|
||||
}
|
||||
// After verification, we preserve the original representation.
|
||||
fallthrough
|
||||
default:
|
||||
v = MakeTrusted(typ, val)
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
||||
// BuildIntegral builds an integral type from a string representation.
|
||||
// The type will be Int64 or Uint64. Int64 will be preferred where possible.
|
||||
func BuildIntegral(val string) (n Value, err error) {
|
||||
signed, err := strconv.ParseInt(val, 0, 64)
|
||||
if err == nil {
|
||||
return MakeTrusted(Int64, strconv.AppendInt(nil, signed, 10)), nil
|
||||
}
|
||||
unsigned, err := strconv.ParseUint(val, 0, 64)
|
||||
if err != nil {
|
||||
return Value{}, err
|
||||
}
|
||||
return MakeTrusted(Uint64, strconv.AppendUint(nil, unsigned, 10)), nil
|
||||
}
|
||||
|
||||
// Type returns the type of Value.
|
||||
func (v Value) Type() Type {
|
||||
return v.typ
|
||||
@@ -247,15 +89,6 @@ func (v Value) Len() int {
|
||||
// Values represents the array of Value.
|
||||
type Values []Value
|
||||
|
||||
// Len implements the interface.
|
||||
func (vs Values) Len() int {
|
||||
len := 0
|
||||
for _, v := range vs {
|
||||
len += v.Len()
|
||||
}
|
||||
return len
|
||||
}
|
||||
|
||||
// String returns the raw value as a string.
|
||||
func (v Value) String() string {
|
||||
return BytesToString(v.val)
|
||||
|
||||
Reference in New Issue
Block a user