Skip to content

Commit 653453a

Browse files
authored
gcs switch to env (#1319)
* switch to env * switch to gcs on tensorflow-io according to tensorflow/tensorflow#47247
1 parent 1711688 commit 653453a

File tree

9 files changed

+26
-223
lines changed

9 files changed

+26
-223
lines changed

tensorflow_io/core/plugins/file_system_plugins.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ void TF_InitPlugin(TF_FilesystemPluginInfo* info) {
3535
tensorflow::io::hdfs::ProvideFilesystemSupportFor(&info->ops[3], "hdfse");
3636
tensorflow::io::hdfs::ProvideFilesystemSupportFor(&info->ops[4], "viewfse");
3737
tensorflow::io::hdfs::ProvideFilesystemSupportFor(&info->ops[5], "hare");
38+
tensorflow::io::gs::ProvideFilesystemSupportFor(&info->ops[6], "gse");
3839
} else {
3940
tensorflow::io::s3::ProvideFilesystemSupportFor(&info->ops[2], "s3");
4041
tensorflow::io::hdfs::ProvideFilesystemSupportFor(&info->ops[3], "hdfs");
4142
tensorflow::io::hdfs::ProvideFilesystemSupportFor(&info->ops[4], "viewfs");
4243
tensorflow::io::hdfs::ProvideFilesystemSupportFor(&info->ops[5], "har");
44+
tensorflow::io::gs::ProvideFilesystemSupportFor(&info->ops[6], "gs");
4345
}
44-
tensorflow::io::gs::ProvideFilesystemSupportFor(&info->ops[6], "gse");
4546
}

