CernVM-FS  2.13.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
swissknife_ingestsql.cc File Reference
#include "swissknife_ingestsql.h"
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <pwd.h>
#include <grp.h>
#include <csignal>
#include <cstdlib>
#include <fstream>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include "acl.h"
#include "catalog_mgr_rw.h"
#include "curl/curl.h"
#include "gateway_util.h"
#include "swissknife_lease_curl.h"
#include "swissknife_lease_json.h"
#include "swissknife_sync.h"
#include "upload.h"
#include "util/logging.h"
#include "catalog_downloader.h"
#include "shortstring.h"
Include dependency graph for swissknife_ingestsql.cc:

Go to the source code of this file.

Macros

#define CHECK_SQLITE_ERROR(ret, expected)
 
#define CUSTOM_ASSERT(check, msg,...)
 
#define SHOW_PROGRESS(item, freq, curr, total)
 

Functions

static string get_lease_from_paths (vector< string > paths)
 
static vector< string > get_all_dirs_from_sqlite (vector< string > &sqlite_db_vec, bool include_additions, bool include_deletions)
 
static string get_parent (const string &path)
 
static string get_basename (const string &path)
 
static XattrList marshal_xattrs (const char *acl)
 
static string sanitise_name (const char *name_cstr, bool allow_leading_slash)
 
static void on_signal (int sig)
 
static string acquire_lease (const string &key_id, const string &secret, const string &lease_path, const string &repo_service_url, bool force_cancel_lease, uint64_t *current_revision, string &current_root_hash, unsigned int refresh_interval)
 
static void cancel_lease ()
 
static void refresh_lease ()
 
static vector< string > get_file_list (string &path)
 
static int check_hash (const char *hash)
 
static void recursively_delete_directory (PathString &path, catalog::WritableCatalogManager &catalog_manager)
 
static void create_empty_database (string &filename)
 
static void relax_db_locking (sqlite3 *db)
 
static bool check_prefix (const std::string &path, const std::string &prefix)
 
static bool isDatabaseMarkedComplete (const char *dbfile)
 
static void setDatabaseMarkedComplete (const char *dbfile)
 
void * lease_refresh_thread (void *payload)
 
static string MakeCatalogPath (const std::string &relative_path)
 
static uint64_t make_commit_on_gateway (const std::string &old_root_hash, const std::string &new_root_hash, int priority)
 
static int get_db_schema_revision (sqlite3 *db, const std::string &db_name="")
 
static int get_row_count (sqlite3 *db, const std::string &table_name)
 
static int calculate_print_frequency (int total)
 
std::unordered_map< string,
string > 
load_config (const string &config_file)
 
string retrieve_config (std::unordered_map< string, string > &config_map, const string &key)
 
size_t writeFunction (void *ptr, size_t size, size_t nmemb, std::string *data)
 
void replaceAllSubstrings (std::string &str, const std::string &from, const std::string &to)
 
void add_dir_to_tree (std::string path, std::unordered_map< std::string, std::set< std::string >> &tree, const std::string &lease_path)
 

Variables

static const unsigned kExternalChunkSize = 24 * 1024 * 1024
 
static const unsigned kInternalChunkSize = 6 * 1024 * 1024
 
static const unsigned kDefaultLeaseBusyRetryInterval = 10
 
static const unsigned kLeaseRefreshInterval = 90
 
static bool g_lease_acquired = false
 
static string g_gateway_url
 
static string g_gateway_key_id
 
static string g_gateway_secret
 
static string g_session_token
 
static string g_session_token_file
 
static string g_s3_file
 
static time_t g_last_lease_refresh =0
 
static bool g_stop_refresh = false
 
static int g_priority =0
 
static bool g_add_missing_catalogs = false
 
bool g_log_with_time
 
const char * schema []
 

Macro Definition Documentation

#define CHECK_SQLITE_ERROR (   ret,
  expected 
)
Value:
do { \
if (ret!=expected) { \
LogCvmfs(kLogCvmfs, kLogStderr, "SQLite error: %d", ret); \
assert(0); \
} \
} while (0)
assert((mem||(size==0))&&"Out Of Memory")
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)
Definition: logging.cc:545

Definition at line 32 of file swissknife_ingestsql.cc.

Referenced by create_empty_database(), swissknife::IngestSQL::do_deletions(), get_all_dirs_from_sqlite(), get_db_schema_revision(), get_row_count(), swissknife::IngestSQL::load_dirs(), swissknife::IngestSQL::load_files(), swissknife::IngestSQL::load_symlinks(), swissknife::IngestSQL::Main(), swissknife::IngestSQL::process_sqlite(), and relax_db_locking().

#define CUSTOM_ASSERT (   check,
  msg,
  ... 
)
#define SHOW_PROGRESS (   item,
  freq,
  curr,
  total 
)
Value:
do { \
if (curr % freq == 0 || curr == total) { \
LogCvmfs(kLogCvmfs, kLogStdout, "Processed %d/%d %s", curr, total, item); \
} \
} while (0)
CVMFS_EXPORT void LogCvmfs(const LogSource source, const int mask, const char *format,...)
Definition: logging.cc:545

Definition at line 46 of file swissknife_ingestsql.cc.

Referenced by swissknife::IngestSQL::do_additions(), and swissknife::IngestSQL::do_deletions().

Function Documentation

static string acquire_lease ( const string &  key_id,
const string &  secret,
const string &  lease_path,
const string &  repo_service_url,
bool  force_cancel_lease,
uint64_t *  current_revision,
string &  current_root_hash,
unsigned int  refresh_interval 
)
static

Definition at line 162 of file swissknife_ingestsql.cc.

Referenced by swissknife::IngestSQL::Main().

Here is the call graph for this function:

Here is the caller graph for this function:

void add_dir_to_tree ( std::string  path,
std::unordered_map< std::string, std::set< std::string >> &  tree,
const std::string &  lease_path 
)

Definition at line 885 of file swissknife_ingestsql.cc.

Referenced by swissknife::IngestSQL::do_additions().

Here is the call graph for this function:

Here is the caller graph for this function:

static int calculate_print_frequency ( int  total)
static

Definition at line 349 of file swissknife_ingestsql.cc.

Referenced by swissknife::IngestSQL::do_additions(), and swissknife::IngestSQL::do_deletions().

Here is the caller graph for this function:

static void cancel_lease ( )
static

Definition at line 246 of file swissknife_ingestsql.cc.

Referenced by swissknife::IngestSQL::Main(), and on_signal().

Here is the call graph for this function:

Here is the caller graph for this function:

static int check_hash ( const char *  hash)
static

Definition at line 1078 of file swissknife_ingestsql.cc.

Referenced by swissknife::IngestSQL::load_files().

Here is the caller graph for this function:

bool check_prefix ( const std::string &  path,
const std::string &  prefix 
)
static

Definition at line 1089 of file swissknife_ingestsql.cc.

Referenced by swissknife::IngestSQL::do_deletions(), swissknife::IngestSQL::load_dirs(), swissknife::IngestSQL::load_files(), and swissknife::IngestSQL::load_symlinks().

Here is the call graph for this function:

Here is the caller graph for this function:

static void create_empty_database ( string &  filename)
static

Definition at line 1369 of file swissknife_ingestsql.cc.

Referenced by swissknife::IngestSQL::Main().

Here is the call graph for this function:

Here is the caller graph for this function:

static vector< string > get_all_dirs_from_sqlite ( vector< string > &  sqlite_db_vec,
bool  include_additions,
bool  include_deletions 
)
static

Definition at line 272 of file swissknife_ingestsql.cc.

Referenced by swissknife::IngestSQL::Main().

Here is the call graph for this function:

Here is the caller graph for this function:

static string get_basename ( const string &  path)
static

Definition at line 149 of file swissknife_ingestsql.cc.

Referenced by swissknife::IngestSQL::add_files(), swissknife::IngestSQL::add_symlinks(), and swissknife::IngestSQL::do_additions().

Here is the caller graph for this function:

static int get_db_schema_revision ( sqlite3 *  db,
const std::string &  db_name = "" 
)
static

Definition at line 320 of file swissknife_ingestsql.cc.

Referenced by swissknife::IngestSQL::load_dirs(), and swissknife::IngestSQL::load_files().

Here is the caller graph for this function:

static vector< string > get_file_list ( string &  path)
static

Definition at line 442 of file swissknife_ingestsql.cc.

Referenced by swissknife::IngestSQL::Main().

Here is the caller graph for this function:

static string get_lease_from_paths ( vector< string >  paths)
static

Definition at line 356 of file swissknife_ingestsql.cc.

Referenced by swissknife::IngestSQL::Main().

Here is the call graph for this function:

Here is the caller graph for this function:

static int get_row_count ( sqlite3 *  db,
const std::string &  table_name 
)
static

Definition at line 335 of file swissknife_ingestsql.cc.

Referenced by swissknife::IngestSQL::do_deletions().

Here is the caller graph for this function:

static bool isDatabaseMarkedComplete ( const char *  dbfile)
static

Definition at line 1441 of file swissknife_ingestsql.cc.

Referenced by swissknife::IngestSQL::Main().

Here is the caller graph for this function:

void * lease_refresh_thread ( void *  payload)

Definition at line 1433 of file swissknife_ingestsql.cc.

Referenced by swissknife::IngestSQL::Main().

Here is the call graph for this function:

Here is the caller graph for this function:

std::unordered_map<string, string> load_config ( const string &  config_file)

Definition at line 407 of file swissknife_ingestsql.cc.

Referenced by swissknife::IngestSQL::Main().

Here is the call graph for this function:

Here is the caller graph for this function:

static uint64_t make_commit_on_gateway ( const std::string &  old_root_hash,
const std::string &  new_root_hash,
int  priority 
)
static

Definition at line 209 of file swissknife_ingestsql.cc.

Referenced by swissknife::IngestSQL::Main().

Here is the call graph for this function:

Here is the caller graph for this function:

static string MakeCatalogPath ( const std::string &  relative_path)
static
static XattrList marshal_xattrs ( const char *  acl)
static

Definition at line 383 of file swissknife_ingestsql.cc.

Referenced by swissknife::IngestSQL::load_dirs().

Here is the call graph for this function:

Here is the caller graph for this function:

static void on_signal ( int  sig)
static

Definition at line 262 of file swissknife_ingestsql.cc.

Referenced by swissknife::IngestSQL::Main().

Here is the call graph for this function:

Here is the caller graph for this function:

static void recursively_delete_directory ( PathString path,
catalog::WritableCatalogManager catalog_manager 
)
static

Definition at line 1385 of file swissknife_ingestsql.cc.

Referenced by swissknife::IngestSQL::do_deletions().

Here is the call graph for this function:

Here is the caller graph for this function:

static void refresh_lease ( )
static

Definition at line 221 of file swissknife_ingestsql.cc.

Referenced by lease_refresh_thread().

Here is the call graph for this function:

Here is the caller graph for this function:

static void relax_db_locking ( sqlite3 *  db)
static

Definition at line 1424 of file swissknife_ingestsql.cc.

Referenced by create_empty_database(), get_all_dirs_from_sqlite(), and swissknife::IngestSQL::Main().

Here is the caller graph for this function:

void replaceAllSubstrings ( std::string &  str,
const std::string &  from,
const std::string &  to 
)

Definition at line 829 of file swissknife_ingestsql.cc.

string retrieve_config ( std::unordered_map< string, string > &  config_map,
const string &  key 
)

Definition at line 436 of file swissknife_ingestsql.cc.

Referenced by swissknife::IngestSQL::Main().

Here is the caller graph for this function:

static string sanitise_name ( const char *  name_cstr,
bool  allow_leading_slash = false 
)
static
static void setDatabaseMarkedComplete ( const char *  dbfile)
static

Definition at line 1465 of file swissknife_ingestsql.cc.

Referenced by swissknife::IngestSQL::Main().

Here is the caller graph for this function:

size_t writeFunction ( void *  ptr,
size_t  size,
size_t  nmemb,
std::string *  data 
)

Definition at line 825 of file swissknife_ingestsql.cc.

Variable Documentation

bool g_add_missing_catalogs = false
static
string g_gateway_key_id
static
string g_gateway_secret
static
string g_gateway_url
static
time_t g_last_lease_refresh =0
static

Definition at line 67 of file swissknife_ingestsql.cc.

Referenced by acquire_lease(), and refresh_lease().

bool g_lease_acquired = false
static

Definition at line 60 of file swissknife_ingestsql.cc.

Referenced by acquire_lease(), and on_signal().

bool g_log_with_time
int g_priority =0
static

Definition at line 69 of file swissknife_ingestsql.cc.

Referenced by swissknife::IngestSQL::Main().

string g_s3_file
static

Definition at line 66 of file swissknife_ingestsql.cc.

string g_session_token
static
string g_session_token_file
static

Definition at line 65 of file swissknife_ingestsql.cc.

Referenced by swissknife::IngestSQL::Main(), and on_signal().

bool g_stop_refresh = false
static
const unsigned kDefaultLeaseBusyRetryInterval = 10
static

Definition at line 56 of file swissknife_ingestsql.cc.

Referenced by swissknife::IngestSQL::Main().

const unsigned kExternalChunkSize = 24 * 1024 * 1024
static

Definition at line 54 of file swissknife_ingestsql.cc.

Referenced by swissknife::IngestSQL::load_files().

const unsigned kInternalChunkSize = 6 * 1024 * 1024
static

Definition at line 55 of file swissknife_ingestsql.cc.

Referenced by swissknife::IngestSQL::load_files().

const unsigned kLeaseRefreshInterval = 90
static

Definition at line 57 of file swissknife_ingestsql.cc.

Referenced by refresh_lease().

const char* schema[]

Definition at line 1320 of file swissknife_ingestsql.cc.

Referenced by create_empty_database().