MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / Finish

Method Finish

tensorflow/core/util/tensor_bundle/tensor_bundle.cc:597–647  ·  view source on GitHub ↗

TODO(zongheng): on metadata write failure or !status_.ok(), consider removing the orphaned data file.

Source from the content-addressed store, hash-verified

595// TODO(zongheng): on metadata write failure or !status_.ok(), consider removing
596// the orphaned data file.
597Status BundleWriter::Finish() {
598 if (out_) {
599 status_.Update(out_->Close());
600 out_ = nullptr;
601 if (status_.ok()) {
602 status_ = Env::Default()->RenameFile(tmp_data_path_,
603 DataFilename(prefix_, 0, 1));
604 } else {
605 Env::Default()->DeleteFile(tmp_data_path_).IgnoreError();
606 }
607 }
608 if (!status_.ok()) return status_;
609 // Build key -> BundleEntryProto table.
610 std::unique_ptr<WritableFile> file;
611 status_ = env_->NewWritableFile(tmp_metadata_path_, &file);
612 if (!status_.ok()) return status_;
613 {
614 // N.B.: the default use of Snappy compression may not be supported on all
615 // platforms (e.g. Android). The metadata file is small, so this is fine.
616 table::Options options;
617 options.compression = table::kNoCompression;
618 table::TableBuilder builder(options, file.get());
619 // Header entry.
620 BundleHeaderProto header;
621 header.set_num_shards(1);
622 header.set_endianness(BundleHeaderProto::LITTLE);
623 if (!port::kLittleEndian) header.set_endianness(BundleHeaderProto::BIG);
624 VersionDef* version = header.mutable_version();
625 version->set_producer(kTensorBundleVersion);
626 version->set_min_consumer(kTensorBundleMinConsumer);
627
628 builder.Add(kHeaderEntryKey, header.SerializeAsString());
629
630 // All others.
631 for (const auto& p : entries_) {
632 builder.Add(p.first, p.second.SerializeAsString());
633 }
634 status_ = builder.Finish();
635 }
636 status_.Update(file->Close());
637 if (!status_.ok()) {
638 Env::Default()->DeleteFile(tmp_metadata_path_).IgnoreError();
639 return status_;
640 } else {
641 status_ =
642 Env::Default()->RenameFile(tmp_metadata_path_, MetaFilename(prefix_));
643 if (!status_.ok()) return status_;
644 }
645 status_ = errors::Internal("BundleWriter is closed");
646 return Status::OK();
647}
648
649// Merging tensor bundles.
650

Callers 9

FlipEndiannessBitFunction · 0.45
TestBasicFunction · 0.45
TestEndiannessFunction · 0.45
TestNonStandardShapesFunction · 0.45
VersionTestFunction · 0.45
TESTFunction · 0.45
TEST_FFunction · 0.45
MergeBundlesFunction · 0.45

Calls 14

DefaultFunction · 0.85
DataFilenameFunction · 0.85
MetaFilenameFunction · 0.85
InternalFunction · 0.85
UpdateMethod · 0.45
CloseMethod · 0.45
okMethod · 0.45
RenameFileMethod · 0.45
IgnoreErrorMethod · 0.45
DeleteFileMethod · 0.45
NewWritableFileMethod · 0.45
getMethod · 0.45

Tested by 8

FlipEndiannessBitFunction · 0.36
TestBasicFunction · 0.36
TestEndiannessFunction · 0.36
TestNonStandardShapesFunction · 0.36
VersionTestFunction · 0.36
TESTFunction · 0.36
TEST_FFunction · 0.36