-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
liuneng1994
committed
Mar 7, 2024
1 parent
c88c7e7
commit 8cd8493
Showing
6 changed files
with
274 additions
and
21 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
cpp-ch/local-engine/Disks/ObjectStorages/GlutenDiskHDFS.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "GlutenDiskHDFS.h" | ||
#include <ranges> | ||
#if USE_HDFS | ||
|
||
namespace local_engine | ||
{ | ||
using namespace DB; | ||
|
||
void GlutenDiskHDFS::createDirectory(const String & path) | ||
{ | ||
DiskObjectStorage::createDirectory(path); | ||
hdfsCreateDirectory(hdfs_object_storage->getHDFSFS(), path.c_str()); | ||
} | ||
|
||
String GlutenDiskHDFS::path2AbsPath(const String & path) | ||
{ | ||
return getObjectStorage()->generateObjectKeyForPath(path).serialize(); | ||
} | ||
|
||
void GlutenDiskHDFS::createDirectories(const String & path) | ||
{ | ||
DiskObjectStorage::createDirectories(path); | ||
auto* hdfs = hdfs_object_storage->getHDFSFS(); | ||
fs::path p = path; | ||
std::vector<std::string> paths_created; | ||
while (hdfsExists(hdfs, p.c_str()) < 0) | ||
{ | ||
paths_created.push_back(p); | ||
if (!p.has_parent_path()) | ||
break; | ||
p = p.parent_path(); | ||
} | ||
for (const auto & path_to_create : paths_created | std::views::reverse) | ||
hdfsCreateDirectory(hdfs, path_to_create.c_str()); | ||
} | ||
|
||
void GlutenDiskHDFS::removeDirectory(const String & path) | ||
{ | ||
DiskObjectStorage::removeDirectory(path); | ||
hdfsDelete(hdfs_object_storage->getHDFSFS(), path.c_str(), 1); | ||
} | ||
|
||
|
||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <config.h> | ||
|
||
#include <Disks/ObjectStorages/DiskObjectStorage.h> | ||
#if USE_HDFS | ||
#include <Disks/ObjectStorages/GlutenHDFSObjectStorage.h> | ||
|
||
namespace local_engine | ||
{ | ||
class GlutenDiskHDFS : public DB::DiskObjectStorage | ||
{ | ||
public: | ||
GlutenDiskHDFS( | ||
const String & name_, | ||
const String & object_key_prefix_, | ||
DB::MetadataStoragePtr metadata_storage_, | ||
DB::ObjectStoragePtr object_storage_, | ||
const Poco::Util::AbstractConfiguration & config, | ||
const String & config_prefix) | ||
: DB::DiskObjectStorage(name_, object_key_prefix_, metadata_storage_, object_storage_, config, config_prefix) | ||
{ | ||
chassert(dynamic_cast<local_engine::GlutenHDFSObjectStorage *>(object_storage_.get()) != nullptr); | ||
hdfs_object_storage = dynamic_cast<local_engine::GlutenHDFSObjectStorage *>(object_storage_.get()); | ||
hdfsSetWorkingDirectory(hdfs_object_storage->getHDFSFS(), "/"); | ||
} | ||
|
||
void createDirectory(const String & path) override; | ||
|
||
void createDirectories(const String & path) override; | ||
|
||
void removeDirectory(const String & path) override; | ||
|
||
private: | ||
String path2AbsPath(const String & path); | ||
|
||
local_engine::GlutenHDFSObjectStorage * hdfs_object_storage; | ||
}; | ||
#endif | ||
} | ||
|
29 changes: 29 additions & 0 deletions
29
cpp-ch/local-engine/Disks/ObjectStorages/GlutenHDFSObjectStorage.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "GlutenHDFSObjectStorage.h" | ||
|
||
#if USE_HDFS | ||
namespace local_engine | ||
{ | ||
DB::ObjectStorageKey local_engine::GlutenHDFSObjectStorage::generateObjectKeyForPath(const std::string & path) const | ||
{ | ||
return DB::ObjectStorageKey::createAsAbsolute(hdfs_root_path + path); | ||
} | ||
} | ||
#endif | ||
|
48 changes: 48 additions & 0 deletions
48
cpp-ch/local-engine/Disks/ObjectStorages/GlutenHDFSObjectStorage.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
#include "config.h" | ||
|
||
#if USE_HDFS | ||
#include <Disks/ObjectStorages/HDFS/HDFSObjectStorage.h> | ||
#endif | ||
|
||
namespace local_engine | ||
{ | ||
|
||
#if USE_HDFS | ||
class GlutenHDFSObjectStorage final : public DB::HDFSObjectStorage | ||
{ | ||
public: | ||
GlutenHDFSObjectStorage( | ||
const String & hdfs_root_path_, | ||
SettingsPtr settings_, | ||
const Poco::Util::AbstractConfiguration & config_) | ||
: HDFSObjectStorage(hdfs_root_path_, std::move(settings_), config_) | ||
{ | ||
} | ||
|
||
DB::ObjectStorageKey generateObjectKeyForPath(const std::string & path) const override; | ||
hdfsFS getHDFSFS() const { return hdfs_fs.get(); } | ||
|
||
}; | ||
#endif | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters