Browse Source

Remove deprecated functions: use new path-based functions directly

Remove deprecated wrapper functions and update all callers to use the
new function names directly.

Removed:
- genPartUploadUrl() → all callers now use genPartUploadPath()
- toFilerUrl() → all callers now use toFilerPath()
- SetFilerClient() → removed along with fallback code

Updated:
- s3api_object_handlers_multipart.go: uploadUrl → filePath
- s3api_object_handlers_put.go: uploadUrl → filePath, versionUploadUrl → versionFilePath
- s3api_object_versioning.go: toFilerUrl → toFilerPath
- s3api_object_handlers_test.go: toFilerUrl → toFilerPath
- auth_credentials.go: removed SetFilerClient fallback
- filer_etc_store.go: removed deprecated SetFilerClient method

Benefits:
- Cleaner codebase with no deprecated functions
- All variable names accurately reflect that they're paths, not URLs
- Single interface for credential stores (SetFilerAddressFunc only)

All code now consistently uses the new path-based approach.
pull/7550/head
Chris Lu 4 days ago
parent
commit
abf85bfe4f
  1. 11
      weed/credential/filer_etc/filer_etc_store.go
  2. 16
      weed/s3api/auth_credentials.go
  3. 5
      weed/s3api/s3api_object_handlers.go
  4. 9
      weed/s3api/s3api_object_handlers_multipart.go
  5. 18
      weed/s3api/s3api_object_handlers_put.go
  6. 2
      weed/s3api/s3api_object_handlers_test.go
  7. 6
      weed/s3api/s3api_object_versioning.go

11
weed/credential/filer_etc/filer_etc_store.go

