public Catalog alterCatalog()

in core/src/main/java/org/apache/gravitino/catalog/CatalogManager.java [623:706]


  public Catalog alterCatalog(NameIdentifier ident, CatalogChange... changes)
      throws NoSuchCatalogException, IllegalArgumentException {
    TreeLockUtils.doWithTreeLock(
        ident,
        LockType.READ,
        () -> {
          checkCatalogInUse(store, ident);

          // There could be a race issue that someone is using the catalog from cache while we are
          // updating it.

          CatalogWrapper catalogWrapper = loadCatalogAndWrap(ident);
          if (catalogWrapper == null) {
            throw new NoSuchCatalogException(CATALOG_DOES_NOT_EXIST_MSG, ident);
          }

          try {
            catalogWrapper.doWithPropertiesMeta(
                f -> {
                  Pair<Map<String, String>, Map<String, String>> alterProperty =
                      getCatalogAlterProperty(changes);
                  validatePropertyForAlter(
                      f.catalogPropertiesMetadata(),
                      alterProperty.getLeft(),
                      alterProperty.getRight());
                  return null;
                });
          } catch (IllegalArgumentException e1) {
            throw e1;
          } catch (Exception e) {
            LOG.error("Failed to alter catalog {}", ident, e);
            throw new RuntimeException(e);
          }
          return null;
        });

    boolean containsRenameCatalog =
        Arrays.stream(changes).anyMatch(c -> c instanceof CatalogChange.RenameCatalog);
    NameIdentifier nameIdentifierForLock =
        containsRenameCatalog ? NameIdentifier.of(ident.namespace().level(0)) : ident;

    return TreeLockUtils.doWithTreeLock(
        nameIdentifierForLock,
        LockType.WRITE,
        () -> {
          catalogCache.invalidate(ident);
          try {
            CatalogEntity updatedCatalog =
                store.update(
                    ident,
                    CatalogEntity.class,
                    EntityType.CATALOG,
                    catalog -> {
                      CatalogEntity.Builder newCatalogBuilder =
                          newCatalogBuilder(ident.namespace(), catalog);

                      Map<String, String> newProps =
                          catalog.getProperties() == null
                              ? new HashMap<>()
                              : new HashMap<>(catalog.getProperties());
                      newCatalogBuilder = updateEntity(newCatalogBuilder, newProps, changes);

                      return newCatalogBuilder.build();
                    });
            return Objects.requireNonNull(
                    catalogCache.get(
                        updatedCatalog.nameIdentifier(),
                        id -> createCatalogWrapper(updatedCatalog, null)))
                .catalog;

          } catch (NoSuchEntityException ne) {
            LOG.warn("Catalog {} does not exist", ident, ne);
            throw new NoSuchCatalogException(CATALOG_DOES_NOT_EXIST_MSG, ident);

          } catch (IllegalArgumentException iae) {
            LOG.warn("Failed to alter catalog {} with unknown change", ident, iae);
            throw iae;

          } catch (IOException ioe) {
            LOG.error("Failed to alter catalog {}", ident, ioe);
            throw new RuntimeException(ioe);
          }
        });
  }