Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#5139] feat: (python-client): Support GCS fileset in the python GVFS client #5160

Open
wants to merge 108 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
d2447a2
Add a framework to support multi-storage in a pluginized manner for …
yuqi1129 Sep 25, 2024
7e5a8b5
Fix compile distribution error.
yuqi1129 Sep 25, 2024
f53c5ef
fix
yuqi1129 Sep 25, 2024
36fedcd
fix
yuqi1129 Sep 25, 2024
e93fba5
fix
yuqi1129 Sep 25, 2024
b1e04b6
fix
yuqi1129 Sep 26, 2024
db00e65
Changed according to comments.
yuqi1129 Sep 29, 2024
c793582
fix
yuqi1129 Sep 29, 2024
013f5cb
fix
yuqi1129 Sep 30, 2024
dba5753
Merge branch 'main' of github.com:datastrato/graviton into issue_5019
yuqi1129 Oct 8, 2024
16dfc73
resolve comments.
yuqi1129 Oct 8, 2024
278fcd8
Polish code.
yuqi1129 Oct 9, 2024
3fb55ad
fix
yuqi1129 Oct 9, 2024
cd04666
fix
yuqi1129 Oct 9, 2024
d0bf13e
Support GCS fileset.
yuqi1129 Oct 9, 2024
ffaa064
Change gvfs accordingly.
yuqi1129 Oct 11, 2024
32d7f3d
Merge remote-tracking branch 'me/issue_5019' into issue_5019
yuqi1129 Oct 11, 2024
d82bf76
Update Java doc for FileSystemProvider
yuqi1129 Oct 11, 2024
dfdb772
Fix
yuqi1129 Oct 11, 2024
8708a8a
Fix
yuqi1129 Oct 11, 2024
ba9f8fa
Fix test error.
yuqi1129 Oct 11, 2024
dae99f7
Polish.
yuqi1129 Oct 11, 2024
e22053b
Polish
yuqi1129 Oct 12, 2024
4fb89e0
Polish
yuqi1129 Oct 12, 2024
e5746c0
Rename `AbstractIT` to `BaseIT`
yuqi1129 Oct 12, 2024
b2d7bed
Fix
yuqi1129 Oct 14, 2024
380717b
Merge branch 'apache:main' into issue_5019
yuqi1129 Oct 14, 2024
f4041ec
Fix python ut error again.
yuqi1129 Oct 14, 2024
66247ab
Merge branch 'issue_5019' of github.com:yuqi1129/gravitino into issue…
yuqi1129 Oct 14, 2024
3cfb94f
Fix test error again.
yuqi1129 Oct 14, 2024
7d1150f
Fix minor.
yuqi1129 Oct 14, 2024
608081b
fix
yuqi1129 Oct 14, 2024
9edfe82
Fix
yuqi1129 Oct 14, 2024
3079bf0
Fix
yuqi1129 Oct 14, 2024
da49e60
Fix
yuqi1129 Oct 14, 2024
b621d89
Fix
yuqi1129 Oct 14, 2024
05dd006
Merge branch 'issue_5019' into issue_5074
yuqi1129 Oct 15, 2024
9d5b8dc
rebase issue_5019
yuqi1129 Oct 15, 2024
e58f9a0
Fix
yuqi1129 Oct 15, 2024
c521daf
resolve comments
yuqi1129 Oct 15, 2024
46e996a
Resolve comments again.
yuqi1129 Oct 15, 2024
da0b7ca
Polish again.
yuqi1129 Oct 15, 2024
e9ccda4
Merge branch 'issue_5019' of github.com:yuqi1129/gravitino into issue…
yuqi1129 Oct 15, 2024
ba1fe5f
Rebase branch issue_5019
yuqi1129 Oct 15, 2024
4ffe389
Merge branch 'main' of github.com:datastrato/graviton into issue_5139
yuqi1129 Oct 15, 2024
7c44a57
Support python gvfs
yuqi1129 Oct 15, 2024
992ba0a
fix
yuqi1129 Oct 15, 2024
5dbca5f
fix
yuqi1129 Oct 15, 2024
f27520a
Update code.
yuqi1129 Oct 15, 2024
e29e47b
Merge branch 'issue_5019' into issue_5074
yuqi1129 Oct 15, 2024
bc1e76f
Rebase branch issue_5019
yuqi1129 Oct 15, 2024
8a9d3bf
Merge branch 'issue_5074' of github.com:yuqi1129/gravitino into issue…
yuqi1129 Oct 15, 2024
2115e31
fix
yuqi1129 Oct 15, 2024
c2e55d4
fix
yuqi1129 Oct 15, 2024
557aa02
fix
yuqi1129 Oct 15, 2024
5c3fa5c
fix
yuqi1129 Oct 15, 2024
408eca7
fix
yuqi1129 Oct 15, 2024
a02065d
fix
yuqi1129 Oct 15, 2024
8762bae
fix
yuqi1129 Oct 15, 2024
dc7a915
fix
yuqi1129 Oct 15, 2024
c230991
fix
yuqi1129 Oct 15, 2024
dc54880
skip some test.
yuqi1129 Oct 15, 2024
7ecc040
fix
yuqi1129 Oct 15, 2024
da46321
fix
yuqi1129 Oct 15, 2024
27bc2ab
Fix
yuqi1129 Oct 16, 2024
017c42e
Merge branch 'issue_5019' into issue_5074
yuqi1129 Oct 16, 2024
9dc0f5a
Fix
yuqi1129 Oct 16, 2024
41ff00d
Merge branch 'issue_5019' of github.com:yuqi1129/gravitino into issue…
yuqi1129 Oct 16, 2024
1fee1e4
Fix
yuqi1129 Oct 16, 2024
1789bd2
fix
yuqi1129 Oct 16, 2024
2ee1709
Fix
yuqi1129 Oct 16, 2024
05e5d20
Fix
yuqi1129 Oct 16, 2024
8f28211
Fix
yuqi1129 Oct 16, 2024
35cba1e
Fix
yuqi1129 Oct 16, 2024
bcf2f12
Fix
yuqi1129 Oct 16, 2024
f25a37d
Fix a problem
yuqi1129 Oct 16, 2024
a3da011
Merge branch 'issue_5019' into issue_5074
yuqi1129 Oct 16, 2024
3517996
Merge branch 'main' of github.com:apache/gravitino into issue_5074
yuqi1129 Oct 16, 2024
27a911a
fix
yuqi1129 Oct 16, 2024
e34dbea
Merge branch 'main' of github.com:apache/gravitino into issue_5074
yuqi1129 Oct 16, 2024
6bae7e5
Fix a problem
yuqi1129 Oct 16, 2024
fe13f5e
Fix a problem
yuqi1129 Oct 16, 2024
0181632
Fix a problem
yuqi1129 Oct 16, 2024
3ff9eef
Fix
yuqi1129 Oct 16, 2024
2ce660c
Fix
yuqi1129 Oct 16, 2024
f0fa87b
Fix
yuqi1129 Oct 16, 2024
d2921a8
Fix
yuqi1129 Oct 16, 2024
dc68dd1
Fix
yuqi1129 Oct 16, 2024
6431e2f
Fix
yuqi1129 Oct 16, 2024
242888f
Fix
yuqi1129 Oct 16, 2024
3ec2dcc
Merge branch 'issue_5074' of github.com:yuqi1129/gravitino into issue…
yuqi1129 Oct 16, 2024
f754997
Fix
yuqi1129 Oct 16, 2024
2cdfb35
Fix
yuqi1129 Oct 16, 2024
67dbc3a
Resolve comments.
yuqi1129 Oct 17, 2024
70a545e
Fix the java doc problem.
yuqi1129 Oct 17, 2024
4d54acf
Merge branch 'issue_5074' into issue_5139
yuqi1129 Oct 17, 2024
15bbf99
rebase issue_5074
yuqi1129 Oct 17, 2024
cfcc544
Optimize code.
yuqi1129 Oct 17, 2024
acf51e1
Merge branch 'issue_5074' of github.com:yuqi1129/gravitino into issue…
yuqi1129 Oct 17, 2024
11f9992
Merge branch 'main' of github.com:datastrato/graviton into issue_5139
yuqi1129 Oct 17, 2024
4f00a2f
Remove s3 related code.
yuqi1129 Oct 17, 2024
b9ef8f0
fix
yuqi1129 Oct 17, 2024
9f65fb5
try to import lazily.
yuqi1129 Oct 18, 2024
4defcc6
format code.
yuqi1129 Oct 18, 2024
3a907f4
fix
yuqi1129 Oct 18, 2024
76912b7
fix
yuqi1129 Oct 18, 2024
4478673
fix
yuqi1129 Oct 18, 2024
5a194df
Merge branch 'main' of github.com:datastrato/graviton into issue_5139
yuqi1129 Oct 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class GCSFileSystemProvider implements FileSystemProvider {
private static final Logger LOGGER = LoggerFactory.getLogger(GCSFileSystemProvider.class);

@Override
public FileSystem getFileSystem(Path path, Map<String, String> config) throws IOException {
Configuration configuration = new Configuration();
Expand All @@ -35,6 +39,7 @@ public FileSystem getFileSystem(Path path, Map<String, String> config) throws IO
configuration.set(k.replace("gravitino.bypass.", ""), v);
});

