0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
TransferLog.h
Go to the documentation of this file.
1 /* -*- c++ -*-
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
26 
27 #ifndef Hypertable_RangeServer_TransferLog_h
28 #define Hypertable_RangeServer_TransferLog_h
29 
30 #include <Common/Error.h>
31 #include <Common/Filesystem.h>
32 #include <Common/Logger.h>
33 #include <Common/md5.h>
34 
35 #include <chrono>
36 #include <ctime>
37 #include <string>
38 #include <thread>
39 
40 namespace Hypertable {
41 
44 
46  class TransferLog {
47  public:
48 
62  TransferLog(FilesystemPtr &fs, const string &toplevel_dir,
63  const string &table_id, const string &end_row) {
64  time_t now {};
65  char md5DigestStr[33];
66  md5_trunc_modified_base64(end_row.c_str(), md5DigestStr);
67  md5DigestStr[16] = 0;
68  do {
69  if (now != 0)
70  std::this_thread::sleep_for(std::chrono::milliseconds(1200));
71  now = time(0);
72  m_logname = format("%s/tables/%s/_xfer/%s_%d", toplevel_dir.c_str(),
73  table_id.c_str(), md5DigestStr, (int)now);
74  }
75  while (fs->exists(m_logname));
76  }
77 
80  string &name() { return m_logname; }
81 
82  private:
83 
85  string m_logname;
86 
87  };
88 
90 
91 }
92 
93 #endif // Hypertable_RangeServer_TransferLog_h
94 
Abstract base class for a filesystem.
String format(const char *fmt,...)
Returns a String using printf like format facilities Vanilla snprintf is about 1.5x faster than this...
Definition: String.cc:37
string & name()
Returns pathname of transfer log.
Definition: TransferLog.h:80
TransferLog(FilesystemPtr &fs, const string &toplevel_dir, const string &table_id, const string &end_row)
Constructor.
Definition: TransferLog.h:62
void md5_trunc_modified_base64(const char *input, char output[17])
Get the modified base64 encoded string of the first 12 Bytes of the 16 Byte MD5 code of a null termin...
Definition: md5.cc:425
Logging routines and macros.
Hypertable definitions
string m_logname
Full path name of transfer log.
Definition: TransferLog.h:85
std::shared_ptr< Filesystem > FilesystemPtr
Smart pointer to Filesystem.
Definition: Filesystem.h:572
Error codes, Exception handling, error logging.
Creates a unique range transfer log pathname.
Definition: TransferLog.h:46
md5 digest routines.