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

@@ -202,32 +202,6 @@ func (m *IAMManager) getFilerAddress() string {
return "" // Fallback to empty string if no provider is set
}
// createRoleStore creates a role store based on configuration
func (m *IAMManager) createRoleStore(config *RoleStoreConfig) (RoleStore, error) {
if config == nil {
// Default to generic cached filer role store when no config provided
return NewGenericCachedRoleStore(nil, nil)
}
switch config.StoreType {
case "", "filer":
// Check if caching is explicitly disabled
if config.StoreConfig != nil {
if noCache, ok := config.StoreConfig["noCache"].(bool); ok && noCache {
return NewFilerRoleStore(config.StoreConfig, nil)
}
}
// Default to generic cached filer store for better performance
return NewGenericCachedRoleStore(config.StoreConfig, nil)
case "cached-filer", "generic-cached":
return NewGenericCachedRoleStore(config.StoreConfig, nil)
case "memory":
return NewMemoryRoleStore(), nil
default:
return nil, fmt.Errorf("unsupported role store type: %s", config.StoreType)
}
}
// createRoleStoreWithProvider creates a role store with a filer address provider function
func (m *IAMManager) createRoleStoreWithProvider(config *RoleStoreConfig, filerAddressProvider func() string) (RoleStore, error) {
if config == nil {

View File

@@ -388,157 +388,3 @@ type CachedFilerRoleStoreConfig struct {
ListTTL string `json:"listTtl,omitempty"` // e.g., "1m", "30s"
MaxCacheSize int `json:"maxCacheSize,omitempty"` // Maximum number of cached roles
}
// NewCachedFilerRoleStore creates a new cached filer-based role store
func NewCachedFilerRoleStore(config map[string]interface{}) (*CachedFilerRoleStore, error) {
// Create underlying filer store
filerStore, err := NewFilerRoleStore(config, nil)
if err != nil {
return nil, fmt.Errorf("failed to create filer role store: %w", err)
}
// Parse cache configuration with defaults
cacheTTL := 5 * time.Minute // Default 5 minutes for role cache
listTTL := 1 * time.Minute // Default 1 minute for list cache
maxCacheSize := 1000 // Default max 1000 cached roles
if config != nil {
if ttlStr, ok := config["ttl"].(string); ok && ttlStr != "" {
if parsed, err := time.ParseDuration(ttlStr); err == nil {
cacheTTL = parsed
}
}
if listTTLStr, ok := config["listTtl"].(string); ok && listTTLStr != "" {
if parsed, err := time.ParseDuration(listTTLStr); err == nil {
listTTL = parsed
}
}
if maxSize, ok := config["maxCacheSize"].(int); ok && maxSize > 0 {
maxCacheSize = maxSize
}
}
// Create ccache instances with appropriate configurations
pruneCount := int64(maxCacheSize) >> 3
if pruneCount <= 0 {
pruneCount = 100
}
store := &CachedFilerRoleStore{
filerStore: filerStore,
cache: ccache.New(ccache.Configure().MaxSize(int64(maxCacheSize)).ItemsToPrune(uint32(pruneCount))),
listCache: ccache.New(ccache.Configure().MaxSize(100).ItemsToPrune(10)), // Smaller cache for lists
ttl: cacheTTL,
listTTL: listTTL,
}
glog.V(2).Infof("Initialized CachedFilerRoleStore with TTL %v, List TTL %v, Max Cache Size %d",
cacheTTL, listTTL, maxCacheSize)
return store, nil
}
// StoreRole stores a role definition and invalidates the cache
func (c *CachedFilerRoleStore) StoreRole(ctx context.Context, filerAddress string, roleName string, role *RoleDefinition) error {
// Store in filer
err := c.filerStore.StoreRole(ctx, filerAddress, roleName, role)
if err != nil {
return err
}
// Invalidate cache entries
c.cache.Delete(roleName)
c.listCache.Clear() // Invalidate list cache
glog.V(3).Infof("Stored and invalidated cache for role %s", roleName)
return nil
}
// GetRole retrieves a role definition with caching
func (c *CachedFilerRoleStore) GetRole(ctx context.Context, filerAddress string, roleName string) (*RoleDefinition, error) {
// Try to get from cache first
item := c.cache.Get(roleName)
if item != nil {
// Cache hit - return cached role (DO NOT extend TTL)
role := item.Value().(*RoleDefinition)
glog.V(4).Infof("Cache hit for role %s", roleName)
return copyRoleDefinition(role), nil
}
// Cache miss - fetch from filer
glog.V(4).Infof("Cache miss for role %s, fetching from filer", roleName)
role, err := c.filerStore.GetRole(ctx, filerAddress, roleName)
if err != nil {
return nil, err
}
// Cache the result with TTL
c.cache.Set(roleName, copyRoleDefinition(role), c.ttl)
glog.V(3).Infof("Cached role %s with TTL %v", roleName, c.ttl)
return role, nil
}
// ListRoles lists all role names with caching
func (c *CachedFilerRoleStore) ListRoles(ctx context.Context, filerAddress string) ([]string, error) {
// Use a constant key for the role list cache
const listCacheKey = "role_list"
// Try to get from list cache first
item := c.listCache.Get(listCacheKey)
if item != nil {
// Cache hit - return cached list (DO NOT extend TTL)
roles := item.Value().([]string)
glog.V(4).Infof("List cache hit, returning %d roles", len(roles))
return append([]string(nil), roles...), nil // Return a copy
}
// Cache miss - fetch from filer
glog.V(4).Infof("List cache miss, fetching from filer")
roles, err := c.filerStore.ListRoles(ctx, filerAddress)
if err != nil {
return nil, err
}
// Cache the result with TTL (store a copy)
rolesCopy := append([]string(nil), roles...)
c.listCache.Set(listCacheKey, rolesCopy, c.listTTL)
glog.V(3).Infof("Cached role list with %d entries, TTL %v", len(roles), c.listTTL)
return roles, nil
}
// DeleteRole deletes a role definition and invalidates the cache
func (c *CachedFilerRoleStore) DeleteRole(ctx context.Context, filerAddress string, roleName string) error {
// Delete from filer
err := c.filerStore.DeleteRole(ctx, filerAddress, roleName)
if err != nil {
return err
}
// Invalidate cache entries
c.cache.Delete(roleName)
c.listCache.Clear() // Invalidate list cache
glog.V(3).Infof("Deleted and invalidated cache for role %s", roleName)
return nil
}
// ClearCache clears all cached entries (for testing or manual cache invalidation)
func (c *CachedFilerRoleStore) ClearCache() {
c.cache.Clear()
c.listCache.Clear()
glog.V(2).Infof("Cleared all role cache entries")
}
// GetCacheStats returns cache statistics
func (c *CachedFilerRoleStore) GetCacheStats() map[string]interface{} {
return map[string]interface{}{
"roleCache": map[string]interface{}{
"size": c.cache.ItemCount(),
"ttl": c.ttl.String(),
},
"listCache": map[string]interface{}{
"size": c.listCache.ItemCount(),
"ttl": c.listTTL.String(),
},
}
}