CernVM-FS  2.12.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
repository_transaction.cc
Go to the documentation of this file.
1 
5 #include "cvmfs_config.h"
6 #include "publish/repository.h"
7 
8 #include <string>
9 
10 #include "backoff.h"
11 #include "catalog_mgr_ro.h"
12 #include "catalog_mgr_rw.h"
13 #include "directory_entry.h"
14 #include "manifest.h"
15 #include "publish/except.h"
17 #include "publish/settings.h"
18 #include "util/exception.h"
19 #include "util/logging.h"
20 #include "util/pointer.h"
21 #include "util/posix.h"
22 
23 namespace publish {
24 
25 
27  if (managed_node_.IsValid()) {
28  int rvi = managed_node_->Check(false /* is_quiet */);
29  if (rvi != 0) throw EPublish("cannot establish writable mountpoint");
30  }
31 
32  BackoffThrottle throttle(500, 5000, 10000);
33  // Negative timeouts (i.e.: no retry) will result in a deadline that has
34  // already passed and thus has the correct effect
35  uint64_t deadline = platform_monotonic_time() +
36  settings_.transaction().GetTimeoutS();
37  if (settings_.transaction().GetTimeoutS() == 0)
38  deadline = uint64_t(-1);
39 
40  while (true) {
41  try {
43  break;
44  } catch (const publish::EPublish& e) {
46  session_->Drop();
48  }
49 
52  {
53  if (platform_monotonic_time() > deadline)
54  throw;
55 
56  LogCvmfs(kLogCvmfs, kLogStdout, "repository busy, retrying");
57  throttle.Throttle();
58  continue;
59  }
60 
61  throw;
62  } // try-catch
63  } // while (true)
64 
65  if (managed_node_.IsValid())
66  managed_node_->Open();
67 }
68 
69 
71  if (in_transaction_.IsSet()) {
72  throw EPublish("another transaction is already open",
74  }
75 
76  InitSpoolArea();
77 
78  // On error, Transaction() will release the transaction lock and drop
79  // the session
81  session_->Acquire();
82 
83  // We might have a valid lease for a non-existing path. Nevertheless, we run
84  // run into problems when merging catalogs later, so for the time being we
85  // disallow transactions on non-existing paths.
86  if (!settings_.transaction().lease_path().empty()) {
87  std::string path = GetParentPath(
88  "/" + settings_.transaction().lease_path());
91  bool retval = catalog_mgr->LookupPath(path, catalog::kLookupDefault,
92  &dirent);
93  if (!retval) {
94  throw EPublish("cannot open transaction on non-existing path " + path,
96  }
97  if (!dirent.IsDirectory()) {
98  throw EPublish(
99  "cannot open transaction on " + path + ", which is not a directory",
101  }
102  }
103 
105 
107  settings_.transaction().spool_area().checkout_marker()));
108  // TODO(jblomer): take root hash from r/o mountpoint?
109  if (marker.IsValid())
110  settings_.GetTransaction()->SetBaseHash(marker->hash());
111  else
112  settings_.GetTransaction()->SetBaseHash(manifest_->catalog_hash());
113 
114  if (settings_.transaction().HasTemplate()) {
116  "CernVM-FS: cloning template %s --> %s ... ",
117  settings_.transaction().template_from().c_str(),
118  settings_.transaction().template_to().c_str());
120 
121  try {
122  catalog_mgr_->CloneTree(settings_.transaction().template_from(),
123  settings_.transaction().template_to());
124  } catch (const ECvmfsException &e) {
125  std::string panic_msg = e.what();
127  // TODO(aandvalenzuela): release session token (gateway publishing)
128  throw publish::EPublish("cannot clone directory tree. " + panic_msg,
130  }
131 
132  Sync();
133  SendTalkCommand(settings_.transaction().spool_area().readonly_talk_socket(),
134  "chroot " + settings_.transaction().base_hash().ToString() + "\n");
135  LogCvmfs(kLogCvmfs, llvl_ | kLogStdout, "[done]");
136  // TODO(jblomer): fix-me
137  // PushReflog();
138  }
139 
141  "(%s) opened transaction", settings_.fqrn().c_str());
142 }
143 
144 } // namespace publish
const SettingsRepository settings_
Definition: repository.h:137
void CloneTree(const std::string &from_dir, const std::string &to_dir)
void ConstructSyncManagers()
Definition: repository.cc:677
catalog::SimpleCatalogManager * GetSimpleCatalogManager()
Definition: repository.cc:118
UniquePtr< ManagedNode > managed_node_
Definition: repository.h:381
bool IsDirectory() const
const unsigned kLookupDefault
Definition: catalog_mgr.h:43
catalog::WritableCatalogManager * catalog_mgr_
Definition: repository.h:385
void Throttle()
Definition: backoff.cc:50
shash::Any hash() const
void Sync()
Definition: repository.cc:773
void InitSpoolArea()
Definition: repository.cc:571
shash::Any catalog_hash() const
Definition: manifest.h:132
uint64_t platform_monotonic_time()
std::string SendTalkCommand(const std::string &socket, const std::string &cmd)
UniquePtr< Session > session_
Definition: repository.h:380
manifest::Manifest * manifest_
Definition: repository.h:148
EFailures failure() const
Definition: except.h:45
ServerFlagFile in_transaction_
Definition: repository.h:370
PathString GetParentPath(const PathString &path)
Definition: shortstring.cc:15
std::string fqrn() const
Definition: settings.h:370
int llvl_
Definition: repository.h:369
void ConstructSpoolers()
Definition: repository.cc:242
static CheckoutMarker * CreateFrom(const std::string &path)
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)
Definition: logging.cc:528