2323
2424import java .io .IOException ;
2525import java .nio .file .InvalidPathException ;
26+ import java .nio .file .Paths ;
2627import java .util .ArrayList ;
2728import java .util .Collections ;
2829import java .util .List ;
3132import java .util .function .BiFunction ;
3233
3334import org .apache .hadoop .hdds .client .ReplicationConfig ;
35+ import org .apache .hadoop .ozone .om .OzoneConfigUtil ;
36+ import org .apache .hadoop .ozone .om .request .file .OMDirectoryCreateRequestWithFSO ;
37+ import org .apache .hadoop .ozone .om .request .file .OMFileRequest ;
38+ import org .apache .hadoop .ozone .protocolPB .OMPBHelper ;
3439import org .apache .ratis .server .protocol .TermIndex ;
3540import org .apache .hadoop .hdds .utils .db .cache .CacheKey ;
3641import org .apache .hadoop .hdds .utils .db .cache .CacheValue ;
4146import org .apache .hadoop .ozone .om .exceptions .OMException ;
4247import org .apache .hadoop .ozone .om .helpers .KeyValueUtil ;
4348import org .apache .hadoop .ozone .om .helpers .OmBucketInfo ;
49+ import org .apache .hadoop .ozone .om .helpers .OmDirectoryInfo ;
4450import org .apache .hadoop .ozone .om .helpers .OmKeyInfo ;
4551import org .apache .hadoop .ozone .om .helpers .BucketLayout ;
4652import org .apache .hadoop .ozone .om .helpers .OmKeyLocationInfo ;
@@ -176,11 +182,72 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, TermIn
176182 OmBucketInfo omBucketInfo = getBucketInfo (omMetadataManager ,
177183 volumeName , bucketName );
178184
179- String ozoneKey = omMetadataManager .getOzoneKey (
180- volumeName , bucketName , keyName );
181-
182- String dbOzoneKey =
183- getDBOzoneKey (omMetadataManager , volumeName , bucketName , keyName );
185+ List <OmDirectoryInfo > missingParentInfos ;
186+ OMFileRequest .OMPathInfoWithFSO pathInfoFSO = OMFileRequest
187+ .verifyDirectoryKeysInPath (omMetadataManager , volumeName , bucketName ,
188+ keyName , Paths .get (keyName ));
189+ missingParentInfos = OMDirectoryCreateRequestWithFSO
190+ .getAllMissingParentDirInfo (ozoneManager , keyArgs , omBucketInfo ,
191+ pathInfoFSO , trxnLogIndex );
192+
193+ if (missingParentInfos != null ) {
194+ final long volumeId = omMetadataManager .getVolumeId (volumeName );
195+ final long bucketId = omMetadataManager .getBucketId (volumeName ,
196+ bucketName );
197+
198+ // add all missing parents to directory table
199+ addMissingParentsToCache (omBucketInfo , missingParentInfos ,
200+ omMetadataManager , volumeId , bucketId , trxnLogIndex );
201+
202+ String multipartOpenKey = omMetadataManager
203+ .getMultipartKey (volumeId , bucketId ,
204+ pathInfoFSO .getLastKnownParentId (),
205+ pathInfoFSO .getLeafNodeName (),
206+ keyArgs .getMultipartUploadID ());
207+
208+ if (getOmKeyInfoFromOpenKeyTable (multipartOpenKey ,
209+ keyName , omMetadataManager ) == null ) {
210+
211+ final ReplicationConfig replicationConfig = OzoneConfigUtil
212+ .resolveReplicationConfigPreference (keyArgs .getType (),
213+ keyArgs .getFactor (), keyArgs .getEcReplicationConfig (),
214+ omBucketInfo != null ?
215+ omBucketInfo .getDefaultReplicationConfig () :
216+ null , ozoneManager );
217+
218+ OmMultipartKeyInfo multipartKeyInfoFromArgs =
219+ new OmMultipartKeyInfo .Builder ()
220+ .setUploadID (keyArgs .getMultipartUploadID ())
221+ .setCreationTime (keyArgs .getModificationTime ())
222+ .setReplicationConfig (replicationConfig )
223+ .setObjectID (pathInfoFSO .getLeafNodeObjectId ())
224+ .setUpdateID (trxnLogIndex )
225+ .setParentID (pathInfoFSO .getLastKnownParentId ())
226+ .build ();
227+
228+ OmKeyInfo keyInfoFromArgs = new OmKeyInfo .Builder ()
229+ .setVolumeName (volumeName )
230+ .setBucketName (bucketName )
231+ .setKeyName (keyName )
232+ .setCreationTime (keyArgs .getModificationTime ())
233+ .setModificationTime (keyArgs .getModificationTime ())
234+ .setReplicationConfig (replicationConfig )
235+ .setOmKeyLocationInfos (Collections .singletonList (
236+ new OmKeyLocationInfoGroup (0 , new ArrayList <>(), true )))
237+ .setAcls (getAclsForKey (keyArgs , omBucketInfo , pathInfoFSO ,
238+ ozoneManager .getPrefixManager ()))
239+ .setObjectID (pathInfoFSO .getLeafNodeObjectId ())
240+ .setUpdateID (trxnLogIndex )
241+ .setFileEncryptionInfo (keyArgs .hasFileEncryptionInfo () ?
242+ OMPBHelper .convert (keyArgs .getFileEncryptionInfo ()) : null )
243+ .setParentObjectID (pathInfoFSO .getLastKnownParentId ())
244+ .build ();
245+
246+ // Add missing multi part info to open key table
247+ addMultiPartToCache (omMetadataManager , multipartOpenKey ,
248+ pathInfoFSO , keyInfoFromArgs , trxnLogIndex );
249+ }
250+ }
184251
185252 String dbMultipartOpenKey =
186253 getDBMultipartOpenKey (volumeName , bucketName , keyName , uploadID ,
@@ -189,6 +256,12 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, TermIn
189256 OmMultipartKeyInfo multipartKeyInfo = omMetadataManager
190257 .getMultipartInfoTable ().get (multipartKey );
191258
259+ String ozoneKey = omMetadataManager .getOzoneKey (
260+ volumeName , bucketName , keyName );
261+
262+ String dbOzoneKey =
263+ getDBOzoneKey (omMetadataManager , volumeName , bucketName , keyName );
264+
192265 // Check for directory exists with same name for the LEGACY_FS,
193266 // if it exists throw error.
194267 checkDirectoryAlreadyExists (ozoneManager , omBucketInfo , keyName ,
@@ -284,7 +357,7 @@ public OMClientResponse validateAndUpdateCache(OzoneManager ozoneManager, TermIn
284357 omClientResponse =
285358 getOmClientResponse (multipartKey , omResponse , dbMultipartOpenKey ,
286359 omKeyInfo , allKeyInfoToRemove , omBucketInfo ,
287- volumeId , bucketId );
360+ volumeId , bucketId , missingParentInfos , multipartKeyInfo );
288361
289362 result = Result .SUCCESS ;
290363 } else {
@@ -325,7 +398,8 @@ protected OMClientResponse getOmClientResponse(String multipartKey,
325398 OMResponse .Builder omResponse , String dbMultipartOpenKey ,
326399 OmKeyInfo omKeyInfo , List <OmKeyInfo > allKeyInfoToRemove ,
327400 OmBucketInfo omBucketInfo ,
328- long volumeId , long bucketId ) {
401+ long volumeId , long bucketId , List <OmDirectoryInfo > missingParentInfos ,
402+ OmMultipartKeyInfo multipartKeyInfo ) {
329403
330404 return new S3MultipartUploadCompleteResponse (omResponse .build (),
331405 multipartKey , dbMultipartOpenKey , omKeyInfo , allKeyInfoToRemove ,
@@ -464,6 +538,22 @@ protected String getDBOzoneKey(OMMetadataManager omMetadataManager,
464538 return omMetadataManager .getOzoneKey (volumeName , bucketName , keyName );
465539 }
466540
541+ protected void addMissingParentsToCache (OmBucketInfo omBucketInfo ,
542+ List <OmDirectoryInfo > missingParentInfos ,
543+ OMMetadataManager omMetadataManager ,
544+ long volumeId , long bucketId , long transactionLogIndex
545+ ) throws IOException {
546+ // FSO is disabled. Do nothing.
547+ }
548+
549+ protected void addMultiPartToCache (
550+ OMMetadataManager omMetadataManager , String multipartOpenKey ,
551+ OMFileRequest .OMPathInfoWithFSO pathInfoFSO , OmKeyInfo omKeyInfo ,
552+ long transactionLogIndex
553+ ) throws IOException {
554+ // FSO is disabled. Do nothing.
555+ }
556+
467557 protected OmKeyInfo getOmKeyInfoFromKeyTable (String dbOzoneKey ,
468558 String keyName , OMMetadataManager omMetadataManager ) throws IOException {
469559 return omMetadataManager .getKeyTable (getBucketLayout ()).get (dbOzoneKey );
0 commit comments