@ -36,19 +36,10 @@ func (store *FilerEtcStore) Initialize(configuration util.Configuration, prefix
}
// TODO: Initialize grpcDialOption based on configuration
}
// Note: filerAddressFunc can be set later via SetFilerClient method
// Note: filerAddressFunc can be set later via SetFilerAddressFunc method
return nil
}
// SetFilerClient sets the filer client details for the file store
// Deprecated: Use SetFilerAddressFunc for better HA support
func (store *FilerEtcStore) SetFilerClient(filerAddress string, grpcDialOption grpc.DialOption) {
store.filerAddressFunc = func() pb.ServerAddress {
return pb.ServerAddress(filerAddress)
}
store.grpcDialOption = grpcDialOption
}
// SetFilerAddressFunc sets a function that returns the current active filer address
// This enables high availability by using the currently active filer
func (store *FilerEtcStore) SetFilerAddressFunc(getFiler func() pb.ServerAddress, grpcDialOption grpc.DialOption) {

16
weed/s3api/auth_credentials.go

@ -140,7 +140,6 @@ func NewIdentityAccessManagementWithStore(option *S3ApiServerOption, explicitSto
// For stores that need filer client details, set them
// Use SetFilerAddressFunc to provide current active filer for HA
if store := credentialManager.GetStore(); store != nil {
// Check for new HA-aware interface first
if filerFuncSetter, ok := store.(interface {
SetFilerAddressFunc(func() pb.ServerAddress, grpc.DialOption)
}); ok {
@ -149,7 +148,7 @@ func NewIdentityAccessManagementWithStore(option *S3ApiServerOption, explicitSto
// For now, use first filer - this will be updated when FilerClient is available
if len(option.Filers) > 0 {
// Create a closure that will use the first filer initially
// In a full implementation, this would get the FilerClient's current filer
// This will be updated later to use FilerClient's current filer
getFiler := func() pb.ServerAddress {
if len(option.Filers) > 0 {
return option.Filers[0]
@ -157,18 +156,7 @@ func NewIdentityAccessManagementWithStore(option *S3ApiServerOption, explicitSto
return ""
}
filerFuncSetter.SetFilerAddressFunc(getFiler, option.GrpcDialOption)
glog.V(1).Infof("Credential store configured with filer function (HA-aware)")
}
} else if filerClientSetter, ok := store.(interface {
SetFilerClient(string, grpc.DialOption)
}); ok {
// Fallback to old interface for backward compatibility
if len(option.Filers) > 0 {
filerAddr := option.Filers[0].ToGrpcAddress()
filerClientSetter.SetFilerClient(filerAddr, option.GrpcDialOption)
glog.V(1).Infof("Credential store configured with first filer: %s (legacy interface)", filerAddr)
} else {
glog.Warningf("No filer addresses configured for credential store")
glog.V(1).Infof("Credential store configured with filer function (will be updated to use FilerClient)")
}
}
}

5
weed/s3api/s3api_object_handlers.go

@ -409,11 +409,6 @@ func (s3a *S3ApiServer) toFilerPath(bucket, object string) string {
return fmt.Sprintf("%s/%s%s", s3a.option.BucketsPath, bucket, object)
}
// Deprecated: Use toFilerPath instead - no need for full URL
func (s3a *S3ApiServer) toFilerUrl(bucket, object string) string {
return s3a.toFilerPath(bucket, object)
}
// hasConditionalHeaders checks if the request has any conditional headers
// This is a lightweight check to avoid unnecessary function calls
func (s3a *S3ApiServer) hasConditionalHeaders(r *http.Request) bool {

9
weed/s3api/s3api_object_handlers_multipart.go

@ -404,7 +404,7 @@ func (s3a *S3ApiServer) PutObjectPartHandler(w http.ResponseWriter, r *http.Requ
}
}
uploadUrl := s3a.genPartUploadUrl(bucket, uploadID, partID)
filePath := s3a.genPartUploadPath(bucket, uploadID, partID)
if partID == 1 && r.Header.Get("Content-Type") == "" {
dataReader = mimeDetect(r, dataReader)
@ -413,7 +413,7 @@ func (s3a *S3ApiServer) PutObjectPartHandler(w http.ResponseWriter, r *http.Requ
glog.V(2).Infof("PutObjectPart: bucket=%s, object=%s, uploadId=%s, partNumber=%d, size=%d",
bucket, object, uploadID, partID, r.ContentLength)
etag, errCode, sseMetadata := s3a.putToFiler(r, uploadUrl, dataReader, bucket, partID)
etag, errCode, sseMetadata := s3a.putToFiler(r, filePath, dataReader, bucket, partID)
if errCode != s3err.ErrNone {
glog.Errorf("PutObjectPart: putToFiler failed with error code %v for bucket=%s, object=%s, partNumber=%d",
errCode, bucket, object, partID)
@ -444,11 +444,6 @@ func (s3a *S3ApiServer) genPartUploadPath(bucket, uploadID string, partID int) s
s3a.genUploadsFolder(bucket), uploadID, partID, uuid.NewString())
}
// Deprecated: Use genPartUploadPath instead - no need for full URL
func (s3a *S3ApiServer) genPartUploadUrl(bucket, uploadID string, partID int) string {
return s3a.genPartUploadPath(bucket, uploadID, partID)
}
// Generate uploadID hash string from object
func (s3a *S3ApiServer) generateUploadID(object string) string {

18
weed/s3api/s3api_object_handlers_put.go

@ -222,12 +222,12 @@ func (s3a *S3ApiServer) PutObjectHandler(w http.ResponseWriter, r *http.Request)
s3a.setSSEResponseHeaders(w, r, sseMetadata)
default:
// Handle regular PUT (never configured versioning)
uploadUrl := s3a.toFilerUrl(bucket, object)
filePath := s3a.toFilerPath(bucket, object)
if objectContentType == "" {
dataReader = mimeDetect(r, dataReader)
}
etag, errCode, sseMetadata := s3a.putToFiler(r, uploadUrl, dataReader, bucket, 1)
etag, errCode, sseMetadata := s3a.putToFiler(r, filePath, dataReader, bucket, 1)
if errCode != s3err.ErrNone {
s3err.WriteErrorResponse(w, r, errCode)
@ -730,7 +730,7 @@ func (s3a *S3ApiServer) setObjectOwnerFromRequest(r *http.Request, entry *filer_
// For suspended versioning, objects are stored as regular files (version ID "null") in the bucket directory,
// while existing versions from when versioning was enabled remain preserved in the .versions subdirectory.
func (s3a *S3ApiServer) putSuspendedVersioningObject(r *http.Request, bucket, object string, dataReader io.Reader, objectContentType string) (etag string, errCode s3err.ErrorCode, sseMetadata SSEResponseMetadata) {
// Normalize object path to ensure consistency with toFilerUrl behavior
// Normalize object path to ensure consistency with toFilerPath behavior
normalizedObject := removeDuplicateSlashes(object)
glog.V(3).Infof("putSuspendedVersioningObject: START bucket=%s, object=%s, normalized=%s",
@ -770,7 +770,7 @@ func (s3a *S3ApiServer) putSuspendedVersioningObject(r *http.Request, bucket, ob
glog.V(3).Infof("putSuspendedVersioningObject: no .versions directory for %s/%s", bucket, object)
}
uploadUrl := s3a.toFilerUrl(bucket, normalizedObject)
filePath := s3a.toFilerPath(bucket, normalizedObject)
body := dataReader
if objectContentType == "" {
@ -833,7 +833,7 @@ func (s3a *S3ApiServer) putSuspendedVersioningObject(r *http.Request, bucket, ob
}
// Upload the file using putToFiler - this will create the file with version metadata
etag, errCode, sseMetadata = s3a.putToFiler(r, uploadUrl, body, bucket, 1)
etag, errCode, sseMetadata = s3a.putToFiler(r, filePath, body, bucket, 1)
if errCode != s3err.ErrNone {
glog.Errorf("putSuspendedVersioningObject: failed to upload object: %v", errCode)
return "", errCode, SSEResponseMetadata{}
@ -924,7 +924,7 @@ func (s3a *S3ApiServer) putVersionedObject(r *http.Request, bucket, object strin
// Generate version ID
versionId = generateVersionId()
// Normalize object path to ensure consistency with toFilerUrl behavior
// Normalize object path to ensure consistency with toFilerPath behavior
normalizedObject := removeDuplicateSlashes(object)
glog.V(2).Infof("putVersionedObject: creating version %s for %s/%s (normalized: %s)", versionId, bucket, object, normalizedObject)
@ -935,7 +935,7 @@ func (s3a *S3ApiServer) putVersionedObject(r *http.Request, bucket, object strin
// Upload directly to the versions directory
// We need to construct the object path relative to the bucket
versionObjectPath := normalizedObject + s3_constants.VersionsFolder + "/" + versionFileName
versionUploadUrl := s3a.toFilerUrl(bucket, versionObjectPath)
versionFilePath := s3a.toFilerPath(bucket, versionObjectPath)
// Ensure the .versions directory exists before uploading
bucketDir := s3a.option.BucketsPath + "/" + bucket
@ -953,9 +953,9 @@ func (s3a *S3ApiServer) putVersionedObject(r *http.Request, bucket, object strin
body = mimeDetect(r, body)
}
glog.V(2).Infof("putVersionedObject: uploading %s/%s version %s to %s", bucket, object, versionId, versionUploadUrl)
glog.V(2).Infof("putVersionedObject: uploading %s/%s version %s to %s", bucket, object, versionId, versionFilePath)
etag, errCode, sseMetadata = s3a.putToFiler(r, versionUploadUrl, body, bucket, 1)
etag, errCode, sseMetadata = s3a.putToFiler(r, versionFilePath, body, bucket, 1)
if errCode != s3err.ErrNone {
glog.Errorf("putVersionedObject: failed to upload version: %v", errCode)
return "", "", errCode, SSEResponseMetadata{}

2
weed/s3api/s3api_object_handlers_test.go

@ -114,7 +114,7 @@ func TestRemoveDuplicateSlashes(t *testing.T) {
}
}
func TestS3ApiServer_toFilerUrl(t *testing.T) {
func TestS3ApiServer_toFilerPath(t *testing.T) {
tests := []struct {
name string
args string

6
weed/s3api/s3api_object_versioning.go

@ -607,7 +607,7 @@ func (s3a *S3ApiServer) calculateETagFromChunks(chunks []*filer_pb.FileChunk) st
// getSpecificObjectVersion retrieves a specific version of an object
func (s3a *S3ApiServer) getSpecificObjectVersion(bucket, object, versionId string) (*filer_pb.Entry, error) {
// Normalize object path to ensure consistency with toFilerUrl behavior
// Normalize object path to ensure consistency with toFilerPath behavior
normalizedObject := removeDuplicateSlashes(object)
if versionId == "" {
@ -639,7 +639,7 @@ func (s3a *S3ApiServer) getSpecificObjectVersion(bucket, object, versionId strin
// deleteSpecificObjectVersion deletes a specific version of an object
func (s3a *S3ApiServer) deleteSpecificObjectVersion(bucket, object, versionId string) error {
// Normalize object path to ensure consistency with toFilerUrl behavior
// Normalize object path to ensure consistency with toFilerPath behavior
normalizedObject := removeDuplicateSlashes(object)
if versionId == "" {
@ -843,7 +843,7 @@ func (s3a *S3ApiServer) ListObjectVersionsHandler(w http.ResponseWriter, r *http
// getLatestObjectVersion finds the latest version of an object by reading .versions directory metadata
func (s3a *S3ApiServer) getLatestObjectVersion(bucket, object string) (*filer_pb.Entry, error) {
// Normalize object path to ensure consistency with toFilerUrl behavior
// Normalize object path to ensure consistency with toFilerPath behavior
normalizedObject := removeDuplicateSlashes(object)
bucketDir := s3a.option.BucketsPath + "/" + bucket

Loading…
Cancel
Save