diff options
author | Zongheng Yang <zongheng@google.com> | 2017-04-06 10:02:29 -0800 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2017-04-06 11:39:17 -0700 |
commit | b3ce6f3df62452fb2f19478076e1648b5862c758 (patch) | |
tree | 39350b292cf84ee8384e4884eeee48f50fcac957 /tensorflow/core/util/tensor_bundle | |
parent | 3bd5c880bf1f4834441c8a2f976fa81e738c9a28 (diff) |
tensor_bundle: propagrates errors related to directory creation.
Change: 152401909
Diffstat (limited to 'tensorflow/core/util/tensor_bundle')
-rw-r--r-- | tensorflow/core/util/tensor_bundle/tensor_bundle.cc | 18 | ||||
-rw-r--r-- | tensorflow/core/util/tensor_bundle/tensor_bundle.h | 4 |
2 files changed, 14 insertions, 8 deletions
diff --git a/tensorflow/core/util/tensor_bundle/tensor_bundle.cc b/tensorflow/core/util/tensor_bundle/tensor_bundle.cc index b8989b2c3e..80a910e689 100644 --- a/tensorflow/core/util/tensor_bundle/tensor_bundle.cc +++ b/tensorflow/core/util/tensor_bundle/tensor_bundle.cc @@ -249,8 +249,10 @@ BundleWriter::BundleWriter(Env* env, StringPiece prefix) random::New64())), out_(nullptr), size_(0) { - status_ = - env_->CreateDir(io::Dirname(prefix_).ToString()); // Ignores errors. + status_ = env_->CreateDir(io::Dirname(prefix_).ToString()); + if (!status_.ok() && !errors::IsAlreadyExists(status_)) { + return; + } const string filename = DataFilename(prefix_, 0, 1); std::unique_ptr<WritableFile> wrapper; status_ = env_->NewWritableFile(tmp_data_path_, &wrapper); @@ -264,9 +266,9 @@ BundleWriter::BundleWriter(Env* env, StringPiece prefix) BundleWriter::~BundleWriter() { CHECK(out_ == nullptr); } Status BundleWriter::Add(StringPiece key, const Tensor& val) { + if (!status_.ok()) return status_; CHECK_NE(key, kHeaderEntryKey); const string key_string = key.ToString(); - if (!status_.ok()) return status_; if (entries_.find(key_string) != entries_.end()) { status_ = errors::InvalidArgument("Adding duplicate key: ", key); return status_; @@ -301,14 +303,14 @@ Status BundleWriter::AddSlice(StringPiece full_tensor_key, const TensorShape& full_tensor_shape, const TensorSlice& slice_spec, const Tensor& slice_tensor) { + if (!status_.ok()) return status_; + CHECK_NE(full_tensor_key, kHeaderEntryKey); + // If just a singleton full slice, use the regular Add() to be more efficient. if (IsFullSlice(slice_spec, full_tensor_shape)) { return Add(full_tensor_key, slice_tensor); } - CHECK_NE(full_tensor_key, kHeaderEntryKey); - if (!status_.ok()) return status_; - // Inserts/updates the full tensor's metadata entry. // // In the case of a sharded save, MergeBundles() is responsible for merging @@ -516,7 +518,8 @@ Status MergeBundles(Env* env, gtl::ArraySlice<string> prefixes, // Merges all metadata tables. // TODO(zhifengc): KeyValue sorter if it becomes too big. MergeState merge; - env->CreateDir(io::Dirname(merged_prefix).ToString()).IgnoreError(); + Status status = env->CreateDir(io::Dirname(merged_prefix).ToString()); + if (!status.ok() && !errors::IsAlreadyExists(status)) return status; for (int i = 0; i < prefixes.size(); ++i) { TF_RETURN_IF_ERROR(MergeOneBundle(env, prefixes[i], &merge)); } @@ -534,7 +537,6 @@ Status MergeBundles(Env* env, gtl::ArraySlice<string> prefixes, std::unique_ptr<WritableFile> merged_metadata; TF_RETURN_IF_ERROR( env->NewWritableFile(MetaFilename(merged_prefix), &merged_metadata)); - Status status; { table::TableBuilder builder(table::Options(), merged_metadata.get()); // Header entry. diff --git a/tensorflow/core/util/tensor_bundle/tensor_bundle.h b/tensorflow/core/util/tensor_bundle/tensor_bundle.h index bca3910f59..676bfe4df6 100644 --- a/tensorflow/core/util/tensor_bundle/tensor_bundle.h +++ b/tensorflow/core/util/tensor_bundle/tensor_bundle.h @@ -100,6 +100,10 @@ extern const int kTensorBundleVersion; extern const char* const kHeaderEntryKey; // Builds a string-string table of tensor names to BundleEntryProto (metadata). +// +// On construction, attempts to create a directory given by the dirname of +// "prefix", so "status()" must be checked before calling any member functions. +// // All threads accessing the same BundleWriter must synchronize. class BundleWriter { public: |