Joedb 9.5.0
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
joedb_push.cpp
Go to the documentation of this file.
4#include "joedb/Signal.h"
5
6#include <iostream>
7#include <limits>
8#include <thread>
9#include <chrono>
10#include <cstring>
11#include <cstdlib>
12
13namespace joedb
14{
15 ////////////////////////////////////////////////////////////////////////////
16 static int joedb_push(int argc, char **argv)
17 ////////////////////////////////////////////////////////////////////////////
18 {
19 const Open_Mode default_mode = Open_Mode::read_existing;
20 Client_Parser client_parser(default_mode, Client_Parser::DB_Type::none);
21
22 int arg_index = 1;
23
24 bool follow = false;
25 if (arg_index < argc && std::strcmp(argv[arg_index], "--follow") == 0)
26 {
27 follow = true;
28 arg_index++;
29 }
30
31 int64_t until_checkpoint = std::numeric_limits<int64_t>::max();
32 if (arg_index + 1 < argc && std::strcmp(argv[arg_index], "--until") == 0)
33 {
34 until_checkpoint = std::atoll(argv[arg_index + 1]);
35 arg_index += 2;
36 }
37
38 if (arg_index >= argc)
39 {
40 std::cerr << "usage: " << argv[0];
41 std::cerr << " [--follow] [--until <checkpoint>]";
42 client_parser.print_help(std::cerr);
43 return 1;
44 }
45
46 Client &client = client_parser.parse(argc - arg_index, argv + arg_index);
47 Readonly_Client *readonly_client = dynamic_cast<Readonly_Client*>(&client);
48 JOEDB_RELEASE_ASSERT(readonly_client);
49
50 if (follow)
51 {
53
54 while
55 (
56 client.get_connection_checkpoint() < until_checkpoint &&
57 Signal::get_signal() != SIGINT
58 )
59 {
60 std::this_thread::sleep_for(std::chrono::seconds(1));
61 client.push_if_ahead();
62 }
63 }
64
65 return 0;
66 }
67}
68
69/////////////////////////////////////////////////////////////////////////////
70int main(int argc, char **argv)
71/////////////////////////////////////////////////////////////////////////////
72{
73 return joedb::main_exception_catcher(joedb::joedb_push, argc, argv);
74}
static int get_signal()
Definition Signal.cpp:27
static void start()
Definition Signal.cpp:34
int main()
#define JOEDB_RELEASE_ASSERT(x)
Definition assert.h:24
Open_Mode
Definition Open_Mode.h:8
@ read_existing
fails if does not exist
int main_exception_catcher(int(*main)(int, char **), int argc, char **argv)
Catch exception from main.
Definition Blob.h:7