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:
Chris Lu
2026-04-03 16:04:27 -07:00
committed by GitHub
parent 8fad85aed7
commit 995dfc4d5d
264 changed files with 62 additions and 46027 deletions

View File

@@ -120,10 +120,6 @@ func Base64Encode(data []byte) string {
return base64.StdEncoding.EncodeToString(data)
}
func Base64Md5(data []byte) string {
return Base64Encode(Md5(data))
}
func Md5(data []byte) []byte {
hash := md5.New()
hash.Write(data)

View File

@@ -1,66 +0,0 @@
package util
// initial version comes from https://hackernoon.com/asyncawait-in-golang-an-introductory-guide-ol1e34sg
import (
"container/list"
"context"
"sync"
)
type Future interface {
Await() interface{}
}
type future struct {
await func(ctx context.Context) interface{}
}
func (f future) Await() interface{} {
return f.await(context.Background())
}
type LimitedAsyncExecutor struct {
executor *LimitedConcurrentExecutor
futureList *list.List
futureListCond *sync.Cond
}
func NewLimitedAsyncExecutor(limit int) *LimitedAsyncExecutor {
return &LimitedAsyncExecutor{
executor: NewLimitedConcurrentExecutor(limit),
futureList: list.New(),
futureListCond: sync.NewCond(&sync.Mutex{}),
}
}
func (ae *LimitedAsyncExecutor) Execute(job func() interface{}) {
var result interface{}
c := make(chan struct{})
ae.executor.Execute(func() {
defer close(c)
result = job()
})
f := future{await: func(ctx context.Context) interface{} {
select {
case <-ctx.Done():
return ctx.Err()
case <-c:
return result
}
}}
ae.futureListCond.L.Lock()
ae.futureList.PushBack(f)
ae.futureListCond.Signal()
ae.futureListCond.L.Unlock()
}
func (ae *LimitedAsyncExecutor) NextFuture() Future {
ae.futureListCond.L.Lock()
for ae.futureList.Len() == 0 {
ae.futureListCond.Wait()
}
f := ae.futureList.Remove(ae.futureList.Front())
ae.futureListCond.L.Unlock()
return f.(Future)
}

View File

@@ -1,64 +0,0 @@
package util
import (
"fmt"
"sort"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestAsyncPool(t *testing.T) {
p := NewLimitedAsyncExecutor(3)
p.Execute(FirstFunc)
p.Execute(SecondFunc)
p.Execute(ThirdFunc)
p.Execute(FourthFunc)
p.Execute(FifthFunc)
var sorted_results []int
for i := 0; i < 5; i++ {
f := p.NextFuture()
x := f.Await().(int)
println(x)
sorted_results = append(sorted_results, x)
}
assert.True(t, sort.IntsAreSorted(sorted_results), "results should be sorted")
}
func FirstFunc() any {
fmt.Println("-- Executing first function --")
time.Sleep(70 * time.Millisecond)
fmt.Println("-- First Function finished --")
return 1
}
func SecondFunc() any {
fmt.Println("-- Executing second function --")
time.Sleep(50 * time.Millisecond)
fmt.Println("-- Second Function finished --")
return 2
}
func ThirdFunc() any {
fmt.Println("-- Executing third function --")
time.Sleep(20 * time.Millisecond)
fmt.Println("-- Third Function finished --")
return 3
}
func FourthFunc() any {
fmt.Println("-- Executing fourth function --")
time.Sleep(100 * time.Millisecond)
fmt.Println("-- Fourth Function finished --")
return 4
}
func FifthFunc() any {
fmt.Println("-- Executing fifth function --")
time.Sleep(40 * time.Millisecond)
fmt.Println("-- Fourth fifth finished --")
return 5
}

View File

@@ -175,7 +175,3 @@ func (lt *LockTable[T]) ReleaseLock(key T, lock *ActiveLock) {
// Notify the next waiter
entry.cond.Broadcast()
}
func main() {
}