Skip to content

Commit 0b44254

Browse files
committed
Fix grib CDM index update logic
isUpdateNeeded only tells you for sure that a collection does not need updated; if isUpdateNeeded returns true, there are still more checks that need to happen before we know that an update is actually needed.
1 parent d260093 commit 0b44254

1 file changed

Lines changed: 17 additions & 31 deletions

File tree

grib/src/main/java/ucar/nc2/grib/collection/GribCdmIndex.java

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,10 @@ public static boolean updateGribCollection(FeatureCollectionConfig config, Colle
368368
public static boolean updateGribCollection(boolean isGrib1, MCollection dcm, CollectionUpdateType updateType,
369369
FeatureCollectionConfig.PartitionType ptype, Logger logger, Formatter errlog) throws IOException {
370370

371-
boolean updateNeeded = isUpdateNeeded(dcm.getIndexFilename(NCX_SUFFIX), updateType,
372-
(isGrib1 ? GribCollectionType.GRIB1 : GribCollectionType.GRIB2), logger);
373-
logger.debug("GribCdmIndex.updateGribCollection (mcoll) {} {} updateNeeded={}", dcm.getCollectionName(), updateType,
374-
updateNeeded);
371+
logger.debug("GribCdmIndex.updateGribCollection {} {}", dcm.getCollectionName(), updateType);
372+
if (!isUpdateNeeded(dcm.getIndexFilename(NCX_SUFFIX), updateType,
373+
(isGrib1 ? GribCollectionType.GRIB1 : GribCollectionType.GRIB2), logger))
374+
return false;
375375

376376
boolean changed;
377377
if (isGrib1) { // existing case handles correctly - make separate index for each runtime (OR) partition == runtime
@@ -381,17 +381,12 @@ public static boolean updateGribCollection(boolean isGrib1, MCollection dcm, Col
381381
Grib2CollectionBuilder builder = new Grib2CollectionBuilder(dcm.getCollectionName(), dcm, logger);
382382
changed = builder.updateNeeded(updateType) && builder.createIndex(ptype, errlog);
383383
}
384-
return changed || updateNeeded;
384+
return changed;
385385
}
386386

387387
// return true if changed, exception on failure
388388
private static boolean updatePartition(boolean isGrib1, PartitionManager dcm, CollectionUpdateType updateType,
389389
Logger logger, Formatter errlog) throws IOException {
390-
boolean updateNeeded = isUpdateNeeded(dcm.getIndexFilename(NCX_SUFFIX), updateType,
391-
(isGrib1 ? GribCollectionType.Partition1 : GribCollectionType.Partition2), logger);
392-
logger.debug("GribCdmIndex.updatePartition {} {} updateNeeded={}", dcm.getCollectionName(), updateType,
393-
updateNeeded);
394-
395390
boolean changed;
396391
if (isGrib1) {
397392
Grib1PartitionBuilder builder =
@@ -403,7 +398,7 @@ private static boolean updatePartition(boolean isGrib1, PartitionManager dcm, Co
403398
new Grib2PartitionBuilder(dcm.getCollectionName(), MFiles.create(dcm.getRoot()), dcm, logger);
404399
changed = builder.updateNeeded(updateType) && builder.createPartitionedIndex(updateType, errlog);
405400
}
406-
return changed || updateNeeded;
401+
return changed;
407402
}
408403

409404

@@ -491,30 +486,25 @@ private static boolean isUpdateNeeded(String idxFilenameOrg, CollectionUpdateTyp
491486
private static boolean updateDirectoryCollectionRecurse(boolean isGrib1, DirectoryPartition dpart,
492487
FeatureCollectionConfig config, CollectionUpdateType updateType, Logger logger) throws IOException {
493488

494-
boolean updateNeeded = isUpdateNeeded(dpart.getIndexFilename(NCX_SUFFIX), updateType,
495-
(isGrib1 ? GribCollectionType.Partition1 : GribCollectionType.Partition2), logger);
496-
logger.debug("GribCdmIndex.updateDirectoryCollectionRecurse {} {} updateNeeded={}", dpart.getRoot(), updateType,
497-
updateNeeded);
489+
logger.debug("GribCdmIndex.updateDirectoryCollectionRecurse {} {}", dpart.getRoot(), updateType);
490+
if (!isUpdateNeeded(dpart.getIndexFilename(NCX_SUFFIX), updateType,
491+
(isGrib1 ? GribCollectionType.Partition1 : GribCollectionType.Partition2), logger))
492+
return false;
498493

499494
long start = System.currentTimeMillis();
500-
AtomicBoolean anyChange = new AtomicBoolean(false);
501495

502496
// check the children partitions first
503497
if (updateType != CollectionUpdateType.testIndexOnly) { // skip children on testIndexOnly
504498
for (MCollection part : dpart.makePartitions(updateType)) {
505499
part.putAuxInfo(FeatureCollectionConfig.AUX_CONFIG, config);
506500
try {
507-
boolean changed;
508501
if (part instanceof DirectoryPartition) { // LOOK if child partition fails, the parent partition doesnt know
509-
// that - suckage
510-
changed = updateDirectoryCollectionRecurse(isGrib1, (DirectoryPartition) part, config, updateType, logger);
502+
// that - suckage
503+
updateDirectoryCollectionRecurse(isGrib1, (DirectoryPartition) part, config, updateType, logger);
511504
} else {
512505
String partPath = part.getRoot();
513-
changed = updateLeafCollection(isGrib1, config, updateType, false, logger, partPath); // LOOK why not using
514-
// part ??
506+
updateLeafCollection(isGrib1, config, updateType, false, logger, partPath); // LOOK why not using part ??
515507
}
516-
if (changed)
517-
anyChange.set(true);
518508
} catch (IllegalStateException t) {
519509
logger.warn("Error making partition {} '{}'", part.getRoot(), t.getMessage());
520510
dpart.removePartition(part); // keep on truckin; can happen if directory is empty
@@ -526,28 +516,24 @@ private static boolean updateDirectoryCollectionRecurse(boolean isGrib1, Directo
526516
} // loop over partitions
527517
}
528518

529-
if (!updateNeeded && !anyChange.get())
530-
return false;
531-
532519
try {
533520
// update the partition
534521
Formatter errlog = new Formatter();
535-
boolean recreated = updatePartition(isGrib1, dpart, updateType, logger, errlog);
522+
boolean changed = updatePartition(isGrib1, dpart, updateType, logger, errlog);
536523

537-
boolean changed = recreated || anyChange.get();
538524
long took = System.currentTimeMillis() - start;
539525
errlog.format(" INFO updateDirectoryCollectionRecurse %s took %d msecs%n", dpart.getRoot(), took);
540526
logger.debug("GribCdmIndex.updateDirectoryCollectionRecurse complete ({}) on {} errlog={}", changed,
541527
dpart.getRoot(), errlog);
542-
return changed || updateNeeded;
528+
return changed;
543529

544530
} catch (IllegalStateException t) {
545531
logger.warn("Error making partition {} '{}'", dpart.getRoot(), t.getMessage());
546-
return updateNeeded;
532+
return false;
547533

548534
} catch (Throwable t) {
549535
logger.error("Error making partition " + dpart.getRoot(), t);
550-
return updateNeeded;
536+
return false;
551537
}
552538
}
553539

0 commit comments

Comments
 (0)