@@ -127,7 +127,8 @@ protected void handlePutDirEvent(OmDirectoryInfo directoryInfo,
127127 long objectId = directoryInfo .getObjectID ();
128128 // write the dir name to the current directory
129129 String dirName = directoryInfo .getName ();
130- // Try to get the NSSummary from our local map that maps NSSummaries to IDs
130+
131+ // Get or create the directory's NSSummary
131132 NSSummary curNSSummary = nsSummaryMap .get (objectId );
132133 if (curNSSummary == null ) {
133134 // If we don't have it in this batch we try to get it from the DB
@@ -140,34 +141,32 @@ protected void handlePutDirEvent(OmDirectoryInfo directoryInfo,
140141 int existingNumOfFiles = directoryAlreadyExists ? curNSSummary .getNumOfFiles () : 0 ;
141142 long existingReplicatedSizeOfFiles = directoryAlreadyExists ? curNSSummary .getReplicatedSizeOfFiles () : 0 ;
142143
143- if (curNSSummary == null ) {
144- // If we don't have it locally and in the DB we create a new instance
145- // as this is a new ID
144+ if (!directoryAlreadyExists ) {
146145 curNSSummary = new NSSummary ();
147146 }
148147 curNSSummary .setDirName (dirName );
149- // Set the parent directory ID
150148 curNSSummary .setParentId (parentObjectId );
151149 nsSummaryMap .put (objectId , curNSSummary );
152150
153- // Write the child dir list to the parent directory
154- // Try to get the NSSummary from our local map that maps NSSummaries to IDs
155- NSSummary nsSummary = nsSummaryMap .get (parentObjectId );
156- if (nsSummary == null ) {
157- // If we don't have it in this batch we try to get it from the DB
158- nsSummary = reconNamespaceSummaryManager .getNSSummary (parentObjectId );
151+ // Get or create the parent's NSSummary
152+ NSSummary parentNSSummary = nsSummaryMap .get (parentObjectId );
153+ if (parentNSSummary == null ) {
154+ parentNSSummary = reconNamespaceSummaryManager .getNSSummary (parentObjectId );
159155 }
160- if (nsSummary == null ) {
156+ if (parentNSSummary == null ) {
161157 // If we don't have it locally and in the DB we create a new instance
162158 // as this is a new ID
163- nsSummary = new NSSummary ();
159+ parentNSSummary = new NSSummary ();
164160 }
165- nsSummary .addChildDir (objectId );
166- nsSummaryMap .put (parentObjectId , nsSummary );
161+
162+ // Add child directory to parent
163+ parentNSSummary .addChildDir (objectId );
164+ nsSummaryMap .put (parentObjectId , parentNSSummary );
167165
168166 // If the directory already existed with content, propagate its totals upward
167+ // propagateSizeUpwards will update parent, grandparent, etc.
169168 if (directoryAlreadyExists && (existingSizeOfFiles > 0 || existingNumOfFiles > 0 )) {
170- propagateSizeUpwards (parentObjectId , existingSizeOfFiles ,
169+ propagateSizeUpwards (objectId , existingSizeOfFiles ,
171170 existingReplicatedSizeOfFiles , existingNumOfFiles , nsSummaryMap );
172171 }
173172 }
@@ -233,32 +232,25 @@ protected void handleDeleteDirEvent(OmDirectoryInfo directoryInfo,
233232 return ;
234233 }
235234
236- // If deleted directory exists, decrement its totals from parent and propagate
235+ // Remove the deleted directory ID from parent's childDir set
236+ parentNsSummary .removeChildDir (deletedDirObjectId );
237+ nsSummaryMap .put (parentObjectId , parentNsSummary );
238+
239+ // If deleted directory exists, propagate its totals upward (as negative deltas)
240+ // propagateSizeUpwards will update parent, grandparent, etc.
237241 if (deletedDirSummary != null ) {
238- // Decrement parent's totals by the deleted directory's totals
239- parentNsSummary .setNumOfFiles (parentNsSummary .getNumOfFiles () - deletedDirSummary .getNumOfFiles ());
240- parentNsSummary .setSizeOfFiles (parentNsSummary .getSizeOfFiles () - deletedDirSummary .getSizeOfFiles ());
241- long parentReplSize = parentNsSummary .getReplicatedSizeOfFiles ();
242242 long deletedReplSize = deletedDirSummary .getReplicatedSizeOfFiles ();
243- if (parentReplSize >= 0 && deletedReplSize >= 0 ) {
244- parentNsSummary .setReplicatedSizeOfFiles (parentReplSize - deletedReplSize );
245- }
246-
247- // Propagate the decrements upwards to all ancestors
248243 if (deletedReplSize < 0 ) {
249244 deletedReplSize = 0 ;
250245 }
251- propagateSizeUpwards (parentObjectId , -deletedDirSummary .getSizeOfFiles (),
246+
247+ propagateSizeUpwards (deletedDirObjectId , -deletedDirSummary .getSizeOfFiles (),
252248 -deletedReplSize , -deletedDirSummary .getNumOfFiles (), nsSummaryMap );
253249
254250 // Set the deleted directory's parentId to 0 (unlink it)
255251 deletedDirSummary .setParentId (0 );
256252 nsSummaryMap .put (deletedDirObjectId , deletedDirSummary );
257253 }
258-
259- // Remove the deleted directory ID from parent's childDir set
260- parentNsSummary .removeChildDir (deletedDirObjectId );
261- nsSummaryMap .put (parentObjectId , parentNsSummary );
262254 }
263255
264256 protected boolean flushAndCommitNSToDB (Map <Long , NSSummary > nsSummaryMap ) {
0 commit comments