@@ -450,8 +450,9 @@ function putData(request, response, bucketInfo, objMd, log, callback) {
450450 errorInstances . BadRequest . customizeDescription ( 'bad request: invalid x-scal-version-id header' ) ,
451451 ) ;
452452 }
453- if ( objMd && objMd . versionId === incomingVersionIdDecoded ) {
454- // Data already at destination for this version; return 409 with the existing
453+ if ( objMd ) {
454+ // objMd is the specific version (fetched by versionId from x-scal-version-id header)
455+ // its existence means data is already at destination. Return 409 with the existing
455456 // microVersionId so backbeat can decide if putMetadata is still needed.
456457 log . debug ( 'crr putData: version already at destination' , {
457458 method : 'putData' ,
@@ -2069,7 +2070,20 @@ function routeBackbeat(clientIP, request, response, log) {
20692070 } ) ;
20702071 return next ( errors . InvalidArgument ) ;
20712072 }
2072- const versionId = decodedVidResult ;
2073+ let versionId = decodedVidResult ;
2074+ // For putData api: the version to check is passed
2075+ // via x-scal-version-id header, not the URL query. Fetch that specific
2076+ // version so objMd matches the replicated version, not always the master.
2077+ const isPutDataApi = request . method === 'PUT' && request . resourceType === 'data' ;
2078+ if ( isPutDataApi ) {
2079+ const versionIdHeader = request . headers [ 'x-scal-version-id' ] ;
2080+ if ( versionIdHeader !== undefined && versionIdHeader !== 'null' ) {
2081+ const decoded = decode ( versionIdHeader ) ;
2082+ if ( ! ( decoded instanceof Error ) ) {
2083+ versionId = decoded ;
2084+ }
2085+ }
2086+ }
20732087 if ( useMultipleBackend ) {
20742088 if ( request . resourceType === 'multiplebackendmetadata' ) {
20752089 return backbeatRoutes [ request . method ] [ request . resourceType ] ( request , response , log , next ) ;
0 commit comments