Skip to content

Conversation

@nk1506
Copy link
Contributor

@nk1506 nk1506 commented Jan 12, 2024

@nk1506
Copy link
Contributor Author

nk1506 commented Jan 12, 2024

cc: @pvary


} finally {
cleanupMetadataAndUnlock(commitStatus, newMetadataLocation, lock);
if (!conf.getBoolean(ConfigProperties.KEEP_HIVE_STATS, false)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the obsolete props are being merged together now. Earlier It was being managed by
removedProps
and hiveStatCheck

}

@SuppressWarnings("checkstyle:CyclomaticComplexity")
default void commitWithLocking(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea here is to generalise doCommit from HiveTableOperations. It should be used by view too.

* @return Commit Status of Success, Failure or Unknown
*/
protected CommitStatus checkCommitStatus(String newMetadataLocation, TableMetadata config) {
int maxAttempts =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needed to move to a common place so that other operations like View can also use it.

@nk1506
Copy link
Contributor Author

nk1506 commented Jan 23, 2024

@szehon-ho With issue #9514 we are discussing what would be the best approach to handle this? We have not concluded on anything yet which is why this PR is still in progress state.

Copy link
Member

@szehon-ho szehon-ho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took a first pass

maxAttempts);
}
return status.get();
return MetastoreOperationsUtil.checkCommitStatus(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My question here is, does it have to be a Util?

Usually in Iceberg, I notice that we tend to do shared code using abstract classes. For example, a BaseMetastoreOperations that defines the common methods, and then have BaseMetastoreTableOperations and then BaseMetastoreViewOperations. That way, we can make those be 'protected'

String tableName,
String newMetadataLocation,
Map<String, String> properties,
Function<String, Boolean> commitStatusSupplier) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about, passing in a method to just get the current metadata location(s)? ie, Runnable<List> refreshMetadataLocations

Then the common logic can include the comparison with new metadata location?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't understand this part very well. Could you please elaborate more?
The validation happens either with current metadata location or with previous files. How only current metadata location is going to help?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant something like:


checkCommitStatus(String newMetadataLocation, TableMetadata config, Runnable<List<String>> loadMetadataLocations)

    ... // existing common code

    Tasks.foreach(newMetadataLocation)
        .retry(maxAttempts)
        .suppressFailureWhenFinished()
        .exponentialBackoff(minWaitMs, maxWaitMs, totalRetryMs, 2.0)
        .onFailure(
            (location, checkException) ->
                LOG.error("Cannot check if commit to {} exists.", tableName(), checkException))
        .run(
            location -> {
              List<String> allMetadataLocations = loadMetadataLocations();
              boolean commitSuccess = allMetadataLocations.contains(newMetadataLocations);

              if (commitSuccess) {
                ...
                 status.set(CommitStatus.SUCCESS);
              } else {
                 ...
              }
            });

      ... // rest of existing common code

That way, we can just have the different implementations like:

HiveTableOperations {
   List<String> loadMetadataLocations() {
       TableMetadata metadata = refresh();
       return ImmutableList.Builder
           .add(metadata.metadataFileLocation())
           .addAll(metadata.previousFiles())
           .build();
   }
}

ViewTableOperations {
      List<String> loadMetadataLocations() {
       ViewMetadata metadata = refresh();
       return ImmutableList.Builder
           .add(metadata.metadataFileLocation())
           .addAll(metadata.previousFiles())
           .build();
   }
}

and pass this::loadMetadataLocations() into checkCommitStatus() call. Is that clearer? This allows us to more code, if we dont go with the common interface for View and Table hierarchies.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean runnable or supplier here for lazy loading ?

@nk1506 nk1506 force-pushed the hive_table_ops_refactor branch 2 times, most recently from 67077a8 to d3e1555 Compare January 27, 2024 01:57
@nk1506 nk1506 requested a review from szehon-ho February 2, 2024 01:17
Copy link
Member

@szehon-ho szehon-ho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi , I am sorry for the late reply.

I left some more comments and explanations of preivous comments.

I am also now thinking, whether it makes sense to have a common interface for TableMetadata and ViewMetadata, as @pvary originally suggested. Something like HasLocations or HasProperties may help us already remove lots of duplicate code here. There is already precdent in Table => HasTableOperations, and many other interfaces in Iceberg code, and should not be very visible to the user.

/**
* Attempt to load the table and see if any current or past metadata location matches the one we
* were attempting to set. This is used as a last resort when we are dealing with exceptions that
* may indicate the commit has failed but are not proof that this is the case. Past locations must
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: 'are not proof' => 'don't have proof'

How about 'Past locations must ...' => 'Note that all previous locations must ...'

COMMIT_STATUS_CHECKS_TOTAL_WAIT_MS_DEFAULT);

AtomicReference<BaseMetastoreTableOperations.CommitStatus> status =
new AtomicReference<>(BaseMetastoreTableOperations.CommitStatus.UNKNOWN);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move CommitStatus to this class, and make it protected?

That way the BaseMetastoreTableOperations should not need to make it public.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can. with the following options:

  1. Move CommitStatus from BaseMetastoreTableOperations to BaseMetastoreOperations which will show changes to many files related to other catalogs.
  2. Keep CommitStatus for both BaseMetastoreTableOperations and BaseMetastoreOperations

Please suggest .

CommitStatus commitStatus = CommitStatus.FAILURE;
boolean updateHiveTable = false;

HiveLock lock = lockObject(metadata);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to put

try {
      HiveLock lock = lockObject();
      ...
 finally {
     lock.unlock()
 }

in the common method as well?

Copy link
Contributor Author

@nk1506 nk1506 Feb 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HiveLock is not exposed as public.

I though to keep lock and unlock operations with doCommit.

String tableName,
String newMetadataLocation,
Map<String, String> properties,
Function<String, Boolean> commitStatusSupplier) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant something like:


checkCommitStatus(String newMetadataLocation, TableMetadata config, Runnable<List<String>> loadMetadataLocations)

    ... // existing common code

    Tasks.foreach(newMetadataLocation)
        .retry(maxAttempts)
        .suppressFailureWhenFinished()
        .exponentialBackoff(minWaitMs, maxWaitMs, totalRetryMs, 2.0)
        .onFailure(
            (location, checkException) ->
                LOG.error("Cannot check if commit to {} exists.", tableName(), checkException))
        .run(
            location -> {
              List<String> allMetadataLocations = loadMetadataLocations();
              boolean commitSuccess = allMetadataLocations.contains(newMetadataLocations);

              if (commitSuccess) {
                ...
                 status.set(CommitStatus.SUCCESS);
              } else {
                 ...
              }
            });

      ... // rest of existing common code

That way, we can just have the different implementations like:

HiveTableOperations {
   List<String> loadMetadataLocations() {
       TableMetadata metadata = refresh();
       return ImmutableList.Builder
           .add(metadata.metadataFileLocation())
           .addAll(metadata.previousFiles())
           .build();
   }
}

ViewTableOperations {
      List<String> loadMetadataLocations() {
       ViewMetadata metadata = refresh();
       return ImmutableList.Builder
           .add(metadata.metadataFileLocation())
           .addAll(metadata.previousFiles())
           .build();
   }
}

and pass this::loadMetadataLocations() into checkCommitStatus() call. Is that clearer? This allows us to more code, if we dont go with the common interface for View and Table hierarchies.

@nk1506
Copy link
Contributor Author

nk1506 commented Feb 6, 2024

Hi , I am sorry for the late reply.

I left some more comments and explanations of preivous comments.

I am also now thinking, whether it makes sense to have a common interface for TableMetadata and ViewMetadata, as @pvary originally suggested. Something like HasLocations or HasProperties may help us already remove lots of duplicate code here. There is already precdent in Table => HasTableOperations, and many other interfaces in Iceberg code, and should not be very visible to the user.

We already have a thread for the same #9514.

@github-actions
Copy link

This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions.

@github-actions github-actions bot added the stale label Oct 13, 2024
@github-actions
Copy link

This pull request has been closed due to lack of activity. This is not a judgement on the merit of the PR in any way. It is just a way of keeping the PR queue manageable. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.

@github-actions github-actions bot closed this Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants