You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by sn...@apache.org on 2023/09/10 21:27:50 UTC
[flink] branch master updated: [FLINK-32796][table] Try to create catalog store path if not exists (#23366)
This is an automated email from the ASF dual-hosted git repository.
snuyanzin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git
The following commit(s) were added to refs/heads/master by this push:
new 9a94891156f [FLINK-32796][table] Try to create catalog store path if not exists (#23366)
9a94891156f is described below
commit 9a94891156f2cd8070df48d75a4f481dc0a8b962
Author: Ferenc Csaky <fe...@pm.me>
AuthorDate: Sun Sep 10 23:27:43 2023 +0200
[FLINK-32796][table] Try to create catalog store path if not exists (#23366)
---
.../flink/table/catalog/FileCatalogStore.java | 5 +--
.../flink/table/catalog/FileCatalogStoreTest.java | 51 ++++++++++++++--------
2 files changed, 33 insertions(+), 23 deletions(-)
diff --git a/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/catalog/FileCatalogStore.java b/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/catalog/FileCatalogStore.java
index c3a414d5032..b4b24da54f6 100644
--- a/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/catalog/FileCatalogStore.java
+++ b/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/catalog/FileCatalogStore.java
@@ -80,10 +80,7 @@ public class FileCatalogStore extends AbstractCatalogStore {
try {
FileSystem fs = catalogStorePath.getFileSystem();
if (!fs.exists(catalogStorePath)) {
- throw new CatalogException(
- String.format(
- "Failed to open catalog store. The catalog store directory %s does not exist.",
- catalogStorePath));
+ fs.mkdirs(catalogStorePath);
}
if (!fs.getFileStatus(catalogStorePath).isDir()) {
diff --git a/flink-table/flink-table-api-java/src/test/java/org/apache/flink/table/catalog/FileCatalogStoreTest.java b/flink-table/flink-table-api-java/src/test/java/org/apache/flink/table/catalog/FileCatalogStoreTest.java
index f79df92b32e..011ce881bb8 100644
--- a/flink-table/flink-table-api-java/src/test/java/org/apache/flink/table/catalog/FileCatalogStoreTest.java
+++ b/flink-table/flink-table-api-java/src/test/java/org/apache/flink/table/catalog/FileCatalogStoreTest.java
@@ -20,17 +20,20 @@ package org.apache.flink.table.catalog;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.table.catalog.exceptions.CatalogException;
+import org.apache.flink.util.OperatingSystem;
import org.assertj.core.api.ThrowableAssert;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import java.io.File;
+import java.io.FileNotFoundException;
import java.nio.file.Path;
import java.util.Set;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
+import static org.assertj.core.api.Assumptions.assumeThat;
/** Tests for {@link FileCatalogStore}. */
class FileCatalogStoreTest {
@@ -51,7 +54,7 @@ class FileCatalogStoreTest {
@Test
void testNotOpened() {
- CatalogStore catalogStore = initCatalogStore(false);
+ CatalogStore catalogStore = initCatalogStore();
assertCatalogStoreNotOpened(catalogStore::listCatalogs);
assertCatalogStoreNotOpened(() -> catalogStore.contains(DUMMY));
@@ -61,21 +64,34 @@ class FileCatalogStoreTest {
}
@Test
- void testStoreDirNotExists() {
- CatalogStore catalogStore = initCatalogStore(false);
- Path catalogStorePath = tempDir.resolve(CATALOG_STORE_DIR_NAME);
-
- assertThatThrownBy(catalogStore::open)
- .isInstanceOf(CatalogException.class)
- .hasMessageContaining(
- "Failed to open catalog store. The catalog store directory "
- + catalogStorePath
- + " does not exist.");
+ void testCannotMakeStorePath() {
+ assumeThat(OperatingSystem.isWindows())
+ .as("setWritable doesn't work on Windows.")
+ .isFalse();
+
+ Path storeParentPath = tempDir.resolve("parent");
+ assertThat(storeParentPath.toFile().mkdir()).isTrue();
+
+ Path storePath = storeParentPath.resolve(CATALOG_STORE_DIR_NAME);
+ FileCatalogStore catalogStore = new FileCatalogStore(storePath.toString());
+
+ File storeParentFile = storeParentPath.toFile();
+ try {
+ assertThat(storeParentFile.setWritable(false, false)).isTrue();
+
+ assertThatThrownBy(catalogStore::open)
+ .isInstanceOf(CatalogException.class)
+ .hasMessageContaining(
+ "Failed to open file catalog store directory " + storePath + ".")
+ .hasRootCauseInstanceOf(FileNotFoundException.class);
+ } finally {
+ storeParentFile.setWritable(true, false);
+ }
}
@Test
void testStore() {
- CatalogStore catalogStore = initCatalogStore(true);
+ CatalogStore catalogStore = initCatalogStore();
catalogStore.open();
catalogStore.storeCatalog(DUMMY, DUMMY_CATALOG);
@@ -92,7 +108,7 @@ class FileCatalogStoreTest {
@Test
void testRemoveExisting() {
- CatalogStore catalogStore = initCatalogStore(true);
+ CatalogStore catalogStore = initCatalogStore();
catalogStore.open();
catalogStore.storeCatalog(DUMMY, DUMMY_CATALOG);
@@ -108,7 +124,7 @@ class FileCatalogStoreTest {
@Test
void testRemoveNonExisting() {
- CatalogStore catalogStore = initCatalogStore(true);
+ CatalogStore catalogStore = initCatalogStore();
catalogStore.open();
catalogStore.removeCatalog(DUMMY, true);
@@ -122,7 +138,7 @@ class FileCatalogStoreTest {
@Test
void testClose() {
- CatalogStore catalogStore = initCatalogStore(true);
+ CatalogStore catalogStore = initCatalogStore();
catalogStore.open();
catalogStore.storeCatalog(DUMMY, DUMMY_CATALOG);
@@ -144,11 +160,8 @@ class FileCatalogStoreTest {
.hasMessageContaining("CatalogStore is not opened yet.");
}
- private CatalogStore initCatalogStore(boolean createDir) {
+ private CatalogStore initCatalogStore() {
Path catalogStorePath = tempDir.resolve(CATALOG_STORE_DIR_NAME);
- if (createDir) {
- catalogStorePath.toFile().mkdir();
- }
return new FileCatalogStore(catalogStorePath.toString());
}