FangYongs commented on code in PR #23063:
URL: https://github.com/apache/flink/pull/23063#discussion_r1287877080
##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/catalog/FileCatalogStore.java:
##########
@@ -97,25 +114,29 @@ public void storeCatalog(String catalogName,
CatalogDescriptor catalog)
throws CatalogException {
checkOpenState();
- Path filePath = getCatalogPath(catalogName);
+ Path catalogPath = getCatalogPath(catalogName);
try {
- File file = filePath.toFile();
- if (file.exists()) {
+ FileSystem fs = catalogPath.getFileSystem();
+
+ if (fs.exists(catalogPath)) {
throw new CatalogException(
String.format(
"Catalog %s's store file %s is already exist.",
- catalogName, filePath));
+ catalogName, catalogPath));
+ }
+
+ try (FSDataOutputStream os = fs.create(catalogPath,
WriteMode.NO_OVERWRITE)) {
+ YAML_MAPPER.writeValue(os, catalog.getConfiguration().toMap());
}
- // create a new file
- file.createNewFile();
- String yamlString =
yaml.dumpAsMap(catalog.getConfiguration().toMap());
- FileUtils.writeFile(file, yamlString, charset);
- LOG.info("Catalog {}'s configuration saved to file {}",
catalogName, filePath);
- } catch (Throwable e) {
+
+ LOG.info("Catalog {}'s configuration saved to file {}",
catalogName, catalogPath);
+ } catch (CatalogException e) {
+ throw e;
+ } catch (Exception e) {
Review Comment:
For example, we only need to catch IOException, StreamWriteException,
DatabindException for the above code and convert them to CatalogException and
rethrow CatalogException here
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]