45 if (changes_fd >= 0) {
47 string changes_tmp = changes_stem;
64 const char *p = getenv(
"XAPIAN_MAX_CHANGESETS");
66 max_changesets = atoi(p);
71 if (max_changesets == 0)
74 string changes_tmp = changes_stem;
77 O_WRONLY | O_CREAT | O_TRUNC |
O_CLOEXEC, 0666);
79 string message =
"Couldn't open changeset ";
80 message += changes_tmp;
81 message +=
" to write";
97 io_write(changes_fd, header.data(), header.size());
118 string changes_tmp = changes_stem;
119 changes_tmp +=
"tmp";
122 int saved_errno = errno;
123 (void)::
close(changes_fd);
125 (void)unlink(changes_tmp.c_str());
126 string m = changes_tmp;
127 m +=
": Failed to sync";
131 (void)::
close(changes_fd);
134 string changes_file = changes_stem;
135 changes_file +=
str(new_rev - 1);
138 string m = changes_tmp;
139 m +=
": Failed to rename to ";
144 if (new_rev <= max_changesets) {
155 while (oldest_changeset < stop_changeset) {
156 changes_file.resize(changes_stem.size());
157 changes_file +=
str(oldest_changeset);
168 string message =
"Couldn't open changeset ";
169 message += changes_file;
185 const char * end = buf + n;
194 if (p == end || (*p != 0 && *p != 1))
201 n +=
io_read(fd, buf + n,
sizeof(buf) - n);
209 unsigned char v = *p++;
220 if (rev != version_rev)
225 if (len <=
size_t(end - p)) {
228 if (lseek(fd, len - (end - p), SEEK_CUR) < 0)
235 unsigned table = (v & 0x7);
242 unsigned block_size = 2048 << v;
253 unsigned level =
static_cast<unsigned char>(p[4]);
257 if (block_size <=
unsigned(end - p)) {
260 if (lseek(fd, block_size - (end - p), SEEK_CUR) < 0)
void io_write(int fd, const char *p, size_t n)
Write n bytes from block pointed to by p to file descriptor fd.
XAPIAN_REVISION_TYPE rev
Revision number of a database.
bool io_unlink(const std::string &filename)
Delete a file.
Internal definitions for glass database replication.
uint4 glass_revision_number_t
The revision number of a glass database.
bool io_sync(int fd)
Ensure all data previously written to file descriptor fd has been written to disk.
Provides wrappers with POSIXy semantics.
Constants in the Xapian namespace.
Convert types to std::string.
static void check(const std::string &changes_file)
void commit(glass_revision_number_t new_rev, int flags)
#define CHANGES_MAGIC_STRING
Hierarchy of classes which Xapian can throw as exceptions.
functions for reading and writing different width words
string str(int value)
Convert int to std::string.
Wrapper class around a file descriptor to avoid leaks.
bool io_tmp_rename(const std::string &tmp_file, const std::string &real_file)
Rename a temporary file to its final position.
#define CONST_STRLEN(S)
Returns the length of a string constant.
size_t io_read(int fd, char *p, size_t n, size_t min)
Read n bytes (or until EOF) into block pointed to by p from file descriptor fd.
GlassChanges * start(glass_revision_number_t old_rev, glass_revision_number_t rev, int flags)
const int DB_DANGEROUS
Update the database in-place.
const int DB_NO_SYNC
Don't attempt to ensure changes have hit disk.
void pack_uint(std::string &s, U value)
Append an encoded unsigned integer to a string.
Pack types into strings and unpack them again.
Wrappers for low-level POSIX I/O routines.
void write_block(const char *p, size_t len)
Various handy helpers which std::string really should provide.
bool unpack_uint(const char **p, const char *end, U *result)
Decode an unsigned integer from a string.
DatabaseError indicates some sort of database related error.
uint32_t unaligned_read4(const unsigned char *ptr)