tensorflow_io/core/plugins/gs/BUILD

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ cc_library(
1212
srcs = [
1313
"cleanup.h",
1414
"expiring_lru_cache.h",
15-
"gcs_env.cc",
16-
"gcs_env.h",
1715
"gcs_filesystem.cc",
1816
"gcs_helper.cc",
1917
"gcs_helper.h",

tensorflow_io/core/plugins/gs/expiring_lru_cache.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ limitations under the License.
2424

2525
#include "absl/base/thread_annotations.h"
2626
#include "absl/synchronization/mutex.h"
27+
#include "tensorflow/c/env.h"
2728
#include "tensorflow/c/tf_status.h"
28-
#include "tensorflow_io/core/plugins/gs/gcs_env.h"
2929

3030
namespace tensorflow {
3131
namespace io {
@@ -44,7 +44,7 @@ class ExpiringLRUCache {
4444
/// that there is no limit on the number of entries in the cache (however, if
4545
/// `max_age` is also 0, the cache will not be populated).
4646
ExpiringLRUCache(uint64_t max_age, size_t max_entries,
47-
std::function<uint64_t()> timer_seconds = GCSNowSeconds)
47+
std::function<uint64_t()> timer_seconds = TF_NowSeconds)
4848
: max_age_(max_age),
4949
max_entries_(max_entries),
5050
timer_seconds_(timer_seconds) {}

tensorflow_io/core/plugins/gs/gcs_env.cc

Lines changed: 0 additions & 164 deletions
This file was deleted.

tensorflow_io/core/plugins/gs/gcs_env.h

Lines changed: 0 additions & 45 deletions
This file was deleted.

tensorflow_io/core/plugins/gs/gcs_helper.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ limitations under the License.
1616

1717
#include <stdio.h>
1818

19+
#include <cstdlib>
1920
#include <fstream>
2021
#include <string>
2122
#include <utility>
2223

24+
#include "tensorflow/c/env.h"
25+
2326
TempFile::TempFile(const std::string& temp_file_name, std::ios::openmode mode)
2427
: std::fstream(temp_file_name, mode), name_(temp_file_name) {}
2528

@@ -38,3 +41,11 @@ bool TempFile::truncate() {
3841
std::fstream::open(name_, std::ios::binary | std::ios::out);
3942
return std::fstream::is_open();
4043
}
44+
45+
std::string GCSGetTempFileName(const std::string& extension) {
46+
char* raw_temp_file_name = TF_GetTempFileName(extension.c_str());
47+
if (!raw_temp_file_name) return "";
48+
std::string temp_file_name(raw_temp_file_name);
49+
std::free(raw_temp_file_name);
50+
return temp_file_name;
51+
}

tensorflow_io/core/plugins/gs/gcs_helper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,6 @@ class TempFile : public std::fstream {
3131
const std::string name_;
3232
};
3333

34+
std::string GCSGetTempFileName(const std::string& extension);
35+
3436
#endif // TENSORFLOW_C_EXPERIMENTAL_FILESYSTEM_PLUGINS_GCS_GCS_HELPER_H_

tensorflow_io/core/plugins/gs/ram_file_block_cache.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ limitations under the License.
2727
#include "absl/base/thread_annotations.h"
2828
#include "absl/synchronization/mutex.h"
2929
#include "absl/synchronization/notification.h"
30+
#include "tensorflow/c/env.h"
3031
#include "tensorflow/c/logging.h"
3132
#include "tensorflow/c/tf_status.h"
32-
#include "tensorflow_io/core/plugins/gs/gcs_env.h"
3333

3434
namespace tensorflow {
3535
namespace io {
@@ -56,19 +56,19 @@ class RamFileBlockCache {
5656

5757
RamFileBlockCache(size_t block_size, size_t max_bytes, uint64_t max_staleness,
5858
BlockFetcher block_fetcher,
59-
std::function<uint64_t()> timer_seconds = GCSNowSeconds)
59+
std::function<uint64_t()> timer_seconds = TF_NowSeconds)
6060
: block_size_(block_size),
6161
max_bytes_(max_bytes),
6262
max_staleness_(max_staleness),
6363
block_fetcher_(block_fetcher),
6464
timer_seconds_(timer_seconds),
6565
pruning_thread_(nullptr,
66-
[](GCSThread* thread) { GCSJoinThread(thread); }) {
66+
[](TF_Thread* thread) { TF_JoinThread(thread); }) {
6767
if (max_staleness_ > 0) {
68-
GCSThreadOptions thread_options;
69-
GCSDefaultThreadOptions(&thread_options);
68+
TF_ThreadOptions thread_options;
69+
TF_DefaultThreadOptions(&thread_options);
7070
pruning_thread_.reset(
71-
GCSStartThread(&thread_options, "TF_prune_FBC", PruneThread, this));
71+
TF_StartThread(&thread_options, "TF_prune_FBC", PruneThread, this));
7272
}
7373
TF_VLog(1, "GCS file block cache is %s.\n",
7474
(IsCacheEnabled() ? "enabled" : "disabled"));
@@ -236,7 +236,7 @@ class RamFileBlockCache {
236236
void RemoveBlock(BlockMap::iterator entry) ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_);
237237

238238
/// The cache pruning thread that removes files with expired blocks.
239-
std::unique_ptr<GCSThread, std::function<void(GCSThread*)>> pruning_thread_;
239+
std::unique_ptr<TF_Thread, std::function<void(TF_Thread*)>> pruning_thread_;
240240

241241
/// Notification for stopping the cache pruning thread.
242242
absl::Notification stop_pruning_thread_;

tests/test_gcs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_read_file():
4545

4646
# Setup the GCS bucket and key
4747
key_name = "TEST"
48-
bucket_name = "gse{}e".format(int(time.time()))
48+
bucket_name = "gs{}e".format(int(time.time()))
4949
bucket = client.create_bucket(bucket_name)
5050

5151
blob = bucket.blob(key_name)
@@ -56,5 +56,5 @@ def test_read_file():
5656

5757
os.environ["CLOUD_STORAGE_TESTBENCH_ENDPOINT"] = "http://localhost:9099"
5858

59-
content = tf.io.read_file("gse://{}/{}".format(bucket_name, key_name))
59+
content = tf.io.read_file("gs://{}/{}".format(bucket_name, key_name))
6060
assert content == body

0 commit comments

Comments
 (0)