CernVM-FS  2.10.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::kLookupSole, &dirent);
92  if (!retval) {
93  throw EPublish("cannot open transaction on non-existing path " + path,
95  }
96  if (!dirent.IsDirectory()) {
97  throw EPublish(
98  "cannot open transaction on " + path + ", which is not a directory",
100  }
101  }
102 
104 
106  settings_.transaction().spool_area().checkout_marker()));
107  // TODO(jblomer): take root hash from r/o mountpoint?
108  if (marker.IsValid())
109  settings_.GetTransaction()->SetBaseHash(marker->hash());
110  else
111  settings_.GetTransaction()->SetBaseHash(manifest_->catalog_hash());
112 
113  if (settings_.transaction().HasTemplate()) {
115  "CernVM-FS: cloning template %s --> %s ... ",
116  settings_.transaction().template_from().c_str(),
117  settings_.transaction().template_to().c_str());
119 
120  try {
121  catalog_mgr_->CloneTree(settings_.transaction().template_from(),
122  settings_.transaction().template_to());
123  } catch (const ECvmfsException &e) {
124  std::string panic_msg = e.what();
126  // TODO(aandvalenzuela): release session token (gateway publishing)
127  throw publish::EPublish("cannot clone directory tree. " + panic_msg,
129  }
130 
131  Sync();
132  SendTalkCommand(settings_.transaction().spool_area().readonly_talk_socket(),
133  "chroot " + settings_.transaction().base_hash().ToString() + "\n");
134  LogCvmfs(kLogCvmfs, llvl_ | kLogStdout, "[done]");
135  // TODO(jblomer): fix-me
136  // PushReflog();
137  }
138 
140  "(%s) opened transaction", settings_.fqrn().c_str());
141 }
142 
143 } // namespace publish
#define LogCvmfs(source, mask,...)
Definition: logging.h:22
const SettingsRepository settings_
Definition: repository.h:137
void CloneTree(const std::string &from_dir, const std::string &to_dir)
void ConstructSyncManagers()
Definition: repository.cc:686
catalog::SimpleCatalogManager * GetSimpleCatalogManager()
Definition: repository.cc:121
UniquePtr< ManagedNode > managed_node_
Definition: repository.h:380
bool IsDirectory() const
catalog::WritableCatalogManager * catalog_mgr_
Definition: repository.h:384
void Throttle()
Definition: backoff.cc:50
shash::Any hash() const
void Sync()
Definition: repository.cc:780
void InitSpoolArea()
Definition: repository.cc:580
shash::Any catalog_hash() const
Definition: manifest.h:124
uint64_t platform_monotonic_time()
std::string SendTalkCommand(const std::string &socket, const std::string &cmd)
UniquePtr< Session > session_
Definition: repository.h:379
manifest::Manifest * manifest_
Definition: repository.h:148
EFailures failure() const
Definition: except.h:45
ServerFlagFile in_transaction_
Definition: repository.h:369
PathString GetParentPath(const PathString &path)
Definition: shortstring.cc:15
std::string fqrn() const
Definition: settings.h:370
int llvl_
Definition: repository.h:368
void ConstructSpoolers()
Definition: repository.cc:251
static CheckoutMarker * CreateFrom(const std::string &path)