MCPcopy Create free account
hub / github.com/apache/impala / WritePBToPath

Function WritePBToPath

be/src/kudu/util/pb_util.cc:512–542  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

510}
511
512Status WritePBToPath(Env* env, const std::string& path,
513 const MessageLite& msg,
514 SyncMode sync) {
515 const string tmp_template = path + kTmpInfix + kTmpTemplateSuffix;
516 string tmp_path;
517
518 unique_ptr<WritableFile> file;
519 WritableFileOptions opts;
520 opts.is_sensitive = false;
521 RETURN_NOT_OK(env->NewTempWritableFile(opts, tmp_template, &tmp_path, &file));
522 auto tmp_deleter = MakeScopedCleanup([&]() {
523 WARN_NOT_OK(env->DeleteFile(tmp_path), "Could not delete file " + tmp_path);
524 });
525
526 WritableFileOutputStream output(file.get());
527 bool res = msg.SerializeToZeroCopyStream(&output);
528 if (!res || !output.Flush()) {
529 return Status::IOError("Unable to serialize PB to file");
530 }
531
532 if (sync == pb_util::SYNC) {
533 RETURN_NOT_OK_PREPEND(file->Sync(), "Failed to Sync() " + tmp_path);
534 }
535 RETURN_NOT_OK_PREPEND(file->Close(), "Failed to Close() " + tmp_path);
536 RETURN_NOT_OK_PREPEND(env->RenameFile(tmp_path, path), "Failed to rename tmp file to " + path);
537 tmp_deleter.cancel();
538 if (sync == pb_util::SYNC) {
539 RETURN_NOT_OK_PREPEND(env->SyncDir(DirName(path)), "Failed to SyncDir() parent of " + path);
540 }
541 return Status::OK();
542}
543
544Status ReadPBFromPath(Env* env, const std::string& path, MessageLite* msg) {
545 unique_ptr<SequentialFile> rfile;

Callers

nothing calls this directly

Calls 13

MakeScopedCleanupFunction · 0.85
DirNameFunction · 0.85
OKFunction · 0.85
NewTempWritableFileMethod · 0.80
RenameFileMethod · 0.80
SyncDirMethod · 0.80
IOErrorFunction · 0.70
getMethod · 0.65
DeleteFileMethod · 0.45
FlushMethod · 0.45
SyncMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected