0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
gc.cc
Go to the documentation of this file.
1 /*
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; version 3 of the
9  * 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 
22 #include <Common/Compat.h>
23 
24 #include "GcWorker.h"
25 
26 #include <Hypertable/Lib/Client.h>
27 #include <Hypertable/Lib/Config.h>
29 
30 #include <FsBroker/Lib/Client.h>
31 
32 #include <Common/Error.h>
33 #include <Common/Init.h>
34 #include <Common/Logger.h>
35 #include <Common/System.h>
36 #include <Common/Thread.h>
37 
38 #include <iostream>
39 
40 using namespace Hypertable;
41 using namespace Config;
42 using namespace std;
43 
44 namespace {
45 
46  struct MyPolicy : Config::Policy {
47  static void init_options() {
48  cmdline_desc().add_options()
49  ("dryrun,n", "Dryrun, don't modify (delete files etc.)")
50  ("full", "Do a full scan of DFS files and compare with METADATA.")
51  ;
52  }
53  };
54 
55  typedef Cons<MyPolicy, DefaultCommPolicy> AppPolicy;
56 
57 } // local namespace
58 
59 int
60 main(int ac, char *av[]) {
61  NamespacePtr ns;
62  ContextPtr context;
63 
64  try {
65  init_with_policy<AppPolicy>(ac, av);
66 
67  context->comm = Comm::instance();
68  context->conn_manager = make_shared<ConnectionManager>(context->comm);
69  context->props = properties;
70  context->toplevel_dir = properties->get_str("Hypertable.Directory");
71  boost::trim_if(context->toplevel_dir, boost::is_any_of("/"));
72  context->toplevel_dir = String("/") + context->toplevel_dir;
73  context->dfs = std::make_shared<FsBroker::Lib::Client>(context->conn_manager, context->props);
74 
75  ClientPtr client = make_shared<Hypertable::Client>("htgc");
76  ns = client->open_namespace("sys");
77  context->metadata_table = ns->open_table("METADATA");
78 
79  GcWorker worker(context);
80 
81  worker.gc();
82 
83  }
84  catch (Exception &e) {
85  HT_ERROR_OUT << e << HT_END;
86  quick_exit(EXIT_FAILURE);
87  }
88  quick_exit(EXIT_SUCCESS);
89 }
static Comm * instance()
Creates/returns singleton instance of the Comm class.
Definition: Comm.h:72
Retrieves system information (hardware, installation directory, etc)
Interface and base of config policy.
Definition: Config.h:149
PropertiesPtr properties
This singleton map stores all options.
Definition: Config.cc:47
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
STL namespace.
Desc & cmdline_desc(const char *usage)
A macro which definds global functions like get_bool(), get_str(), get_i16() etc. ...
Definition: Config.cc:72
std::shared_ptr< Context > ContextPtr
Smart pointer to Context.
Definition: Context.h:265
std::shared_ptr< Namespace > NamespacePtr
Shared smart pointer to Namespace.
Definition: Namespace.h:333
std::shared_ptr< Client > ClientPtr
Definition: Client.h:156
Helpers to compose init policies; allow to combine two policies into one.
Definition: Config.h:174
Logging routines and macros.
Compatibility Macros for C/C++.
Initialization helper for applications.
#define HT_END
Definition: Logger.h:220
Importing boost::thread and boost::thread_group into the Hypertable namespace.
int main(int ac, char *av[])
Definition: gc.cc:60
#define HT_ERROR_OUT
Definition: Logger.h:301
Hypertable definitions
This is a generic exception class for Hypertable.
Definition: Error.h:314
Error codes, Exception handling, error logging.
Declarations for Client.