diff --git a/weed/s3api/bucket_paths.go b/weed/s3api/bucket_paths.go index f9bf71518..88843f374 100644 --- a/weed/s3api/bucket_paths.go +++ b/weed/s3api/bucket_paths.go @@ -58,16 +58,7 @@ func (s3a *S3ApiServer) tableLocationDir(bucket string) (string, bool) { s3a.bucketRegistry.tableLocationLock.RUnlock() } - entry, err := s3a.getEntry(s3tables.GetTableLocationMappingDir(), bucket) - tablePath := "" - if err == nil && entry != nil { - if entry.IsDirectory { - tablePath, err = s3a.readTableLocationMappingFromDirectory(bucket) - } else if len(entry.Content) > 0 { - // Backward compatibility with legacy single-file mappings. - tablePath = normalizeTableLocationMappingPath(string(entry.Content)) - } - } + tablePath, err := s3a.lookupTableLocationMapping(bucket, s3tables.GetTableLocationMappingDir()) // Only cache definitive results: successful lookup (tablePath set) or definitive not-found (ErrNotFound) // Don't cache transient errors to avoid treating temporary failures as permanent misses @@ -89,8 +80,7 @@ func (s3a *S3ApiServer) tableLocationDir(bucket string) (string, bool) { return tablePath, true } -func (s3a *S3ApiServer) readTableLocationMappingFromDirectory(bucket string) (string, error) { - mappingDir := s3tables.GetTableLocationMappingPath(bucket) +func (s3a *S3ApiServer) readTableLocationMappingFromDirectory(mappingDir string) (string, error) { var mappedPath string conflict := false @@ -134,12 +124,26 @@ func (s3a *S3ApiServer) readTableLocationMappingFromDirectory(bucket string) (st } if conflict { - glog.V(1).Infof("table location mapping conflict for %s: multiple mapped roots found", bucket) + glog.V(1).Infof("table location mapping conflict under %s: multiple mapped roots found", mappingDir) return "", nil } return mappedPath, nil } +func (s3a *S3ApiServer) lookupTableLocationMapping(bucket, mappingDir string) (string, error) { + entry, err := s3a.getEntry(mappingDir, bucket) + if err != nil || entry == nil { + return "", err + } + if entry.IsDirectory { + return s3a.readTableLocationMappingFromDirectory(path.Join(mappingDir, bucket)) + } + if len(entry.Content) == 0 { + return "", nil + } + return normalizeTableLocationMappingPath(string(entry.Content)), nil +} + func normalizeTableLocationMappingPath(rawPath string) string { rawPath = strings.TrimSpace(rawPath) if rawPath == "" { diff --git a/weed/s3api/s3tables/utils.go b/weed/s3api/s3tables/utils.go index 1d8357040..1e64bfbf6 100644 --- a/weed/s3api/s3tables/utils.go +++ b/weed/s3api/s3tables/utils.go @@ -21,7 +21,7 @@ const ( ) const ( - tableLocationMappingsDirName = ".table-location-mappings" + tableLocationMappingsDirPath = "/etc/s3tables" tableObjectRootDirName = ".objects" ) @@ -111,7 +111,7 @@ func GetTableObjectBucketPath(bucketName string) string { // GetTableLocationMappingDir returns the root path for table location bucket mappings func GetTableLocationMappingDir() string { - return path.Join(TablesPath, tableLocationMappingsDirName) + return tableLocationMappingsDirPath } // GetTableLocationMappingPath returns the filer path for a table location bucket mapping