LOGGER.info("Creating GCS file system with config: {}", config);
return GoogleHadoopFileSystem.newInstance(path.toUri(), configuration);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class HadoopGCSCatalogIT extends HadoopCatalogIT {

@Override
public void startIntegrationTest() throws Exception {
// Do nothing.
// Just overwrite super, do nothing.
}

@BeforeAll
Expand Down
47 changes: 40 additions & 7 deletions clients/client-python/gravitino/filesystem/gvfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

import os
from enum import Enum
from pathlib import PurePosixPath
from typing import Dict, Tuple
import re
import importlib
import fsspec

from cachetools import TTLCache, LRUCache
from fsspec import AbstractFileSystem
from fsspec.implementations.local import LocalFileSystem
from fsspec.implementations.arrow import ArrowFSWrapper
from fsspec.utils import infer_storage_options
from pyarrow.fs import HadoopFileSystem

from readerwriterlock import rwlock
from gravitino.audit.caller_context import CallerContext, CallerContextHolder
from gravitino.audit.fileset_audit_constants import FilesetAuditConstants
Expand All @@ -47,6 +48,7 @@
class StorageType(Enum):
HDFS = "hdfs"
LOCAL = "file"
GCS = "gs"


class FilesetContextPair:
Expand All @@ -66,7 +68,7 @@ def filesystem(self):


class GravitinoVirtualFileSystem(fsspec.AbstractFileSystem):
"""This is a virtual file system which users can access `fileset` and
"""This is a virtual file system that users can access `fileset` and
other resources.

It obtains the actual storage location corresponding to the resource from the
Expand Down Expand Up @@ -149,6 +151,7 @@ def __init__(
self._cache_lock = rwlock.RWLockFair()
self._catalog_cache = LRUCache(maxsize=100)
self._catalog_cache_lock = rwlock.RWLockFair()
self._options = options

super().__init__(**kwargs)

Expand Down Expand Up @@ -309,7 +312,9 @@ def mv(self, path1, path2, recursive=False, maxdepth=None, **kwargs):
)
dst_actual_path = dst_context_pair.actual_file_location()

if storage_type == StorageType.HDFS:
# convert the following to in

if storage_type in [StorageType.HDFS, StorageType.GCS]:
src_context_pair.filesystem().mv(
self._strip_storage_protocol(storage_type, src_actual_path),
self._strip_storage_protocol(storage_type, dst_actual_path),
Expand Down Expand Up @@ -540,7 +545,11 @@ def _convert_actual_path(
:param virtual_location: Virtual location
:return A virtual path
"""
if storage_location.startswith(f"{StorageType.HDFS.value}://"):

# If the storage path starts with hdfs, gcs, we should use the path as the prefix.
if storage_location.startswith(
f"{StorageType.HDFS.value}://"
) or storage_location.startswith(f"{StorageType.GCS.value}://"):
actual_prefix = infer_storage_options(storage_location)["path"]
elif storage_location.startswith(f"{StorageType.LOCAL.value}:/"):
actual_prefix = storage_location[len(f"{StorageType.LOCAL.value}:") :]
Expand Down Expand Up @@ -681,6 +690,8 @@ def _recognize_storage_type(path: str):
return StorageType.HDFS
if path.startswith(f"{StorageType.LOCAL.value}:/"):
return StorageType.LOCAL
if path.startswith(f"{StorageType.GCS.value}://"):
return StorageType.GCS
raise GravitinoRuntimeException(
f"Storage type doesn't support now. Path:{path}"
)
Expand All @@ -705,10 +716,11 @@ def _strip_storage_protocol(storage_type: StorageType, path: str):
:param path: The path
:return: The stripped path
"""
if storage_type == StorageType.HDFS:
if storage_type in (StorageType.HDFS, StorageType.GCS):
return path
if storage_type == StorageType.LOCAL:
return path[len(f"{StorageType.LOCAL.value}:") :]

raise GravitinoRuntimeException(
f"Storage type:{storage_type} doesn't support now."
)
Expand Down Expand Up @@ -774,9 +786,12 @@ def _get_filesystem(self, actual_file_location: str):
if cache_value is not None:
return cache_value
if storage_type == StorageType.HDFS:
fs = ArrowFSWrapper(HadoopFileSystem.from_uri(actual_file_location))
fs_class = importlib.import_module("pyarrow.fs").HadoopFileSystem
fs = ArrowFSWrapper(fs_class.from_uri(actual_file_location))
elif storage_type == StorageType.LOCAL:
fs = LocalFileSystem()
elif storage_type == StorageType.GCS:
fs = ArrowFSWrapper(self._get_gcs_filesystem())
else:
raise GravitinoRuntimeException(
f"Storage type: `{storage_type}` doesn't support now."
Expand All @@ -786,5 +801,23 @@ def _get_filesystem(self, actual_file_location: str):
finally:
write_lock.release()

def _get_gcs_filesystem(self):
# get All keys from the options that start with 'gravitino.bypass.gcs.' and remove the prefix
gcs_options = {
key[len(GVFSConfig.GVFS_FILESYSTEM_BY_PASS_GCS) :]: value
for key, value in self._options.items()
if key.startswith(GVFSConfig.GVFS_FILESYSTEM_BY_PASS_GCS)
}

# get 'service-account-key' from gcs_options, if the key is not found, throw an exception
service_account_key_path = gcs_options.get(GVFSConfig.GVFS_FILESYSTEM_KEY_FILE)
if service_account_key_path is None:
raise GravitinoRuntimeException(
"Service account key is not found in the options."
)
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = service_account_key_path

return importlib.import_module("pyarrow.fs").GcsFileSystem()


fsspec.register_implementation(PROTOCOL_NAME, GravitinoVirtualFileSystem)
4 changes: 4 additions & 0 deletions clients/client-python/gravitino/filesystem/gvfs_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ class GVFSConfig:
OAUTH2_CREDENTIAL = "oauth2_credential"
OAUTH2_PATH = "oauth2_path"
OAUTH2_SCOPE = "oauth2_scope"

GVFS_FILESYSTEM_BY_PASS = "gravitino.bypass"
GVFS_FILESYSTEM_BY_PASS_GCS = "gravitino.bypass.gcs."
GVFS_FILESYSTEM_KEY_FILE = "service-account-key-path"
3 changes: 2 additions & 1 deletion clients/client-python/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ dataclasses-json==0.6.6
readerwriterlock==1.0.9
fsspec==2024.3.1
pyarrow==15.0.2
cachetools==5.3.3
cachetools==5.3.3
google-auth==2.35.0
12 changes: 12 additions & 0 deletions clients/client-python/tests/integration/integration_test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ def setUpClass(cls):
)
sys.exit(0)

# remove data dir under gravitino_home
data_dir = os.path.join(cls.gravitino_home, "data")
if os.path.exists(data_dir):
logger.info("Remove Gravitino data directory: %s", data_dir)
subprocess.run(["rm", "-rf", data_dir], check=False)

logger.info("Starting integration test environment...")

# Start Gravitino Server
Expand Down Expand Up @@ -141,6 +147,12 @@ def restart_server(cls):
"project root directory."
)

# remove data dir under gravitino_home
data_dir = os.path.join(gravitino_home, "data")
if os.path.exists(data_dir):
logger.info("Remove Gravitino data directory: %s", data_dir)
subprocess.run(["rm", "-rf", data_dir], check=False)

# Restart Gravitino Server
env_vars = os.environ.copy()
env_vars["HADOOP_USER_NAME"] = "anonymous"
Expand Down
15 changes: 10 additions & 5 deletions clients/client-python/tests/integration/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
class TestCatalog(IntegrationTestEnv):
metalake_name: str = "TestSchema_metalake" + str(randint(1, 10000))

catalog_name: str = "testCatalog"
catalog_name: str = "testCatalog" + str(randint(1, 10000))
catalog_name_bak = catalog_name
catalog_comment: str = "catalogComment"
catalog_location_prop: str = "location" # Fileset Catalog must set `location`
catalog_provider: str = "hadoop"
Expand Down Expand Up @@ -81,21 +82,25 @@ def clean_test_data(self):
)
try:
logger.info(
"Drop catalog %s[%s]",
"TestCatalog: drop catalog %s[%s]",
self.catalog_ident,
self.gravitino_client.drop_catalog(name=self.catalog_name, force=True),
)
except GravitinoRuntimeException:
logger.warning("Failed to drop catalog %s", self.catalog_name)
logger.warning("TestCatalog: failed to drop catalog %s", self.catalog_name)

try:
logger.info(
"Drop metalake %s[%s]",
"TestCatalog: drop metalake %s[%s]",
self.metalake_name,
self.gravitino_admin_client.drop_metalake(self.metalake_name),
)
except GravitinoRuntimeException:
logger.warning("Failed to drop metalake %s", self.metalake_name)
logger.warning(
"TestCatalog: failed to drop metalake %s", self.metalake_name
)

self.catalog_name = self.catalog_name_bak

def test_list_catalogs(self):
self.create_catalog(self.catalog_name)
Expand Down
Loading
Loading