39 # include <winerror.h> 47 string dbtype =
"multi";
48 if (sub_managers.size() == 2 &&
49 sub_managers[0]->get_dbtype() == sub_managers[1]->get_dbtype()) {
50 dbtype +=
"_" + sub_managers[0]->get_dbtype();
52 for (
auto sub_manager : sub_managers) {
53 dbtype +=
"_" + sub_manager->get_dbtype();
60 const vector<BackendManager*>& sub_managers_)
62 sub_managers(sub_managers_)
70 cachedir += sub_manager->get_dbtype();
77 #define NUMBER_OF_SUB_DBS 2 81 const vector<string>& files)
88 for (
const string& file : files) {
102 if (unlink(db_path.c_str()) < 0 && errno != ENOENT) {
104 if (errno == EACCES && _doserrno == ERROR_SHARING_VIOLATION) {
114 string msg =
"Couldn't unlink file '";
126 string tmpfile = db_path +
".tmp";
127 ofstream out(tmpfile.c_str());
128 if (!out.is_open()) {
129 string msg =
"Couldn't create file '";
141 string dbbase = db_path;
143 size_t dbbase_len = dbbase.
size();
148 if (subtype ==
"glass") {
152 out << subtype <<
' ' << dbname <<
"___" << n <<
'\n';
153 }
else if (subtype ==
"chert") {
157 out << subtype <<
' ' << dbname <<
"___" << n <<
'\n';
158 }
else if (subtype ==
"remoteprog_glass") {
163 string args =
sub_managers[n]->get_writable_database_args(dbbase,
170 <<
" " << args <<
'\n';
172 string msg =
"Unknown multidb subtype: ";
176 dbbase.resize(dbbase_len);
187 if (rename(tmpfile.c_str(), db_path.c_str()) < 0) {
189 if (errno == EACCES) {
190 if (_doserrno == ERROR_SHARING_VIOLATION) {
207 string msg =
"rename failed (";
226 vector<string> files;
227 if (!file.empty()) files.push_back(file);
244 if (sub_manager->get_dbtype().find(
"remote") == string::npos) {
250 db.
add_database(sub_manager->get_remote_database(files, timeout));
258 const char* m =
"BackendManager::get_remote_database() called for " 259 "multi with no remote shards";
static const char * get_xapian_progsrv_command()
Get the command line required to run xapian-progsrv.
const std::string & get_datadir() const
Get the directory to store data in.
static std::string build_dbtype(const vector< BackendManager *> &sub_managers)
This class is used to access a database, or a group of databases.
unsigned timeout
A timeout value in milliseconds.
InvalidOperationError indicates the API was used in an invalid way.
Convert errno value to std::string, thread-safe if possible.
void sleep(double t)
Sleep until the time represented by this object.
Convert types to std::string.
Xapian::WritableDatabase get_writable_database_again()
Create a WritableDatabase object for the last opened WritableDatabase.
Utility functions for testing files.
std::string last_wdb_path
The path of the last writable database used.
BackendManager subclass for multi databases.
std::string get_writable_database_path(const std::string &name)
Get the path of Xapian::WritableDatabase instance.
std::string get_generated_database_path(const std::string &name)
Get the path to use for generating a database, if supported.
const int DB_BACKEND_GLASS
Use the glass backend.
bool create_dir_if_needed(const std::string &dirname)
Create the directory dirname if needed.
std::string createdb_multi(const std::string &name, const std::vector< std::string > &files)
This class provides read/write access to a database.
void errno_to_string(int e, string &s)
virtual Xapian::WritableDatabase get_remote_writable_database(std::string args)
Get a remote Xapian::WritableDatabase instance with specified args.
std::string get_compaction_output_path(const std::string &name)
Get a path to compact a database to.
std::string get_writable_database_path_again()
Get the path of the last opened WritableDatabase.
string str(int value)
Convert int to std::string.
std::vector< BackendManager * > sub_managers
void add_database(const Database &database)
Add an existing database (or group of databases) to those accessed by this object.
size_t size() const
Return number of shards in this Database object.
Xapian::Database get_remote_database(const std::vector< std::string > &files, unsigned int timeout)
Get a remote database instance with the specified timeout.
Xapian::WritableDatabase get_writable_database(const std::string &name, const std::string &file)
Create a Multi Xapian::WritableDatabase object indexing a single file.
std::string do_get_database_path(const std::vector< std::string > &files)
Get the path of the Xapian::Database instance.
void add_database(const WritableDatabase &other)
Add shards from another WritableDatabase.
void index_to(Xapian::WritableDatabase &db)
<unistd.h>, but with compat.
BackendManagerMulti(const BackendManagerMulti &)
Don't allow copying.
utility functions for indexing testcase data
const int DB_CREATE_OR_OVERWRITE
Create database if it doesn't already exist, or overwrite if it does.
bool file_exists(const char *path)
Test if a file exists.
#define NUMBER_OF_SUB_DBS
virtual void close()
Close the database.
const int DB_BACKEND_CHERT
Use the chert backend.