xapian-core  1.4.21
replicatetcpclient.cc
Go to the documentation of this file.
1 
4 /* Copyright (C) 2008,2010,2011,2015 Olly Betts
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of the
9  * License, or (at your option) any later version.
10  *
11  * This program 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 St, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <config.h>
22 
23 #include "replicatetcpclient.h"
24 
25 #include "api/replication.h"
26 
27 #include "socket_utils.h"
28 #include "tcpclient.h"
29 
30 using namespace std;
31 
32 ReplicateTcpClient::ReplicateTcpClient(const string & hostname, int port,
33  double timeout_connect,
34  double socket_timeout)
35  : socket(open_socket(hostname, port, timeout_connect)),
36  remconn(-1, socket)
37 {
38  set_socket_timeouts(socket, socket_timeout);
39 }
40 
41 int
42 ReplicateTcpClient::open_socket(const string & hostname, int port,
43  double timeout_connect)
44 {
45  return TcpClient::open_socket(hostname, port, timeout_connect, false);
46 }
47 
48 void
49 ReplicateTcpClient::update_from_master(const std::string & path,
50  const std::string & masterdb,
52  double reader_close_time,
53  bool force_copy)
54 {
55  Xapian::DatabaseReplica replica(path);
56  remconn.send_message('R',
57  force_copy ? string() : replica.get_revision_info(),
58  0.0);
59  remconn.send_message('D', masterdb, 0.0);
60  replica.set_read_fd(socket);
61  info.clear();
62  bool more;
63  do {
65  more = replica.apply_next_changeset(&subinfo, reader_close_time);
66  info.changeset_count += subinfo.changeset_count;
67  info.fullcopy_count += subinfo.fullcopy_count;
68  if (subinfo.changed)
69  info.changed = true;
70  } while (more);
71 }
72 
73 ReplicateTcpClient::~ReplicateTcpClient()
74 {
75  remconn.shutdown();
76 }
Open a TCP connection to a server.
void set_socket_timeouts(int fd, double timeout)
Attempt to set socket-level timeouts.
Definition: socket_utils.cc:59
int fullcopy_count
Number of times a full database copy was performed.
Definition: replication.h:38
Access to a database replica, for applying replication to it.
Definition: replication.h:114
STL namespace.
TCP/IP replication client class.
Information about the steps involved in performing a replication.
Definition: replication.h:33
int changeset_count
Number of changesets applied.
Definition: replication.h:35
bool changed
True if and only if the replication corresponds to a change in the live version of the database...
Definition: replication.h:45
Socket handling utilities.
Replication support for Xapian databases.
int open_socket(const std::string &hostname, int port, double timeout_connect, bool tcp_nodelay)
Attempt to open a TCP/IP socket connection to a server.
Definition: tcpclient.cc:56